1 19 20 package org.netbeans.modules.tomcat5.wizard; 21 22 import java.io.File ; 23 import java.io.FilenameFilter ; 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.Properties ; 29 import javax.swing.JFileChooser ; 30 import javax.swing.SwingUtilities ; 31 import javax.swing.event.ChangeEvent ; 32 import javax.swing.event.ChangeListener ; 33 import javax.swing.event.DocumentEvent ; 34 import javax.swing.event.DocumentListener ; 35 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 36 import org.netbeans.modules.tomcat5.TomcatFactory; 37 import org.netbeans.modules.tomcat5.TomcatManager.TomcatVersion; 38 import org.netbeans.modules.tomcat5.config.gen.Server; 39 import org.netbeans.modules.tomcat5.util.TomcatInstallUtil; 40 import org.netbeans.modules.tomcat5.util.TomcatProperties; 41 import org.openide.ErrorManager; 42 import org.openide.util.NbBundle; 43 import org.openide.util.RequestProcessor; 44 45 46 51 class InstallPanelVisual extends javax.swing.JPanel { 52 53 private final String SERVER_XML = "conf/server.xml"; 55 private final List listeners = new ArrayList (); 56 private final TomcatVersion tomcatVersion; 57 58 private String errorMessage; 59 60 private String serverPort; 61 private String shutdownPort; 62 63 private RequestProcessor.Task validationTask; 64 65 66 67 public InstallPanelVisual(TomcatVersion tomcatVersion) { 68 this.tomcatVersion = tomcatVersion; 69 initComponents(); 70 DocumentListener updateListener = new DocumentListener () { 71 public void changedUpdate(DocumentEvent e) { 72 fireChange(); 73 } 74 75 public void removeUpdate(DocumentEvent e) { 76 fireChange(); 77 } 78 79 public void insertUpdate(DocumentEvent e) { 80 fireChange(); 81 } 82 }; 83 jTextFieldHomeDir.getDocument().addDocumentListener(updateListener); 84 jTextFieldBaseDir.getDocument().addDocumentListener(updateListener); 85 addChangeListener(new ChangeListener () { 86 public void stateChanged(ChangeEvent e) { 87 if (isJWSDP()) { 89 if (jCheckBoxShared.isEnabled()) { 90 jCheckBoxShared.setEnabled(false); 91 setBaseEnabled(false); 92 } 93 } else { 94 if (!jCheckBoxShared.isEnabled()) { 95 jCheckBoxShared.setEnabled(true); 96 if (jCheckBoxShared.isSelected()) { 97 setBaseEnabled(true); 98 } 99 } 100 } 101 } 102 }); 103 } 104 105 public void addChangeListener(ChangeListener l) { 106 synchronized (listeners) { 107 listeners.add(l); 108 } 109 } 110 111 public void removeChangeListener(ChangeListener l) { 112 synchronized (listeners) { 113 listeners.remove(l); 114 } 115 } 116 117 122 private void initComponents() { 124 java.awt.GridBagConstraints gridBagConstraints; 125 126 jLabelHomeDir = new javax.swing.JLabel (); 127 jLabelBaseDir = new javax.swing.JLabel (); 128 jTextFieldHomeDir = new javax.swing.JTextField (); 129 jTextFieldBaseDir = new javax.swing.JTextField (); 130 jButtonBaseBrowse = new javax.swing.JButton (); 131 jButtonHomeBrowse = new javax.swing.JButton (); 132 jCheckBoxShared = new javax.swing.JCheckBox (); 133 jLabelUsername = new javax.swing.JLabel (); 134 jLabelPassword = new javax.swing.JLabel (); 135 jLabel1 = new javax.swing.JLabel (); 136 jPanel1 = new javax.swing.JPanel (); 137 jTextFieldUsername = new javax.swing.JTextField (); 138 jLabel2 = new javax.swing.JLabel (); 139 jPanel2 = new javax.swing.JPanel (); 140 jTextFieldPassword = new javax.swing.JPasswordField (); 141 jLabel3 = new javax.swing.JLabel (); 142 143 setLayout(new java.awt.GridBagLayout ()); 144 145 setName(org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_InstanceProperties")); 146 getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_panel")); 147 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_panel")); 148 jLabelHomeDir.setLabelFor(jTextFieldHomeDir); 149 org.openide.awt.Mnemonics.setLocalizedText(jLabelHomeDir, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_home_dir")); 150 gridBagConstraints = new java.awt.GridBagConstraints (); 151 gridBagConstraints.gridx = 0; 152 gridBagConstraints.gridy = 1; 153 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 154 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 155 add(jLabelHomeDir, gridBagConstraints); 156 jLabelHomeDir.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_labelHomeDir")); 157 jLabelHomeDir.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_labelHomeDir")); 158 159 jLabelBaseDir.setLabelFor(jTextFieldBaseDir); 160 org.openide.awt.Mnemonics.setLocalizedText(jLabelBaseDir, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_base_dir")); 161 jLabelBaseDir.setEnabled(false); 162 gridBagConstraints = new java.awt.GridBagConstraints (); 163 gridBagConstraints.gridx = 0; 164 gridBagConstraints.gridy = 3; 165 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 166 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 167 add(jLabelBaseDir, gridBagConstraints); 168 jLabelBaseDir.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_labelBaseDir")); 169 jLabelBaseDir.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_labelBaseDir")); 170 171 jTextFieldHomeDir.setColumns(15); 172 gridBagConstraints = new java.awt.GridBagConstraints (); 173 gridBagConstraints.gridx = 1; 174 gridBagConstraints.gridy = 1; 175 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 176 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 177 gridBagConstraints.weightx = 1.0; 178 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 179 add(jTextFieldHomeDir, gridBagConstraints); 180 jTextFieldHomeDir.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_homeDir")); 181 jTextFieldHomeDir.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_homeDir")); 182 183 jTextFieldBaseDir.setColumns(15); 184 jTextFieldBaseDir.setEnabled(false); 185 gridBagConstraints = new java.awt.GridBagConstraints (); 186 gridBagConstraints.gridx = 1; 187 gridBagConstraints.gridy = 3; 188 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 189 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 190 gridBagConstraints.weightx = 2.0; 191 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 192 add(jTextFieldBaseDir, gridBagConstraints); 193 jTextFieldBaseDir.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_baseDir")); 194 jTextFieldBaseDir.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_baseDir")); 195 196 org.openide.awt.Mnemonics.setLocalizedText(jButtonBaseBrowse, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_file_chooser_base")); 197 jButtonBaseBrowse.setEnabled(false); 198 jButtonBaseBrowse.addActionListener(new java.awt.event.ActionListener () { 199 public void actionPerformed(java.awt.event.ActionEvent evt) { 200 jButtonBaseBrowseActionPerformed(evt); 201 } 202 }); 203 204 gridBagConstraints = new java.awt.GridBagConstraints (); 205 gridBagConstraints.gridx = 2; 206 gridBagConstraints.gridy = 3; 207 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 208 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 209 add(jButtonBaseBrowse, gridBagConstraints); 210 jButtonBaseBrowse.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_ButtonBaseBrowse")); 211 jButtonBaseBrowse.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_ButtonBaseBrowse")); 212 213 org.openide.awt.Mnemonics.setLocalizedText(jButtonHomeBrowse, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_file_chooser_home")); 214 jButtonHomeBrowse.addActionListener(new java.awt.event.ActionListener () { 215 public void actionPerformed(java.awt.event.ActionEvent evt) { 216 jButtonHomeBrowseActionPerformed(evt); 217 } 218 }); 219 220 gridBagConstraints = new java.awt.GridBagConstraints (); 221 gridBagConstraints.gridx = 2; 222 gridBagConstraints.gridy = 1; 223 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 224 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 225 add(jButtonHomeBrowse, gridBagConstraints); 226 jButtonHomeBrowse.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_ButtonHomeBrowse")); 227 jButtonHomeBrowse.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_ButtonHomeBrowse")); 228 229 org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxShared, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_SharedInstall")); 230 jCheckBoxShared.addActionListener(new java.awt.event.ActionListener () { 231 public void actionPerformed(java.awt.event.ActionEvent evt) { 232 jCheckBoxSharedActionPerformed(evt); 233 } 234 }); 235 236 gridBagConstraints = new java.awt.GridBagConstraints (); 237 gridBagConstraints.gridx = 0; 238 gridBagConstraints.gridy = 2; 239 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 240 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 241 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 242 add(jCheckBoxShared, gridBagConstraints); 243 jCheckBoxShared.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_shared")); 244 jCheckBoxShared.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_shared")); 245 246 jLabelUsername.setLabelFor(jTextFieldUsername); 247 org.openide.awt.Mnemonics.setLocalizedText(jLabelUsername, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_Username")); 248 gridBagConstraints = new java.awt.GridBagConstraints (); 249 gridBagConstraints.gridx = 0; 250 gridBagConstraints.gridy = 4; 251 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 252 gridBagConstraints.insets = new java.awt.Insets (11, 0, 0, 0); 253 add(jLabelUsername, gridBagConstraints); 254 jLabelUsername.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_labelUsername")); 255 jLabelUsername.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_labelUsername")); 256 257 jLabelPassword.setLabelFor(jTextFieldPassword); 258 org.openide.awt.Mnemonics.setLocalizedText(jLabelPassword, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_Password")); 259 gridBagConstraints = new java.awt.GridBagConstraints (); 260 gridBagConstraints.gridx = 0; 261 gridBagConstraints.gridy = 5; 262 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 263 gridBagConstraints.weighty = 1.0; 264 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 265 add(jLabelPassword, gridBagConstraints); 266 jLabelPassword.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_labelPassword")); 267 jLabelPassword.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_labelPassword")); 268 269 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "MSG_TextAbove")); 270 gridBagConstraints = new java.awt.GridBagConstraints (); 271 gridBagConstraints.gridx = 0; 272 gridBagConstraints.gridy = 0; 273 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 274 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 275 add(jLabel1, gridBagConstraints); 276 277 jPanel1.setLayout(new java.awt.GridBagLayout ()); 278 279 jTextFieldUsername.setColumns(15); 280 gridBagConstraints = new java.awt.GridBagConstraints (); 281 gridBagConstraints.gridx = 0; 282 gridBagConstraints.gridy = 0; 283 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 284 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 285 gridBagConstraints.weightx = 1.0; 286 gridBagConstraints.insets = new java.awt.Insets (11, 5, 0, 0); 287 jPanel1.add(jTextFieldUsername, gridBagConstraints); 288 jTextFieldUsername.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_username")); 289 jTextFieldUsername.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_username")); 290 291 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_ForManager")); 292 gridBagConstraints = new java.awt.GridBagConstraints (); 293 gridBagConstraints.gridx = 1; 294 gridBagConstraints.gridy = 0; 295 gridBagConstraints.gridwidth = 2; 296 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 297 gridBagConstraints.insets = new java.awt.Insets (11, 5, 0, 0); 298 jPanel1.add(jLabel2, gridBagConstraints); 299 300 gridBagConstraints = new java.awt.GridBagConstraints (); 301 gridBagConstraints.gridx = 1; 302 gridBagConstraints.gridy = 4; 303 gridBagConstraints.gridwidth = 2; 304 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 305 gridBagConstraints.weightx = 1.0; 306 add(jPanel1, gridBagConstraints); 307 308 jPanel2.setLayout(new java.awt.GridBagLayout ()); 309 310 jTextFieldPassword.setColumns(15); 311 gridBagConstraints = new java.awt.GridBagConstraints (); 312 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 313 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 314 gridBagConstraints.weightx = 1.0; 315 gridBagConstraints.weighty = 1.0; 316 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 317 jPanel2.add(jTextFieldPassword, gridBagConstraints); 318 jTextFieldPassword.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_password")); 319 jTextFieldPassword.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_password")); 320 321 jLabel3.setForeground(getBackground()); 322 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_ForManager")); 323 gridBagConstraints = new java.awt.GridBagConstraints (); 324 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; 325 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 326 jPanel2.add(jLabel3, gridBagConstraints); 327 328 gridBagConstraints = new java.awt.GridBagConstraints (); 329 gridBagConstraints.gridx = 1; 330 gridBagConstraints.gridy = 5; 331 gridBagConstraints.gridwidth = 2; 332 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 333 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 334 gridBagConstraints.weightx = 1.0; 335 gridBagConstraints.weighty = 1.0; 336 add(jPanel2, gridBagConstraints); 337 338 } 339 341 private void jButtonBaseBrowseActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (); 343 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 344 chooser.setSelectedFile(new File (jTextFieldBaseDir.getText().trim())); 345 if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { 346 jTextFieldBaseDir.setText(chooser.getSelectedFile().getAbsolutePath()); 347 fireChange(); 348 } 349 } 351 private void jButtonHomeBrowseActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (); 353 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 354 chooser.setSelectedFile(new File (jTextFieldHomeDir.getText().trim())); 355 if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { 356 jTextFieldHomeDir.setText(chooser.getSelectedFile().getAbsolutePath()); 357 fireChange(); 358 } 359 } 361 private void jCheckBoxSharedActionPerformed(java.awt.event.ActionEvent evt) { setBaseEnabled(jCheckBoxShared.isSelected()); 363 fireChange(); 364 } 366 public java.util.Properties getProperties() { 367 Properties p = new Properties (); 368 p.put(TomcatProperties.PROP_SERVER_PORT, serverPort); 369 p.put(TomcatProperties.PROP_SHUTDOWN, shutdownPort); 370 p.put(TomcatProperties.PROP_MONITOR, "false"); return p; 372 } 373 374 public String getUrl() { 375 String url; 376 switch (tomcatVersion) { 377 case TOMCAT_60: 378 url = TomcatFactory.TOMCAT_URI_PREFIX_60; 379 break; 380 case TOMCAT_55: 381 url = TomcatFactory.TOMCAT_URI_PREFIX_55; 382 break; 383 case TOMCAT_50: 384 default: 385 url = TomcatFactory.TOMCAT_URI_PREFIX_50; 386 break; 387 } 388 389 url += "home=" + jTextFieldHomeDir.getText(); 391 if (jCheckBoxShared.isEnabled() && jCheckBoxShared.isSelected()) { 392 url += ":base=" + jTextFieldBaseDir.getText(); } 394 395 TomcatFactory.getEM().log("TomcatInstall.getUrl: " + url); return url; 397 } 398 399 public String getUsername() { 400 return jTextFieldUsername.getText(); 401 } 402 403 public String getPassword() { 404 return new String (jTextFieldPassword.getPassword()); 405 } 406 407 public File getHomeDir() { 408 return new File (jTextFieldHomeDir.getText()); 409 } 410 411 public String getErrorMessage() { 412 return errorMessage == null 414 ? null 415 : "<html>" + errorMessage.replaceAll("<", "<").replaceAll(">", ">") + "</html>"; } 417 418 boolean isServerXmlValid(File file) { 419 try { 420 Server server = Server.createGraph(file); 421 serverPort = TomcatInstallUtil.getPort(server); 422 shutdownPort = TomcatInstallUtil.getShutdownPort(server); 423 if (serverPort != null && shutdownPort != null) { 424 Integer.parseInt(serverPort); 426 Integer.parseInt(shutdownPort); 427 return true; 428 } 429 } catch (IOException ioe) { 430 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 431 } catch (NumberFormatException nfe) { 432 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, nfe); 433 } catch (RuntimeException e) { 434 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 436 } 437 return false; 438 } 439 440 private boolean isHomeValid() { 441 String homeDir = jTextFieldHomeDir.getText(); 442 if (homeDir.length() == 0) { 443 errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_SpecifyHomeDir"); 444 return false; 445 } 446 if (!new File (homeDir, "bin/bootstrap.jar").exists()) { errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_InvalidHomeDir"); 448 return false; 449 } 450 if ((!jCheckBoxShared.isEnabled() || !jCheckBoxShared.isSelected()) && !isServerXmlValid(new File (homeDir, SERVER_XML))) { 451 errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_CorruptedHomeServerXml"); 452 return false; 453 } 454 return true; 455 } 456 457 458 private boolean isJWSDP() { 459 if (isHomeValid()) { 460 File homeDir = getHomeDir(); 461 if (homeDir != null && homeDir.exists()) { 462 File files[] = homeDir.listFiles(new FilenameFilter () { 463 public boolean accept(File dir, String name) { 464 if ("jwsdp-shared".equals(name)) { return true; 466 } 467 return false; 468 } 469 }); 470 return files.length != 0 ? true : false; 471 } 472 } 473 return false; 474 } 475 476 private boolean isBaseValid() { 477 if (jCheckBoxShared.isEnabled() && jCheckBoxShared.isSelected()) { 479 String base = jTextFieldBaseDir.getText(); 480 if (base.length() == 0) { 481 errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_SpecifyBaseDir"); 482 return false; 483 } 484 File baseDir = new File (base); 485 String [] files = baseDir.list(); 486 File serverXml = new File (baseDir, SERVER_XML); 487 if (!baseDir.exists() || files == null 489 || (files.length > 0 && !serverXml.exists())) { 490 errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_InvalidBaseDir"); 491 return false; 492 } 493 if (files.length > 0) { 494 if (!isServerXmlValid(serverXml)) { 496 errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_CorruptedBaseServerXml"); 497 return false; 498 } 499 } else { 500 if (!isServerXmlValid(new File (jTextFieldHomeDir.getText(), SERVER_XML))) { 502 errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_CorruptedHomeServerXml"); 503 return false; 504 } 505 } 506 } 507 return true; 508 } 509 510 private boolean isAlreadyRegistered() { 511 if (InstanceProperties.getInstanceProperties(getUrl()) != null) { 512 errorMessage = NbBundle.getMessage(InstallPanelVisual.class, 513 jCheckBoxShared.isEnabled() && jCheckBoxShared.isSelected() 514 ? "MSG_AlreadyRegisteredBase" 515 : "MSG_AlreadyRegisteredHome"); 516 return true; 517 } 518 return false; 519 } 520 521 private void setBaseEnabled(boolean enabled) { 522 jLabelBaseDir.setEnabled(enabled); 523 jTextFieldBaseDir.setEnabled(enabled); 524 jButtonBaseBrowse.setEnabled(enabled); 525 } 526 527 public boolean isValid() { 528 errorMessage = null; 529 return isHomeValid() && isBaseValid() && !isAlreadyRegistered(); 530 } 531 532 private void fireChange() { 533 if (validationTask == null) { 538 validationTask = RequestProcessor.getDefault().create(new Runnable () { 539 public void run() { 540 if (!SwingUtilities.isEventDispatchThread()) { 541 SwingUtilities.invokeLater(this); 542 return; 543 } 544 545 ChangeEvent event = new ChangeEvent (this); 546 ArrayList tempList; 547 548 synchronized(listeners) { 549 tempList = new ArrayList (listeners); 550 } 551 552 Iterator iter = tempList.iterator(); 553 while (iter.hasNext()) { 554 ((ChangeListener )iter.next()).stateChanged(event); 555 } 556 } 557 }); 558 } 559 validationTask.schedule(60); 560 } 561 562 private javax.swing.JButton jButtonBaseBrowse; 564 private javax.swing.JButton jButtonHomeBrowse; 565 private javax.swing.JCheckBox jCheckBoxShared; 566 private javax.swing.JLabel jLabel1; 567 private javax.swing.JLabel jLabel2; 568 private javax.swing.JLabel jLabel3; 569 private javax.swing.JLabel jLabelBaseDir; 570 private javax.swing.JLabel jLabelHomeDir; 571 private javax.swing.JLabel jLabelPassword; 572 private javax.swing.JLabel jLabelUsername; 573 private javax.swing.JPanel jPanel1; 574 private javax.swing.JPanel jPanel2; 575 private javax.swing.JTextField jTextFieldBaseDir; 576 private javax.swing.JTextField jTextFieldHomeDir; 577 private javax.swing.JPasswordField jTextFieldPassword; 578 private javax.swing.JTextField jTextFieldUsername; 579 581 } 582 | Popular Tags |