0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 2004-2005 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041: package org.netbeans.modules.jmx.configwizard;
0042:
0043: import java.awt.Component;
0044: import java.util.Iterator;
0045: import java.util.Vector;
0046: import java.util.ResourceBundle;
0047: import java.io.File;
0048: import java.awt.Dimension;
0049:
0050: import java.util.ArrayList;
0051:
0052: import javax.swing.table.TableCellRenderer;
0053: import javax.swing.table.DefaultTableCellRenderer;
0054: import javax.swing.table.DefaultTableModel;
0055: import javax.swing.table.AbstractTableModel;
0056: import javax.swing.table.TableCellEditor;
0057: import javax.swing.DefaultCellEditor;
0058: import javax.swing.JTable;
0059: import javax.swing.JScrollPane;
0060: import javax.swing.JComboBox;
0061:
0062: import javax.swing.event.DocumentEvent;
0063: import javax.swing.event.DocumentListener;
0064: import javax.swing.ListSelectionModel;
0065: import javax.swing.JComponent;
0066: import javax.swing.SwingUtilities;
0067:
0068: import org.openide.WizardDescriptor;
0069: import org.openide.util.NbBundle;
0070: import org.openide.awt.Mnemonics;
0071:
0072: import org.netbeans.modules.jmx.WizardConstants;
0073: import org.netbeans.modules.jmx.GenericWizardPanel;
0074: import java.awt.event.ActionEvent;
0075: import java.awt.event.ActionListener;
0076: import java.awt.event.KeyAdapter;
0077: import java.awt.event.KeyEvent;
0078: import java.awt.event.KeyListener;
0079: import javax.swing.JTextField;
0080: import org.openide.util.HelpCtx;
0081:
0082: /**
0083: *
0084: * Class handling the graphical part of the standard Options wizard panel
0085: *
0086: */
0087: public class RMIPanel extends javax.swing.JPanel {
0088:
0089: private RMIWizardPanel wiz;
0090: private ResourceBundle bundle;
0091: private AuthTable authTable;
0092: private AuthTableModel tableModel;
0093:
0094: private boolean rMISelected = false;
0095: private boolean sslSelected = false;
0096: private boolean authSelected = false;
0097:
0098: /**
0099: * Access renderer for authenticate table.
0100: */
0101: class AccessRenderer extends DefaultTableCellRenderer {
0102: private JComboBox comp;
0103:
0104: /**
0105: * Constructor of access renderer for authenticate table.
0106: * @param comp <CODE>JComboBox</CODE>
0107: */
0108: AccessRenderer(JComboBox comp) {
0109: this .comp = comp;
0110: }
0111:
0112: public Component getTableCellRendererComponent(JTable table,
0113: Object value, boolean isSelected, boolean hasFocus,
0114: int row, int column) {
0115: Object obj = table.getModel().getValueAt(row, column);
0116: if (obj == null)
0117: comp.setSelectedIndex(0);
0118: else
0119: comp.setSelectedItem(obj);
0120: return comp;
0121: }
0122:
0123: public Component getComponent() {
0124: return comp;
0125: }
0126: }
0127:
0128: /**
0129: * Name renderer for authenticate table.
0130: */
0131: class NameRenderer extends DefaultTableCellRenderer {
0132: private JTextField comp;
0133:
0134: /**
0135: * Constructor of name cell renderer in authenticate table.
0136: * @param comp <CODE>JTextField</CODE>
0137: */
0138: NameRenderer(JTextField comp) {
0139: this .comp = comp;
0140: }
0141:
0142: public Component getTableCellRendererComponent(JTable table,
0143: Object value, boolean isSelected, boolean hasFocus,
0144: int row, int column) {
0145: String obj = (String) table.getModel().getValueAt(row,
0146: column);
0147:
0148: comp.setText(obj);
0149:
0150: return comp;
0151: }
0152:
0153: public Component getComponent() {
0154: return comp;
0155: }
0156: }
0157:
0158: private class ValidatorListener implements ActionListener {
0159: public void actionPerformed(ActionEvent evt) {
0160: wiz.event();
0161: }
0162: }
0163:
0164: private class AuthTable extends JTable {
0165: /** Creates a new instance of AttributeTable */
0166: public AuthTable(AbstractTableModel model) {
0167: super (model);
0168: }
0169:
0170: public TableCellEditor getCellEditor(int row, int column) {
0171: //In case we have a repaint thread that is in the process of
0172: //repainting an obsolete table, just ignore the call.
0173: //It can happen when MBean selection is switched at a very quick rate
0174: if (row >= getRowCount())
0175: return null;
0176: switch (column) {
0177: case 0: {
0178: JTextField name = new JTextField();
0179: name.addKeyListener(new KeyListener() {
0180: public void keyTyped(KeyEvent e) {
0181: char c = e.getKeyChar();
0182: /*
0183: if (!(Character.i ||
0184: c == KeyEvent.VK_BACK_SPACE ||
0185: c == KeyEvent.VK_DELETE)) {
0186: authTable.getToolkit().beep();
0187: e.consume();
0188: }*/
0189: }
0190:
0191: public void keyPressed(KeyEvent e) {
0192: }
0193:
0194: public void keyReleased(KeyEvent e) {
0195:
0196: }
0197: });
0198: name.addActionListener(new ValidatorListener());
0199: String obj = (String) getModel()
0200: .getValueAt(row, column);
0201: name.setText(obj);
0202: return new DefaultCellEditor(name);
0203: }
0204: case 1: {
0205: JTextField password = new JTextField();
0206: password.addActionListener(new ValidatorListener());
0207: String obj = (String) getModel()
0208: .getValueAt(row, column);
0209: password.setText(obj);
0210: return new DefaultCellEditor(password);
0211: }
0212:
0213: case 2: {
0214: JComboBox access = new JComboBox();
0215: access.setName("access");// NOI18N
0216: access.setModel(new javax.swing.DefaultComboBoxModel(
0217: new String[] { "readonly", "readwrite" }));// NOI18N
0218: Object obj = getModel().getValueAt(row, column);
0219: if (obj == null)
0220: access.setSelectedIndex(0);
0221: else
0222: access.setSelectedItem(obj);
0223: access.setEditable(false);
0224: return new DefaultCellEditor(access);
0225: }
0226: }
0227:
0228: return super .getCellEditor(row, column);
0229: }
0230:
0231: public TableCellRenderer getCellRenderer(int row, int column) {
0232: //In case we have a repaint thread that is in the process of
0233: //repainting an obsolete table, just ignore the call.
0234: //It can happen when MBean selection is switched at a very quick rate
0235: if (row >= getRowCount())
0236: return null;
0237:
0238: if (column == 2) {
0239: JComboBox access = new JComboBox();
0240: access.setModel(new javax.swing.DefaultComboBoxModel(
0241: new String[] { "readonly", "readwrite" }));// NOI18N
0242: access.setEditable(false);
0243: access.setSelectedIndex(0);
0244: return new AccessRenderer(access);
0245: }
0246:
0247: return super .getCellRenderer(row, column);
0248: }
0249: }
0250:
0251: private class AuthTableModel extends DefaultTableModel {
0252:
0253: private ArrayList data;
0254:
0255: /** Creates a new instance of AbstractJMXTableModel */
0256: public AuthTableModel() {
0257: }
0258:
0259: public int getSize() {
0260: return data.size();
0261: }
0262:
0263: public void addRow() {
0264: RMIAuthenticatedUser row = new RMIAuthenticatedUser();
0265: data.add(row);
0266: this .fireTableDataChanged();
0267: }
0268:
0269: public void removeRow(int i) {
0270: if (authTable.isEditing())
0271: authTable.getCellEditor().stopCellEditing();
0272: data.remove(i);
0273: this .fireTableDataChanged();
0274: }
0275:
0276: public int getRowCount() {
0277: //retourne la taille de ArrayList
0278: if (data == null)
0279: data = new ArrayList();
0280:
0281: return data.size();
0282: }
0283:
0284: public int getColumnCount() {
0285: return 3;
0286: }
0287:
0288: public Object getValueAt(int rowIndex, int columnIndex) {
0289: RMIAuthenticatedUser row = (RMIAuthenticatedUser) data
0290: .get(rowIndex);
0291: return row.getValueAt(columnIndex);
0292: }
0293:
0294: public void setValueAt(Object aValue, int rowIndex,
0295: int columnIndex) {
0296: RMIAuthenticatedUser row = (RMIAuthenticatedUser) data
0297: .get(rowIndex);
0298: row.setValueAt(aValue, columnIndex);
0299: wiz.event();
0300: }
0301:
0302: public boolean isCellEditable(int r, int c) {
0303: return true;
0304: }
0305:
0306: ArrayList getRawData() {
0307: return data;
0308: }
0309:
0310: public boolean isValid() {
0311: for (int i = 0; i < data.size(); i++) {
0312: RMIAuthenticatedUser row = (RMIAuthenticatedUser) data
0313: .get(i);
0314: if (!row.isValid())
0315: return false;
0316: }
0317: return true;
0318: }
0319: }
0320:
0321: /**
0322: * Create the wizard panel component and set up some basic properties.
0323: * @param wiz <CODE>WizardDescriptor</CODE> the wizard
0324: */
0325: public RMIPanel(RMIWizardPanel wiz) {
0326: this .wiz = wiz;
0327: bundle = NbBundle.getBundle(ConfigPanel.class);
0328: initComponents();
0329:
0330: //Table
0331: final String[] columnNames = {
0332: bundle.getString("LBL_TABLE_ROLE"),// NOI18N
0333: bundle.getString("LBL_TABLE_PASSWORD"),// NOI18N
0334: bundle.getString("LBL_TABLE_ACCESS") };// NOI18N
0335: tableModel = new AuthTableModel();
0336: authTable = new AuthTable(tableModel);
0337: authTable.setName("authTable");// NOI18N
0338: authTable.setPreferredSize(new Dimension(400, 100));
0339: authTable.setRowSelectionAllowed(true);
0340: authTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
0341: authTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
0342: JScrollPane jscp = new JScrollPane(authTable);
0343: jscp.setPreferredSize(new Dimension(400, 100));
0344: java.awt.GridBagConstraints tablegridBagConstraints = new java.awt.GridBagConstraints();
0345: tablegridBagConstraints.gridx = 0;
0346: tablegridBagConstraints.gridy = 4;
0347: tablegridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0348: tablegridBagConstraints.gridheight = 1;
0349:
0350: tablegridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0351: tablegridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0352:
0353: tablegridBagConstraints.weightx = 1.0;
0354: tablegridBagConstraints.weighty = 1.0;
0355: tablegridBagConstraints.insets = new java.awt.Insets(0, 30, 0,
0356: 0);
0357: jPanel2.add(jscp, tablegridBagConstraints);
0358: ((DefaultTableModel) authTable.getModel())
0359: .setColumnIdentifiers(columnNames);
0360: //AddAuthTableListener listener = new AddAuthTableListener(tableModel, removeAuth);
0361: //addAuth.addActionListener(listener);
0362:
0363: Mnemonics.setLocalizedText(tableNameJLabel, bundle
0364: .getString("LBL_Authenticate_Table_Name"));// NOI18N
0365: Mnemonics.setLocalizedText(addAuth, bundle
0366: .getString("LBL_RMI_ADD_AUTH"));// NOI18N
0367: Mnemonics.setLocalizedText(removeAuth, bundle
0368: .getString("LBL_RMI_REMOVE_AUTH"));// NOI18N
0369:
0370: removeAuth.setEnabled(false);
0371: addAuth.setEnabled(false);
0372: tableNameJLabel.setEnabled(false);
0373:
0374: Mnemonics.setLocalizedText(rMIJCheckBox, bundle
0375: .getString("LBL_RMI"));//NOI18N
0376: Mnemonics.setLocalizedText(rMIPortJLabel, bundle
0377: .getString("LBL_RMI_Port"));//NOI18N
0378: Mnemonics.setLocalizedText(sslJCheckBox, bundle
0379: .getString("LBL_SSL"));//NOI18N
0380: Mnemonics.setLocalizedText(sslClientAuthJCheckBox, bundle
0381: .getString("LBL_SSL_Required_Auth"));//NOI18N
0382: Mnemonics.setLocalizedText(sslCipherJLabel, bundle
0383: .getString("LBL_SSL_Cipher"));//NOI18N
0384: Mnemonics.setLocalizedText(sslProtocolJLabel, bundle
0385: .getString("LBL_SSL_Protocol_Version"));//NOI18N
0386: Mnemonics.setLocalizedText(authJCheckBox, bundle
0387: .getString("LBL_Authenticate"));//NOI18N
0388: //Mnemonics.setLocalizedText(authJButton,
0389: // bundle.getString("LBL_Authenticate_Edit"));//NOI18N
0390:
0391: //Set tooltips
0392:
0393: rMIJCheckBox.setToolTipText(bundle.getString("TLTP_RMI"));//NOI18N
0394: rMIPortJLabel.setToolTipText(bundle.getString("TLTP_RMI_PORT"));//NOI18N
0395: sslJCheckBox.setToolTipText(bundle.getString("TLTP_SSL"));//NOI18N
0396: sslClientAuthJCheckBox.setToolTipText(bundle
0397: .getString("TLTP_SSL_Client_Auth"));//NOI18N
0398: sslCipherJLabel.setToolTipText(bundle
0399: .getString("TLTP_SSL_Cipher_Suite"));//NOI18N
0400: sslProtocolJLabel.setToolTipText(bundle
0401: .getString("TLTP_SSL_Protocol"));//NOI18N
0402: authJCheckBox.setToolTipText(bundle.getString("TLTP_RMI_Auth"));//NOI18N
0403:
0404: // init flags
0405: rMIJCheckBox.setSelected(true);
0406: updateSelected();
0407: setRMIPanelEnabled(true);
0408: setSSLPanelEnabled(false);
0409: updateSelected();
0410: rMIPortJTextField.addKeyListener(new KeyListener() {
0411: public void keyTyped(KeyEvent e) {
0412: char c = e.getKeyChar();
0413: if (!(Character.isDigit(c)
0414: || c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE)) {
0415: authTable.getToolkit().beep();
0416: e.consume();
0417: }
0418: }
0419:
0420: public void keyPressed(KeyEvent e) {
0421: }
0422:
0423: public void keyReleased(KeyEvent e) {
0424:
0425: }
0426: });
0427:
0428: // Provide a name in the title bar.
0429: //setName(NbBundle.getMessage(ConfigPanel.class,
0430: // "LBL_RMI_Panel"));
0431: setName(bundle.getString("ACCESS_RMI_ENABLE_RMI")); // NOI18N
0432:
0433: //Accessibility
0434: rMIJCheckBox.getAccessibleContext().setAccessibleName(
0435: bundle.getString("ACCESS_RMI_ENABLE_RMI")); // NOI18N
0436: rMIJCheckBox.getAccessibleContext().setAccessibleDescription(
0437: bundle.getString("ACCESS_RMI_ENABLE_RMI_DESCRIPTION"));// NOI18N
0438:
0439: rMIPortJTextField.getAccessibleContext().setAccessibleName(
0440: bundle.getString("ACCESS_RMI_PORT")); // NOI18N
0441: rMIPortJTextField
0442: .getAccessibleContext()
0443: .setAccessibleDescription(
0444: bundle.getString("ACCESS_RMI_PORT_DESCRIPTION"));// NOI18N
0445:
0446: rMIPortJLabel.setLabelFor(rMIPortJTextField);
0447:
0448: authJCheckBox.getAccessibleContext().setAccessibleName(
0449: bundle.getString("ACCESS_RMI_AUTHENTICATION")); // NOI18N
0450: authJCheckBox
0451: .getAccessibleContext()
0452: .setAccessibleDescription(
0453: bundle
0454: .getString("ACCESS_RMI_AUTHENTICATION_DESCRIPTION")); // NOI18N
0455:
0456: authTable.getAccessibleContext().setAccessibleName(
0457: bundle.getString("ACCESS_RMI_AUTHENTICATION_TABLE")); // NOI18N
0458: authTable
0459: .getAccessibleContext()
0460: .setAccessibleDescription(
0461: bundle
0462: .getString("ACCESS_RMI_AUTHENTICATION_TABLE_DESCRIPTION")); // NOI18N
0463:
0464: tableNameJLabel.setLabelFor(authTable);
0465:
0466: addAuth.getAccessibleContext().setAccessibleName(
0467: bundle.getString("ACCESS_RMI_AUTHENTICATION_ADD")); // NOI18N
0468: addAuth
0469: .getAccessibleContext()
0470: .setAccessibleDescription(
0471: bundle
0472: .getString("ACCESS_RMI_AUTHENTICATION_ADD_DESCRIPTION")); // NOI18N
0473:
0474: removeAuth.getAccessibleContext().setAccessibleName(
0475: bundle.getString("ACCESS_RMI_AUTHENTICATION_REMOVE")); // NOI18N
0476: removeAuth
0477: .getAccessibleContext()
0478: .setAccessibleDescription(
0479: bundle
0480: .getString("ACCESS_RMI_AUTHENTICATION_REMOVE_DESCRIPTION")); // NOI18N
0481:
0482: sslJCheckBox.getAccessibleContext().setAccessibleName(
0483: bundle.getString("ACCESS_RMI_SSL")); // NOI18N
0484: sslJCheckBox.getAccessibleContext().setAccessibleDescription(
0485: bundle.getString("ACCESS_RMI_SSL_DESCRIPTION")); // NOI18N
0486:
0487: sslProtocolJTextField.getAccessibleContext().setAccessibleName(
0488: bundle.getString("ACCESS_RMI_SSL_PROTOCOL")); // NOI18N
0489: sslProtocolJTextField
0490: .getAccessibleContext()
0491: .setAccessibleDescription(
0492: bundle
0493: .getString("ACCESS_RMI_SSL_PROTOCOL_DESCRIPTION")); // NOI18N
0494:
0495: sslProtocolJLabel.setLabelFor(sslProtocolJTextField);
0496:
0497: sslCipherJTextField.getAccessibleContext().setAccessibleName(
0498: bundle.getString("ACCESS_RMI_SSL_CIPHER")); // NOI18N
0499: sslCipherJTextField
0500: .getAccessibleContext()
0501: .setAccessibleDescription(
0502: bundle
0503: .getString("ACCESS_RMI_SSL_CIPHER_DESCRIPTION")); // NOI18N
0504:
0505: sslCipherJLabel.setLabelFor(sslCipherJTextField);
0506:
0507: sslClientAuthJCheckBox.getAccessibleContext()
0508: .setAccessibleName(
0509: bundle.getString("ACCESS_RMI_SSL_CLIENT")); // NOI18N
0510: sslClientAuthJCheckBox
0511: .getAccessibleContext()
0512: .setAccessibleDescription(
0513: bundle
0514: .getString("ACCESS_RMI_SSL_CLIENT_DESCRIPTION")); // NOI18N
0515:
0516: getAccessibleContext().setAccessibleDescription(
0517: bundle.getString("ACCESS_PANEL"));// NOI18N
0518: }
0519:
0520: /**
0521: * Checks if all the user inputs are valid.
0522: * @return <CODE>boolean</CODE> true if user inputs are valid
0523: */
0524: public boolean isValid() {
0525: if (authSelected)
0526: return tableModel.isValid();
0527: return true;
0528: }
0529:
0530: /*
0531: * update all the selected flags
0532: */
0533: private void updateSelected() {
0534: sslSelected = sslJCheckBox.isSelected();
0535: rMISelected = rMIJCheckBox.isSelected();
0536: authSelected = authJCheckBox.isSelected();
0537: }
0538:
0539: /*
0540: * calls setEnabled(enable) method of all components included in SSLPanel
0541: */
0542: private void setSSLPanelEnabled(boolean enable) {
0543: Vector<JComponent> jcVector = new Vector<JComponent>();
0544: jcVector.add(sslClientAuthJCheckBox);
0545: jcVector.add(sslProtocolJLabel);
0546: jcVector.add(sslProtocolJTextField);
0547: jcVector.add(sslCipherJLabel);
0548: jcVector.add(sslCipherJTextField);
0549: for (Iterator<JComponent> it = jcVector.iterator(); it
0550: .hasNext();) {
0551: JComponent jc = it.next();
0552: jc.setEnabled(enable);
0553: }
0554: }
0555:
0556: /*
0557: * calls setEnabled(enable) method of all components included in RMIPanel
0558: */
0559: private void setRMIPanelEnabled(boolean enable) {
0560: Vector<JComponent> jcVector = new Vector<JComponent>();
0561: jcVector.add(rMIPortJLabel);
0562: jcVector.add(rMIPortJTextField);
0563: jcVector.add(authJCheckBox);
0564: jcVector.add(sslJCheckBox);
0565: for (Iterator<JComponent> it = jcVector.iterator(); it
0566: .hasNext();) {
0567: JComponent jc = it.next();
0568: jc.setEnabled(enable);
0569: }
0570: if (enable && sslSelected) {
0571: setSSLPanelEnabled(true);
0572: } else {
0573: setSSLPanelEnabled(false);
0574: }
0575: updateSelected();
0576:
0577: if (enable) {
0578: authTable.setEnabled(authSelected);
0579: addAuth.setEnabled(authSelected);
0580: removeAuth.setEnabled(tableModel.getSize() > 0);
0581: tableNameJLabel.setEnabled(authSelected);
0582: } else {
0583: authTable.setEnabled(false);
0584: addAuth.setEnabled(false);
0585: removeAuth.setEnabled(false);
0586: tableNameJLabel.setEnabled(false);
0587: }
0588:
0589: }
0590:
0591: private void checkPortValue(javax.swing.JTextField jt) {
0592: if (Integer.getInteger(jt.getText()) > 65536) {
0593: jt.setText(new Integer(65536).toString());
0594: } else if (Integer.getInteger(jt.getText()) < 0) {
0595: jt.setText(new Integer(0).toString());
0596: }
0597: }
0598:
0599: /** This method is called from within the constructor to
0600: * initialize the form.
0601: * WARNING: Do NOT modify this code. The content of this method is
0602: * always regenerated by the Form Editor.
0603: */
0604: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
0605: private void initComponents() {
0606: java.awt.GridBagConstraints gridBagConstraints;
0607:
0608: managementFilesGroup = new javax.swing.ButtonGroup();
0609: jTable1 = new javax.swing.JTable();
0610: jPanel2 = new javax.swing.JPanel();
0611: rMIPortJLabel = new javax.swing.JLabel();
0612: rMIPortJTextField = new javax.swing.JTextField();
0613: rMIJCheckBox = new javax.swing.JCheckBox();
0614: authJCheckBox = new javax.swing.JCheckBox();
0615: sslJCheckBox = new javax.swing.JCheckBox();
0616: tableNameJLabel = new javax.swing.JLabel();
0617: sslProtocolJLabel = new javax.swing.JLabel();
0618: sslProtocolJTextField = new javax.swing.JTextField();
0619: sslCipherJLabel = new javax.swing.JLabel();
0620: sslCipherJTextField = new javax.swing.JTextField();
0621: sslClientAuthJCheckBox = new javax.swing.JCheckBox();
0622: addAuth = new javax.swing.JButton();
0623: removeAuth = new javax.swing.JButton();
0624:
0625: jTable1.setModel(new javax.swing.table.DefaultTableModel(
0626: new Object[][] { { null, null, null, null },
0627: { null, null, null, null },
0628: { null, null, null, null },
0629: { null, null, null, null } }, new String[] {
0630: "Title 1", "Title 2", "Title 3", "Title 4" }));
0631:
0632: setLayout(new java.awt.BorderLayout());
0633:
0634: jPanel2.setLayout(new java.awt.GridBagLayout());
0635:
0636: rMIPortJLabel.setName("rMIPortJLabel");
0637: gridBagConstraints = new java.awt.GridBagConstraints();
0638: gridBagConstraints.gridx = 0;
0639: gridBagConstraints.gridy = 1;
0640: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0641: gridBagConstraints.insets = new java.awt.Insets(0, 15, 0, 0);
0642: jPanel2.add(rMIPortJLabel, gridBagConstraints);
0643:
0644: rMIPortJTextField
0645: .setMinimumSize(new java.awt.Dimension(55, 20));
0646: rMIPortJTextField.setName("rMIPortJTextField");
0647: rMIPortJTextField.setPreferredSize(new java.awt.Dimension(55,
0648: 20));
0649: rMIPortJTextField
0650: .addActionListener(new java.awt.event.ActionListener() {
0651: public void actionPerformed(
0652: java.awt.event.ActionEvent evt) {
0653: rMIPortJTextFieldActionPerformed(evt);
0654: }
0655: });
0656:
0657: gridBagConstraints = new java.awt.GridBagConstraints();
0658: gridBagConstraints.gridx = 1;
0659: gridBagConstraints.gridy = 1;
0660: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0661: gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
0662: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0663: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
0664: jPanel2.add(rMIPortJTextField, gridBagConstraints);
0665:
0666: rMIJCheckBox.setName("rMIJCheckBox");
0667: rMIJCheckBox
0668: .addActionListener(new java.awt.event.ActionListener() {
0669: public void actionPerformed(
0670: java.awt.event.ActionEvent evt) {
0671: rMIJCheckBoxActionPerformed(evt);
0672: }
0673: });
0674:
0675: gridBagConstraints = new java.awt.GridBagConstraints();
0676: gridBagConstraints.gridx = 0;
0677: gridBagConstraints.gridy = 0;
0678: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0679: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0680: jPanel2.add(rMIJCheckBox, gridBagConstraints);
0681:
0682: authJCheckBox.setName("authJCheckBox");
0683: authJCheckBox
0684: .addActionListener(new java.awt.event.ActionListener() {
0685: public void actionPerformed(
0686: java.awt.event.ActionEvent evt) {
0687: authJCheckBoxActionPerformed(evt);
0688: }
0689: });
0690:
0691: gridBagConstraints = new java.awt.GridBagConstraints();
0692: gridBagConstraints.gridx = 0;
0693: gridBagConstraints.gridy = 2;
0694: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0695: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0696: gridBagConstraints.insets = new java.awt.Insets(8, 13, 0, 0);
0697: jPanel2.add(authJCheckBox, gridBagConstraints);
0698:
0699: sslJCheckBox.setName("sslJCheckBox");
0700: sslJCheckBox
0701: .addActionListener(new java.awt.event.ActionListener() {
0702: public void actionPerformed(
0703: java.awt.event.ActionEvent evt) {
0704: sslJCheckBoxActionPerformed(evt);
0705: }
0706: });
0707:
0708: gridBagConstraints = new java.awt.GridBagConstraints();
0709: gridBagConstraints.gridx = 0;
0710: gridBagConstraints.gridy = 6;
0711: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0712: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0713: gridBagConstraints.insets = new java.awt.Insets(8, 13, 0, 0);
0714: jPanel2.add(sslJCheckBox, gridBagConstraints);
0715:
0716: tableNameJLabel.setName("tableNameJLabel");
0717: gridBagConstraints = new java.awt.GridBagConstraints();
0718: gridBagConstraints.gridx = 0;
0719: gridBagConstraints.gridy = 3;
0720: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0721: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0722: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0723: gridBagConstraints.weightx = 1.0;
0724: gridBagConstraints.insets = new java.awt.Insets(5, 30, 5, 0);
0725: jPanel2.add(tableNameJLabel, gridBagConstraints);
0726:
0727: sslProtocolJLabel.setName("sslProtocolJLabel");
0728: gridBagConstraints = new java.awt.GridBagConstraints();
0729: gridBagConstraints.gridx = 0;
0730: gridBagConstraints.gridy = 7;
0731: gridBagConstraints.gridwidth = 2;
0732: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0733: gridBagConstraints.insets = new java.awt.Insets(2, 30, 0, 0);
0734: jPanel2.add(sslProtocolJLabel, gridBagConstraints);
0735:
0736: sslProtocolJTextField.setMinimumSize(new java.awt.Dimension(50,
0737: 20));
0738: sslProtocolJTextField.setName("sslProtocolJTextField");
0739: sslProtocolJTextField.setPreferredSize(new java.awt.Dimension(
0740: 65, 20));
0741: gridBagConstraints = new java.awt.GridBagConstraints();
0742: gridBagConstraints.gridx = 2;
0743: gridBagConstraints.gridy = 7;
0744: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0745: gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
0746: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0747: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
0748: jPanel2.add(sslProtocolJTextField, gridBagConstraints);
0749:
0750: sslCipherJLabel.setName("sslCipherJLabel");
0751: gridBagConstraints = new java.awt.GridBagConstraints();
0752: gridBagConstraints.gridx = 0;
0753: gridBagConstraints.gridy = 8;
0754: gridBagConstraints.gridwidth = 2;
0755: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0756: gridBagConstraints.insets = new java.awt.Insets(5, 30, 0, 0);
0757: jPanel2.add(sslCipherJLabel, gridBagConstraints);
0758:
0759: sslCipherJTextField.setMinimumSize(new java.awt.Dimension(50,
0760: 20));
0761: sslCipherJTextField.setName("sslCipherJTextField");
0762: sslCipherJTextField.setPreferredSize(new java.awt.Dimension(65,
0763: 20));
0764: gridBagConstraints = new java.awt.GridBagConstraints();
0765: gridBagConstraints.gridx = 2;
0766: gridBagConstraints.gridy = 8;
0767: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0768: gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
0769: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0770: gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0);
0771: jPanel2.add(sslCipherJTextField, gridBagConstraints);
0772:
0773: sslClientAuthJCheckBox.setName("sslClientAuthJCheckBox");
0774: gridBagConstraints = new java.awt.GridBagConstraints();
0775: gridBagConstraints.gridx = 0;
0776: gridBagConstraints.gridy = 9;
0777: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0778: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0779: gridBagConstraints.insets = new java.awt.Insets(5, 28, 0, 0);
0780: jPanel2.add(sslClientAuthJCheckBox, gridBagConstraints);
0781:
0782: addAuth.setName("addAuth");
0783: addAuth.addActionListener(new java.awt.event.ActionListener() {
0784: public void actionPerformed(java.awt.event.ActionEvent evt) {
0785: addAuthActionPerformed(evt);
0786: }
0787: });
0788:
0789: gridBagConstraints = new java.awt.GridBagConstraints();
0790: gridBagConstraints.gridx = 0;
0791: gridBagConstraints.gridy = 5;
0792: gridBagConstraints.gridwidth = 2;
0793: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0794: gridBagConstraints.insets = new java.awt.Insets(5, 30, 0, 5);
0795: jPanel2.add(addAuth, gridBagConstraints);
0796:
0797: removeAuth.setName("removeAuth");
0798: removeAuth
0799: .addActionListener(new java.awt.event.ActionListener() {
0800: public void actionPerformed(
0801: java.awt.event.ActionEvent evt) {
0802: removeAuthActionPerformed(evt);
0803: }
0804: });
0805:
0806: gridBagConstraints = new java.awt.GridBagConstraints();
0807: gridBagConstraints.gridx = 2;
0808: gridBagConstraints.gridy = 5;
0809: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0810: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0811: gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 5);
0812: jPanel2.add(removeAuth, gridBagConstraints);
0813:
0814: add(jPanel2, java.awt.BorderLayout.NORTH);
0815:
0816: }
0817:
0818: // </editor-fold>//GEN-END:initComponents
0819:
0820: private void removeAuthActionPerformed(
0821: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeAuthActionPerformed
0822: final int row = authTable.getSelectedRow();
0823: if (row == -1)
0824: return;
0825:
0826: tableModel.removeRow(row);
0827: removeAuth.setEnabled(tableModel.getSize() > 0);
0828: if (tableModel.getSize() > 0) {
0829: SwingUtilities.invokeLater(new Runnable() {
0830: public void run() {
0831: if (row == 0)
0832: authTable.setRowSelectionInterval(0, 0);
0833: else if (row == tableModel.getSize())
0834: authTable.setRowSelectionInterval(row - 1,
0835: row - 1);
0836: else
0837: authTable.setRowSelectionInterval(row, row);
0838: }
0839: });
0840: }
0841: wiz.event();
0842: }//GEN-LAST:event_removeAuthActionPerformed
0843:
0844: private void addAuthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addAuthActionPerformed
0845: tableModel.addRow();
0846: removeAuth.setEnabled(tableModel.getSize() > 0);
0847: wiz.event();
0848: }//GEN-LAST:event_addAuthActionPerformed
0849:
0850: private void rMIPortJTextFieldActionPerformed(
0851: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rMIPortJTextFieldActionPerformed
0852: // TODO add your handling code here:
0853: }//GEN-LAST:event_rMIPortJTextFieldActionPerformed
0854:
0855: private void authJCheckBoxActionPerformed(
0856: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_authJCheckBoxActionPerformed
0857: updateSelected();
0858: authTable.setEnabled(authSelected);
0859: addAuth.setEnabled(authSelected);
0860: removeAuth.setEnabled(authSelected && tableModel.getSize() > 0);
0861: tableNameJLabel.setEnabled(authSelected);
0862: wiz.event();
0863: }//GEN-LAST:event_authJCheckBoxActionPerformed
0864:
0865: private void sslJCheckBoxActionPerformed(
0866: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sslJCheckBoxActionPerformed
0867: updateSelected();
0868: if (rMISelected) {
0869: setSSLPanelEnabled(sslSelected);
0870: } else {
0871: setSSLPanelEnabled(false);
0872: }
0873: //wiz.fireChangeEvent ();
0874: }//GEN-LAST:event_sslJCheckBoxActionPerformed
0875:
0876: private void rMIJCheckBoxActionPerformed(
0877: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rMIJCheckBoxActionPerformed
0878: updateSelected();
0879: setRMIPanelEnabled(rMISelected);
0880: //wiz.fireChangeEvent ();
0881: }//GEN-LAST:event_rMIJCheckBoxActionPerformed
0882:
0883: // Variables declaration - do not modify//GEN-BEGIN:variables
0884: private javax.swing.JButton addAuth;
0885: private javax.swing.JCheckBox authJCheckBox;
0886: private javax.swing.JPanel jPanel2;
0887: private javax.swing.JTable jTable1;
0888: private javax.swing.ButtonGroup managementFilesGroup;
0889: private javax.swing.JCheckBox rMIJCheckBox;
0890: private javax.swing.JLabel rMIPortJLabel;
0891: private javax.swing.JTextField rMIPortJTextField;
0892: private javax.swing.JButton removeAuth;
0893: private javax.swing.JLabel sslCipherJLabel;
0894: private javax.swing.JTextField sslCipherJTextField;
0895: private javax.swing.JCheckBox sslClientAuthJCheckBox;
0896: private javax.swing.JCheckBox sslJCheckBox;
0897: private javax.swing.JLabel sslProtocolJLabel;
0898: private javax.swing.JTextField sslProtocolJTextField;
0899: private javax.swing.JLabel tableNameJLabel;
0900:
0901: // End of variables declaration//GEN-END:variables
0902:
0903: /**
0904: *
0905: * Class handling the standard RMI wizard panel
0906: *
0907: */
0908: public static class RMIWizardPanel extends GenericWizardPanel
0909: implements org.openide.WizardDescriptor.FinishablePanel {
0910: private RMIPanel panel = null;
0911: private String projectLocation = null;
0912: private WizardDescriptor wiz;
0913:
0914: public boolean isValid() {
0915: boolean val = true;
0916: if (getPanel().authSelected)
0917: val = getPanel().tableModel.isValid();
0918:
0919: String msg = "";// NOI18N
0920: if (!val)
0921: msg = getPanel().bundle
0922: .getString("LBL_State_Invalid_User");// NOI18N
0923:
0924: setErrorMsg(msg);
0925: return val;
0926: }
0927:
0928: /**
0929: * Displays the given message in the wizard's message area.
0930: *
0931: * @param message message to be displayed, or <code>null</code>
0932: * if the message area should be cleared
0933: */
0934: private void setErrorMsg(String message) {
0935: if (wiz != null) {
0936: wiz.putProperty(WizardConstants.WIZARD_ERROR_MESSAGE,
0937: message);
0938: }
0939: }
0940:
0941: /**
0942: * Fire a change event (designed to be call from out of this class).
0943: */
0944: public void event() {
0945: fireChangeEvent();
0946: }
0947:
0948: public Component getComponent() {
0949: return getPanel();
0950: }
0951:
0952: private RMIPanel getPanel() {
0953: if (panel == null) {
0954: panel = new RMIPanel(this );
0955: }
0956: return panel;
0957: }
0958:
0959: public boolean isFinishPanel() {
0960: return false;
0961: }
0962:
0963: //=====================================================================
0964: // Called to read information from the wizard map in order to populate
0965: // the GUI correctly.
0966: //=====================================================================
0967: public void readSettings(Object settings) {
0968: wiz = (WizardDescriptor) settings;
0969:
0970: // store project location to detect existing mbeans
0971: String location = (String) wiz
0972: .getProperty(WizardConstants.PROP_PROJECT_LOCATION);
0973: projectLocation = location + File.separatorChar
0974: + WizardConstants.SRC_DIR;
0975:
0976: getPanel().rMIPortJTextField.setText(wiz.getProperty(
0977: WizardConstants.RMI_PORT).toString());
0978: }
0979:
0980: //=====================================================================
0981: // Called to store information from the GUI into the wizard map.
0982: //=====================================================================
0983: public void storeSettings(Object settings) {
0984: getPanel().updateSelected();
0985: wiz = (WizardDescriptor) settings;
0986: wiz.putProperty(WizardConstants.RMI_SELECTED, new Boolean(
0987: getPanel().rMISelected));
0988: wiz.putProperty(WizardConstants.RMI_AUTHENTICATE,
0989: new Boolean(getPanel().authSelected));
0990: wiz.putProperty(WizardConstants.RMI_AUTHENTICATED_USERS,
0991: getPanel().tableModel.getRawData());
0992: wiz.putProperty(WizardConstants.RMI_PORT, Integer
0993: .valueOf(getPanel().rMIPortJTextField.getText()));
0994: wiz.putProperty(WizardConstants.SSL_SELECTED,
0995: getPanel().sslSelected);
0996: wiz.putProperty(WizardConstants.RMI_SSL_PROTOCOLS,
0997: getPanel().sslProtocolJTextField.getText());
0998: wiz.putProperty(WizardConstants.RMI_SSL_TLS_CIPHER,
0999: getPanel().sslCipherJTextField.getText());
1000: Boolean sslClientAuth = getPanel().sslClientAuthJCheckBox
1001: .isSelected();
1002: wiz.putProperty(
1003: WizardConstants.RMI_SSL_CLIENT_AUTHENTICATE,
1004: new Boolean(sslClientAuth));
1005: }
1006:
1007: public HelpCtx getHelp() {
1008: return new HelpCtx("mgt_properties"); // NOI18N
1009: }
1010: }
1011: }
|