1 19 package org.netbeans.modules.j2ee.websphere6.ui.wizard; 20 21 import java.util.*; 22 import java.awt.*; 23 import java.awt.event.*; 24 import javax.swing.*; 25 import javax.swing.event.*; 26 27 import org.openide.*; 28 import org.openide.awt.Mnemonics; 29 import org.openide.util.*; 30 import org.netbeans.modules.j2ee.websphere6.ui.Instance; 31 import org.netbeans.modules.j2ee.websphere6.ui.Customizer; 32 import org.netbeans.modules.j2ee.websphere6.ui.InstancesModel; 33 import org.netbeans.modules.j2ee.websphere6.ui.ServerProperties; 34 41 public class ServerPropertiesPanel extends JPanel 42 implements WizardDescriptor.Panel { 43 47 private final static String PROP_ERROR_MESSAGE = 48 "WizardPanel_errorMessage"; 50 53 private transient WizardDescriptor wizardDescriptor; 54 55 58 private transient WSInstantiatingIterator instantiatingIterator; 59 60 61 public class WizardServerProperties extends ServerProperties{ 62 public WizardServerProperties(JComboBox serverCombobox, 63 JComboBox localInstancesCombobox, 64 JTextField domainPathField, 65 JTextField hostField, 66 JTextField portField) { 67 super(serverCombobox,localInstancesCombobox,domainPathField,hostField,portField); 68 } 69 public WizardServerProperties() { 70 super(); 71 } 72 73 public class WizardServerTypeActionListener extends ServerTypeActionListener{ 74 public void actionPerformed(ActionEvent e) { 75 super.actionPerformed(e); 76 isValid(); 77 } 78 } 79 } 80 81 private WizardServerProperties wizardServerProperties=new WizardServerProperties(); 82 83 86 public WizardServerProperties getWizardServerProperties(){ 87 return wizardServerProperties; 88 } 89 90 91 101 102 public ServerPropertiesPanel(String [] steps, int index, 103 ChangeListener listener, 104 WSInstantiatingIterator instantiatingIterator) { 105 this.instantiatingIterator = instantiatingIterator; 107 108 putClientProperty("WizardPanel_contentData", steps); putClientProperty("WizardPanel_contentSelectedIndex", 112 new Integer (index)); 114 addChangeListener(listener); 116 117 setName(steps[index]); 119 120 init(); 122 } 123 124 129 public HelpCtx getHelp() { 130 return new HelpCtx("j2eeplugins_registering_app_" + "server_websphere"); } 133 134 140 public Component getComponent() { 141 return this; 142 } 143 144 150 public boolean isValid() { 151 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, ""); 154 if (serverTypeCombo.getSelectedItem().equals(NbBundle.getMessage( 157 Customizer.class, 158 "TXT_ServerTypeLocal"))) { if (!wizardServerProperties.isValidDomainRoot(domainPathField.getText())) { 160 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, 161 NbBundle.getMessage(ServerPropertiesPanel.class, 162 "ERR_INVALID_DOMAIN_ROOT")); return false; 164 } 165 } 166 167 if (hostField.getText().trim().equals("")) { 169 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, 170 NbBundle.getMessage(ServerPropertiesPanel.class, 171 "ERR_INVALID_HOST")); } 173 174 if (!portField.getText().trim().matches("[0-9]+")) { 177 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, 178 NbBundle.getMessage(ServerPropertiesPanel.class, 179 "ERR_INVALID_PORT")); } 181 if (portField.getText().trim().matches("[0-9]+") && 182 new java.lang.Integer (portField.getText().trim()).intValue()>65535) { 183 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, 184 NbBundle.getMessage(ServerPropertiesPanel.class, 185 "ERR_INVALID_PORT")); } 187 188 190 instantiatingIterator.setDomainRoot(domainPathField.getText()); 192 instantiatingIterator.setHost(hostField.getText()); 193 instantiatingIterator.setPort(portField.getText()); 195 instantiatingIterator.setUsername(usernameField.getText()); 196 instantiatingIterator.setPassword(new String ( 197 passwordField.getPassword())); 198 instantiatingIterator.setIsLocal(serverTypeCombo.getSelectedItem(). 199 equals(NbBundle.getMessage(Customizer.class, 200 "TXT_ServerTypeLocal")) ? "true" : "false"); instantiatingIterator.setServerName(((Instance) localInstancesCombo. 202 getSelectedItem()).getName()); 203 instantiatingIterator.setConfigXmlPath(((Instance) localInstancesCombo. 204 getSelectedItem()).getConfigXmlPath()); 205 instantiatingIterator.setAdminPort(((Instance) localInstancesCombo. 206 getSelectedItem()).getAdminPort()); 207 instantiatingIterator.setDefaultHostPort(((Instance) localInstancesCombo. 208 getSelectedItem()).getDefaultHostPort()); 209 210 return true; 212 } 213 214 215 private JLabel domainPathLabel; 219 private JLabel hostLabel; 220 private JLabel portLabel; 221 private JLabel userNameLabel; 222 private JLabel passwordLabel; 223 private JPasswordField passwordField; 224 private JTextField domainPathField; 225 private JTextField hostField; 226 private JTextField portField; 227 private JTextField usernameField; 228 private JPanel formattingPanel; 229 private JComboBox serverTypeCombo; 230 private JComboBox localInstancesCombo; 231 private JLabel localInstanceLabel; 232 private JLabel serverTypeLabel; 233 private JTextArea remoteWarningLabel; 234 235 236 239 private void init() { 240 GridBagConstraints gridBagConstraints; 243 getAccessibleContext().setAccessibleDescription( 244 java.util.ResourceBundle.getBundle( 245 "org/netbeans/modules/j2ee/websphere6/ui/Bundle"). 246 getString("MSG_ServerPropertiesPanelDescription")); 247 domainPathLabel = new JLabel(); 249 domainPathField = new JTextField(); 250 hostLabel = new JLabel(); 251 hostField = new JTextField(); 252 portLabel = new JLabel(); 253 portField = new JTextField(); 254 userNameLabel = new JLabel(); 255 usernameField = new JTextField(); 256 passwordLabel = new JLabel(); 257 passwordField = new JPasswordField(); 258 formattingPanel = new JPanel(); 259 serverTypeLabel = new JLabel(); 260 serverTypeCombo = new JComboBox(new Object [] {NbBundle.getMessage( 261 Customizer.class, "TXT_ServerTypeLocal")}); localInstanceLabel = new JLabel(); 265 localInstancesCombo = new JComboBox(new InstancesModel( 266 wizardServerProperties.getServerInstances( 267 instantiatingIterator.getServerRoot()))); 268 remoteWarningLabel = new JTextArea(NbBundle.getMessage( 269 ServerPropertiesPanel.class, 270 "LBL_remoteIncompatibilityWarning")); 272 setLayout(new GridBagLayout()); 274 275 276 277 serverTypeLabel.setText(NbBundle.getMessage( 279 Customizer.class, "LBL_LocalRemote")); gridBagConstraints = new GridBagConstraints(); 281 gridBagConstraints.gridx = 0; 282 gridBagConstraints.gridy = 0; 283 gridBagConstraints.anchor = GridBagConstraints.EAST; 284 gridBagConstraints.insets = new Insets(0, 0, 5, 0); 285 add(serverTypeLabel, gridBagConstraints); 286 287 serverTypeCombo.addActionListener(wizardServerProperties.getServerTypeActionListener()); 289 gridBagConstraints = new GridBagConstraints(); 290 gridBagConstraints.gridx = 1; 291 gridBagConstraints.gridy = 0; 292 gridBagConstraints.anchor = GridBagConstraints.WEST; 293 gridBagConstraints.insets = new Insets(0, 10, 5, 0); 294 serverTypeCombo.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_AccessMethod")); 295 serverTypeCombo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_AccessMethodDescription")); 296 add(serverTypeCombo, gridBagConstraints); 297 298 localInstanceLabel.setText(NbBundle.getMessage( 300 Customizer.class, "LBL_LocalInstances")); gridBagConstraints = new GridBagConstraints(); 302 gridBagConstraints.gridx = 0; 303 gridBagConstraints.gridy = 1; 304 gridBagConstraints.anchor = GridBagConstraints.EAST; 305 gridBagConstraints.insets = new Insets(0, 0, 5, 0); 306 add(localInstanceLabel, gridBagConstraints); 307 308 localInstancesCombo.addActionListener( 310 wizardServerProperties.getInstanceSelectionListener()); 311 312 gridBagConstraints = new GridBagConstraints(); 313 gridBagConstraints.gridx = 1; 314 gridBagConstraints.gridy = 1; 315 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 316 gridBagConstraints.insets = new Insets(0, 10, 5, 0); 317 localInstancesCombo.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_LocalInstances")); 318 localInstancesCombo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_LocalInstances")); 319 add(localInstancesCombo, gridBagConstraints); 320 321 domainPathLabel.setText(NbBundle.getMessage( 323 Customizer.class, "LBL_ProfilePath")); gridBagConstraints = new GridBagConstraints(); 325 gridBagConstraints.gridx = 0; 326 gridBagConstraints.gridy = 2; 327 gridBagConstraints.anchor = GridBagConstraints.EAST; 328 gridBagConstraints.insets = new Insets(0, 0, 5, 0); 329 add(domainPathLabel, gridBagConstraints); 330 331 domainPathField.setText(""); domainPathField.setEditable(false); 334 gridBagConstraints = new GridBagConstraints(); 335 gridBagConstraints.gridx = 1; 336 gridBagConstraints.gridy = 2; 337 gridBagConstraints.weightx = 1.0; 338 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 339 gridBagConstraints.insets = new Insets(0, 10, 5, 0); 340 domainPathField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_ProfilePath")); 341 domainPathField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_ProfilePath")); 342 add(domainPathField, gridBagConstraints); 343 344 hostLabel.setText(NbBundle.getMessage(Customizer.class, 346 "LBL_Host")); gridBagConstraints = new GridBagConstraints(); 348 gridBagConstraints.gridx = 0; 349 gridBagConstraints.gridy = 3; 350 gridBagConstraints.anchor = GridBagConstraints.EAST; 351 gridBagConstraints.insets = new Insets(0, 0, 5, 0); 352 add(hostLabel, gridBagConstraints); 353 354 hostField.setText(""); hostField.addKeyListener(new KeyListener()); 357 gridBagConstraints = new GridBagConstraints(); 358 gridBagConstraints.gridx = 1; 359 gridBagConstraints.gridy = 3; 360 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 361 gridBagConstraints.insets = new Insets(0, 10, 5, 0); 362 hostField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Host")); 363 hostField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Host")); 364 add(hostField, gridBagConstraints); 365 hostField.setEditable(false); 366 367 portLabel.setText(NbBundle.getMessage(Customizer.class, 369 "LBL_Port")); gridBagConstraints = new GridBagConstraints(); 371 gridBagConstraints.gridx = 0; 372 gridBagConstraints.gridy = 4; 373 gridBagConstraints.anchor = GridBagConstraints.EAST; 374 gridBagConstraints.insets = new Insets(0, 0, 5, 0); 375 add(portLabel, gridBagConstraints); 376 377 379 portField.setText("8880"); portField.addKeyListener(new KeyListener()); 383 portField.setPreferredSize(new Dimension(50, 20)); 384 portField.setFont(hostField.getFont()); 385 gridBagConstraints = new GridBagConstraints(); 386 gridBagConstraints.gridx = 1; 387 gridBagConstraints.gridy = 4; 388 gridBagConstraints.anchor = GridBagConstraints.WEST; 389 gridBagConstraints.insets = new Insets(0, 10, 5, 0); 390 portField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Port")); 391 portField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Port")); 392 add(portField, gridBagConstraints); 393 portField.setEditable(false); 394 395 userNameLabel.setText(NbBundle.getMessage(Customizer.class, 397 "LBL_Username")); gridBagConstraints = new GridBagConstraints(); 399 gridBagConstraints.gridx = 0; 400 gridBagConstraints.gridy = 5; 401 gridBagConstraints.anchor = GridBagConstraints.EAST; 402 gridBagConstraints.insets = new Insets(0, 0, 5, 0); 403 add(userNameLabel, gridBagConstraints); 404 405 usernameField.setText(""); usernameField.addKeyListener(new KeyListener()); 408 usernameField.setPreferredSize(new Dimension(100, 20)); 409 gridBagConstraints = new GridBagConstraints(); 410 gridBagConstraints.gridx = 1; 411 gridBagConstraints.gridy = 5; 412 gridBagConstraints.anchor = GridBagConstraints.WEST; 413 gridBagConstraints.insets = new Insets(0, 10, 5, 0); 414 usernameField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Username")); 415 usernameField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Username")); 416 add(usernameField, gridBagConstraints); 417 418 passwordLabel.setText(NbBundle.getMessage(Customizer.class, 420 "LBL_Password")); gridBagConstraints = new GridBagConstraints(); 422 gridBagConstraints.gridx = 0; 423 gridBagConstraints.gridy = 6; 424 gridBagConstraints.anchor = GridBagConstraints.EAST; 425 gridBagConstraints.insets = new Insets(0, 0, 5, 0); 426 add(passwordLabel, gridBagConstraints); 427 428 passwordField.setPreferredSize(new Dimension(100, 20)); 430 passwordField.addKeyListener(new KeyListener()); 431 gridBagConstraints = new GridBagConstraints(); 432 gridBagConstraints.gridx = 1; 433 gridBagConstraints.gridy = 6; 434 gridBagConstraints.anchor = GridBagConstraints.WEST; 435 gridBagConstraints.insets = new Insets(0, 10, 5, 0); 436 passwordField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Password")); 437 passwordField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Password")); 438 add(passwordField, gridBagConstraints); 439 440 remoteWarningLabel.setEditable(false); 442 remoteWarningLabel.setWrapStyleWord(true); 443 remoteWarningLabel.setLineWrap(true); 444 remoteWarningLabel.setOpaque(false); 445 remoteWarningLabel.getAccessibleContext().setAccessibleName( 446 java.util.ResourceBundle.getBundle( 447 "org/netbeans/modules/j2ee/websphere6/ui/wizard/Bundle"). 448 getString("TTL_RemoteWarningA11Name")); 449 remoteWarningLabel.getAccessibleContext().setAccessibleDescription( 450 java.util.ResourceBundle.getBundle( 451 "org/netbeans/modules/j2ee/websphere6/ui/wizard/Bundle"). 452 getString("MSG_RemoteWarningA11Description")); 453 454 gridBagConstraints = new GridBagConstraints(); 455 gridBagConstraints.gridx = 0; 456 gridBagConstraints.gridy = 7; 457 gridBagConstraints.gridwidth = 2; 458 gridBagConstraints.fill = GridBagConstraints.BOTH; 459 gridBagConstraints.anchor = GridBagConstraints.NORTH; 460 gridBagConstraints.weighty = 1.0; 461 gridBagConstraints.insets = new Insets(10, 0, 5, 0); 462 add(remoteWarningLabel, gridBagConstraints); 463 464 setMnemonics(domainPathLabel); 465 domainPathLabel.setLabelFor(domainPathField); 466 setMnemonics(serverTypeLabel); 467 serverTypeLabel.setLabelFor(serverTypeCombo); 468 setMnemonics(localInstanceLabel); 469 localInstanceLabel.setLabelFor(localInstancesCombo); 470 setMnemonics(hostLabel); 471 hostLabel.setLabelFor(hostField); 472 setMnemonics(portLabel); 473 portLabel.setLabelFor(portField); 474 setMnemonics(userNameLabel); 475 userNameLabel.setLabelFor(usernameField); 476 setMnemonics(passwordLabel); 477 passwordLabel.setLabelFor(passwordField); 478 479 wizardServerProperties.setVariables(serverTypeCombo,localInstancesCombo, 480 domainPathField,hostField,portField,instantiatingIterator); 481 } 482 483 484 private void setMnemonics(JLabel label) { 485 String name = label.getText(); 486 int index = Mnemonics.findMnemonicAmpersand(name); 487 if(index < 0) { 488 Mnemonics.setLocalizedText(label,name); 489 label.setDisplayedMnemonic(name.charAt(0)); 490 } else { 491 Mnemonics.setLocalizedText(label,name.substring(0,index) + name.substring(index+1)); 492 label.setDisplayedMnemonic(name.charAt(index+1)); 493 } 494 } 495 504 public void readSettings(Object object) { 505 this.wizardDescriptor = (WizardDescriptor) object; 506 } 507 508 512 public void storeSettings(Object object) { 513 } 514 515 521 private Vector listeners = new Vector(); 522 523 528 public void removeChangeListener(ChangeListener listener) { 529 if (listeners != null) { 530 synchronized (listeners) { 531 listeners.remove(listener); 532 } 533 } 534 } 535 536 541 public void addChangeListener(ChangeListener listener) { 542 synchronized (listeners) { 543 listeners.add(listener); 544 } 545 } 546 547 550 private void fireChangeEvent() { 551 ChangeEvent event = new ChangeEvent(this); 552 fireChangeEvent(event); 553 } 554 555 560 private void fireChangeEvent(ChangeEvent event) { 561 Vector targetListeners; 562 synchronized (listeners) { 563 targetListeners = (Vector) listeners.clone(); 564 } 565 566 for (int i = 0; i < targetListeners.size(); i++) { 567 ChangeListener listener = 568 (ChangeListener) targetListeners.elementAt(i); 569 listener.stateChanged(event); 570 } 571 } 572 573 581 public class KeyListener extends KeyAdapter { 582 585 public void keyTyped(KeyEvent event) { 586 fireChangeEvent(); 587 } 588 589 592 public void keyReleased(KeyEvent event) { 593 fireChangeEvent(); 594 } 595 } 596 } | Popular Tags |