1 19 20 package org.netbeans.modules.j2ee.clientproject.ui.wizards; 21 22 import java.awt.Dialog ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.math.BigDecimal ; 28 import java.text.MessageFormat ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 import java.util.Set ; 32 import java.util.TreeSet ; 33 import javax.swing.DefaultComboBoxModel ; 34 import javax.swing.JButton ; 35 import javax.swing.JFileChooser ; 36 import javax.swing.JPanel ; 37 import javax.swing.event.DocumentEvent ; 38 import javax.swing.event.DocumentListener ; 39 import org.netbeans.api.project.Project; 40 import org.netbeans.api.project.ProjectInformation; 41 import org.netbeans.api.project.ProjectManager; 42 import org.netbeans.api.project.ProjectUtils; 43 import org.netbeans.api.project.ui.OpenProjects; 44 import org.netbeans.modules.j2ee.clientproject.AppClientProvider; 45 import org.netbeans.modules.j2ee.clientproject.ui.FoldersListSettings; 46 import org.netbeans.modules.j2ee.dd.api.client.AppClient; 47 import org.netbeans.modules.j2ee.dd.api.client.DDProvider; 48 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 49 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 50 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModuleContainer; 51 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 52 import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerManager; 53 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 54 import org.netbeans.spi.project.ui.support.ProjectChooser; 55 import org.netbeans.spi.project.ui.templates.support.Templates; 56 import org.openide.DialogDescriptor; 57 import org.openide.DialogDisplayer; 58 import org.openide.ErrorManager; 59 import org.openide.NotifyDescriptor; 60 import org.openide.WizardDescriptor; 61 import org.openide.WizardValidationException; 62 import org.openide.filesystems.FileObject; 63 import org.openide.filesystems.FileUtil; 64 import org.openide.util.NbBundle; 65 66 70 public class ImportLocationVisual extends JPanel { 71 72 private final DefaultComboBoxModel serversModel = new DefaultComboBoxModel (); 73 private static final String J2EE_SPEC_15_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "J2EESpecLevel_15"); private static final String J2EE_SPEC_14_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "J2EESpecLevel_14"); private static final String J2EE_SPEC_13_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "J2EESpecLevel_13"); private final ImportLocation panel; 77 private final DocumentListener documentListener; 78 79 private boolean projectFolderTouched; 80 81 private boolean projectNameTouched; 82 private List <Project> earProjects; 83 private WizardDescriptor wizardDescriptor; 84 private J2eeVersionWarningPanel warningPanel; 85 86 87 public ImportLocationVisual (ImportLocation panel) { 88 this.panel = panel; 89 initComponents (); 90 setJ2eeVersionWarningPanel(); 91 initServers(FoldersListSettings.getDefault().getLastUsedServer()); 92 if (j2eeSpecComboBox.getModel().getSize() > 0) { 94 j2eeSpecComboBox.setSelectedIndex(0); 95 } 96 initEnterpriseApplications(); 97 this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_NWP1_NamePanel_A11YDesc")); setName(NbBundle.getBundle("org/netbeans/modules/j2ee/clientproject/ui/wizards/Bundle").getString("LBL_IW_ImportTitle")); putClientProperty ("NewProjectWizard_Title", NbBundle.getMessage(ImportLocationVisual.class, "TXT_ImportAppClientModule")); this.projectName.setText(""); 101 documentListener = new DocumentListener () { 102 public void insertUpdate(DocumentEvent e) { 103 update(e); 104 } 105 106 public void removeUpdate(DocumentEvent e) { 107 update(e); 108 } 109 110 public void changedUpdate(DocumentEvent e) { 111 update(e); 112 } 113 }; 114 this.projectName.getDocument().addDocumentListener(documentListener); 115 this.projectFolder.getDocument().addDocumentListener(documentListener); 116 } 117 118 123 private void initComponents() { 125 java.awt.GridBagConstraints gridBagConstraints; 126 127 jLabelSrcLocationDesc = new javax.swing.JLabel (); 128 jLabelSrcLocation = new javax.swing.JLabel (); 129 projectLocation = new javax.swing.JTextField (); 130 browseProjectLocation = new javax.swing.JButton (); 131 jLabelPrjLocationDesc = new javax.swing.JLabel (); 132 jLabelPrjName = new javax.swing.JLabel (); 133 projectName = new javax.swing.JTextField (); 134 jLabelPrjLocation = new javax.swing.JLabel (); 135 projectFolder = new javax.swing.JTextField (); 136 browseProjectFolder = new javax.swing.JButton (); 137 jSeparator1 = new javax.swing.JSeparator (); 138 jPanel1 = new javax.swing.JPanel (); 139 jCheckBox1 = new javax.swing.JCheckBox (); 140 serverInstanceLabel = new javax.swing.JLabel (); 141 serverInstanceComboBox = new javax.swing.JComboBox (); 142 jLabel7 = new javax.swing.JLabel (); 143 j2eeSpecComboBox = new javax.swing.JComboBox (); 144 addToAppLabel = new javax.swing.JLabel (); 145 addToAppComboBox = new javax.swing.JComboBox (); 146 warningPlaceHolderPanel = new javax.swing.JPanel (); 147 manageServersButton = new javax.swing.JButton (); 148 149 setNextFocusableComponent(projectLocation); 150 setLayout(new java.awt.GridBagLayout ()); 151 152 org.openide.awt.Mnemonics.setLocalizedText(jLabelSrcLocationDesc, NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationSrcDesc")); gridBagConstraints = new java.awt.GridBagConstraints (); 154 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 155 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 156 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 157 add(jLabelSrcLocationDesc, gridBagConstraints); 158 159 jLabelSrcLocation.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 160 jLabelSrcLocation.setLabelFor(projectLocation); 161 org.openide.awt.Mnemonics.setLocalizedText(jLabelSrcLocation, NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationSrc_Label")); gridBagConstraints = new java.awt.GridBagConstraints (); 163 gridBagConstraints.gridx = 0; 164 gridBagConstraints.gridy = 1; 165 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 166 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 167 add(jLabelSrcLocation, gridBagConstraints); 168 jLabelSrcLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_IW_Location_A11Desc")); 170 projectLocation.setNextFocusableComponent(browseProjectLocation); 171 projectLocation.addFocusListener(new java.awt.event.FocusAdapter () { 172 public void focusLost(java.awt.event.FocusEvent evt) { 173 projectLocationFocusLost(evt); 174 } 175 }); 176 gridBagConstraints = new java.awt.GridBagConstraints (); 177 gridBagConstraints.gridx = 1; 178 gridBagConstraints.gridy = 1; 179 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 180 gridBagConstraints.weightx = 1.0; 181 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 182 add(projectLocation, gridBagConstraints); 183 projectLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_IW_ImportLocation_A11YDesc")); 185 org.openide.awt.Mnemonics.setLocalizedText(browseProjectLocation, NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_BrowseLocation_Button_w")); browseProjectLocation.setNextFocusableComponent(projectName); 187 browseProjectLocation.addActionListener(new java.awt.event.ActionListener () { 188 public void actionPerformed(java.awt.event.ActionEvent evt) { 189 browseProjectLocationActionPerformed(evt); 190 } 191 }); 192 gridBagConstraints = new java.awt.GridBagConstraints (); 193 gridBagConstraints.gridx = 2; 194 gridBagConstraints.gridy = 1; 195 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 196 add(browseProjectLocation, gridBagConstraints); 197 browseProjectLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_IW_ImportLocationBrowse_A11YDesc")); 199 org.openide.awt.Mnemonics.setLocalizedText(jLabelPrjLocationDesc, NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationPrjDesc")); gridBagConstraints = new java.awt.GridBagConstraints (); 201 gridBagConstraints.gridx = 0; 202 gridBagConstraints.gridy = 2; 203 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 204 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 205 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 206 add(jLabelPrjLocationDesc, gridBagConstraints); 207 208 jLabelPrjName.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 209 jLabelPrjName.setLabelFor(projectName); 210 org.openide.awt.Mnemonics.setLocalizedText(jLabelPrjName, org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_ProjectName_Label")); gridBagConstraints = new java.awt.GridBagConstraints (); 212 gridBagConstraints.gridx = 0; 213 gridBagConstraints.gridy = 3; 214 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 215 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 216 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 217 add(jLabelPrjName, gridBagConstraints); 218 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/clientproject/ui/wizards/Bundle"); jLabelPrjName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_IW_ProjectName_A11Desc")); 221 projectName.setNextFocusableComponent(projectFolder); 222 gridBagConstraints = new java.awt.GridBagConstraints (); 223 gridBagConstraints.gridx = 1; 224 gridBagConstraints.gridy = 3; 225 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 226 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 227 add(projectName, gridBagConstraints); 228 projectName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NWP1_ProjectName_A11YDesc")); 230 jLabelPrjLocation.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 231 jLabelPrjLocation.setLabelFor(projectFolder); 232 org.openide.awt.Mnemonics.setLocalizedText(jLabelPrjLocation, NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_CreatedProjectFolder_Label")); gridBagConstraints = new java.awt.GridBagConstraints (); 234 gridBagConstraints.gridx = 0; 235 gridBagConstraints.gridy = 4; 236 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 237 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 238 add(jLabelPrjLocation, gridBagConstraints); 239 jLabelPrjLocation.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_IW_ProjectFolder_A11Desc")); 241 projectFolder.setNextFocusableComponent(browseProjectFolder); 242 gridBagConstraints = new java.awt.GridBagConstraints (); 243 gridBagConstraints.gridx = 1; 244 gridBagConstraints.gridy = 4; 245 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 246 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 247 add(projectFolder, gridBagConstraints); 248 projectFolder.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NPW1_ProjectLocation_A11YDesc")); 250 org.openide.awt.Mnemonics.setLocalizedText(browseProjectFolder, NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_BrowseLocation_Button")); browseProjectFolder.addActionListener(new java.awt.event.ActionListener () { 252 public void actionPerformed(java.awt.event.ActionEvent evt) { 253 browseProjectFolderActionPerformed(evt); 254 } 255 }); 256 gridBagConstraints = new java.awt.GridBagConstraints (); 257 gridBagConstraints.gridx = 2; 258 gridBagConstraints.gridy = 4; 259 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 260 add(browseProjectFolder, gridBagConstraints); 261 browseProjectFolder.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NWP1_BrowseLocation_A11YDesc")); 263 gridBagConstraints = new java.awt.GridBagConstraints (); 264 gridBagConstraints.gridx = 0; 265 gridBagConstraints.gridy = 5; 266 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 267 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 268 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 269 gridBagConstraints.weightx = 1.0; 270 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 271 add(jSeparator1, gridBagConstraints); 272 273 jPanel1.setLayout(new java.awt.GridBagLayout ()); 274 275 jCheckBox1.setSelected(true); 276 org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, bundle.getString("LBL_IW_SetAsMainProject_CheckBox")); jCheckBox1.setMargin(new java.awt.Insets (0, 0, 0, 0)); 278 gridBagConstraints = new java.awt.GridBagConstraints (); 279 gridBagConstraints.gridx = 0; 280 gridBagConstraints.gridy = 4; 281 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 282 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; 283 gridBagConstraints.weightx = 1.0; 284 gridBagConstraints.weighty = 1.0; 285 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 286 jPanel1.add(jCheckBox1, gridBagConstraints); 287 jCheckBox1.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_IW_SetAsMainProject_A11YDesc")); 289 serverInstanceLabel.setLabelFor(serverInstanceComboBox); 290 org.openide.awt.Mnemonics.setLocalizedText(serverInstanceLabel, org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Server")); gridBagConstraints = new java.awt.GridBagConstraints (); 292 gridBagConstraints.gridx = 0; 293 gridBagConstraints.gridy = 1; 294 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 295 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 11); 296 jPanel1.add(serverInstanceLabel, gridBagConstraints); 297 298 serverInstanceComboBox.setModel(serversModel); 299 serverInstanceComboBox.setNextFocusableComponent(j2eeSpecComboBox); 300 serverInstanceComboBox.addActionListener(new java.awt.event.ActionListener () { 301 public void actionPerformed(java.awt.event.ActionEvent evt) { 302 serverInstanceComboBoxActionPerformed(evt); 303 } 304 }); 305 gridBagConstraints = new java.awt.GridBagConstraints (); 306 gridBagConstraints.gridx = 1; 307 gridBagConstraints.gridy = 1; 308 gridBagConstraints.gridwidth = 2; 309 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 310 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 311 gridBagConstraints.weightx = 1.0; 312 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 313 jPanel1.add(serverInstanceComboBox, gridBagConstraints); 314 serverInstanceComboBox.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_IW_SelectServerInstance_A11YDesc")); 316 jLabel7.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_SelectJ2EEVersion_LabelMnemonic").charAt(0)); 317 jLabel7.setLabelFor(j2eeSpecComboBox); 318 jLabel7.setText(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_J2EESpecLevel_Label")); gridBagConstraints = new java.awt.GridBagConstraints (); 320 gridBagConstraints.gridx = 0; 321 gridBagConstraints.gridy = 2; 322 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 323 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 324 jPanel1.add(jLabel7, gridBagConstraints); 325 326 j2eeSpecComboBox.setNextFocusableComponent(jCheckBox1); 327 j2eeSpecComboBox.setPrototypeDisplayValue("MMMMMMMMM" ); 328 j2eeSpecComboBox.addActionListener(new java.awt.event.ActionListener () { 329 public void actionPerformed(java.awt.event.ActionEvent evt) { 330 j2eeSpecComboBoxActionPerformed(evt); 331 } 332 }); 333 gridBagConstraints = new java.awt.GridBagConstraints (); 334 gridBagConstraints.gridx = 1; 335 gridBagConstraints.gridy = 2; 336 gridBagConstraints.gridwidth = 2; 337 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 338 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 339 jPanel1.add(j2eeSpecComboBox, gridBagConstraints); 340 j2eeSpecComboBox.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_IW_SelectJ2EEVersion_A11YDesc")); 342 addToAppLabel.setLabelFor(addToAppComboBox); 343 org.openide.awt.Mnemonics.setLocalizedText(addToAppLabel, bundle.getString("LBL_NWP1_AddToEApp_CheckBox")); gridBagConstraints = new java.awt.GridBagConstraints (); 345 gridBagConstraints.gridx = 0; 346 gridBagConstraints.gridy = 0; 347 gridBagConstraints.gridwidth = 2; 348 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 349 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 350 jPanel1.add(addToAppLabel, gridBagConstraints); 351 352 addToAppComboBox.setNextFocusableComponent(serverInstanceComboBox); 353 gridBagConstraints = new java.awt.GridBagConstraints (); 354 gridBagConstraints.gridx = 2; 355 gridBagConstraints.gridy = 0; 356 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 357 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 358 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 359 gridBagConstraints.weightx = 1.0; 360 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 361 jPanel1.add(addToAppComboBox, gridBagConstraints); 362 363 warningPlaceHolderPanel.setLayout(new java.awt.BorderLayout ()); 364 gridBagConstraints = new java.awt.GridBagConstraints (); 365 gridBagConstraints.gridx = 0; 366 gridBagConstraints.gridy = 3; 367 gridBagConstraints.gridwidth = 3; 368 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 369 gridBagConstraints.weightx = 1.0; 370 jPanel1.add(warningPlaceHolderPanel, gridBagConstraints); 371 372 org.openide.awt.Mnemonics.setLocalizedText(manageServersButton, org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_ManageServers")); manageServersButton.addActionListener(new java.awt.event.ActionListener () { 374 public void actionPerformed(java.awt.event.ActionEvent evt) { 375 manageServersButtonActionPerformed(evt); 376 } 377 }); 378 gridBagConstraints = new java.awt.GridBagConstraints (); 379 gridBagConstraints.gridx = 3; 380 gridBagConstraints.gridy = 1; 381 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 382 gridBagConstraints.insets = new java.awt.Insets (0, 6, 5, 0); 383 jPanel1.add(manageServersButton, gridBagConstraints); 384 manageServersButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ASCN_ManageServers")); manageServersButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ASCD_ManageServers")); 387 gridBagConstraints = new java.awt.GridBagConstraints (); 388 gridBagConstraints.gridx = 0; 389 gridBagConstraints.gridy = 6; 390 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 391 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 392 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 393 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 394 gridBagConstraints.weightx = 1.0; 395 gridBagConstraints.weighty = 1.0; 396 add(jPanel1, gridBagConstraints); 397 398 getAccessibleContext().setAccessibleName(null); 399 getAccessibleContext().setAccessibleDescription(null); 400 } 402 private void manageServersButtonActionPerformed(java.awt.event.ActionEvent evt) { ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem(); 404 String lastSelectedServerInstanceID = null; 405 if (serverInstanceWrapper != null) { 406 lastSelectedServerInstanceID = serverInstanceWrapper.getServerInstanceID(); 407 } 408 ServerManager.showCustomizer(lastSelectedServerInstanceID); 409 String lastSelectedJ2eeSpecLevel = (String ) j2eeSpecComboBox.getSelectedItem(); 410 initServers(lastSelectedServerInstanceID); 412 if (lastSelectedJ2eeSpecLevel != null) { 413 j2eeSpecComboBox.setSelectedItem(lastSelectedJ2eeSpecLevel); 414 } 415 } 417 private void j2eeSpecComboBoxActionPerformed(java.awt.event.ActionEvent evt) { setJ2eeVersionWarningPanel(); 419 } 421 private void projectLocationFocusLost(java.awt.event.FocusEvent evt) { if (projectLocation.getText().trim().length() > 0) { 423 updateProjectName(); 424 updateProjectFolder(); 425 updateJ2EEVersion(); 426 panel.stateChanged(null); 427 } 428 } 430 private void serverInstanceComboBoxActionPerformed(java.awt.event.ActionEvent evt) { String prevSelectedItem = (String ) j2eeSpecComboBox.getSelectedItem(); 432 ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem(); 434 if (serverInstanceWrapper != null) { 435 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceWrapper.getServerInstanceID()); 436 Set supportedVersions = j2eePlatform.getSupportedSpecVersions(J2eeModule.CLIENT); 437 j2eeSpecComboBox.removeAllItems(); 438 if (supportedVersions.contains(J2eeModule.JAVA_EE_5)) { 439 j2eeSpecComboBox.addItem(J2EE_SPEC_15_LABEL); 440 } 441 if (supportedVersions.contains(J2eeModule.J2EE_14)) { 442 j2eeSpecComboBox.addItem(J2EE_SPEC_14_LABEL); 443 } 444 if (prevSelectedItem != null) { 445 j2eeSpecComboBox.setSelectedItem(prevSelectedItem); 446 } 447 } else { 448 j2eeSpecComboBox.removeAllItems(); 449 } 450 panel.fireChangeEvent(); 452 } 454 private void browseProjectFolderActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (); 456 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 457 chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); 458 if (projectFolder.getText().length() > 0 && getProjectFolder().exists()) { 459 chooser.setSelectedFile(getProjectFolder()); 460 } else if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) { 461 chooser.setSelectedFile(getProjectLocation()); 462 } else { 463 chooser.setSelectedFile(ProjectChooser.getProjectsFolder()); 464 } 465 chooser.setDialogTitle(NbBundle.getMessage(ImportLocationVisual.class, "LBL_SelectNewLocation")); if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { 467 File projectDir = FileUtil.normalizeFile(chooser.getSelectedFile()); 468 projectFolder.setText(projectDir.getAbsolutePath()); 469 } 470 } 472 private void browseProjectLocationActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (); 474 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 475 chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); 476 if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) { 477 chooser.setSelectedFile(getProjectLocation()); 478 } else { 479 File currentDirectory = null; 481 FileObject existingSourcesFO = Templates.getExistingSourcesFolder(wizardDescriptor); 482 if (existingSourcesFO != null) { 483 File existingSourcesFile = FileUtil.toFile(existingSourcesFO); 484 if (existingSourcesFile != null && existingSourcesFile.isDirectory()) { 485 currentDirectory = existingSourcesFile; 486 } 487 } 488 if (currentDirectory != null) { 489 chooser.setCurrentDirectory(currentDirectory); 490 } else { 491 chooser.setSelectedFile(ProjectChooser.getProjectsFolder()); 492 } 493 } 494 495 chooser.setDialogTitle(NbBundle.getMessage(ImportLocationVisual.class, "LBL_SelectExistingLocation")); if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { 497 projectLocation.setText(FileUtil.normalizeFile(chooser.getSelectedFile()).getAbsolutePath()); 498 updateJ2EEVersion(); 499 updateProjectName(); 500 updateProjectFolder(); 501 panel.stateChanged(null); 502 } 503 } 505 private javax.swing.JComboBox addToAppComboBox; 507 private javax.swing.JLabel addToAppLabel; 508 private javax.swing.JButton browseProjectFolder; 509 private javax.swing.JButton browseProjectLocation; 510 private javax.swing.JComboBox j2eeSpecComboBox; 511 private javax.swing.JCheckBox jCheckBox1; 512 private javax.swing.JLabel jLabel7; 513 private javax.swing.JLabel jLabelPrjLocation; 514 private javax.swing.JLabel jLabelPrjLocationDesc; 515 private javax.swing.JLabel jLabelPrjName; 516 private javax.swing.JLabel jLabelSrcLocation; 517 private javax.swing.JLabel jLabelSrcLocationDesc; 518 private javax.swing.JPanel jPanel1; 519 private javax.swing.JSeparator jSeparator1; 520 private javax.swing.JButton manageServersButton; 521 public javax.swing.JTextField projectFolder; 522 public javax.swing.JTextField projectLocation; 523 public javax.swing.JTextField projectName; 524 private javax.swing.JComboBox serverInstanceComboBox; 525 private javax.swing.JLabel serverInstanceLabel; 526 private javax.swing.JPanel warningPlaceHolderPanel; 527 529 private boolean ignoreEvent; 530 531 private void update(DocumentEvent e) { 532 if (ignoreEvent) { 533 return; 535 } 536 537 ignoreEvent = true; 539 540 if (projectLocation.getDocument() == e.getDocument()) { 541 updateProjectName(); 542 updateProjectFolder(); 543 } 544 545 ignoreEvent = false; 547 548 if (projectFolder.getDocument() == e.getDocument()) { 549 projectFolderTouched = !"".equals(projectFolder.getText()); 550 } 551 if (projectName.getDocument() == e.getDocument()) { 552 projectNameTouched = !"".equals(projectName.getText()); 553 } 554 panel.stateChanged(null); 555 } 556 557 private void updateProjectName() { 558 if (projectNameTouched) { 559 return; 560 } 561 FileObject fo = FileUtil.toFileObject(getProjectLocation()); 562 if (fo != null) { 563 projectName.setText(fo.getName()); } 565 } 566 567 private void updateJ2EEVersion() { 568 File f = new File (projectLocation.getText().trim()); 569 FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(f)); 570 if (fo != null) { 571 FileObject configFilesPath = FileSearchUtility.guessConfigFilesPath(fo); 572 if (configFilesPath != null) { 573 FileObject appClientXML = configFilesPath.getFileObject(AppClientProvider.FILE_DD); 574 checkACXmlJ2eeVersion(appClientXML); 575 } else { 576 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_15_LABEL); 577 } 578 } 579 } 580 581 private void updateProjectFolder() { 582 if (projectFolderTouched) { 583 return; 584 } 585 if (isValidProjectLocation()) { 586 projectFolder.setText(getProjectLocation().getAbsolutePath()); 587 } else { 588 projectFolder.setText(""); } 590 } 591 592 private boolean isValidProjectLocation() { 593 return (getProjectLocation().exists() && getProjectLocation().isDirectory() && 594 projectLocation.getText().length() > 0 && (!projectLocation.getText().endsWith(":"))); } 596 597 public boolean valid(WizardDescriptor wizardDescriptor) { 598 File prjDir = new File (projectLocation.getText().trim()); 599 String prjName = projectName.getText().trim(); 601 602 if (getSelectedServerInstanceID() == null) { 603 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_NoServer")); return false; 605 } 606 607 if (!prjDir.isDirectory()) { 608 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_ProvideExistingSourcesLocation")); return false; } 611 612 618 if (FileSearchUtility.guessJavaRoots(FileUtil.toFileObject(prjDir)) == null) { 619 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_NoAppClientModule")); return false; } 622 623 if (prjName == null || prjName.length() == 0) { 624 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_ProvideProjectName")); return false; } 627 628 String result = checkValidity (this.projectName.getText(), this.projectFolder.getText()); 629 if (result != null) { 630 wizardDescriptor.putProperty( "WizardPanel_errorMessage", result); return false; 632 } 633 634 wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); 636 return true; 637 } 638 639 static String checkValidity (final String projectName, final String projectLocation) { 640 File projLoc = new File (projectLocation).getAbsoluteFile(); 641 642 if (PanelProjectLocationVisual.getCanonicalFile(projLoc) == null) { 643 return NbBundle.getMessage (ImportLocationVisual.class,"MSG_IllegalProjectLocation"); 644 } 645 646 while (projLoc != null && !projLoc.exists()) { 647 projLoc = projLoc.getParentFile(); 648 } 649 if (projLoc == null || !projLoc.canWrite()) { 650 return NbBundle.getMessage(ImportLocationVisual.class,"MSG_ProjectFolderReadOnly"); 651 } 652 653 File destFolder = FileUtil.normalizeFile(new File ( projectLocation )); 654 File [] kids = destFolder.listFiles(); 655 if ( destFolder.exists() && kids != null && kids.length > 0) { 656 String file = null; 657 for (int i=0; i< kids.length; i++) { 658 String childName = kids[i].getName(); 659 if ("nbproject".equals(childName)) { file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_NetBeansProject"); 661 } 662 else if ("build".equals(childName)) { file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_BuildFolder"); 664 } 665 else if ("dist".equals(childName)) { file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_DistFolder"); 667 } 668 else if ("build.xml".equals(childName)) { file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_BuildXML"); 670 } 671 else if ("manifest.mf".equals(childName)) { file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_Manifest"); 673 } 674 if (file != null) { 675 String format = NbBundle.getMessage (ImportLocationVisual.class,"MSG_ProjectFolderInvalid"); 676 return MessageFormat.format(format, new Object [] {file}); 677 } 678 } 679 } 680 681 if (destFolder.isDirectory()) { 682 FileObject destFO = FileUtil.toFileObject(destFolder); 683 assert destFO != null : "No FileObject for " + destFolder; 684 boolean clear = false; 685 try { 686 clear = ProjectManager.getDefault().findProject(destFO) == null; 687 } catch (IOException e) { 688 } 690 if (!clear) { 691 return NbBundle.getMessage(ImportLocationVisual.class, "MSG_ProjectFolderHasDeletedProject"); 692 } 693 } 694 return null; 695 } 696 697 void read (WizardDescriptor d) { 698 wizardDescriptor = d; 699 } 700 701 void store( WizardDescriptor d ) { 702 String name = projectName.getText().trim(); 703 String moduleLoc = projectLocation.getText().trim(); 704 705 if (name.equals("") || moduleLoc.equals("")) { 706 return; 707 } 708 709 d.putProperty(WizardProperties.PROJECT_DIR, new File (projectFolder.getText().trim())); 710 File moduleLocFile = new File (moduleLoc); 711 d.putProperty(WizardProperties.SOURCE_ROOT, moduleLocFile); 712 d.putProperty(WizardProperties.NAME, name); 713 d.putProperty(WizardProperties.JAVA_ROOT, FileSearchUtility.guessJavaRootsAsFiles(FileUtil.toFileObject(moduleLocFile))); 714 d.putProperty(WizardProperties.SERVER_INSTANCE_ID, getSelectedServerInstanceID()); 715 d.putProperty(WizardProperties.J2EE_LEVEL, getSelectedJ2eeSpec()); 716 d.putProperty(WizardProperties.EAR_APPLICATION, getSelectedEarApplication()); 717 if (warningPanel != null && warningPanel.getDowngradeAllowed()) { 718 d.putProperty(WizardProperties.JAVA_PLATFORM, warningPanel.getSuggestedJavaPlatformName()); 719 FoldersListSettings fls = FoldersListSettings.getDefault(); 720 d.putProperty(WizardProperties.SOURCE_LEVEL, fls.isAgreedSetSourceLevel14() 721 ? "1.4" : fls.isAgreedSetSourceLevel15() ? "1.5" : "1.6"); } 723 724 } 726 727 private Dialog dialog; 729 730 void validate (WizardDescriptor d) throws WizardValidationException { 731 File dirF = new File (projectFolder.getText()); 732 JButton ok = new JButton (NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_OK")); ok.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_IW_BuildFileDialog_OKButton_LabelMnemonic")); ok.setMnemonic(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BuildFileDialog_OK_LabelMnemonic").charAt(0)); JButton cancel = new JButton (NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_Cancel")); cancel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_IW_BuildFileDialog_CancelButton_LabelMnemonic")); cancel.setMnemonic(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BuildFileDialog_Cancel_LabelMnemonic").charAt(0)); 739 final ImportBuildfile ibf = new ImportBuildfile(dirF.getAbsolutePath(), ok); 740 if ((new File (dirF, GeneratedFilesHelper.BUILD_XML_PATH)).exists()) { 741 ActionListener actionListener = new ActionListener () { 742 public void actionPerformed(ActionEvent event) { 743 Object src = event.getSource(); 744 if (src instanceof JButton ) { 745 String name = ((JButton ) src).getText(); 746 if (name.equals(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_OK"))) { closeDialog(); 748 } else if (name.equals(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_Cancel"))) { NotifyDescriptor ndesc = new NotifyDescriptor.Confirmation(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_CancelConfirmation"), NotifyDescriptor.YES_NO_OPTION); Object ret = DialogDisplayer.getDefault().notify(ndesc); 751 if (ret == NotifyDescriptor.YES_OPTION) { 752 closeDialog(); 753 } 754 } 755 } 756 } 757 }; 758 759 DialogDescriptor descriptor = new DialogDescriptor( 760 ibf, 761 NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BuildfileTitle"), true, 763 new Object [] {ok, cancel}, 764 DialogDescriptor.OK_OPTION, 765 DialogDescriptor.DEFAULT_ALIGN, 766 null, 767 actionListener 768 ); 769 770 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 771 dialog.setVisible(true); 772 } else { 773 return; 774 } 775 } 776 777 private void closeDialog() { 778 dialog.dispose(); 779 } 780 781 public boolean isSuitableProjectRoot(FileObject dir) { 785 FileObject configFilesRoot = FileSearchUtility.guessConfigFilesPath(dir); 786 if (configFilesRoot != null && !FileUtil.isParentOf(dir, configFilesRoot)) { 787 return false; 788 } 789 FileObject[] srcRoots = FileSearchUtility.guessJavaRoots(dir); 790 if (srcRoots != null && !isParentOf(dir, srcRoots)) { 791 return false; 792 } 793 return true; 794 } 795 796 private boolean isParentOf(FileObject dir, FileObject[] fos) { 797 boolean result = true; 798 if (fos != null) { 799 for (int i = 0; i < fos.length; i++) { 800 result = FileUtil.isParentOf(dir, fos[i]); 801 if (!result) { 802 return result; 803 } 804 } 805 } 806 return result; 807 } 808 809 813 private void initServers(String selectedServerInstanceID) { 814 serversModel.removeAllElements(); 816 Set <ServerInstanceWrapper> servers = new TreeSet <ServerInstanceWrapper>(); 817 ServerInstanceWrapper selectedItem = null; 818 boolean sjasFound = false; 819 for (String serverInstanceID : Deployment.getDefault().getServerInstanceIDs()) { 820 String displayName = Deployment.getDefault().getServerInstanceDisplayName(serverInstanceID); 821 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID); 822 if (displayName != null && j2eePlatform != null && j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.CLIENT)) { 823 ServerInstanceWrapper serverWrapper = new ServerInstanceWrapper(serverInstanceID, displayName); 824 if (selectedItem == null || !sjasFound) { 826 if (selectedServerInstanceID != null) { 827 if (selectedServerInstanceID.equals(serverInstanceID)) { 828 selectedItem = serverWrapper; 829 } 830 } else { 831 String shortName = Deployment.getDefault().getServerID(serverInstanceID); 833 if ("J2EE".equals(shortName)) { selectedItem = serverWrapper; 835 sjasFound = true; 836 } 837 else 838 if ("JBoss4".equals(shortName)) { selectedItem = serverWrapper; 840 } 841 } 842 } 843 servers.add(serverWrapper); 844 } 845 } 846 for (ServerInstanceWrapper item : servers) { 847 serversModel.addElement(item); 848 } 849 if (selectedItem != null) { 850 serversModel.setSelectedItem(selectedItem); 852 } else if (serversModel.getSize() > 0) { 853 serversModel.setSelectedItem(serversModel.getElementAt(0)); 855 } 856 } 857 858 public String getSelectedServerInstanceID() { 859 ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem(); 860 if (serverInstanceWrapper == null) { 861 return null; 862 } 863 return serverInstanceWrapper.getServerInstanceID(); 864 } 865 866 public String getSelectedJ2eeSpec() { 867 Object item = j2eeSpecComboBox.getSelectedItem(); 868 return item == null ? null 869 : item.equals(J2EE_SPEC_14_LABEL) ? J2eeModule.J2EE_14 870 : item.equals(J2EE_SPEC_15_LABEL) ? J2eeModule.JAVA_EE_5 : J2eeModule.J2EE_13; 871 } 872 873 private File getAsFile(String filename) { 874 return FileUtil.normalizeFile(new File (filename)); 875 } 876 877 public File getProjectLocation() { 878 return getAsFile(projectLocation.getText()); 879 } 880 881 public File getProjectFolder() { 882 return getAsFile(projectFolder.getText()); 883 } 884 885 public String getProjectName() { 886 return projectName.getText(); 887 } 888 889 private Project getSelectedEarApplication() { 890 int idx = addToAppComboBox.getSelectedIndex(); 891 return (idx <= 0) ? null : earProjects.get(idx - 1); 892 } 893 894 private void initEnterpriseApplications() { 895 addToAppComboBox.addItem(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_AddToEApp_None")); 896 addToAppComboBox.setSelectedIndex(0); 897 898 Project[] allProjects = OpenProjects.getDefault().getOpenProjects(); 899 earProjects = new ArrayList <Project>(); 900 for (int i = 0; i < allProjects.length; i++) { 901 J2eeModuleContainer container = (J2eeModuleContainer) allProjects[i].getLookup().lookup(J2eeModuleContainer.class); 902 ProjectInformation projectInfo = ProjectUtils.getInformation(allProjects[i]); 903 if (container != null) { 904 earProjects.add(projectInfo.getProject()); 905 addToAppComboBox.addItem(projectInfo.getDisplayName()); 906 } 907 } 908 if (earProjects.size() <= 0) { 909 addToAppComboBox.setEnabled(false); 910 } 911 } 912 913 private BigDecimal getACXmlVersion(FileObject appClientXML) throws IOException { 914 if (appClientXML != null) { 915 return DDProvider.getDefault().getDDRoot(appClientXML).getVersion(); 917 } else { 918 return null; 919 } 920 } 921 922 private void checkACXmlJ2eeVersion(FileObject appClientXML) { 923 try { 924 BigDecimal version = getACXmlVersion(appClientXML); 925 if (version == null) { 926 return; 927 } 928 929 if (new BigDecimal (AppClient.VERSION_1_3).equals(version)) { 930 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_13_LABEL); 931 } else if(new BigDecimal (AppClient.VERSION_1_4).equals(version)) { 932 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_14_LABEL); 933 } else if(new BigDecimal (AppClient.VERSION_5_0).equals(version)) { 934 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_15_LABEL); 935 } 936 } catch (IOException e) { 937 final ErrorManager errorManager = ErrorManager.getDefault(); 938 String message = NbBundle.getMessage(ImportLocationVisual.class, "MSG_AppClientXmlCorrupted"); errorManager.notify(errorManager.annotate(e, message)); 940 } 941 } 942 943 private void setJ2eeVersionWarningPanel() { 944 String j2ee = getSelectedJ2eeSpec(); 945 if (j2ee == null) { 946 return; 947 } 948 String warningType = J2eeVersionWarningPanel.findWarningType(j2ee); 949 if (warningType == null && warningPanel == null) { 950 return; 951 } 952 if (warningPanel == null) { 953 warningPanel = new J2eeVersionWarningPanel(warningType); 954 warningPlaceHolderPanel.add(warningPanel, java.awt.BorderLayout.CENTER); 955 warningPanel.setWarningType(warningType); 956 } else { 957 warningPanel.setWarningType(warningType); 958 } 959 } 960 961 965 private static class ServerInstanceWrapper implements Comparable { 966 967 private final String serverInstanceID; 968 private final String displayName; 969 970 ServerInstanceWrapper(String serverInstanceID, String displayName) { 971 this.serverInstanceID = serverInstanceID; 972 this.displayName = displayName; 973 } 974 975 public String getServerInstanceID() { 976 return serverInstanceID; 977 } 978 979 public String toString() { 980 return displayName; 981 } 982 983 public int compareTo(Object o) { 984 return toString().compareTo(o.toString()); 985 } 986 } 987 988 } 989 | Popular Tags |