1 19 20 package org.netbeans.modules.j2ee.earproject.ui.customizer; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.util.Arrays ; 25 import java.util.Collection ; 26 import java.util.LinkedHashSet ; 27 import java.util.Map ; 28 import java.util.TreeMap ; 29 import javax.swing.JPanel ; 30 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 31 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 32 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 33 import org.netbeans.modules.j2ee.earproject.ProjectEar; 34 import org.openide.util.HelpCtx; 35 import org.openide.util.NbBundle; 36 37 public final class CustomizerRun extends JPanel implements ArchiveCustomizerPanel, HelpCtx.Provider { 38 39 private final VisualPropertySupport vps; 41 private final VisualPropertySupport vps1; 44 47 private String [] serverInstanceIDs; 48 private String [] serverNames; 49 50 51 private boolean initialized; 52 53 private final EarProjectProperties earProperties; 54 55 public CustomizerRun(final EarProjectProperties earProperties, final ProjectEar wm) { 56 this.earProperties = earProperties; 57 initComponents(); 58 this.getAccessibleContext().setAccessibleDescription( 59 NbBundle.getMessage(CustomizerRun.class, "ACS_CustomizeRun_A11YDesc")); vps = new VisualPropertySupport(earProperties); 63 vps1 = new VisualPropertySupport(earProperties); 64 clientModuleUriCombo.addActionListener(new ActionListener () { 65 public void actionPerformed(ActionEvent e) { 66 updateEnabled(); 67 } 68 }); 69 updateEnabled(); 70 String j2eeVersion = earProperties.getProject().getJ2eePlatformVersion(); 71 if (J2eeModule.JAVA_EE_5.equals(j2eeVersion)) { 72 jTextFieldVersion.setText(EarProjectProperties.JAVA_EE_SPEC_50_LABEL); 73 } else if (J2eeModule.J2EE_14.equals(j2eeVersion)) { 74 jTextFieldVersion.setText(EarProjectProperties.J2EE_SPEC_14_LABEL); 75 } 76 } 77 78 private void updateEnabled() { 79 boolean displayInBrowser = jCheckBoxDisplayBrowser.isSelected(); 80 boolean isWebUri = earProperties.isWebUri((String ) clientModuleUriCombo.getSelectedItem()); 81 jTextFieldRelativeURL.setEnabled(displayInBrowser && isWebUri); 82 jLabelContextPathDesc.setEnabled(displayInBrowser && isWebUri); 83 jLabelRelativeURL.setEnabled(displayInBrowser && isWebUri); 84 jTextMainClass.setEnabled(!isWebUri); 85 jTextArgs.setEnabled(!isWebUri); 86 jTextVMOptions.setEnabled(!isWebUri); 87 jLabelMainClass.setEnabled(!isWebUri); 88 jLabelArgs.setEnabled(!isWebUri); 89 jLabelVMOptions.setEnabled(!isWebUri); 90 jLabelVMOptionsExample.setEnabled(!isWebUri); 91 } 92 93 public void initValues() { 94 if (initialized) { 95 return; 96 } 97 initServerInstances(); 98 99 vps.register(jCheckBoxDisplayBrowser, EarProjectProperties.DISPLAY_BROWSER); 100 vps.register(jTextFieldRelativeURL, EarProjectProperties.LAUNCH_URL_RELATIVE); 101 vps.register(jComboBoxServer, serverNames, serverInstanceIDs, EarProjectProperties.J2EE_SERVER_INSTANCE); 102 103 vps.register(jTextMainClass, EarProjectProperties.APPCLIENT_MAIN_CLASS); 104 vps.register(jTextArgs, EarProjectProperties.APPCLIENT_ARGS); 105 vps.register(jTextVMOptions, EarProjectProperties.APPCLIENT_JVM_OPTIONS); 106 107 126 String [] displayUris = getDisplayUris(); 127 vps1.register(clientModuleUriCombo, displayUris, getUris(displayUris), 128 EarProjectProperties.CLIENT_MODULE_URI); 129 130 jTextFieldRelativeURL.setEditable(jCheckBoxDisplayBrowser.isSelected()); 131 initialized = true; 132 } 133 134 private String [] getDisplayUris() { 135 Collection <String > uris = new LinkedHashSet <String >(); 136 uris.addAll(Arrays.asList(earProperties.getWebUris())); 137 uris.addAll(Arrays.asList(earProperties.getAppClientUris())); 138 return uris.toArray(new String [uris.size()]); 139 } 140 141 private String [] getUris(final String [] displayUris) { 142 String appClient = (String ) earProperties.get(earProperties.APPLICATION_CLIENT); 143 String [] uris = new String [displayUris.length]; 144 for (int i = 0; i < uris.length; i++) { 145 if (earProperties.isWebUri(displayUris[i])) { 146 uris[i] = displayUris[i]; 147 } else if (earProperties.isAppClientUri(displayUris[i])) { 148 if (displayUris[i].equals(appClient)) { 149 uris[i] = earProperties.getClientModuleUriForAppClient(); 150 } else { 151 uris[i] = displayUris[i]; 152 } 153 } else { 154 assert false : "Nor web module neither application client: " + displayUris[i]; } 156 } 157 return uris; 158 } 159 160 private int getLongestVersionLength() { 161 return Math.max( 162 EarProjectProperties.JAVA_EE_SPEC_50_LABEL.length(), 163 EarProjectProperties.J2EE_SPEC_14_LABEL.length()); 164 } 165 166 171 private void initComponents() { 173 java.awt.GridBagConstraints gridBagConstraints; 174 175 jLabelContextPath = new javax.swing.JLabel (); 176 jLabelServer = new javax.swing.JLabel (); 177 jComboBoxServer = new javax.swing.JComboBox (); 178 jCheckBoxDisplayBrowser = new javax.swing.JCheckBox (); 179 clientModuleUriCombo = new javax.swing.JComboBox (); 180 webInfoPanel = new javax.swing.JPanel (); 181 jLabelContextPathDesc = new javax.swing.JLabel (); 182 jLabelRelativeURL = new javax.swing.JLabel (); 183 jTextFieldRelativeURL = new javax.swing.JTextField (); 184 clientInfoPanel = new javax.swing.JPanel (); 185 jLabelVMOptionsExample = new javax.swing.JLabel (); 186 jTextVMOptions = new javax.swing.JTextField (); 187 jLabelVMOptions = new javax.swing.JLabel (); 188 jLabelArgs = new javax.swing.JLabel (); 189 jLabelMainClass = new javax.swing.JLabel (); 190 jTextMainClass = new javax.swing.JTextField (); 191 jTextArgs = new javax.swing.JTextField (); 192 filler = new javax.swing.JLabel (); 193 jLabelVersion = new javax.swing.JLabel (); 194 jTextFieldVersion = new javax.swing.JTextField (); 195 196 setLayout(new java.awt.GridBagLayout ()); 197 198 jLabelContextPath.setLabelFor(clientModuleUriCombo); 199 org.openide.awt.Mnemonics.setLocalizedText(jLabelContextPath, NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_ClientModuleURI_JLabel")); 200 gridBagConstraints = new java.awt.GridBagConstraints (); 201 gridBagConstraints.gridx = 0; 202 gridBagConstraints.gridy = 0; 203 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 204 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 205 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 206 add(jLabelContextPath, gridBagConstraints); 207 208 jLabelServer.setLabelFor(jComboBoxServer); 209 org.openide.awt.Mnemonics.setLocalizedText(jLabelServer, NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Server_JLabel")); 210 gridBagConstraints = new java.awt.GridBagConstraints (); 211 gridBagConstraints.gridx = 0; 212 gridBagConstraints.gridy = 1; 213 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 214 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 215 add(jLabelServer, gridBagConstraints); 216 217 jComboBoxServer.addActionListener(new java.awt.event.ActionListener () { 218 public void actionPerformed(java.awt.event.ActionEvent evt) { 219 jComboBoxServerActionPerformed(evt); 220 } 221 }); 222 223 gridBagConstraints = new java.awt.GridBagConstraints (); 224 gridBagConstraints.gridx = 1; 225 gridBagConstraints.gridy = 1; 226 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 227 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 228 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 229 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 230 add(jComboBoxServer, gridBagConstraints); 231 jComboBoxServer.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerRun.class, "ACS_CustomizeRun_Server_A11YDesc")); 232 233 jCheckBoxDisplayBrowser.setSelected(true); 234 org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxDisplayBrowser, NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_DisplayBrowser_JCheckBox")); 235 jCheckBoxDisplayBrowser.addActionListener(new java.awt.event.ActionListener () { 236 public void actionPerformed(java.awt.event.ActionEvent evt) { 237 jCheckBoxDisplayBrowserActionPerformed(evt); 238 } 239 }); 240 241 gridBagConstraints = new java.awt.GridBagConstraints (); 242 gridBagConstraints.gridx = 0; 243 gridBagConstraints.gridy = 3; 244 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 245 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 246 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 247 gridBagConstraints.insets = new java.awt.Insets (11, 0, 0, 0); 248 add(jCheckBoxDisplayBrowser, gridBagConstraints); 249 jCheckBoxDisplayBrowser.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerRun.class, "ACS_CustomizeRun_DisplayBrowser_A11YDesc")); 250 251 gridBagConstraints = new java.awt.GridBagConstraints (); 252 gridBagConstraints.gridx = 1; 253 gridBagConstraints.gridy = 0; 254 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 255 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 256 gridBagConstraints.insets = new java.awt.Insets (0, 12, 6, 0); 257 add(clientModuleUriCombo, gridBagConstraints); 258 259 webInfoPanel.setLayout(new java.awt.GridBagLayout ()); 260 261 webInfoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_WebModInfo"))); 262 org.openide.awt.Mnemonics.setLocalizedText(jLabelContextPathDesc, NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_ContextPathDesc_JLabel")); 263 gridBagConstraints = new java.awt.GridBagConstraints (); 264 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 265 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 266 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 267 webInfoPanel.add(jLabelContextPathDesc, gridBagConstraints); 268 269 jLabelRelativeURL.setLabelFor(jTextFieldRelativeURL); 270 org.openide.awt.Mnemonics.setLocalizedText(jLabelRelativeURL, NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_RelativeURL_JLabel")); 271 gridBagConstraints = new java.awt.GridBagConstraints (); 272 gridBagConstraints.gridx = 0; 273 gridBagConstraints.gridy = 1; 274 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 275 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 276 webInfoPanel.add(jLabelRelativeURL, gridBagConstraints); 277 278 gridBagConstraints = new java.awt.GridBagConstraints (); 279 gridBagConstraints.gridx = 1; 280 gridBagConstraints.gridy = 1; 281 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 282 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; 283 gridBagConstraints.weightx = 1.0; 284 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 285 webInfoPanel.add(jTextFieldRelativeURL, gridBagConstraints); 286 jTextFieldRelativeURL.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerRun.class, "ACS_CustomizeRun_RelativeURL_A11YDesc")); 287 288 gridBagConstraints = new java.awt.GridBagConstraints (); 289 gridBagConstraints.gridx = 0; 290 gridBagConstraints.gridy = 4; 291 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 292 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 293 gridBagConstraints.insets = new java.awt.Insets (11, 0, 0, 0); 294 add(webInfoPanel, gridBagConstraints); 295 296 clientInfoPanel.setLayout(new java.awt.GridBagLayout ()); 297 298 clientInfoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_ClientInfo"))); 299 org.openide.awt.Mnemonics.setLocalizedText(jLabelVMOptionsExample, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_VM_Options_Example")); 300 gridBagConstraints = new java.awt.GridBagConstraints (); 301 gridBagConstraints.gridx = 1; 302 gridBagConstraints.gridy = 3; 303 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 304 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 305 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 306 gridBagConstraints.weighty = 1.0; 307 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 308 clientInfoPanel.add(jLabelVMOptionsExample, gridBagConstraints); 309 310 gridBagConstraints = new java.awt.GridBagConstraints (); 311 gridBagConstraints.gridx = 1; 312 gridBagConstraints.gridy = 2; 313 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 314 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 315 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 316 gridBagConstraints.weightx = 1.0; 317 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 318 clientInfoPanel.add(jTextVMOptions, gridBagConstraints); 319 320 jLabelVMOptions.setLabelFor(jTextVMOptions); 321 org.openide.awt.Mnemonics.setLocalizedText(jLabelVMOptions, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_VM_Options")); 322 gridBagConstraints = new java.awt.GridBagConstraints (); 323 gridBagConstraints.gridx = 0; 324 gridBagConstraints.gridy = 2; 325 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 326 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 327 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 328 clientInfoPanel.add(jLabelVMOptions, gridBagConstraints); 329 330 jLabelArgs.setLabelFor(jTextArgs); 331 org.openide.awt.Mnemonics.setLocalizedText(jLabelArgs, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Args_JLabel")); 332 gridBagConstraints = new java.awt.GridBagConstraints (); 333 gridBagConstraints.gridx = 0; 334 gridBagConstraints.gridy = 1; 335 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 336 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 337 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 338 clientInfoPanel.add(jLabelArgs, gridBagConstraints); 339 340 jLabelMainClass.setLabelFor(jTextMainClass); 341 org.openide.awt.Mnemonics.setLocalizedText(jLabelMainClass, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_MainClass_JLabel")); 342 gridBagConstraints = new java.awt.GridBagConstraints (); 343 gridBagConstraints.gridx = 0; 344 gridBagConstraints.gridy = 0; 345 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 346 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 347 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 348 clientInfoPanel.add(jLabelMainClass, gridBagConstraints); 349 350 gridBagConstraints = new java.awt.GridBagConstraints (); 351 gridBagConstraints.gridx = 1; 352 gridBagConstraints.gridy = 0; 353 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 354 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 355 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 356 gridBagConstraints.weightx = 1.0; 357 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 358 clientInfoPanel.add(jTextMainClass, gridBagConstraints); 359 360 gridBagConstraints = new java.awt.GridBagConstraints (); 361 gridBagConstraints.gridx = 1; 362 gridBagConstraints.gridy = 1; 363 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 364 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 365 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 366 gridBagConstraints.weightx = 1.0; 367 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 368 clientInfoPanel.add(jTextArgs, gridBagConstraints); 369 370 gridBagConstraints = new java.awt.GridBagConstraints (); 371 gridBagConstraints.gridx = 0; 372 gridBagConstraints.gridy = 5; 373 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 374 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 375 gridBagConstraints.weightx = 1.0; 376 gridBagConstraints.insets = new java.awt.Insets (11, 0, 0, 0); 377 add(clientInfoPanel, gridBagConstraints); 378 379 gridBagConstraints = new java.awt.GridBagConstraints (); 380 gridBagConstraints.gridx = 0; 381 gridBagConstraints.gridy = 6; 382 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 383 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 384 gridBagConstraints.weighty = 1.0; 385 add(filler, gridBagConstraints); 386 387 jLabelVersion.setLabelFor(jTextFieldVersion); 388 org.openide.awt.Mnemonics.setLocalizedText(jLabelVersion, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Version_JLabel")); 389 gridBagConstraints = new java.awt.GridBagConstraints (); 390 gridBagConstraints.gridx = 0; 391 gridBagConstraints.gridy = 2; 392 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 393 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 394 gridBagConstraints.insets = new java.awt.Insets (6, 0, 6, 0); 395 add(jLabelVersion, gridBagConstraints); 396 397 jTextFieldVersion.setColumns(getLongestVersionLength()); 398 jTextFieldVersion.setEditable(false); 399 gridBagConstraints = new java.awt.GridBagConstraints (); 400 gridBagConstraints.gridx = 1; 401 gridBagConstraints.gridy = 2; 402 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 403 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 404 gridBagConstraints.insets = new java.awt.Insets (6, 12, 6, 0); 405 add(jTextFieldVersion, gridBagConstraints); 406 407 } 409 private void jComboBoxServerActionPerformed(java.awt.event.ActionEvent evt) { } 415 private void jCheckBoxDisplayBrowserActionPerformed(java.awt.event.ActionEvent evt) { updateEnabled(); 417 } 419 private javax.swing.JPanel clientInfoPanel; 421 private javax.swing.JComboBox clientModuleUriCombo; 422 private javax.swing.JLabel filler; 423 private javax.swing.JCheckBox jCheckBoxDisplayBrowser; 424 private javax.swing.JComboBox jComboBoxServer; 425 private javax.swing.JLabel jLabelArgs; 426 private javax.swing.JLabel jLabelContextPath; 427 private javax.swing.JLabel jLabelContextPathDesc; 428 private javax.swing.JLabel jLabelMainClass; 429 private javax.swing.JLabel jLabelRelativeURL; 430 private javax.swing.JLabel jLabelServer; 431 private javax.swing.JLabel jLabelVMOptions; 432 private javax.swing.JLabel jLabelVMOptionsExample; 433 private javax.swing.JLabel jLabelVersion; 434 private javax.swing.JTextField jTextArgs; 435 private javax.swing.JTextField jTextFieldRelativeURL; 436 private javax.swing.JTextField jTextFieldVersion; 437 private javax.swing.JTextField jTextMainClass; 438 private javax.swing.JTextField jTextVMOptions; 439 private javax.swing.JPanel webInfoPanel; 440 442 445 public HelpCtx getHelpCtx() { 446 return new HelpCtx(CustomizerRun.class); 447 } 448 449 private void initServerInstances() { 450 String j2eeSpec = (String )earProperties.get(EarProjectProperties.J2EE_PLATFORM); 451 String [] servInstIDs = Deployment.getDefault().getServerInstanceIDs(); 452 Deployment deployment = Deployment.getDefault(); 453 Map <String , String > servers = new TreeMap <String , String >(); 454 for (int i = 0; i < servInstIDs.length; i++) { 455 String instanceID = servInstIDs[i]; 456 J2eePlatform j2eePlat = deployment.getJ2eePlatform(instanceID); 457 String servInstDisplayName = Deployment.getDefault().getServerInstanceDisplayName(servInstIDs[i]); 458 if (servInstDisplayName != null 459 && j2eePlat != null && j2eePlat.getSupportedModuleTypes().contains(J2eeModule.EAR) 460 && j2eePlat.getSupportedSpecVersions(J2eeModule.EAR).contains(j2eeSpec)) { 461 servers.put(servInstDisplayName, instanceID); 462 } 463 } 464 serverInstanceIDs = servers.values().toArray(new String [servers.size()]); 465 serverNames = servers.keySet().toArray(new String [servers.size()]); 466 } 467 468 } 469 | Popular Tags |