1 19 20 package org.netbeans.modules.j2ee.oc4j.ui.wizards; 21 22 import java.awt.event.ItemEvent ; 23 import java.awt.event.ItemListener ; 24 import java.util.ArrayList ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import javax.swing.event.ChangeEvent ; 29 import javax.swing.event.ChangeListener ; 30 import javax.swing.event.DocumentEvent ; 31 import javax.swing.event.DocumentListener ; 32 import org.netbeans.modules.j2ee.oc4j.ui.wizards.AddServerPropertiesVisualPanel.ServerType; 33 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginUtils; 34 import org.openide.util.NbBundle; 35 36 40 public class AddServerPropertiesVisualPanel extends javax.swing.JPanel { 41 42 private String j2eeLocalHome; 43 private final List <ChangeListener > listeners = new ArrayList <ChangeListener >(); 44 45 46 public AddServerPropertiesVisualPanel(String j2eeLocalHome) { 47 this.j2eeLocalHome = j2eeLocalHome; 48 49 setName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "TITLE_Properties")); 50 51 initComponents(); 52 53 DocumentListener changeListener = new DocumentListener () { 54 public void changedUpdate(DocumentEvent e) { 55 fireChange(); 56 } 57 58 public void removeUpdate(DocumentEvent e) { 59 fireChange(); 60 } 61 62 public void insertUpdate(DocumentEvent e) { 63 fireChange(); 64 } 65 }; 66 67 hostTxt.getDocument().addDocumentListener(changeListener); 68 adminPortTxt.getDocument().addDocumentListener(changeListener); 69 portTxt.getDocument().addDocumentListener(changeListener); 70 passwordTxt.getDocument().addDocumentListener(changeListener); 71 72 typeComboBox.addItemListener(new ItemListener () { 73 public void itemStateChanged(ItemEvent evt) { 74 ServerType t = (ServerType) evt.getItem(); 75 76 if (t.equals(LOCAL)) { 77 hostTxt.setText(LOCALHOST); 78 hostTxt.setEnabled(false); 79 usersComboBox.setEditable(false); 80 webSiteComboBox.setEnabled(true); 81 } else { 82 hostTxt.setText(""); 83 hostTxt.setEnabled(true); 84 usersComboBox.setEditable(true); 85 webSiteComboBox.setSelectedItem(DEFAULT_WEB_SITE); 86 webSiteComboBox.setEnabled(false); 87 setInitialization(false); 88 } 89 } 90 }); 91 92 setInitValues(); 93 } 94 95 public void setInitialization(boolean active) { 96 initializationPanel.setVisible(active); 97 } 98 99 public void addChangeListener(ChangeListener l) { 100 synchronized (listeners) { 101 listeners.add(l); 102 } 103 } 104 105 public void removeChangeListener(ChangeListener l) { 106 synchronized (listeners) { 107 listeners.remove(l); 108 } 109 } 110 111 private void fireChange() { 112 Iterator it; 113 synchronized (listeners) { 114 it = new HashSet <ChangeListener >(listeners).iterator(); 115 } 116 ChangeEvent ev = new ChangeEvent (this); 117 while (it.hasNext()) { 118 ((ChangeListener )it.next()).stateChanged(ev); 119 } 120 } 121 122 127 private void initComponents() { 129 130 userLbl = new javax.swing.JLabel (); 131 passwordLbl = new javax.swing.JLabel (); 132 passwordTxt = new javax.swing.JPasswordField (); 133 adminPortLbl = new javax.swing.JLabel (); 134 adminPortTxt = new javax.swing.JTextField (); 135 portLbl = new javax.swing.JLabel (); 136 portTxt = new javax.swing.JTextField (); 137 webSiteLbl = new javax.swing.JLabel (); 138 webSiteComboBox = new javax.swing.JComboBox (); 139 usersComboBox = new javax.swing.JComboBox (); 140 initializationPanel = new javax.swing.JPanel (); 141 initializeButton = new javax.swing.JButton (); 142 jLabel1 = new javax.swing.JLabel (); 143 typeLbl = new javax.swing.JLabel (); 144 typeComboBox = new javax.swing.JComboBox (); 145 hostLbl = new javax.swing.JLabel (); 146 hostTxt = new javax.swing.JTextField (); 147 jSeparator1 = new javax.swing.JSeparator (); 148 149 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/oc4j/ui/wizards/Bundle"); org.openide.awt.Mnemonics.setLocalizedText(userLbl, bundle.getString("LBL_USER")); 152 passwordLbl.setLabelFor(passwordTxt); 153 org.openide.awt.Mnemonics.setLocalizedText(passwordLbl, bundle.getString("LBL")); 155 adminPortLbl.setLabelFor(adminPortTxt); 156 org.openide.awt.Mnemonics.setLocalizedText(adminPortLbl, bundle.getString("LBL_ADMIN_PORT")); 158 portLbl.setLabelFor(portTxt); 159 org.openide.awt.Mnemonics.setLocalizedText(portLbl, bundle.getString("LBL_HTTP_PORT")); 161 webSiteLbl.setLabelFor(webSiteComboBox); 162 org.openide.awt.Mnemonics.setLocalizedText(webSiteLbl, bundle.getString("LBL_WEB_SITE")); 164 initializationPanel.setBackground(new java.awt.Color (204, 204, 204)); 165 initializationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color (0, 0, 0))); 166 167 initializeButton.setText(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_InitializationTitle", new Object [] {})); initializeButton.addActionListener(new java.awt.event.ActionListener () { 169 public void actionPerformed(java.awt.event.ActionEvent evt) { 170 initializeButtonActionPerformed(evt); 171 } 172 }); 173 174 jLabel1.setText(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Initialization", new Object [] {})); 176 org.jdesktop.layout.GroupLayout initializationPanelLayout = new org.jdesktop.layout.GroupLayout(initializationPanel); 177 initializationPanel.setLayout(initializationPanelLayout); 178 initializationPanelLayout.setHorizontalGroup( 179 initializationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 180 .add(org.jdesktop.layout.GroupLayout.TRAILING, initializationPanelLayout.createSequentialGroup() 181 .addContainerGap() 182 .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 198, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 183 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 24, Short.MAX_VALUE) 184 .add(initializeButton) 185 .addContainerGap()) 186 ); 187 initializationPanelLayout.setVerticalGroup( 188 initializationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 189 .add(initializationPanelLayout.createSequentialGroup() 190 .addContainerGap() 191 .add(initializationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 192 .add(initializeButton) 193 .add(jLabel1)) 194 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 195 ); 196 197 typeLbl.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/oc4j/ui/wizards/Bundle").getString("LBL_SERVER_TYPE").charAt(0)); 198 typeLbl.setText(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_SERVER_TYPE")); 200 hostLbl.setText(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_HOST")); 202 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 203 this.setLayout(layout); 204 layout.setHorizontalGroup( 205 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 206 .add(layout.createSequentialGroup() 207 .addContainerGap() 208 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 209 .add(initializationPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 210 .add(layout.createSequentialGroup() 211 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 212 .add(hostLbl) 213 .add(typeLbl)) 214 .add(53, 53, 53) 215 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 216 .add(typeComboBox, 0, 250, Short.MAX_VALUE) 217 .add(org.jdesktop.layout.GroupLayout.LEADING, hostTxt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE))) 218 .add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE) 219 .add(layout.createSequentialGroup() 220 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 221 .add(userLbl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 222 .add(passwordLbl) 223 .add(adminPortLbl) 224 .add(portLbl) 225 .add(webSiteLbl)) 226 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 227 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 228 .add(webSiteComboBox, 0, 250, Short.MAX_VALUE) 229 .add(portTxt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE) 230 .add(adminPortTxt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE) 231 .add(passwordTxt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE) 232 .add(usersComboBox, 0, 250, Short.MAX_VALUE)))) 233 .addContainerGap()) 234 ); 235 layout.setVerticalGroup( 236 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 237 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 238 .addContainerGap() 239 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 240 .add(typeLbl) 241 .add(typeComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 242 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 243 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 244 .add(hostLbl) 245 .add(hostTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 246 .add(14, 14, 14) 247 .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 248 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 249 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 250 .add(userLbl) 251 .add(usersComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 252 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 253 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 254 .add(passwordLbl) 255 .add(passwordTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 256 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 257 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 258 .add(adminPortLbl) 259 .add(adminPortTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 260 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 261 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 262 .add(portLbl) 263 .add(portTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 264 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 265 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 266 .add(webSiteComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 267 .add(webSiteLbl)) 268 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 92, Short.MAX_VALUE) 269 .add(initializationPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 270 .addContainerGap()) 271 ); 272 273 passwordTxt.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_PASSWD_TXT")); passwordTxt.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_PASSWD_TXT")); adminPortTxt.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_ADMIN_PORT_TXT")); adminPortTxt.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_ADMIN_PORT_TXT")); portTxt.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_HTTP_PORT_TXT")); portTxt.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_HTTP_PORT_TXT")); webSiteComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_WEB_SITES_CMB")); webSiteComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_WEB_SITES_CMB")); 282 getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_NAME_PANEL")); getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_DESC_PANEL")); } 286 private void initializeButtonActionPerformed(java.awt.event.ActionEvent evt) { 288 initializeButton.setEnabled(false); 289 290 String password = null; 291 292 while(password == null || password.equals(ADMIN_USER)) { 293 password = OC4JPluginUtils.requestPassword(ADMIN_USER); 294 } 295 296 if(OC4JPluginUtils.activateUser(j2eeLocalHome, ADMIN_USER, password)) { 297 initializeButton.setEnabled(true); 298 setInitialization(false); 299 passwordTxt.setText(password); 300 fireChange(); 301 } 302 303 initializeButton.setEnabled(true); 304 fireChange(); 305 } 307 public ServerType getType() { 308 return (ServerType) typeComboBox.getSelectedItem(); 309 } 310 311 public String getHost() { 312 return hostTxt.getText().trim(); 313 } 314 315 public String getAdminPort() { 316 return adminPortTxt.getText().trim(); 317 } 318 319 public String getPassword() { 320 return new String (passwordTxt.getPassword()); 321 } 322 323 public String getUser() { 324 return (String ) usersComboBox.getSelectedItem(); 325 } 326 327 public String getPort() { 328 return portTxt.getText().trim(); 329 } 330 331 public String getWebSite() { 332 return (String )webSiteComboBox.getSelectedItem(); 333 } 334 335 private void setInitValues() { 336 usersComboBox.removeAllItems(); 337 338 portTxt.setText(Integer.toString(OC4JPluginUtils.getHttpPort(j2eeLocalHome, "default"))); 339 adminPortTxt.setText(Integer.toString(OC4JPluginUtils.getAdminPort(j2eeLocalHome))); 340 341 for (String item : OC4JPluginUtils.getWebSites(j2eeLocalHome)) 342 webSiteComboBox.addItem(item); 343 344 for (String item : OC4JPluginUtils.getUsers(j2eeLocalHome)) { 345 usersComboBox.addItem(item); 346 } 347 348 typeComboBox.addItem(LOCAL); 349 typeComboBox.addItem(REMOTE); 350 351 setInitialization(false); 352 } 353 354 private javax.swing.JLabel adminPortLbl; 356 private javax.swing.JTextField adminPortTxt; 357 private javax.swing.JLabel hostLbl; 358 private javax.swing.JTextField hostTxt; 359 private javax.swing.JPanel initializationPanel; 360 private javax.swing.JButton initializeButton; 361 private javax.swing.JLabel jLabel1; 362 private javax.swing.JSeparator jSeparator1; 363 private javax.swing.JLabel passwordLbl; 364 private javax.swing.JPasswordField passwordTxt; 365 private javax.swing.JLabel portLbl; 366 private javax.swing.JTextField portTxt; 367 private javax.swing.JComboBox typeComboBox; 368 private javax.swing.JLabel typeLbl; 369 private javax.swing.JLabel userLbl; 370 private javax.swing.JComboBox usersComboBox; 371 private javax.swing.JComboBox webSiteComboBox; 372 private javax.swing.JLabel webSiteLbl; 373 375 private final static String LOCALHOST = "localhost"; 376 private final static String ADMIN_USER = "oc4jadmin"; 377 private final static String DEFAULT_WEB_SITE = "default"; 378 379 protected final static ServerType LOCAL = new ServerType("Local Server"); 380 protected final static ServerType REMOTE = new ServerType("Remote Server"); 381 382 protected final static class ServerType { 383 384 private String description; 385 386 public ServerType(String description) { 387 this.description = description; 388 } 389 390 @Override 391 public String toString() { 392 return description; 393 } 394 } 395 } | Popular Tags |