1 19 20 package org.netbeans.modules.j2ee.earproject.ui.wizards; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.text.MessageFormat ; 25 import java.util.Set ; 26 import java.util.StringTokenizer ; 27 import java.util.TreeSet ; 28 import javax.swing.DefaultComboBoxModel ; 29 import javax.swing.JPanel ; 30 import javax.swing.event.DocumentEvent ; 31 import javax.swing.event.DocumentListener ; 32 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 33 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 34 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 35 import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerManager; 36 import org.netbeans.modules.j2ee.earproject.ui.FoldersListSettings; 37 import org.netbeans.modules.j2ee.earproject.ui.customizer.EarProjectProperties; 38 import org.openide.WizardDescriptor; 39 import org.openide.util.NbBundle; 40 import org.openide.util.Utilities; 41 42 public class PanelOptionsVisual extends JPanel implements PropertyChangeListener { 43 44 private final PanelConfigureProject panel; 45 private final DefaultComboBoxModel serversModel = new DefaultComboBoxModel (); 46 private J2eeVersionWarningPanel warningPanel; 47 private boolean valid; 48 49 50 public PanelOptionsVisual(PanelConfigureProject panel, boolean importStyle) { 51 panel.getProjectTypeFlag(); 52 initComponents(); 53 this.panel = panel; 54 setJ2eeVersionWarningPanel(); 55 initServers(FoldersListSettings.getDefault().getLastUsedServer()); 56 if (j2eeSpecComboBox.getModel().getSize() > 0) { 58 j2eeSpecComboBox.setSelectedIndex(0); 59 } 60 if (importStyle) { 63 createEjbCheckBox.setSelected(!importStyle); 64 createWARCheckBox.setSelected(!importStyle); 65 createCarCheckBox.setSelected(!importStyle); 66 createEjbCheckBox.setVisible(!importStyle); 67 createWARCheckBox.setVisible(!importStyle); 68 createCarCheckBox.setVisible(!importStyle); 69 jTextFieldEjbModuleName.setVisible(!importStyle); 70 jTextFieldWebAppName.setVisible(!importStyle); 71 jTextFieldCarName.setVisible(!importStyle); 72 mainClassLabel.setVisible(!importStyle); 73 mainClassTextField.setVisible(!importStyle); 74 } else { 75 DocumentListener subProjectNameListener = new DocumentListener () { 76 public void insertUpdate(DocumentEvent e) { 77 projectNameChanged(); 78 } 79 public void removeUpdate(DocumentEvent e) { 80 projectNameChanged(); 81 } 82 public void changedUpdate(DocumentEvent e) { 83 projectNameChanged(); 84 } 85 }; 86 jTextFieldEjbModuleName.getDocument().addDocumentListener(subProjectNameListener); 87 jTextFieldWebAppName.getDocument().addDocumentListener(subProjectNameListener); 88 jTextFieldCarName.getDocument().addDocumentListener(subProjectNameListener); 89 this.mainClassTextField.getDocument().addDocumentListener( new DocumentListener () { 90 public void insertUpdate(DocumentEvent e) { 91 mainClassChanged(); 92 } 93 94 public void removeUpdate(DocumentEvent e) { 95 mainClassChanged(); 96 } 97 98 public void changedUpdate(DocumentEvent e) { 99 mainClassChanged(); 100 } 101 102 }); 103 } 104 } 107 108 113 private void initComponents() { 115 java.awt.GridBagConstraints gridBagConstraints; 116 117 setAsMainCheckBox = new javax.swing.JCheckBox (); 118 createEjbCheckBox = new javax.swing.JCheckBox (); 119 jTextFieldEjbModuleName = new javax.swing.JTextField (); 120 createWARCheckBox = new javax.swing.JCheckBox (); 121 jTextFieldWebAppName = new javax.swing.JTextField (); 122 warningPlaceHolderPanel = new javax.swing.JPanel (); 123 createCarCheckBox = new javax.swing.JCheckBox (); 124 jTextFieldCarName = new javax.swing.JTextField (); 125 mainClassLabel = new javax.swing.JLabel (); 126 mainClassTextField = new javax.swing.JTextField (); 127 serverAndVersionPanel = new javax.swing.JPanel (); 128 serverInstanceLabel = new javax.swing.JLabel (); 129 serverInstanceComboBox = new javax.swing.JComboBox (); 130 manageServersButton = new javax.swing.JButton (); 131 j2eeSpecLabel = new javax.swing.JLabel (); 132 j2eeSpecComboBox = new javax.swing.JComboBox (); 133 134 setLayout(new java.awt.GridBagLayout ()); 135 136 getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ASCN_ManageServers")); getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ASCD_ManageServers")); setAsMainCheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_SetAsMain_CheckBoxMnemonic").charAt(0)); 139 setAsMainCheckBox.setSelected(true); 140 setAsMainCheckBox.setText(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_SetAsMain_CheckBox")); setAsMainCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 142 gridBagConstraints = new java.awt.GridBagConstraints (); 143 gridBagConstraints.gridx = 0; 144 gridBagConstraints.gridy = 6; 145 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 146 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 147 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; 148 gridBagConstraints.weighty = 1.0; 149 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 0); 150 add(setAsMainCheckBox, gridBagConstraints); 151 setAsMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NWP1_SetAsMain_A11YDesc")); 153 createEjbCheckBox.setSelected(true); 154 org.openide.awt.Mnemonics.setLocalizedText(createEjbCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_NEAP_CreateEjbModule")); createEjbCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 156 createEjbCheckBox.addActionListener(new java.awt.event.ActionListener () { 157 public void actionPerformed(java.awt.event.ActionEvent evt) { 158 createEjbCheckBox_action(evt); 159 } 160 }); 161 162 gridBagConstraints = new java.awt.GridBagConstraints (); 163 gridBagConstraints.gridx = 0; 164 gridBagConstraints.gridy = 1; 165 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 166 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 11); 167 add(createEjbCheckBox, gridBagConstraints); 168 createEjbCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_CreateEJBModule")); 170 gridBagConstraints = new java.awt.GridBagConstraints (); 171 gridBagConstraints.gridx = 1; 172 gridBagConstraints.gridy = 1; 173 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 174 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 175 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 176 gridBagConstraints.weightx = 1.0; 177 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 5); 178 add(jTextFieldEjbModuleName, gridBagConstraints); 179 jTextFieldEjbModuleName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_EjbModuleName")); jTextFieldEjbModuleName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_EjbModuleName")); 182 createWARCheckBox.setSelected(true); 183 org.openide.awt.Mnemonics.setLocalizedText(createWARCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_NEAP_CreatWebAppModule")); createWARCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 185 createWARCheckBox.addActionListener(new java.awt.event.ActionListener () { 186 public void actionPerformed(java.awt.event.ActionEvent evt) { 187 createWebAppCheckBox_action(evt); 188 } 189 }); 190 191 gridBagConstraints = new java.awt.GridBagConstraints (); 192 gridBagConstraints.gridx = 0; 193 gridBagConstraints.gridy = 2; 194 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 195 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 11); 196 add(createWARCheckBox, gridBagConstraints); 197 createWARCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_CreateWebModule")); 199 gridBagConstraints = new java.awt.GridBagConstraints (); 200 gridBagConstraints.gridx = 1; 201 gridBagConstraints.gridy = 2; 202 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 203 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 204 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 205 gridBagConstraints.weightx = 1.0; 206 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 5); 207 add(jTextFieldWebAppName, gridBagConstraints); 208 jTextFieldWebAppName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSN_WebAppName")); jTextFieldWebAppName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_WebAppName")); 211 warningPlaceHolderPanel.setLayout(new java.awt.BorderLayout ()); 212 213 gridBagConstraints = new java.awt.GridBagConstraints (); 214 gridBagConstraints.gridx = 0; 215 gridBagConstraints.gridy = 5; 216 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 217 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 218 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 5); 219 add(warningPlaceHolderPanel, gridBagConstraints); 220 221 org.openide.awt.Mnemonics.setLocalizedText(createCarCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_NEAP_CreateCarModule")); createCarCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 223 createCarCheckBox.addActionListener(new java.awt.event.ActionListener () { 224 public void actionPerformed(java.awt.event.ActionEvent evt) { 225 createCarCheckBox_action(evt); 226 } 227 }); 228 229 gridBagConstraints = new java.awt.GridBagConstraints (); 230 gridBagConstraints.gridx = 0; 231 gridBagConstraints.gridy = 3; 232 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 233 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 11); 234 add(createCarCheckBox, gridBagConstraints); 235 createCarCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_CreateAppClientModule")); 237 jTextFieldCarName.setEnabled(false); 238 gridBagConstraints = new java.awt.GridBagConstraints (); 239 gridBagConstraints.gridx = 1; 240 gridBagConstraints.gridy = 3; 241 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 242 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 243 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 244 gridBagConstraints.weightx = 1.0; 245 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 5); 246 add(jTextFieldCarName, gridBagConstraints); 247 jTextFieldCarName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSN_AppClientName")); jTextFieldCarName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_AppClientName")); 250 mainClassLabel.setLabelFor(mainClassTextField); 251 org.openide.awt.Mnemonics.setLocalizedText(mainClassLabel, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_NWP1_MainClass_Label")); gridBagConstraints = new java.awt.GridBagConstraints (); 253 gridBagConstraints.gridx = 0; 254 gridBagConstraints.gridy = 4; 255 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 256 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 257 add(mainClassLabel, gridBagConstraints); 258 259 mainClassTextField.setEnabled(false); 260 gridBagConstraints = new java.awt.GridBagConstraints (); 261 gridBagConstraints.gridx = 1; 262 gridBagConstraints.gridy = 4; 263 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 264 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 265 gridBagConstraints.weightx = 1.0; 266 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 5); 267 add(mainClassTextField, gridBagConstraints); 268 mainClassTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCN_mainClassTextFiled")); mainClassTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_mainClassTextFiled")); 271 serverAndVersionPanel.setLayout(new java.awt.GridBagLayout ()); 272 273 serverInstanceLabel.setLabelFor(serverInstanceComboBox); 274 org.openide.awt.Mnemonics.setLocalizedText(serverInstanceLabel, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_Server_Label")); gridBagConstraints = new java.awt.GridBagConstraints (); 276 gridBagConstraints.gridx = 0; 277 gridBagConstraints.gridy = 0; 278 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 279 gridBagConstraints.insets = new java.awt.Insets (5, 5, 5, 11); 280 serverAndVersionPanel.add(serverInstanceLabel, gridBagConstraints); 281 282 serverInstanceComboBox.setModel(serversModel); 283 serverInstanceComboBox.addActionListener(new java.awt.event.ActionListener () { 284 public void actionPerformed(java.awt.event.ActionEvent evt) { 285 serverInstanceComboBoxActionPerformed(evt); 286 } 287 }); 288 289 gridBagConstraints = new java.awt.GridBagConstraints (); 290 gridBagConstraints.gridx = 1; 291 gridBagConstraints.gridy = 0; 292 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 293 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 294 gridBagConstraints.weightx = 1.0; 295 gridBagConstraints.insets = new java.awt.Insets (5, 0, 5, 6); 296 serverAndVersionPanel.add(serverInstanceComboBox, gridBagConstraints); 297 serverInstanceComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_NWP1_Server_ComboBox_A11YDesc")); 299 org.openide.awt.Mnemonics.setLocalizedText(manageServersButton, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_ManageServers")); manageServersButton.addActionListener(new java.awt.event.ActionListener () { 301 public void actionPerformed(java.awt.event.ActionEvent evt) { 302 manageServersButtonActionPerformed(evt); 303 } 304 }); 305 306 gridBagConstraints = new java.awt.GridBagConstraints (); 307 gridBagConstraints.gridx = 2; 308 gridBagConstraints.gridy = 0; 309 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 310 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 311 gridBagConstraints.insets = new java.awt.Insets (5, 0, 5, 5); 312 serverAndVersionPanel.add(manageServersButton, gridBagConstraints); 313 manageServersButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_ManageButton")); 315 j2eeSpecLabel.setLabelFor(j2eeSpecComboBox); 316 org.openide.awt.Mnemonics.setLocalizedText(j2eeSpecLabel, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_J2EESpecLevel_Label")); gridBagConstraints = new java.awt.GridBagConstraints (); 318 gridBagConstraints.gridx = 0; 319 gridBagConstraints.gridy = 1; 320 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 321 gridBagConstraints.insets = new java.awt.Insets (0, 5, 11, 11); 322 serverAndVersionPanel.add(j2eeSpecLabel, gridBagConstraints); 323 324 j2eeSpecComboBox.setPrototypeDisplayValue("MMMMMMMMM" ); 325 j2eeSpecComboBox.addActionListener(new java.awt.event.ActionListener () { 326 public void actionPerformed(java.awt.event.ActionEvent evt) { 327 j2eeSpecComboBoxActionPerformed(evt); 328 } 329 }); 330 331 gridBagConstraints = new java.awt.GridBagConstraints (); 332 gridBagConstraints.gridx = 1; 333 gridBagConstraints.gridy = 1; 334 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 335 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 336 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 5); 337 serverAndVersionPanel.add(j2eeSpecComboBox, gridBagConstraints); 338 j2eeSpecComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NPW1_J2EESpecLevel_A11YDesc")); 340 gridBagConstraints = new java.awt.GridBagConstraints (); 341 gridBagConstraints.gridx = 0; 342 gridBagConstraints.gridy = 0; 343 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 344 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 345 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 346 gridBagConstraints.weightx = 1.0; 347 add(serverAndVersionPanel, gridBagConstraints); 348 349 } 351 private void manageServersButtonActionPerformed(java.awt.event.ActionEvent evt) { ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem(); 353 String lastSelectedServerInstanceID = null; 354 if (serverInstanceWrapper != null) { 355 lastSelectedServerInstanceID = serverInstanceWrapper.getServerInstanceID(); 356 } 357 ServerManager.showCustomizer(lastSelectedServerInstanceID); 358 String lastSelectedJ2eeSpecLevel = (String ) j2eeSpecComboBox.getSelectedItem(); 359 initServers(lastSelectedServerInstanceID); 361 if (lastSelectedJ2eeSpecLevel != null) { 362 j2eeSpecComboBox.setSelectedItem(lastSelectedJ2eeSpecLevel); 363 } 364 } 366 private void createCarCheckBox_action(java.awt.event.ActionEvent evt) { jTextFieldCarName.setEnabled(createCarCheckBox.isSelected()); 368 mainClassTextField.setEnabled(createCarCheckBox.isSelected()); 369 this.panel.fireChangeEvent(); 370 } 372 private void createWebAppCheckBox_action(java.awt.event.ActionEvent evt) { jTextFieldWebAppName.setEnabled(createWARCheckBox.isSelected()); 374 this.panel.fireChangeEvent(); 375 } 377 private void createEjbCheckBox_action(java.awt.event.ActionEvent evt) { jTextFieldEjbModuleName.setEnabled(createEjbCheckBox.isSelected()); 379 this.panel.fireChangeEvent(); 380 } 382 private void serverInstanceComboBoxActionPerformed(java.awt.event.ActionEvent evt) { String prevSelectedItem = (String ) j2eeSpecComboBox.getSelectedItem(); 384 ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem(); 386 if (serverInstanceWrapper != null) { 387 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceWrapper.getServerInstanceID()); 388 Set supportedVersions = j2eePlatform.getSupportedSpecVersions(J2eeModule.EAR); 389 j2eeSpecComboBox.removeAllItems(); 390 if (supportedVersions.contains(J2eeModule.JAVA_EE_5)) { 391 j2eeSpecComboBox.addItem(EarProjectProperties.JAVA_EE_SPEC_50_LABEL); 392 } 393 if (supportedVersions.contains(J2eeModule.J2EE_14)) { 394 j2eeSpecComboBox.addItem(EarProjectProperties.J2EE_SPEC_14_LABEL); 395 } 396 if (prevSelectedItem != null) { 397 j2eeSpecComboBox.setSelectedItem(prevSelectedItem); 398 } 399 boolean carSupported = j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.CLIENT); 400 createCarCheckBox.setEnabled(carSupported); 401 jTextFieldCarName.setEnabled(carSupported && createCarCheckBox.isSelected()); 402 mainClassLabel.setEnabled(carSupported); 403 mainClassTextField.setEnabled(carSupported && createCarCheckBox.isSelected()); 404 } else { 405 j2eeSpecComboBox.removeAllItems(); 406 } 407 panel.fireChangeEvent(); 409 } 411 private void j2eeSpecComboBoxActionPerformed(java.awt.event.ActionEvent evt) { setJ2eeVersionWarningPanel(); 413 } 415 public void propertyChange(PropertyChangeEvent event) { 416 if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event.getPropertyName())) { 417 String newProjectName = (String ) event.getNewValue(); 418 if (newProjectName.trim().equals("")) { 419 return; 420 } 421 this.jTextFieldEjbModuleName.setText(MessageFormat.format( 422 NbBundle.getMessage(PanelOptionsVisual.class,"TXT_EJBProjectName"), new Object [] {newProjectName})); 423 this.jTextFieldWebAppName.setText(MessageFormat.format( 424 NbBundle.getMessage(PanelOptionsVisual.class,"TXT_WebAppProjectName"), new Object [] {newProjectName})); 425 this.jTextFieldCarName.setText(MessageFormat.format( 426 NbBundle.getMessage(PanelOptionsVisual.class,"TXT_AppClientProjectName"), new Object [] {newProjectName})); 427 newProjectName = getPackageName(newProjectName); 428 if (!Utilities.isJavaIdentifier(newProjectName)) { 429 newProjectName = NbBundle.getMessage(PanelOptionsVisual.class, "TXT_PackageNameSuffix", newProjectName); 430 } 431 this.mainClassTextField.setText(MessageFormat.format( 432 NbBundle.getMessage(PanelOptionsVisual.class,"TXT_ClassName"), new Object [] {newProjectName})); 433 } 434 } 435 436 boolean valid(WizardDescriptor wizardDescriptor) { 437 if (getSelectedServer() == null) { 438 setErrorMessage("MSG_NoServer", wizardDescriptor); return false; 440 } 441 442 if (createWARCheckBox.isSelected()) { 443 String warName = jTextFieldWebAppName.getText(); 444 if (warName.length() < 1) { 445 setErrorMessage("MSG_NoWARName", wizardDescriptor); return false; 447 } 448 if (!warName.endsWith("-war")) { setErrorMessage("MSG_WARNameNotBlueprints", wizardDescriptor); } 452 } 453 454 if (createEjbCheckBox.isSelected()) { 455 String jarName = jTextFieldEjbModuleName.getText(); 456 if (jarName.length() < 1) { 457 setErrorMessage("MSG_NoJARName", wizardDescriptor); return false; 459 } 460 if (!jarName.endsWith("-ejb")) { setErrorMessage("MSG_JARNameNotBlueprints", wizardDescriptor); } 464 } 465 466 if (createCarCheckBox.isSelected()) { 467 String jarName = jTextFieldCarName.getText(); 468 if (jarName.length() < 1) { 469 setErrorMessage("MSG_NoCARName", wizardDescriptor); return false; 471 } 472 if (!valid) { 473 setErrorMessage("ERROR_IllegalMainClassName", wizardDescriptor); return this.valid; 475 } 476 if (!jarName.endsWith("-app-client")) { setErrorMessage("MSG_CARNameNotBlueprints", wizardDescriptor); } 480 } 481 482 ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem(); 484 if (serverInstanceWrapper != null) { 485 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceWrapper.getServerInstanceID()); 486 if (!j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.CLIENT)) { 487 setErrorMessage("MSG_CARIsNotSupported", wizardDescriptor); 489 } 490 } 491 492 String specVer = getSelectedJ2eeSpec(); 493 if (null == specVer || specVer.equals(J2eeModule.J2EE_13)) { 494 setErrorMessage("MSG_UnsupportedSpec", wizardDescriptor); return false; 496 } 497 return true; 498 } 499 500 private static void setErrorMessage( 501 final String errMsgKey, final WizardDescriptor wizardDescriptor) { 502 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(PanelOptionsVisual.class, errMsgKey)); 504 } 505 506 void store(WizardDescriptor d) { 507 d.putProperty(WizardProperties.SET_AS_MAIN, setAsMainCheckBox.isSelected() ? Boolean.TRUE : Boolean.FALSE ); 508 d.putProperty(WizardProperties.SERVER_INSTANCE_ID, getSelectedServer()); 509 d.putProperty(WizardProperties.J2EE_LEVEL, getSelectedJ2eeSpec()); 510 d.putProperty(WizardProperties.CREATE_WAR, createWARCheckBox.isSelected() ? Boolean.TRUE: Boolean.FALSE); 512 d.putProperty(WizardProperties.CREATE_JAR, createEjbCheckBox.isSelected() ? Boolean.TRUE: Boolean.FALSE); 513 d.putProperty(WizardProperties.CREATE_CAR, createCarCheckBox.isSelected() ? Boolean.TRUE: Boolean.FALSE); 514 d.putProperty(WizardProperties.WAR_NAME, jTextFieldWebAppName.getText()); 515 d.putProperty(WizardProperties.JAR_NAME, jTextFieldEjbModuleName.getText()); 516 d.putProperty(WizardProperties.CAR_NAME, jTextFieldCarName.getText()); 517 d.putProperty(WizardProperties.MAIN_CLASS, mainClassTextField.getText().trim()); if (warningPanel != null && warningPanel.getWarningType() != null && warningPanel.getDowngradeAllowed()) { 519 d.putProperty(WizardProperties.JAVA_PLATFORM, warningPanel.getSuggestedJavaPlatformName()); 520 String j2ee = getSelectedJ2eeSpec(); 521 if (j2ee != null) { 522 String warningType = J2eeVersionWarningPanel.findWarningType(j2ee); 523 FoldersListSettings fls = FoldersListSettings.getDefault(); 524 String srcLevel = "1.6"; if ((warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_14) 526 || warningType.equals(J2eeVersionWarningPanel.WARN_SET_JDK_14)) 527 && fls.isAgreedSetSourceLevel14()) { 528 srcLevel = "1.4"; } else if ((warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_15) 530 || warningType.equals(J2eeVersionWarningPanel.WARN_SET_JDK_15)) 531 && fls.isAgreedSetSourceLevel15()) { 532 srcLevel = "1.5"; } 534 d.putProperty(WizardProperties.SOURCE_LEVEL, srcLevel); 535 } 536 } else { 537 d.putProperty(WizardProperties.SOURCE_LEVEL, null); 538 } 539 } 540 541 void read(WizardDescriptor d) { 542 } 543 544 private javax.swing.JCheckBox createCarCheckBox; 546 private javax.swing.JCheckBox createEjbCheckBox; 547 private javax.swing.JCheckBox createWARCheckBox; 548 private javax.swing.JComboBox j2eeSpecComboBox; 549 private javax.swing.JLabel j2eeSpecLabel; 550 private javax.swing.JTextField jTextFieldCarName; 551 private javax.swing.JTextField jTextFieldEjbModuleName; 552 private javax.swing.JTextField jTextFieldWebAppName; 553 private javax.swing.JLabel mainClassLabel; 554 private javax.swing.JTextField mainClassTextField; 555 private javax.swing.JButton manageServersButton; 556 private javax.swing.JPanel serverAndVersionPanel; 557 private javax.swing.JComboBox serverInstanceComboBox; 558 private javax.swing.JLabel serverInstanceLabel; 559 private javax.swing.JCheckBox setAsMainCheckBox; 560 private javax.swing.JPanel warningPlaceHolderPanel; 561 563 567 private void initServers(String selectedServerInstanceID) { 568 serversModel.removeAllElements(); 570 Set <ServerInstanceWrapper> servers = new TreeSet <ServerInstanceWrapper>(); 571 ServerInstanceWrapper selectedItem = null; 572 boolean sjasFound = false; 573 for (String serverInstanceID : Deployment.getDefault().getServerInstanceIDs()) { 574 String displayName = Deployment.getDefault().getServerInstanceDisplayName(serverInstanceID); 575 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID); 576 if (displayName != null && j2eePlatform != null && j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.EAR)) { 577 ServerInstanceWrapper serverWrapper = new ServerInstanceWrapper(serverInstanceID, displayName); 578 if (selectedItem == null || !sjasFound) { 580 if (selectedServerInstanceID != null) { 581 if (selectedServerInstanceID.equals(serverInstanceID)) { 582 selectedItem = serverWrapper; 583 } 584 } else { 585 String shortName = Deployment.getDefault().getServerID(serverInstanceID); 587 if ("J2EE".equals(shortName)) { selectedItem = serverWrapper; 589 sjasFound = true; 590 } 591 else 592 if ("JBoss4".equals(shortName)) { selectedItem = serverWrapper; 594 } 595 } 596 } 597 servers.add(serverWrapper); 598 } 599 } 600 for (ServerInstanceWrapper item : servers) { 601 serversModel.addElement(item); 602 } 603 if (selectedItem != null) { 604 serversModel.setSelectedItem(selectedItem); 606 } else if (serversModel.getSize() > 0) { 607 serversModel.setSelectedItem(serversModel.getElementAt(0)); 609 } 610 } 611 612 private String getSelectedJ2eeSpec() { 613 Object item = j2eeSpecComboBox.getSelectedItem(); 614 return item == null ? null 615 : item.equals(EarProjectProperties.JAVA_EE_SPEC_50_LABEL) ? J2eeModule.JAVA_EE_5 : 616 ( item.equals(EarProjectProperties.J2EE_SPEC_14_LABEL) ? J2eeModule.J2EE_14 : J2eeModule.J2EE_13); 617 } 618 619 private String getSelectedServer() { 620 ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem(); 621 if (serverInstanceWrapper == null) { 622 return null; 623 } 624 return serverInstanceWrapper.getServerInstanceID(); 625 } 626 627 private void setJ2eeVersionWarningPanel() { 628 String j2ee = getSelectedJ2eeSpec(); 629 if (j2ee == null) { 630 return; 631 } 632 String warningType = J2eeVersionWarningPanel.findWarningType(j2ee); 633 if (warningType == null && warningPanel == null) { 634 return; 635 } 636 if (warningPanel == null) { 637 warningPanel = new J2eeVersionWarningPanel(warningType); 638 warningPlaceHolderPanel.add(warningPanel, java.awt.BorderLayout.CENTER); 639 } 640 warningPanel.setWarningType(warningType); 641 } 642 643 private void mainClassChanged() { 644 String mainClassName = this.mainClassTextField.getText().trim(); 645 StringTokenizer tk = new StringTokenizer (mainClassName, "."); boolean valid = tk.countTokens() > 0; 647 while (tk.hasMoreTokens()) { 648 String token = tk.nextToken(); 649 if (token.length() == 0 || !Utilities.isJavaIdentifier(token)) { 650 valid = false; 651 break; 652 } 653 } 654 this.valid = valid; 655 this.panel.fireChangeEvent(); 656 } 657 658 private void projectNameChanged() { 659 this.panel.fireChangeEvent(); 660 } 661 662 private String getPackageName(String displayName) { 663 StringBuffer builder = new StringBuffer (); 664 boolean firstLetter = true; 665 for (int i=0; i< displayName.length(); i++) { 666 char c = displayName.charAt(i); 667 if ((!firstLetter && Character.isJavaIdentifierPart(c)) || (firstLetter && Character.isJavaIdentifierStart(c))) { 668 firstLetter = false; 669 if (Character.isUpperCase(c)) { 670 c = Character.toLowerCase(c); 671 } 672 builder.append(c); 673 } 674 } 675 return builder.length() == 0 ? NbBundle.getMessage(PanelOptionsVisual.class,"TXT_DefaultPackageName") : builder.toString(); 676 } 677 678 682 private static class ServerInstanceWrapper implements Comparable { 683 684 private final String serverInstanceID; 685 private final String displayName; 686 687 ServerInstanceWrapper(String serverInstanceID, String displayName) { 688 this.serverInstanceID = serverInstanceID; 689 this.displayName = displayName; 690 } 691 692 public String getServerInstanceID() { 693 return serverInstanceID; 694 } 695 696 public String toString() { 697 return displayName; 698 } 699 700 public int compareTo(Object o) { 701 return toString().compareTo(o.toString()); 702 } 703 704 } 705 706 } 707 708 | Popular Tags |