1 19 20 package org.netbeans.modules.j2ee.ejbfreeform.ui; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.io.File ; 25 import java.io.FilenameFilter ; 26 import java.io.IOException ; 27 import java.math.BigDecimal ; 28 import java.util.ArrayList ; 29 import java.util.HashSet ; 30 import java.util.List ; 31 import java.util.Set ; 32 import javax.swing.JFileChooser ; 33 import javax.swing.event.ChangeListener ; 34 import javax.swing.event.DocumentEvent ; 35 import javax.swing.event.DocumentListener ; 36 import org.netbeans.api.project.Project; 37 import org.netbeans.api.queries.CollocationQuery; 38 import org.netbeans.modules.ant.freeform.spi.support.Util; 39 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 40 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 41 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 42 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 43 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 44 import org.netbeans.modules.j2ee.ejbfreeform.EJBProjectGenerator; 45 import org.netbeans.modules.j2ee.ejbfreeform.EJBProjectNature; 46 import org.netbeans.modules.j2ee.ejbfreeform.EjbFreeformProperties; 47 import org.openide.ErrorManager; 48 import org.openide.filesystems.FileUtil; 49 import org.openide.util.HelpCtx; 50 import org.openide.util.NbBundle; 51 import org.netbeans.spi.project.AuxiliaryConfiguration; 52 import org.netbeans.spi.project.support.ant.AntProjectHelper; 53 import org.netbeans.spi.project.support.ant.PropertyUtils; 54 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 55 import org.openide.WizardDescriptor; 56 import org.openide.filesystems.FileObject; 57 import org.w3c.dom.Element ; 58 59 60 64 public class EJBLocationsPanel extends javax.swing.JPanel implements HelpCtx.Provider { 65 66 67 private File baseFolder; 68 69 private File nbProjectFolder; 70 71 private File srcPackagesLocation; 72 73 private AntProjectHelper projectHelper; 74 75 private java.util.List serverIDs; 76 private ChangeListener listener; 77 private DocumentListener documentListener; 78 79 private BigDecimal ejbJarXmlVersion; 80 81 private boolean isNew = false; 82 private boolean isNS2 = false; 83 private boolean is15 = false; 84 85 private boolean updatingLevels = false; 86 87 private static final String J2EE_SPEC_15_LABEL = NbBundle.getMessage(EJBLocationsPanel.class, "TXT_J2EESpecLevel_2"); private static final String J2EE_SPEC_14_LABEL = NbBundle.getMessage(EJBLocationsPanel.class, "TXT_J2EESpecLevel_0"); private static final String J2EE_SPEC_13_LABEL = NbBundle.getMessage(EJBLocationsPanel.class, "TXT_J2EESpecLevel_1"); 91 92 public EJBLocationsPanel(EJBLocationsWizardPanel panel) { 93 this.listener = panel; 94 initComponents(); 95 96 isNew = true; 97 initServerInstances(); 98 99 documentListener = new DocumentListener () { 100 public void insertUpdate(DocumentEvent e) { 101 update(e); 102 } 103 public void removeUpdate(DocumentEvent e) { 104 update(e); 105 } 106 public void changedUpdate(DocumentEvent e) { 107 update(e); 108 } 109 }; 110 111 this.jTextFieldConfigFiles.getDocument().addDocumentListener(documentListener); 112 } 113 114 public EJBLocationsPanel(EJBLocationsWizardPanel panel, Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { 115 this(panel); 116 this.projectHelper = projectHelper; 117 setFolders(Util.getProjectLocation(projectHelper, projectEvaluator), FileUtil.toFile(projectHelper.getProjectDirectory())); 118 119 Element ejbData = aux.getConfigurationFragment(EJBProjectNature.EL_EJB, EJBProjectNature.NS_EJB_2, true); 120 if (ejbData != null) { 121 isNS2 = true; 122 } 123 124 List ejbModules = EJBProjectGenerator.getEJBmodules(projectHelper, aux); 125 if (ejbModules != null) { 126 EJBProjectGenerator.EJBModule em = (EJBProjectGenerator.EJBModule) ejbModules.get(0); 127 is15 = em.j2eeSpecLevel.equals("1.5") ? true : false; 128 } 129 130 isNew = false; 131 updateJ2eeLevels(); 132 133 if (is15) { 135 serverIDs.remove("GENERIC"); serverTypeComboBox.removeItem(Deployment.getDefault().getServerDisplayName("GENERIC")); } 138 139 if (ejbModules != null) { 140 EJBProjectGenerator.EJBModule wm = (EJBProjectGenerator.EJBModule)ejbModules.get(0); 141 String configFiles = getLocationDisplayName(projectEvaluator, nbProjectFolder, wm.configFiles); 142 String classpath = getLocationDisplayName(projectEvaluator, nbProjectFolder, wm.classpath); 143 String resourceFiles = getLocationDisplayName(projectEvaluator, nbProjectFolder, projectEvaluator.getProperty(EjbFreeformProperties.RESOURCE_DIR)); 144 String serverID = projectEvaluator.getProperty(EjbFreeformProperties.J2EE_SERVER_TYPE); 145 jTextFieldConfigFiles.setText(configFiles); 146 resourcesTextField.setText(resourceFiles); 147 148 setSrcPackages(classpath); 149 if (wm.j2eeSpecLevel.equals("1.5")) { 150 j2eeSpecComboBox.setSelectedItem(NbBundle.getMessage(EJBLocationsPanel.class, "TXT_J2EESpecLevel_2")); 151 } else if (wm.j2eeSpecLevel.equals("1.4")) { 152 j2eeSpecComboBox.setSelectedItem(NbBundle.getMessage(EJBLocationsPanel.class, "TXT_J2EESpecLevel_0")); 153 } else { 154 j2eeSpecComboBox.setSelectedItem(NbBundle.getMessage(EJBLocationsPanel.class, "TXT_J2EESpecLevel_1")); 155 } 156 157 if (serverID != null) 158 selectServerID(serverID); 159 } 160 161 } 162 163 private void updateJ2eeLevels() { 164 String prevSelectedItem = (String )j2eeSpecComboBox.getSelectedItem(); 165 int selectedServerIndex = serverTypeComboBox.getSelectedIndex(); 166 if (selectedServerIndex == -1) { 167 return; 168 } 169 String serverID = (String ) serverIDs.get(selectedServerIndex); 170 String servInsID = getFirstServerInstanceID(serverID); 171 Set supportedVersions; 172 if (servInsID != null) { 173 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(servInsID); 174 supportedVersions = j2eePlatform.getSupportedSpecVersions(); 175 } else { 176 supportedVersions = new HashSet (); 177 supportedVersions.add(J2eeModule.J2EE_13); 178 supportedVersions.add(J2eeModule.J2EE_14); 179 } 180 updatingLevels = true; 181 j2eeSpecComboBox.removeAllItems(); 182 183 if (supportedVersions.contains(J2eeModule.JAVA_EE_5) && (isNew || isNS2)) { 184 j2eeSpecComboBox.addItem(J2EE_SPEC_15_LABEL); 185 } 186 if (supportedVersions.contains(J2eeModule.J2EE_14) && !is15) { 187 j2eeSpecComboBox.addItem(J2EE_SPEC_14_LABEL); 188 } 189 if (supportedVersions.contains(J2eeModule.J2EE_13) && !is15) { 190 j2eeSpecComboBox.addItem(J2EE_SPEC_13_LABEL); 191 } 192 if (prevSelectedItem != null) { 193 j2eeSpecComboBox.setSelectedItem(prevSelectedItem); 194 } 195 updatingLevels = false; 196 if (listener != null) { 197 listener.stateChanged(null); 198 } 199 } 200 201 private void update(DocumentEvent e) { 202 setEjbJarXmlJ2eeVersion(findEbjJarXml(getAsFile(jTextFieldConfigFiles.getText()))); 203 if (listener != null) { 204 listener.stateChanged(null); 205 } 206 } 207 208 212 public static String getLocationDisplayName(PropertyEvaluator evaluator, File base, String val) { 214 if (val == null || val.trim().length() <= 0) 215 return ""; File f = Util.resolveFile(evaluator, base, val); 217 if (f == null) { 218 return val; 219 } 220 String location = f.getAbsolutePath(); 221 if (CollocationQuery.areCollocated(base, f)) { 222 location = PropertyUtils.relativizeFile(base, f).replace('/', File.separatorChar); } 224 return location; 225 } 226 227 228 public HelpCtx getHelpCtx() { 229 return new HelpCtx( EJBLocationsPanel.class ); 230 } 231 232 237 private void initComponents() { 239 java.awt.GridBagConstraints gridBagConstraints; 240 241 jLabel1 = new javax.swing.JLabel (); 242 jLabel2 = new javax.swing.JLabel (); 243 jTextFieldConfigFiles = new javax.swing.JTextField (); 244 jButtonEJB = new javax.swing.JButton (); 245 jLabel5 = new javax.swing.JLabel (); 246 j2eeSpecComboBox = new javax.swing.JComboBox (); 247 jLabel3 = new javax.swing.JLabel (); 248 serverTypeComboBox = new javax.swing.JComboBox (); 249 jLabel6 = new javax.swing.JLabel (); 250 resourcesTextField = new javax.swing.JTextField (); 251 jButton1 = new javax.swing.JButton (); 252 jPanel1 = new javax.swing.JPanel (); 253 warningLabel = new javax.swing.JLabel (); 254 255 setLayout(new java.awt.GridBagLayout ()); 256 257 setPreferredSize(new java.awt.Dimension (375, 135)); 258 jLabel1.setText(org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "LBL_ConfigFilesPanel_Description")); gridBagConstraints = new java.awt.GridBagConstraints (); 260 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 261 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 262 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 263 add(jLabel1, gridBagConstraints); 264 265 jLabel2.setLabelFor(jTextFieldConfigFiles); 266 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "LBL_ConfigFilesPanel_ConfigFilesLocation_Label")); gridBagConstraints = new java.awt.GridBagConstraints (); 268 gridBagConstraints.gridx = 0; 269 gridBagConstraints.gridy = 1; 270 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 271 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 11); 272 add(jLabel2, gridBagConstraints); 273 jLabel2.getAccessibleContext().setAccessibleName(null); 274 275 gridBagConstraints = new java.awt.GridBagConstraints (); 276 gridBagConstraints.gridx = 1; 277 gridBagConstraints.gridy = 1; 278 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 279 gridBagConstraints.weightx = 1.0; 280 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 11); 281 add(jTextFieldConfigFiles, gridBagConstraints); 282 jTextFieldConfigFiles.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "ACS_LBL_ConfigFilesPanel_ConfigFilesLocation_A11YDesc")); 284 org.openide.awt.Mnemonics.setLocalizedText(jButtonEJB, org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "BTN_BasicProjectInfoPanel_browseAntScript")); jButtonEJB.addActionListener(new java.awt.event.ActionListener () { 286 public void actionPerformed(java.awt.event.ActionEvent evt) { 287 jButtonEJBActionPerformed(evt); 288 } 289 }); 290 291 gridBagConstraints = new java.awt.GridBagConstraints (); 292 gridBagConstraints.gridx = 2; 293 gridBagConstraints.gridy = 1; 294 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 295 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 296 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 297 add(jButtonEJB, gridBagConstraints); 298 jButtonEJB.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "ACS_LBL_ConfigFilesPanel_ConfigFilesLocationBrowse_A11YDesc")); 300 jLabel5.setLabelFor(j2eeSpecComboBox); 301 org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "LBL_ConfigFilesPanel_J2EESpecLevel_Label")); gridBagConstraints = new java.awt.GridBagConstraints (); 303 gridBagConstraints.gridx = 0; 304 gridBagConstraints.gridy = 4; 305 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 306 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 11); 307 add(jLabel5, gridBagConstraints); 308 309 j2eeSpecComboBox.addActionListener(new java.awt.event.ActionListener () { 310 public void actionPerformed(java.awt.event.ActionEvent evt) { 311 j2eeSpecComboBoxActionPerformed(evt); 312 } 313 }); 314 315 gridBagConstraints = new java.awt.GridBagConstraints (); 316 gridBagConstraints.gridx = 1; 317 gridBagConstraints.gridy = 4; 318 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 319 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 320 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 321 add(j2eeSpecComboBox, gridBagConstraints); 322 j2eeSpecComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "ACS_LBL_ConfigFilesPanel_J2EESpecLevel_A11YDesc")); 324 jLabel3.setLabelFor(serverTypeComboBox); 325 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "LBL_ConfigFilesPanel_ServerType_Label")); gridBagConstraints = new java.awt.GridBagConstraints (); 327 gridBagConstraints.gridx = 0; 328 gridBagConstraints.gridy = 3; 329 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 330 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 11); 331 add(jLabel3, gridBagConstraints); 332 333 serverTypeComboBox.addItemListener(new java.awt.event.ItemListener () { 334 public void itemStateChanged(java.awt.event.ItemEvent evt) { 335 serverTypeComboBoxItemStateChanged(evt); 336 } 337 }); 338 339 gridBagConstraints = new java.awt.GridBagConstraints (); 340 gridBagConstraints.gridx = 1; 341 gridBagConstraints.gridy = 3; 342 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 343 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 344 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 345 add(serverTypeComboBox, gridBagConstraints); 346 serverTypeComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "ACS_LBL_ConfigFilesPanel_ServerType_A11YDesc")); 348 jLabel6.setLabelFor(resourcesTextField); 349 org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "LBL_ConfigFilesPanel_Resources_label")); gridBagConstraints = new java.awt.GridBagConstraints (); 351 gridBagConstraints.gridx = 0; 352 gridBagConstraints.gridy = 2; 353 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 354 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 11); 355 add(jLabel6, gridBagConstraints); 356 357 gridBagConstraints = new java.awt.GridBagConstraints (); 358 gridBagConstraints.gridx = 1; 359 gridBagConstraints.gridy = 2; 360 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 361 gridBagConstraints.weightx = 1.0; 362 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 11); 363 add(resourcesTextField, gridBagConstraints); 364 resourcesTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "ACS_LBL_ConfigFilesPanel_ResourceFolder_A11YDesc")); 366 org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "BTN_ConfigFilesPanel_ResourcesBrowse")); jButton1.addActionListener(new java.awt.event.ActionListener () { 368 public void actionPerformed(java.awt.event.ActionEvent evt) { 369 jButton1ActionPerformed(evt); 370 } 371 }); 372 373 gridBagConstraints = new java.awt.GridBagConstraints (); 374 gridBagConstraints.gridx = 2; 375 gridBagConstraints.gridy = 2; 376 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 377 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 378 add(jButton1, gridBagConstraints); 379 jButton1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EJBLocationsPanel.class, "ACS_LBL_ConfigFilesPanel_ResourceFolderBrowse_A11YDesc")); 381 gridBagConstraints = new java.awt.GridBagConstraints (); 382 gridBagConstraints.gridx = 0; 383 gridBagConstraints.gridy = 5; 384 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 385 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 386 gridBagConstraints.weightx = 1.0; 387 gridBagConstraints.weighty = 1.0; 388 add(jPanel1, gridBagConstraints); 389 390 warningLabel.setForeground(new java.awt.Color (89, 71, 191)); 391 gridBagConstraints = new java.awt.GridBagConstraints (); 392 gridBagConstraints.gridx = 0; 393 gridBagConstraints.gridy = 6; 394 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 395 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 396 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; 397 gridBagConstraints.weightx = 1.0; 398 gridBagConstraints.insets = new java.awt.Insets (11, 0, 0, 0); 399 add(warningLabel, gridBagConstraints); 400 401 } 403 private void j2eeSpecComboBoxActionPerformed(java.awt.event.ActionEvent evt) { String selectedItem = (String )j2eeSpecComboBox.getSelectedItem(); 405 String warningMessage = null; 406 407 if (!updatingLevels && listener != null) { 408 listener.stateChanged(null); 409 } 410 411 if (J2EE_SPEC_14_LABEL.equals(selectedItem) && new BigDecimal (EjbJar.VERSION_2_0).equals(ejbJarXmlVersion)) { 412 warningMessage = NbBundle.getMessage(EJBLocationsPanel.class, "MSG_EjbJarXmlUpdate"); 413 } 414 415 warningLabel.setText(warningMessage); 416 } 418 private void serverTypeComboBoxItemStateChanged(java.awt.event.ItemEvent evt) { updateJ2eeLevels(); 420 } 422 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { File resources = getResourcesLocation(); 424 JFileChooser chooser = createChooser(resources != null ? resources.getAbsolutePath() : baseFolder.getAbsolutePath()); if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { 426 setResources(chooser.getSelectedFile()); 427 } 428 } 430 private void jButtonEJBActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = createChooser(getConfigFilesLocation().getAbsolutePath()); 432 if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { 433 setConfigFiles(chooser.getSelectedFile()); 434 } 435 } 437 private javax.swing.JComboBox j2eeSpecComboBox; 439 private javax.swing.JButton jButton1; 440 private javax.swing.JButton jButtonEJB; 441 private javax.swing.JLabel jLabel1; 442 private javax.swing.JLabel jLabel2; 443 private javax.swing.JLabel jLabel3; 444 private javax.swing.JLabel jLabel5; 445 private javax.swing.JLabel jLabel6; 446 private javax.swing.JPanel jPanel1; 447 private javax.swing.JTextField jTextFieldConfigFiles; 448 private javax.swing.JTextField resourcesTextField; 449 private javax.swing.JComboBox serverTypeComboBox; 450 private javax.swing.JLabel warningLabel; 451 453 private static JFileChooser createChooser(String path) { 454 JFileChooser chooser = new JFileChooser (); 455 FileUtil.preventFileChooserSymlinkTraversal(chooser, new File (path)); 456 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 457 chooser.setAcceptAllFileFilterUsed(false); 458 459 return chooser; 460 } 461 462 protected List getEJBModules() { 463 ArrayList l = new ArrayList (); 464 465 EJBProjectGenerator.EJBModule ejbModule = new EJBProjectGenerator.EJBModule(); 466 ejbModule.configFiles = getRelativeLocation(getConfigFilesLocation()); 467 468 String j2eeLevel = (String ) j2eeSpecComboBox.getSelectedItem(); 469 if (j2eeLevel != null) { 470 if (j2eeLevel.equals(NbBundle.getMessage(EJBLocationsPanel.class, "TXT_J2EESpecLevel_2"))) { 471 ejbModule.j2eeSpecLevel = "1.5"; 472 } else if (j2eeLevel.equals(NbBundle.getMessage(EJBLocationsPanel.class, "TXT_J2EESpecLevel_0"))) { 473 ejbModule.j2eeSpecLevel = "1.4"; 474 } else { 475 ejbModule.j2eeSpecLevel = "1.3"; 476 } 477 } 478 ejbModule.classpath = ""; l.add(ejbModule); 484 485 return l; 486 } 487 488 protected List getJavaSrcFolder() { 489 ArrayList l = new ArrayList (); 490 File sourceLoc = getSrcPackagesLocation(); 491 l.add(getRelativeLocation(sourceLoc)); 492 l.add(sourceLoc.getName()); 493 return l; 494 } 495 496 499 protected List getEJBSrcFolder() { 500 ArrayList l = new ArrayList (); 501 final File webLocation = getConfigFilesLocation(); 502 l.add(getRelativeLocation(webLocation)); 503 l.add(webLocation.getName()); 504 return l; 505 } 506 507 protected List getResourcesFolder() { 508 ArrayList l = new ArrayList (); 509 File resourceLoc = getResourcesLocation(); 510 l.add(resourceLoc != null ? getRelativeLocation(resourceLoc) : null); 511 l.add(resourceLoc != null ? resourceLoc.getName() : null); 512 return l; 513 } 514 515 private File getAsFile(String filename) { 516 final File f = new File (filename.trim()); 517 return PropertyUtils.resolveFile(nbProjectFolder, filename); 518 } 519 520 525 public void setFolders(File baseFolder, File nbProjectFolder) { 526 this.baseFolder = baseFolder; 527 this.nbProjectFolder = nbProjectFolder; 528 } 529 530 protected void setConfigFilesField(String path) { 531 if (path != null && !path.equals("")) { 532 setConfigFiles(new File (path)); 533 } else { 534 setConfigFiles(path); 535 } 536 } 537 538 protected void setConfigFiles(String path) { 539 jTextFieldConfigFiles.setText(path); 540 } 541 542 protected void setSrcPackages(String path) { 543 setSrcPackages(getAsFile(path)); 544 } 545 546 private void setConfigFiles(final File file) { 547 setConfigFiles(relativizeFile(file)); 548 } 549 550 private void setResources(final File file) { 551 resourcesTextField.setText(relativizeFile(file)); 552 } 553 554 protected File getConfigFilesLocation() { 555 return getAsFile(jTextFieldConfigFiles.getText()).getAbsoluteFile(); 556 } 557 558 protected File getResourcesLocation() { 559 String resources = resourcesTextField.getText().trim(); 560 return resources.length() <= 0 ? null : getAsFile(resourcesTextField.getText()).getAbsoluteFile(); 561 } 562 563 private void setSrcPackages(final File file) { 564 srcPackagesLocation = file; 565 } 566 567 protected File getSrcPackagesLocation() { 568 return srcPackagesLocation; 569 } 570 571 private String relativizeFile(final File file) { 572 File normalizedFile = FileUtil.normalizeFile(file); 573 if (CollocationQuery.areCollocated(nbProjectFolder, file)) { 574 return PropertyUtils.relativizeFile(nbProjectFolder, normalizedFile); 575 } else { 576 return normalizedFile.getAbsolutePath(); 577 } 578 } 579 580 private String getRelativeLocation(final File location) { 581 final File normalizedLocation = FileUtil.normalizeFile(location); 582 return Util.relativizeLocation(baseFolder, nbProjectFolder, normalizedLocation); 583 } 584 585 ActionListener getCustomizerOkListener() { 586 return new ActionListener () { 587 public void actionPerformed(ActionEvent arg0) { 588 589 AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper); 590 EJBProjectGenerator.putEJBModules(projectHelper, aux, getEJBModules()); 591 EJBProjectGenerator.putServerID(projectHelper, getSelectedServerID()); 592 EJBProjectGenerator.putResourceFolder(projectHelper, getResourcesFolder()); 593 594 String j2eeLevel = ((EJBProjectGenerator.EJBModule)getEJBModules().get(0)).j2eeSpecLevel; 595 EJBProjectGenerator.putJ2EELevel(projectHelper, j2eeLevel); 596 597 FileObject ejbJarXml = findEbjJarXml(getConfigFilesLocation()); 599 try { 600 if (j2eeLevel.equals("1.4") && !new BigDecimal (EjbJar.VERSION_2_1).equals(getEjbJarXmlVersion(ejbJarXml))) { EjbJar root = DDProvider.getDefault().getDDRoot(ejbJarXml); 602 root.setVersion(new BigDecimal (EjbJar.VERSION_2_1)); 603 root.write(ejbJarXml); 604 } 605 } catch (IOException e) { 606 final ErrorManager errorManager = ErrorManager.getDefault(); 607 String message = NbBundle.getMessage(EJBLocationsPanel.class, "MSG_EjbJarXmlCorrupted"); 608 errorManager.notify(errorManager.annotate(e, message)); 609 } 610 } 611 }; 612 } 613 614 615 private void initServerInstances() { 616 String [] servInstIDs = Deployment.getDefault().getServerInstanceIDs(); 617 serverIDs = new ArrayList (); 618 for (int i = 0; i < servInstIDs.length; i++) { 619 J2eePlatform j2eePlat = Deployment.getDefault().getJ2eePlatform(servInstIDs[i]); 620 String serverID = Deployment.getDefault().getServerID(servInstIDs[i]); 621 String servDisplayName = Deployment.getDefault().getServerDisplayName(serverID); 622 if (servDisplayName != null && !serverIDs.contains(serverID) 623 && j2eePlat != null && j2eePlat.getSupportedModuleTypes().contains(J2eeModule.EJB)) { 624 serverIDs.add(serverID); 625 serverTypeComboBox.addItem(servDisplayName); 626 } 627 } 628 serverIDs.add("GENERIC"); serverTypeComboBox.addItem(Deployment.getDefault().getServerDisplayName("GENERIC")); if (serverIDs.size() > 0) { 631 serverTypeComboBox.setSelectedIndex(0); 632 } else { 633 serverTypeComboBox.setEnabled(false); 634 j2eeSpecComboBox.setEnabled(false); 635 } 636 } 637 638 643 private String getFirstServerInstanceID(String serverID) { 644 if (serverID == null) { 645 return null; 646 } 647 String [] servInstIDs = Deployment.getDefault().getServerInstanceIDs(); 648 for (int i = 0; i < servInstIDs.length; i++) { 649 if (serverID == Deployment.getDefault().getServerID(servInstIDs[i])) { 650 return (String ) servInstIDs[i]; 651 } 652 } 653 return null; 654 } 655 656 public String getSelectedServerID() { 657 int idx = serverTypeComboBox.getSelectedIndex(); 658 if (idx == -1) { 659 return null; 660 } 661 String serverID = (String ) serverIDs.get(idx); 662 return serverID; 663 } 664 665 private void selectServerID(String serverID) { 666 for (int i = 0; i < serverIDs.size(); i++) { 667 if (serverID.equals(serverIDs.get(i))) { 668 serverTypeComboBox.setSelectedIndex(i); 669 break; 670 } 671 } 672 } 673 674 public String getSelectedJ2eeSpec() { 675 Object item = j2eeSpecComboBox.getSelectedItem(); 676 if (item == null) { 677 return null; 678 } else { 679 if (item.equals(J2EE_SPEC_15_LABEL)) { 680 return J2eeModule.JAVA_EE_5; 681 } else if (item.equals(J2EE_SPEC_14_LABEL)) { 682 return J2eeModule.J2EE_14; 683 } else { 684 return J2eeModule.J2EE_13; 685 } 686 } 687 } 688 689 public boolean valid(WizardDescriptor wizardDescriptor) { 690 File cfLoc = getConfigFilesLocation(); 691 if (jTextFieldConfigFiles.getText().equals("") || !cfLoc.isDirectory()) { 692 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(EJBLocationsPanel.class,"MSG_NoConfFolder")); return false; 694 } 695 696 if (is15 && getSelectedServerID().equals("GENERIC")) { 697 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(EJBLocationsPanel.class,"MSG_NoGENERICServer")); return false; 699 } 700 701 File [] dds = getConfigFilesLocation().listFiles(new FilenameFilter () { 702 public boolean accept(File dir, String name) { 703 return name.equals("ejb-jar.xml"); 704 } 705 }); 706 707 if (dds.length == 0 && !getSelectedJ2eeSpec().equals(J2eeModule.JAVA_EE_5)) { 708 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(EJBLocationsPanel.class,"MSG_NoEjbJarXml")); return false; 710 } 711 712 wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); return true; 714 } 715 716 public static FileObject findEbjJarXml(File configFolder) { 717 FileObject confFolderFo = FileUtil.toFileObject(configFolder); 718 FileObject ejbJarXml = null; 719 if (confFolderFo != null) { 720 ejbJarXml = confFolderFo.getFileObject("ejb-jar.xml"); } 722 return ejbJarXml; 723 } 724 725 public static BigDecimal getEjbJarXmlVersion(FileObject ejbJarXml) throws IOException { 726 if (ejbJarXml != null) { 727 return DDProvider.getDefault().getDDRoot(ejbJarXml).getVersion(); 728 } else { 729 return null; 730 } 731 } 732 733 private void setEjbJarXmlJ2eeVersion(FileObject ejbJarXml) { 734 try { 735 BigDecimal version = getEjbJarXmlVersion(ejbJarXml); 736 ejbJarXmlVersion = version; 737 if (version == null) 738 return; 739 740 if (new BigDecimal (EjbJar.VERSION_2_0).equals(version)) { 741 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_13_LABEL); 742 } else if (new BigDecimal (EjbJar.VERSION_2_1).equals(version)) { 743 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_14_LABEL); 744 } else if (new BigDecimal (EjbJar.VERSION_3_0).equals(version)) { 745 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_15_LABEL); 746 } 747 748 } catch (IOException e) { 749 final ErrorManager errorManager = ErrorManager.getDefault(); 750 String message = NbBundle.getMessage(EJBLocationsPanel.class, "MSG_EjbJarXmlCorrupted"); 751 errorManager.notify(errorManager.annotate(e, message)); 752 } 753 } 754 } 755 | Popular Tags |