1 19 package org.netbeans.modules.j2ee.jboss4.ide.ui; 20 21 import java.awt.Color ; 22 import java.awt.Dimension ; 23 import java.awt.GridBagConstraints ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 import java.awt.event.InputMethodEvent ; 27 import java.awt.event.InputMethodListener ; 28 import java.awt.event.KeyEvent ; 29 import java.awt.event.KeyListener ; 30 import java.io.File ; 31 import java.util.Enumeration ; 32 import java.util.HashSet ; 33 import java.util.Hashtable ; 34 import java.util.Iterator ; 35 import java.util.Set ; 36 import javax.swing.AbstractListModel ; 37 import javax.swing.BorderFactory ; 38 import javax.swing.ComboBoxModel ; 39 import javax.swing.JButton ; 40 import javax.swing.JComboBox ; 41 import javax.swing.JFileChooser ; 42 import javax.swing.JFrame ; 43 import javax.swing.JLabel ; 44 import javax.swing.JPanel ; 45 import javax.swing.JPasswordField ; 46 import javax.swing.JTextField ; 47 import javax.swing.event.ChangeEvent ; 48 import javax.swing.event.ChangeListener ; 49 import org.openide.util.NbBundle; 50 51 52 56 public class AddServerPropertiesVisualPanel extends JPanel { 57 58 private final Set listeners = new HashSet (); 59 60 private javax.swing.JComboBox domainField; private javax.swing.JTextField domainPathField; private javax.swing.JLabel domainLabel; 63 private javax.swing.JLabel domainPathLabel; 64 private javax.swing.JLabel label1; 65 private javax.swing.JPanel panel1; 66 private javax.swing.JLabel hostLabel; 67 private javax.swing.JTextField hostField; 68 private javax.swing.JLabel portLabel; 69 private javax.swing.JTextField portField; 70 private javax.swing.JLabel userLabel; 71 private javax.swing.JTextField userField; 72 private javax.swing.JLabel passwordLabel; 73 private javax.swing.JPasswordField passwordField; 74 private javax.swing.JComboBox serverType; 76 77 78 public AddServerPropertiesVisualPanel() { 79 init(); 80 setName(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "TITLE_ServerProperties")); } 82 83 public void addChangeListener(ChangeListener l) { 84 synchronized (listeners) { 85 listeners.add(l); 86 } 87 } 88 89 public void removeChangeListener(ChangeListener l ) { 90 synchronized (listeners) { 91 listeners.remove(l); 92 } 93 } 94 95 private void somethingChanged() { 96 fireChangeEvent(); 97 } 98 99 private void fireChangeEvent() { 100 Iterator it; 101 synchronized (listeners) { 102 it = new HashSet (listeners).iterator(); 103 } 104 ChangeEvent ev = new ChangeEvent (this); 105 while (it.hasNext()) { 106 ((ChangeListener )it.next()).stateChanged(ev); 107 } 108 } 109 110 public boolean isLocalServer(){ 111 if (serverType.getSelectedItem().equals("Local")) 112 return true; 113 else 114 return false; 115 } 116 117 public String getHost(){ 118 return hostField.getText().trim(); 119 } 120 121 public String getPort(){ 122 return portField.getText().trim(); 123 } 124 125 public String getUser(){ 126 return userField.getText(); 127 } 128 129 public String getPassword(){ 130 return new String (passwordField.getPassword()); 131 } 132 133 public String getDomainPath(){ 134 return domainPathField.getText(); 135 } 136 137 public String getDomain(){ 138 return (String )domainField.getSelectedItem(); 139 } 140 141 private void domainChanged(){ 142 DomainComboModel model = (DomainComboModel)domainField.getModel(); 143 144 String path = model.getCurrentPath(); 145 domainPathField.setText(path); 146 portField.setText(JBPluginUtils.getHTTPConnectorPort(path)); 147 148 fireChangeEvent(); 150 } 151 152 void installLocationChanged() { 153 DomainComboModel domainModel = (DomainComboModel) domainField.getModel(); 154 String serverLocation = JBPluginProperties.getInstance().getInstallLocation(); 155 domainModel.setDomains(JBPluginUtils.getRegisteredDomains(serverLocation)); 156 domainChanged(); 157 } 158 159 private void serverTypeChanged(){ 160 161 if (serverType.getSelectedItem().equals("Local")){ domainLabel.setVisible(true); 163 domainField.setVisible(true); 164 165 domainPathLabel.setVisible(true); 166 domainPathField.setVisible(true); 167 169 hostField.setEditable(false); 170 172 174 }else{ 176 domainLabel.setVisible(false); 177 domainField.setVisible(false); 178 179 domainPathLabel.setVisible(false); 180 domainPathField.setVisible(false); 181 183 186 hostField.setEditable(true); 187 portField.setEditable(true); 188 } 189 190 somethingChanged(); 191 } 192 193 private void init(){ 194 195 197 java.awt.GridBagConstraints gridBagConstraints; 198 199 label1 = new JLabel (NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "TXT_PROPERTY_TEXT")); 201 serverType = new JComboBox (new String []{"Local","Remote"}); serverType.addActionListener(new ActionListener (){ 203 public void actionPerformed(ActionEvent e) { 204 serverTypeChanged(); 205 } 206 }); 207 208 domainLabel = new JLabel (NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Domain")); domainPathLabel = new JLabel (NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_DomainPath")); domainPathField = new JTextField (); 211 domainPathField.setColumns(20); 212 domainPathField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_DomainPath")); 213 domainPathField.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_DomainPath")); 214 215 216 panel1 = new JPanel (); 217 218 String serverLocation = JBPluginProperties.getInstance().getInstallLocation(); 220 domainField = new JComboBox (new DomainComboModel(JBPluginUtils.getRegisteredDomains(serverLocation))); 221 domainField.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Domain")); 222 domainField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Domain")); 223 domainField.addActionListener(new ActionListener (){ 225 public void actionPerformed(ActionEvent e) { 226 domainChanged(); 227 } 228 }); 229 230 231 232 hostLabel = new JLabel (NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Host")); hostField = new JTextField (); 234 hostField.setColumns(20); 235 hostField.setEditable(false); 236 hostField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Host")); 237 hostField.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Host")); 238 hostField.addKeyListener(new SomeChangesListener()); 239 240 hostLabel.setLabelFor(hostField); 241 242 portLabel = new JLabel (NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Port")); portField = new JTextField (); 244 portField.setColumns(20); 245 portField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Port")); 246 portField.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Port")); 247 portField.addKeyListener(new SomeChangesListener()); 249 250 portLabel.setLabelFor(portField); 251 252 userLabel = new JLabel (NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_User")); userField = new JTextField (); 254 userField.addKeyListener(new SomeChangesListener()); 255 256 passwordLabel = new JLabel (NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Password")); passwordField = new JPasswordField (); 258 passwordField.addKeyListener(new SomeChangesListener()); 259 260 261 setLayout(new java.awt.GridBagLayout ()); 262 263 setFocusable(false); 264 265 setMinimumSize(new java.awt.Dimension (280, 217)); 266 268 269 gridBagConstraints = new java.awt.GridBagConstraints (); 271 gridBagConstraints.gridwidth = 3; 272 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 273 gridBagConstraints.weightx = 1.0; 274 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 275 add(label1, gridBagConstraints); 276 277 278 279 gridBagConstraints = new java.awt.GridBagConstraints (); 280 gridBagConstraints.gridy = 0; 281 gridBagConstraints.gridx = 2; 282 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 283 284 add(serverType, gridBagConstraints); 285 286 287 gridBagConstraints = new java.awt.GridBagConstraints (); 289 gridBagConstraints.gridx = 0; 290 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 291 gridBagConstraints.anchor = GridBagConstraints.WEST; 292 add(domainLabel, gridBagConstraints); 293 294 295 gridBagConstraints = new java.awt.GridBagConstraints (); 296 gridBagConstraints.gridy = 1; 297 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 298 gridBagConstraints.weightx = 1.0; 299 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 300 add(domainField, gridBagConstraints); 301 302 303 304 305 gridBagConstraints = new java.awt.GridBagConstraints (); 307 gridBagConstraints.gridx = 0; 308 gridBagConstraints.gridy = 2; 309 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 310 add(domainPathLabel, gridBagConstraints); 311 312 gridBagConstraints = new java.awt.GridBagConstraints (); 313 gridBagConstraints.gridy = 2; 314 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 315 gridBagConstraints.weightx = 1.0; 316 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 317 add(domainPathField, gridBagConstraints); 318 319 325 326 327 328 329 gridBagConstraints = new java.awt.GridBagConstraints (); 331 gridBagConstraints.gridx = 0; 332 gridBagConstraints.gridy = 3; 333 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 334 gridBagConstraints.anchor = GridBagConstraints.WEST; 335 add(hostLabel, gridBagConstraints); 336 337 338 gridBagConstraints = new java.awt.GridBagConstraints (); 339 gridBagConstraints.gridy = 3; 340 gridBagConstraints.gridx = 1; 341 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 342 gridBagConstraints.weightx = 1.0; 343 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 344 add(hostField, gridBagConstraints); 345 346 347 gridBagConstraints = new java.awt.GridBagConstraints (); 349 gridBagConstraints.gridx = 0; 350 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 351 gridBagConstraints.anchor = GridBagConstraints.WEST; 352 add(portLabel, gridBagConstraints); 353 354 355 gridBagConstraints = new java.awt.GridBagConstraints (); 356 gridBagConstraints.gridy = 4; 357 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 358 gridBagConstraints.weightx = 1.0; 359 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 360 add(portField, gridBagConstraints); 361 362 363 gridBagConstraints = new java.awt.GridBagConstraints (); 365 gridBagConstraints.gridx = 0; 366 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 367 gridBagConstraints.anchor = GridBagConstraints.WEST; 368 add(userLabel, gridBagConstraints); 369 370 371 gridBagConstraints = new java.awt.GridBagConstraints (); 372 gridBagConstraints.gridy = 5; 373 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 374 gridBagConstraints.weightx = 1.0; 375 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 376 add(userField, gridBagConstraints); 377 378 379 380 gridBagConstraints = new java.awt.GridBagConstraints (); 382 gridBagConstraints.gridx = 0; 383 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 384 gridBagConstraints.anchor = GridBagConstraints.WEST; 385 add(passwordLabel, gridBagConstraints); 386 387 388 gridBagConstraints = new java.awt.GridBagConstraints (); 389 gridBagConstraints.gridy = 6; 390 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 391 gridBagConstraints.weightx = 1.0; 392 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 5); 393 add(passwordField, gridBagConstraints); 394 395 gridBagConstraints = new java.awt.GridBagConstraints (); 397 gridBagConstraints.gridx = 0; 398 gridBagConstraints.gridwidth = 3; 399 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 400 gridBagConstraints.weightx = 1.0; 401 gridBagConstraints.weighty = 1.0; 402 403 404 domainPathField.setEnabled(false); 405 portField.setEditable(false); 406 407 userField.setVisible(false); 408 userLabel.setVisible(false); 409 passwordField.setVisible(false); 410 passwordLabel.setVisible(false); 411 412 413 serverType.setVisible(false); 414 415 add(panel1, gridBagConstraints); 416 417 hostField.setText("localhost"); portField.setText(JBPluginUtils.getHTTPConnectorPort(domainPathField.getText())); domainChanged(); 421 422 } 423 424 425 class SomeChangesListener implements KeyListener { 426 427 public void keyTyped(KeyEvent e){} 428 429 public void keyPressed(KeyEvent e){} 430 431 public void keyReleased(KeyEvent e){ somethingChanged();} 432 433 } 434 435 private String browseDomainLocation(){ 436 String insLocation = null; 437 JFileChooser chooser = getJFileChooser(); 438 int returnValue = chooser.showDialog(this, NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_ChooseButton")); 440 if(returnValue == JFileChooser.APPROVE_OPTION){ 441 insLocation = chooser.getSelectedFile().getAbsolutePath(); 442 } 443 return insLocation; 444 } 445 446 private JFileChooser getJFileChooser(){ 447 JFileChooser chooser = new JFileChooser (); 448 449 chooser.setDialogTitle("LBL_Chooser_Name"); chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); 451 452 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 453 chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); chooser.setMultiSelectionEnabled(false); 455 chooser.addChoosableFileFilter(new dirFilter()); 456 chooser.setAcceptAllFileFilterUsed(false); 457 chooser.setApproveButtonToolTipText("LBL_Chooser_Name"); 459 chooser.getAccessibleContext().setAccessibleName("LBL_Chooser_Name"); chooser.getAccessibleContext().setAccessibleDescription("LBL_Chooser_Name"); 462 return chooser; 463 } 464 465 private static class dirFilter extends javax.swing.filechooser.FileFilter { 466 467 public boolean accept(File f) { 468 if(!f.exists() || !f.canRead() || !f.isDirectory() ) { 469 return false; 470 }else{ 471 return true; 472 } 473 } 474 475 public String getDescription() { 476 return NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_DirType"); } 478 479 } 480 481 } 482 483 484 class DomainComboModel extends AbstractListModel implements ComboBoxModel { 485 private int current = -1; 486 private String [][] domains = null; 487 488 489 public void addDomain(String domain, String path){ 490 String [][] newDomains = new String [domains.length+1][2]; 491 int i = 0; 492 for(;i<domains.length; i++){ 493 newDomains[i][0] = domains[i][0]; 494 newDomains[i][1] = domains[i][1]; 495 } 496 newDomains[i][0] = domain; 497 newDomains[i][1] = path; 498 domains = newDomains; 499 500 } 501 502 public DomainComboModel(Hashtable domains){ 503 setDomains(domains); 504 } 505 506 public void setDomains(Hashtable domains) { 507 508 current = -1; 509 this.domains = null; 510 511 int len = domains.size(); 512 this.domains = new String [len][2]; 513 Enumeration en = domains.keys(); 514 515 if (len > 0) current = 0; 516 517 int i = 0; 518 while(en.hasMoreElements()){ 519 this.domains[i][0] = (String )en.nextElement(); 520 this.domains[i][1] = (String )domains.get(this.domains[i][0]); 521 if(this.domains[i][0].equalsIgnoreCase("default")) current=i; 523 i++; 524 } 525 } 526 527 public Object getSelectedItem() { 528 if (current ==-1 ) 529 return ""; 530 return domains[current][0]; 531 } 532 533 public void setSelectedItem(Object anItem) { 534 for (int i = 0; i < getSize(); i++){ 535 if (domains[i][0].equals(anItem)){ 536 current = i; 537 fireContentsChanged(this, -1, -1); 538 return; 539 } 540 } 541 current = -1; 542 fireContentsChanged(this, -1, -1); 544 } 545 546 public Object getElementAt(int index){ 547 return domains[index][0]; 548 } 549 550 public int getSize(){ 551 return domains.length; 552 } 553 555 public String getCurrentPath(){ 556 if (current == -1) return ""; 557 return domains[current][1]; 558 } 559 560 public boolean hasDomain(String domain){ 561 for (int i = 0; i < getSize(); i++){ 562 if (domains[i][0].equals(domain)){ 563 return true; 564 } 565 } 566 return false; 567 } 568 569 } 570 571 572 573 574 575 | Popular Tags |