1 19 20 package org.netbeans.modules.j2ee.ejbjarproject.ui.wizards; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import java.util.Set ; 25 import java.util.TreeSet ; 26 import javax.swing.DefaultComboBoxModel ; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.api.project.ProjectInformation; 29 import org.netbeans.api.project.ProjectUtils; 30 import org.netbeans.api.project.ui.OpenProjects; 31 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 32 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 33 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModuleContainer; 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.ejbjarproject.ui.FoldersListSettings; 37 import org.openide.WizardDescriptor; 38 import org.openide.util.NbBundle; 39 40 public class PanelOptionsVisual extends javax.swing.JPanel { 41 42 44 private PanelConfigureProject panel; 45 private J2eeVersionWarningPanel warningPanel; 46 private final DefaultComboBoxModel serversModel = new DefaultComboBoxModel (); 47 48 private List earProjects; 49 50 private static final String J2EE_SPEC_15_LABEL = NbBundle.getMessage(PanelOptionsVisual.class, "J2EESpecLevel_15"); private static final String J2EE_SPEC_14_LABEL = NbBundle.getMessage(PanelOptionsVisual.class, "J2EESpecLevel_14"); 54 55 public PanelOptionsVisual(PanelConfigureProject panel) { 56 initComponents(); 57 this.panel = panel; 58 setJ2eeVersionWarningPanel(); 59 initServers(FoldersListSettings.getDefault().getLastUsedServer()); 60 if (j2eeSpecComboBox.getModel().getSize() > 0) { 62 j2eeSpecComboBox.setSelectedIndex(0); 63 } 64 initEnterpriseApplications(); 65 } 66 67 72 private void initComponents() { 74 java.awt.GridBagConstraints gridBagConstraints; 75 76 setAsMainCheckBox = new javax.swing.JCheckBox (); 77 j2eeSpecLabel = new javax.swing.JLabel (); 78 j2eeSpecComboBox = new javax.swing.JComboBox (); 79 serverInstanceLabel = new javax.swing.JLabel (); 80 serverInstanceComboBox = new javax.swing.JComboBox (); 81 addToAppLabel = new javax.swing.JLabel (); 82 addToAppComboBox = new javax.swing.JComboBox (); 83 warningPlaceHolderPanel = new javax.swing.JPanel (); 84 manageServersButton = new javax.swing.JButton (); 85 86 setLayout(new java.awt.GridBagLayout ()); 87 88 setAsMainCheckBox.setSelected(true); 89 org.openide.awt.Mnemonics.setLocalizedText(setAsMainCheckBox, NbBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_SetAsMain_CheckBox")); 90 setAsMainCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 91 gridBagConstraints = new java.awt.GridBagConstraints (); 92 gridBagConstraints.gridx = 0; 93 gridBagConstraints.gridy = 4; 94 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 95 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; 96 gridBagConstraints.weightx = 1.0; 97 gridBagConstraints.weighty = 1.0; 98 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 99 add(setAsMainCheckBox, gridBagConstraints); 100 setAsMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NWP1_SetAsMain_A11YDesc")); 101 102 j2eeSpecLabel.setLabelFor(j2eeSpecComboBox); 103 org.openide.awt.Mnemonics.setLocalizedText(j2eeSpecLabel, NbBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_J2EESpecLevel_Label")); 104 gridBagConstraints = new java.awt.GridBagConstraints (); 105 gridBagConstraints.gridx = 0; 106 gridBagConstraints.gridy = 2; 107 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 108 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 109 add(j2eeSpecLabel, gridBagConstraints); 110 111 j2eeSpecComboBox.setPrototypeDisplayValue("MMMMMMMMM" ); 112 j2eeSpecComboBox.addActionListener(new java.awt.event.ActionListener () { 113 public void actionPerformed(java.awt.event.ActionEvent evt) { 114 j2eeSpecComboBoxActionPerformed(evt); 115 } 116 }); 117 118 gridBagConstraints = new java.awt.GridBagConstraints (); 119 gridBagConstraints.gridx = 1; 120 gridBagConstraints.gridy = 2; 121 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 122 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 123 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 124 add(j2eeSpecComboBox, gridBagConstraints); 125 j2eeSpecComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NPW1_J2EESpecLevel_A11YDesc")); 126 127 serverInstanceLabel.setLabelFor(serverInstanceComboBox); 128 org.openide.awt.Mnemonics.setLocalizedText(serverInstanceLabel, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_Server_Label")); 129 gridBagConstraints = new java.awt.GridBagConstraints (); 130 gridBagConstraints.gridx = 0; 131 gridBagConstraints.gridy = 1; 132 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 133 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 11); 134 add(serverInstanceLabel, gridBagConstraints); 135 136 serverInstanceComboBox.setModel(serversModel); 137 serverInstanceComboBox.addActionListener(new java.awt.event.ActionListener () { 138 public void actionPerformed(java.awt.event.ActionEvent evt) { 139 serverInstanceComboBoxActionPerformed(evt); 140 } 141 }); 142 143 gridBagConstraints = new java.awt.GridBagConstraints (); 144 gridBagConstraints.gridx = 1; 145 gridBagConstraints.gridy = 1; 146 gridBagConstraints.gridwidth = 2; 147 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 148 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 149 gridBagConstraints.weightx = 1.0; 150 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 6); 151 add(serverInstanceComboBox, gridBagConstraints); 152 serverInstanceComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_NEJB_Server_ComboBox_A11YDesc")); 153 154 addToAppLabel.setLabelFor(addToAppComboBox); 155 org.openide.awt.Mnemonics.setLocalizedText(addToAppLabel, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_AddToEApp_CheckBox")); 156 gridBagConstraints = new java.awt.GridBagConstraints (); 157 gridBagConstraints.gridx = 0; 158 gridBagConstraints.gridy = 0; 159 gridBagConstraints.gridwidth = 2; 160 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 161 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 162 add(addToAppLabel, gridBagConstraints); 163 164 gridBagConstraints = new java.awt.GridBagConstraints (); 165 gridBagConstraints.gridx = 2; 166 gridBagConstraints.gridy = 0; 167 gridBagConstraints.gridwidth = 2; 168 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 169 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 170 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 171 add(addToAppComboBox, gridBagConstraints); 172 173 warningPlaceHolderPanel.setLayout(new java.awt.BorderLayout ()); 174 175 gridBagConstraints = new java.awt.GridBagConstraints (); 176 gridBagConstraints.gridx = 0; 177 gridBagConstraints.gridy = 3; 178 gridBagConstraints.gridwidth = 3; 179 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 180 gridBagConstraints.weightx = 1.0; 181 add(warningPlaceHolderPanel, gridBagConstraints); 182 183 org.openide.awt.Mnemonics.setLocalizedText(manageServersButton, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_ManageServers")); 184 manageServersButton.addActionListener(new java.awt.event.ActionListener () { 185 public void actionPerformed(java.awt.event.ActionEvent evt) { 186 manageServersButtonActionPerformed(evt); 187 } 188 }); 189 190 gridBagConstraints = new java.awt.GridBagConstraints (); 191 gridBagConstraints.gridx = 3; 192 gridBagConstraints.gridy = 1; 193 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 194 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 195 add(manageServersButton, gridBagConstraints); 196 manageServersButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ASCN_ManageServers")); 197 manageServersButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ASCD_ManageServers")); 198 199 } 201 private void manageServersButtonActionPerformed(java.awt.event.ActionEvent evt) { ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem(); 203 String lastSelectedServerInstanceID = null; 204 if (serverInstanceWrapper != null) { 205 lastSelectedServerInstanceID = serverInstanceWrapper.getServerInstanceID(); 206 } 207 ServerManager.showCustomizer(lastSelectedServerInstanceID); 208 String lastSelectedJ2eeSpecLevel = (String ) j2eeSpecComboBox.getSelectedItem(); 209 initServers(lastSelectedServerInstanceID); 211 if (lastSelectedJ2eeSpecLevel != null) { 212 j2eeSpecComboBox.setSelectedItem(lastSelectedJ2eeSpecLevel); 213 } 214 } 216 private void j2eeSpecComboBoxActionPerformed(java.awt.event.ActionEvent evt) { setJ2eeVersionWarningPanel(); 218 } 220 private void serverInstanceComboBoxActionPerformed(java.awt.event.ActionEvent evt) { String prevSelectedItem = (String ) j2eeSpecComboBox.getSelectedItem(); 222 ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem(); 224 if (serverInstanceWrapper != null) { 225 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceWrapper.getServerInstanceID()); 226 Set supportedVersions = j2eePlatform.getSupportedSpecVersions(J2eeModule.EJB); 227 j2eeSpecComboBox.removeAllItems(); 228 if (supportedVersions.contains(J2eeModule.JAVA_EE_5)) { 229 j2eeSpecComboBox.addItem(J2EE_SPEC_15_LABEL); 230 } 231 if (supportedVersions.contains(J2eeModule.J2EE_14)) { 232 j2eeSpecComboBox.addItem(J2EE_SPEC_14_LABEL); 233 } 234 if (prevSelectedItem != null) { 235 j2eeSpecComboBox.setSelectedItem(prevSelectedItem); 236 } 237 } else { 238 j2eeSpecComboBox.removeAllItems(); 239 } 240 panel.fireChangeEvent(); 242 } 244 boolean valid(WizardDescriptor wizardDescriptor) { 245 if (getSelectedServer() == null) { 246 String errMsg = NbBundle.getMessage(PanelOptionsVisual.class, "MSG_NoServer"); 247 wizardDescriptor.putProperty( "WizardPanel_errorMessage", errMsg); return false; 249 } 250 return true; 251 } 252 253 void store(WizardDescriptor d) { 254 d.putProperty(WizardProperties.SET_AS_MAIN, setAsMainCheckBox.isSelected() ? Boolean.TRUE : Boolean.FALSE ); 255 d.putProperty(WizardProperties.SERVER_INSTANCE_ID, getSelectedServer()); 256 d.putProperty(WizardProperties.J2EE_LEVEL, getSelectedJ2eeSpec()); 257 d.putProperty(WizardProperties.EAR_APPLICATION, getSelectedEarApplication()); 258 if (warningPanel != null && warningPanel.getWarningType() != null && warningPanel.getDowngradeAllowed()) { 259 d.putProperty(WizardProperties.JAVA_PLATFORM, warningPanel.getSuggestedJavaPlatformName()); 260 261 String j2ee = getSelectedJ2eeSpec(); 262 if (j2ee != null) { 263 String warningType = J2eeVersionWarningPanel.findWarningType(j2ee); 264 FoldersListSettings fls = FoldersListSettings.getDefault(); 265 String srcLevel = "1.6"; if (warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_14) && fls.isAgreedSetSourceLevel14()) 267 srcLevel = "1.4"; else if (warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_15) && fls.isAgreedSetSourceLevel15()) 269 srcLevel = "1.5"; 271 d.putProperty(WizardProperties.SOURCE_LEVEL, srcLevel); 272 } 273 } else 274 d.putProperty(WizardProperties.SOURCE_LEVEL, null); 275 } 276 277 void read(WizardDescriptor d) { 278 } 279 280 private javax.swing.JComboBox addToAppComboBox; 282 private javax.swing.JLabel addToAppLabel; 283 private javax.swing.JComboBox j2eeSpecComboBox; 284 private javax.swing.JLabel j2eeSpecLabel; 285 private javax.swing.JButton manageServersButton; 286 private javax.swing.JComboBox serverInstanceComboBox; 287 private javax.swing.JLabel serverInstanceLabel; 288 private javax.swing.JCheckBox setAsMainCheckBox; 289 private javax.swing.JPanel warningPlaceHolderPanel; 290 292 296 private void initServers(String selectedServerInstanceID) { 297 serversModel.removeAllElements(); 299 Set <ServerInstanceWrapper> servers = new TreeSet <ServerInstanceWrapper>(); 300 ServerInstanceWrapper selectedItem = null; 301 boolean sjasFound = false; 302 for (String serverInstanceID : Deployment.getDefault().getServerInstanceIDs()) { 303 String displayName = Deployment.getDefault().getServerInstanceDisplayName(serverInstanceID); 304 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID); 305 if (displayName != null && j2eePlatform != null && j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.EJB)) { 306 ServerInstanceWrapper serverWrapper = new ServerInstanceWrapper(serverInstanceID, displayName); 307 if (selectedItem == null || !sjasFound) { 309 if (selectedServerInstanceID != null) { 310 if (selectedServerInstanceID.equals(serverInstanceID)) { 311 selectedItem = serverWrapper; 312 } 313 } else { 314 String shortName = Deployment.getDefault().getServerID(serverInstanceID); 316 if ("J2EE".equals(shortName)) { selectedItem = serverWrapper; 318 sjasFound = true; 319 } 320 else 321 if ("JBoss4".equals(shortName)) { selectedItem = serverWrapper; 323 } 324 } 325 } 326 servers.add(serverWrapper); 327 } 328 } 329 for (ServerInstanceWrapper item : servers) { 330 serversModel.addElement(item); 331 } 332 if (selectedItem != null) { 333 serversModel.setSelectedItem(selectedItem); 335 } else if (serversModel.getSize() > 0) { 336 serversModel.setSelectedItem(serversModel.getElementAt(0)); 338 } 339 } 340 341 private String getSelectedJ2eeSpec() { 342 Object item = j2eeSpecComboBox.getSelectedItem(); 343 return item == null ? null 344 : item.equals(J2EE_SPEC_14_LABEL) ? J2eeModule.J2EE_14 345 : item.equals(J2EE_SPEC_15_LABEL) ? J2eeModule.JAVA_EE_5 : J2eeModule.J2EE_13; 346 } 347 348 private String getSelectedServer() { 349 ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem(); 350 if (serverInstanceWrapper == null) { 351 return null; 352 } 353 return serverInstanceWrapper.getServerInstanceID(); 354 } 355 356 private Project getSelectedEarApplication() { 357 int idx = addToAppComboBox.getSelectedIndex(); 358 return (idx <= 0) ? null : (Project) earProjects.get(idx - 1); 359 } 360 361 private void initEnterpriseApplications() { 362 addToAppComboBox.addItem(NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_AddToEApp_None")); 363 addToAppComboBox.setSelectedIndex(0); 364 365 Project[] allProjects = OpenProjects.getDefault().getOpenProjects(); 366 earProjects = new ArrayList (); 367 for (int i = 0; i < allProjects.length; i++) { 368 J2eeModuleContainer container = (J2eeModuleContainer) allProjects[i].getLookup().lookup(J2eeModuleContainer.class); 369 ProjectInformation projectInfo = ProjectUtils.getInformation(allProjects[i]); 370 if (container != null) { 371 earProjects.add(projectInfo.getProject()); 372 addToAppComboBox.addItem(projectInfo.getDisplayName()); 373 } 374 } 375 if (earProjects.size() <= 0) { 376 addToAppComboBox.setEnabled(false); 377 } 378 } 379 380 private void setJ2eeVersionWarningPanel() { 381 String j2ee = getSelectedJ2eeSpec(); 382 if (j2ee == null) 383 return; 384 String warningType = J2eeVersionWarningPanel.findWarningType(j2ee); 385 if (warningType == null && warningPanel == null) 386 return; 387 if (warningPanel == null) { 388 warningPanel = new J2eeVersionWarningPanel(warningType); 389 warningPlaceHolderPanel.add(warningPanel, java.awt.BorderLayout.CENTER); 390 warningPanel.setWarningType(warningType); 391 } else { 392 warningPanel.setWarningType(warningType); 393 } 394 } 395 396 397 401 private static class ServerInstanceWrapper implements Comparable { 402 403 private final String serverInstanceID; 404 private final String displayName; 405 406 ServerInstanceWrapper(String serverInstanceID, String displayName) { 407 this.serverInstanceID = serverInstanceID; 408 this.displayName = displayName; 409 } 410 411 public String getServerInstanceID() { 412 return serverInstanceID; 413 } 414 415 public String toString() { 416 return displayName; 417 } 418 419 public int compareTo(Object o) { 420 return toString().compareTo(o.toString()); 421 } 422 } 423 } 424 425 | Popular Tags |