1 19 package org.netbeans.modules.j2ee.websphere6.ui; 20 21 import java.util.Vector ; 22 import java.awt.event.*; 23 import javax.swing.*; 24 import org.openide.ErrorManager; 25 import org.openide.util.NbBundle; 26 import org.netbeans.modules.j2ee.websphere6.ui.InstancesModel; 27 import org.netbeans.modules.j2ee.websphere6.WSURIManager; 28 import org.netbeans.modules.j2ee.websphere6.j2ee.DeploymentManagerProperties; 29 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 30 import org.openide.awt.Mnemonics; 31 35 public class ConnectionTabVisualPanel extends javax.swing.JPanel { 36 37 38 private final DeploymentManagerProperties targetData; 39 40 41 42 public class TabServerProperties extends ServerProperties { 43 public TabServerProperties() { 44 super(); 45 } 46 public TabServerProperties(JComboBox serverCombobox, 47 JComboBox localInstancesCombobox, 48 JTextField domainPathField, 49 JTextField hostField, 50 JTextField portField) { 51 super(serverCombobox, 52 localInstancesCombobox, 53 domainPathField, 54 hostField, 55 portField); 56 } 57 public class TabServerTypeActionListener extends ServerTypeActionListener{ 58 public void actionPerformed(ActionEvent e) { 59 super.actionPerformed(e); 60 isValid(); 61 } 62 } 63 } 64 TabServerProperties tabServerProperties=null; 65 66 public ConnectionTabVisualPanel(DeploymentManagerProperties data) { 67 this.targetData=data; 68 initComponents(); 69 tabServerProperties=new TabServerProperties( 70 serverTypeCombo, 71 localInstancesCombo, 72 profilePathField, 73 hostField, 74 portField); 75 InstanceProperties ips = targetData. getInstanceProperties(); 76 ips.refreshServerInstance(); 77 String url = (String ) ips.getProperty("url"); int dex = url.indexOf(WSURIManager.WSURI); 79 if (dex > -1) 80 url = url.substring(dex+WSURIManager.WSURI.length()); 81 82 localInstancesCombo.setModel( 83 new InstancesModel( 84 tabServerProperties.getServerInstances( 85 targetData.getServerRoot()))); 86 for(int i=0;i<localInstancesCombo.getModel().getSize();i++) { 87 if(((Instance)localInstancesCombo.getItemAt(i)).getDomainPath().equals( 88 targetData.getDomainRoot())) { 89 localInstancesCombo.setSelectedIndex(i); 90 break; 91 } 92 } 93 94 96 97 dex=url.indexOf(":"); 98 if(dex>-1) 99 url=url.substring(0,dex); 100 hostField.setText(url); 101 102 103 userNameField.setText(targetData.getUserName()); 104 userNameField.addKeyListener(new java.awt.event.KeyAdapter () { 105 public void keyReleased(java.awt.event.KeyEvent evt) { 106 String userName = userNameField.getText(); 107 targetData.setUserName(userName); 108 } 109 }); 110 111 passwordField.setText(targetData.getPassword()); 112 passwordField.addKeyListener(new java.awt.event.KeyAdapter () { 113 public void keyReleased(java.awt.event.KeyEvent evt) { 114 String password = new String (passwordField.getPassword()); 115 targetData.setPassword(password); 116 } 117 }); 118 119 120 121 profilePathField.setText(targetData.getDomainRoot()); 123 portField.setText(targetData.getPort()); 124 139 167 168 171 Vector types=new Vector (); 172 types.add(NbBundle.getMessage(ConnectionTabVisualPanel.class, "TXT_ServerTypeLocal")); 173 types.add(NbBundle.getMessage(ConnectionTabVisualPanel.class,"TXT_ServerTypeRemote")); 174 serverTypeCombo.setModel(new InstancesModel(types)); 175 176 178 190 191 portField.setEditable(false); 192 hostField.setEditable(false); 194 String getLocal=targetData.getIsLocal(); 195 if(getLocal!=null) 196 serverTypeCombo.setSelectedItem(getLocal.equals("true")? 197 NbBundle.getMessage(ConnectionTabVisualPanel.class, "TXT_ServerTypeLocal"): 198 NbBundle.getMessage(ConnectionTabVisualPanel.class, "TXT_ServerTypeRemote")); 199 200 202 setMnemonics(jLabel1); 203 setMnemonics(jLabel2); 204 setMnemonics(jLabel3); 205 setMnemonics(jLabel4); 206 setMnemonics(jLabel5); 207 setMnemonics(jLabel6); 208 setMnemonics(jLabel7); 209 210 } 211 private void setMnemonics(JLabel label) { 212 String name = label.getText(); 213 int index = Mnemonics.findMnemonicAmpersand(name); 214 if(index < 0) { 215 Mnemonics.setLocalizedText(label,name); 216 label.setDisplayedMnemonic(name.charAt(0)); 217 } else { 218 Mnemonics.setLocalizedText(label,name.substring(0,index) + name.substring(index+1)); 219 label.setDisplayedMnemonic(name.charAt(index+1)); 220 } 221 } 222 223 228 public boolean isValid() { 229 230 if (serverTypeCombo.getSelectedItem().equals(NbBundle.getMessage( 233 ConnectionTabVisualPanel.class, 234 "TXT_ServerTypeLocal"))) { if (!tabServerProperties.isValidDomainRoot(profilePathField.getText())) { 236 JOptionPane.showMessageDialog(null, 237 NbBundle.getMessage(ConnectionTabVisualPanel.class, 238 "ERR_InvalidDomainRoot")); return false; 240 } 241 } 242 243 if (hostField.getText().trim().equals("")) { 245 JOptionPane.showMessageDialog(null, 246 NbBundle.getMessage(ConnectionTabVisualPanel.class, 247 "ERR_InvalidHost")); return false; 249 } 250 251 if (!portField.getText().trim().matches("[0-9]+")) { 255 JOptionPane.showMessageDialog(null, 256 NbBundle.getMessage(ConnectionTabVisualPanel.class, 257 "ERR_InvalidPort")); return false; 259 } 260 261 263 265 targetData.setDomainRoot(profilePathField.getText()); 266 targetData.setHost(hostField.getText()); 267 targetData.setPort(portField.getText()); 269 targetData.setUserName(userNameField.getText()); 270 targetData.setPassword(new String ( 271 passwordField.getPassword())); 272 273 targetData.setIsLocal(serverTypeCombo.getSelectedItem(). 274 equals(NbBundle.getMessage(ConnectionTabVisualPanel.class, 275 "TXT_ServerTypeLocal")) ? "true" : "false"); 277 targetData.setServerName(((Instance) localInstancesCombo. 278 getSelectedItem()).getName()); 279 targetData.setConfigXmlPath(((Instance) localInstancesCombo. 280 getSelectedItem()).getConfigXmlPath()); 281 282 targetData.getInstanceProperties().refreshServerInstance(); 283 return true; 285 } 286 287 288 289 294 private void initComponents() { 296 jLabel2 = new javax.swing.JLabel (); 297 serverTypeCombo = new javax.swing.JComboBox (); 298 jLabel3 = new javax.swing.JLabel (); 299 localInstancesCombo = new javax.swing.JComboBox (); 300 jLabel4 = new javax.swing.JLabel (); 301 jLabel5 = new javax.swing.JLabel (); 302 hostField = new javax.swing.JTextField (); 303 jLabel6 = new javax.swing.JLabel (); 304 jLabel7 = new javax.swing.JLabel (); 305 userNameField = new javax.swing.JTextField (); 306 passwordField = new javax.swing.JPasswordField (); 307 profilePathField = new javax.swing.JTextField (); 308 jLabel1 = new javax.swing.JLabel (); 309 portField = new javax.swing.JTextField (); 310 311 jLabel2.setLabelFor(serverTypeCombo); 312 jLabel2.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("LBL_LocalRemote")); 313 314 serverTypeCombo.setEnabled(false); 315 serverTypeCombo.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_AccessMethod")); 316 serverTypeCombo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_AccessMethodDescription")); 317 318 jLabel3.setLabelFor(localInstancesCombo); 319 jLabel3.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("LBL_LocalInstances")); 320 jLabel3.getAccessibleContext().setAccessibleName("Local Instances Label"); 321 322 localInstancesCombo.setEnabled(false); 323 localInstancesCombo.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_LocalInstances")); 324 localInstancesCombo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_LocalInstances")); 325 326 jLabel4.setLabelFor(hostField); 327 jLabel4.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("LBL_Host")); 328 jLabel4.getAccessibleContext().setAccessibleName("Host Label"); 329 330 jLabel5.setLabelFor(portField); 331 jLabel5.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("LBL_Port")); 332 jLabel5.getAccessibleContext().setAccessibleName("Port Label"); 333 334 hostField.setEditable(false); 335 hostField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Host")); 336 hostField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Host")); 337 338 jLabel6.setLabelFor(userNameField); 339 jLabel6.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("LBL_Username")); 340 jLabel6.getAccessibleContext().setAccessibleName("Username Label"); 341 342 jLabel7.setLabelFor(passwordField); 343 jLabel7.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("LBL_Password")); 344 jLabel7.getAccessibleContext().setAccessibleName("Password Label"); 345 346 userNameField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Username")); 347 userNameField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Username")); 348 349 passwordField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Password")); 350 passwordField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Password")); 351 352 profilePathField.setEditable(false); 353 profilePathField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_ProfilePath")); 354 profilePathField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_ProfilePath")); 355 356 jLabel1.setLabelFor(profilePathField); 357 jLabel1.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("LBL_ProfilePath")); 358 359 portField.setEditable(false); 360 portField.addFocusListener(new java.awt.event.FocusAdapter () { 361 public void focusLost(java.awt.event.FocusEvent evt) { 362 portFieldFocusLost(evt); 363 } 364 }); 365 366 portField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Port")); 367 portField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Port")); 368 369 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 370 this.setLayout(layout); 371 layout.setHorizontalGroup( 372 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 373 .add(layout.createSequentialGroup() 374 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 375 .add(layout.createSequentialGroup() 376 .addContainerGap() 377 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 378 .add(jLabel3) 379 .add(jLabel2) 380 .add(jLabel1)) 381 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 382 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) 383 .add(serverTypeCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 384 .add(localInstancesCombo, 0, 320, Short.MAX_VALUE) 385 .add(profilePathField))) 386 .add(layout.createSequentialGroup() 387 .add(36, 36, 36) 388 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 389 .add(jLabel7) 390 .add(jLabel6) 391 .add(jLabel5)) 392 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 393 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 394 .add(portField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 65, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 395 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) 396 .add(passwordField) 397 .add(userNameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 117, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) 398 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 399 .add(62, 62, 62) 400 .add(jLabel4) 401 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 402 .add(hostField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE))) 403 .addContainerGap()) 404 ); 405 layout.setVerticalGroup( 406 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 407 .add(layout.createSequentialGroup() 408 .addContainerGap() 409 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 410 .add(jLabel2) 411 .add(serverTypeCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 412 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 413 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 414 .add(jLabel3) 415 .add(localInstancesCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 416 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 417 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 418 .add(profilePathField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 419 .add(jLabel1)) 420 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 421 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 422 .add(jLabel4) 423 .add(hostField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 424 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 425 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 426 .add(jLabel5) 427 .add(portField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 428 .add(8, 8, 8) 429 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 430 .add(jLabel6) 431 .add(userNameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 432 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 433 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 434 .add(passwordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 435 .add(jLabel7)) 436 .addContainerGap()) 437 ); 438 } 440 private void portFieldFocusLost(java.awt.event.FocusEvent evt) { String port = portField.getText(); 442 if(!port.trim().matches("[0-9]+")){ 443 JOptionPane.showMessageDialog(portField,NbBundle.getMessage(ConnectionTabVisualPanel.class,"ERR_InvalidPort")); 444 } else if((new java.lang.Integer (port)).intValue() > 65535) { 445 JOptionPane.showMessageDialog(portField,NbBundle.getMessage(ConnectionTabVisualPanel.class,"ERR_InvalidPort")); 446 } else { 447 targetData.setPort(port); 448 } 449 } 451 452 private javax.swing.JTextField hostField; 454 private javax.swing.JLabel jLabel1; 455 private javax.swing.JLabel jLabel2; 456 private javax.swing.JLabel jLabel3; 457 private javax.swing.JLabel jLabel4; 458 private javax.swing.JLabel jLabel5; 459 private javax.swing.JLabel jLabel6; 460 private javax.swing.JLabel jLabel7; 461 private javax.swing.JComboBox localInstancesCombo; 462 private javax.swing.JPasswordField passwordField; 463 private javax.swing.JTextField portField; 464 private javax.swing.JTextField profilePathField; 465 private javax.swing.JComboBox serverTypeCombo; 466 private javax.swing.JTextField userNameField; 467 469 470 471 472 473 474 475 476 477 484 private class ServerTypeActionListener implements ActionListener { 485 489 490 public void actionPerformed(ActionEvent e) { 491 if (serverTypeCombo.getSelectedItem().equals(NbBundle. 493 getMessage(ServerProperties.class, 494 "TXT_ServerTypeLocal"))) { Instance instance = (Instance) localInstancesCombo. 496 getSelectedItem(); 497 498 localInstancesCombo.setEnabled(true); 500 501 profilePathField.setEnabled(true); 503 profilePathField.setEditable(false); 504 505 hostField.setEnabled(true); 507 hostField.setEditable(false); 508 hostField.setText(instance.getHost()); 509 510 portField.setEnabled(true); 515 portField.setEditable(false); 516 portField.setText(instance.getPort()); 518 519 } else { 520 localInstancesCombo.setEnabled(false); 522 523 profilePathField.setEnabled(false); 525 profilePathField.setEditable(false); 526 527 hostField.setEnabled(true); 529 hostField.setEditable(false); 530 531 portField.setEnabled(true); 533 portField.setEditable(true); 534 } 536 537 isValid(); 538 } 539 } 540 544 public void updateInstancesList() { 545 localInstancesCombo.setModel( 546 new InstancesModel( 547 tabServerProperties.getServerInstances( 548 targetData.getServerRoot()))); 549 updateInstanceInfo(); 550 } 551 552 556 private void updateInstanceInfo() { 557 Instance instance = (Instance) localInstancesCombo.getSelectedItem(); 559 560 profilePathField.setText(instance.getDomainPath()); 562 hostField.setText(instance.getHost()); 563 portField.setText(instance.getPort()); 565 } 566 572 private class InstanceSelectionListener implements ActionListener { 573 577 public void actionPerformed(ActionEvent e) { 578 updateInstanceInfo(); 579 } 580 } 581 582 583 584 585 } 586 | Popular Tags |