1 19 20 package org.netbeans.modules.j2ee.clientproject; 21 22 import java.awt.Dialog ; 23 import java.awt.event.MouseEvent ; 24 import java.io.IOException ; 25 import java.text.MessageFormat ; 26 import java.util.Arrays ; 27 import java.util.HashMap ; 28 import java.util.HashSet ; 29 import java.util.Map ; 30 import java.util.Properties ; 31 import java.util.Set ; 32 import java.util.regex.Pattern ; 33 import javax.swing.JButton ; 34 import javax.swing.event.ChangeEvent ; 35 import javax.swing.event.ChangeListener ; 36 import org.apache.tools.ant.module.api.support.ActionUtils; 37 import org.netbeans.api.debugger.DebuggerManager; 38 import org.netbeans.api.debugger.Session; 39 import org.netbeans.api.debugger.jpda.AttachingDICookie; 40 import org.netbeans.api.fileinfo.NonRecursiveFolder; 41 import org.netbeans.api.java.classpath.ClassPath; 42 import org.netbeans.api.java.project.JavaProjectConstants; 43 import org.netbeans.api.java.source.SourceUtils; 44 import org.netbeans.api.project.ProjectInformation; 45 import org.netbeans.api.project.ProjectManager; 46 import org.netbeans.api.project.ProjectUtils; 47 import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants; 48 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; 49 import org.netbeans.modules.j2ee.clientproject.ui.customizer.MainClassChooser; 50 import org.netbeans.modules.j2ee.clientproject.ui.customizer.MainClassWarning; 51 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 52 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 53 import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo; 54 import org.netbeans.spi.project.ActionProvider; 55 import org.netbeans.spi.project.support.ant.AntProjectHelper; 56 import org.netbeans.spi.project.support.ant.EditableProperties; 57 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 58 import org.netbeans.spi.project.ui.support.DefaultProjectOperations; 59 import org.openide.DialogDescriptor; 60 import org.openide.DialogDisplayer; 61 import org.openide.ErrorManager; 62 import org.openide.NotifyDescriptor; 63 import org.openide.awt.MouseUtils; 64 import org.openide.filesystems.FileObject; 65 import org.openide.filesystems.FileUtil; 66 import org.openide.util.Lookup; 67 import org.openide.util.NbBundle; 68 69 72 class AppClientActionProvider implements ActionProvider { 73 74 private static final String COMMAND_COMPILE = "compile"; private static final String COMMAND_VERIFY = "verify"; 77 private static final String [] supportedActions = { 79 COMMAND_BUILD, 80 COMMAND_CLEAN, 81 COMMAND_REBUILD, 82 COMMAND_COMPILE_SINGLE, 83 COMMAND_RUN, 84 COMMAND_RUN_SINGLE, 85 COMMAND_DEBUG, 86 COMMAND_DEBUG_SINGLE, 87 EjbProjectConstants.COMMAND_REDEPLOY, 88 JavaProjectConstants.COMMAND_JAVADOC, 89 COMMAND_TEST, 90 COMMAND_TEST_SINGLE, 91 COMMAND_DEBUG_TEST_SINGLE, 92 JavaProjectConstants.COMMAND_DEBUG_FIX, 93 COMMAND_DEBUG_STEP_INTO, 94 COMMAND_COMPILE, 95 COMMAND_VERIFY, 96 COMMAND_DELETE, 97 COMMAND_COPY, 98 COMMAND_MOVE, 99 COMMAND_RENAME, 100 }; 101 102 103 private static final String [] platformSensitiveActions = { 104 COMMAND_BUILD, 105 COMMAND_REBUILD, 106 COMMAND_COMPILE_SINGLE, 107 COMMAND_RUN, 108 COMMAND_RUN_SINGLE, 109 COMMAND_DEBUG, 110 COMMAND_DEBUG_SINGLE, 111 JavaProjectConstants.COMMAND_JAVADOC, 112 COMMAND_TEST, 113 COMMAND_TEST_SINGLE, 114 COMMAND_DEBUG_TEST_SINGLE, 115 JavaProjectConstants.COMMAND_DEBUG_FIX, 116 COMMAND_DEBUG_STEP_INTO, 117 }; 118 119 AppClientProject project; 121 122 private final AntProjectHelper antProjectHelper; 124 private final UpdateHelper updateHelper; 125 126 127 Map <String ,String []> commands; 128 129 130 final Set <String > bkgScanSensitiveActions; 131 132 public AppClientActionProvider( AppClientProject project, AntProjectHelper antProjectHelper, UpdateHelper updateHelper ) { 133 commands = new HashMap <String , String []>(); 134 commands.put(COMMAND_BUILD, new String [] {"dist"}); commands.put(COMMAND_CLEAN, new String [] {"clean"}); commands.put(COMMAND_REBUILD, new String [] {"clean", "dist"}); commands.put(COMMAND_COMPILE_SINGLE, new String [] {"compile-single"}); commands.put(COMMAND_RUN, new String [] {"run"}); commands.put(COMMAND_RUN_SINGLE, new String [] {"run-single"}); commands.put(EjbProjectConstants.COMMAND_REDEPLOY, new String [] {"run-deploy"}); commands.put(COMMAND_DEBUG, new String [] {"debug"}); commands.put(JavaProjectConstants.COMMAND_JAVADOC, new String [] {"javadoc"}); commands.put(COMMAND_TEST, new String [] {"test"}); commands.put(COMMAND_TEST_SINGLE, new String [] {"test-single"}); commands.put(COMMAND_DEBUG_TEST_SINGLE, new String [] {"debug-test"}); commands.put(JavaProjectConstants.COMMAND_DEBUG_FIX, new String [] {"debug-fix"}); commands.put(COMMAND_DEBUG_STEP_INTO, new String [] {"debug-stepinto"}); commands.put(COMMAND_COMPILE, new String [] {"compile"}); commands.put(COMMAND_VERIFY, new String [] {"verify"}); 153 this.bkgScanSensitiveActions = new HashSet <String >(Arrays.asList(new String [] { 154 COMMAND_RUN, 155 COMMAND_RUN_SINGLE, 156 COMMAND_DEBUG, 157 COMMAND_DEBUG_SINGLE, 158 COMMAND_DEBUG_STEP_INTO 159 })); 160 161 this.antProjectHelper = antProjectHelper; 162 this.updateHelper = updateHelper; 163 this.project = project; 164 } 165 166 private FileObject findBuildXml() { 167 return project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); 168 } 169 170 public String [] getSupportedActions() { 171 return supportedActions; 172 } 173 174 public void invokeAction( final String command, final Lookup context ) throws IllegalArgumentException { 175 if (COMMAND_DELETE.equals(command)) { 176 DefaultProjectOperations.performDefaultDeleteOperation(project); 177 return ; 178 } 179 180 if (COMMAND_COPY.equals(command)) { 181 DefaultProjectOperations.performDefaultCopyOperation(project); 182 return ; 183 } 184 185 if (COMMAND_MOVE.equals(command)) { 186 DefaultProjectOperations.performDefaultMoveOperation(project); 187 return ; 188 } 189 190 if (COMMAND_RENAME.equals(command)) { 191 DefaultProjectOperations.performDefaultRenameOperation(project, null); 192 return ; 193 } 194 195 Runnable action = new Runnable () { 196 public void run() { 197 Properties p = new Properties (); 198 String [] targetNames; 199 200 targetNames = getTargetNames(command, context, p); 201 if (targetNames == null) { 202 return; 203 } 204 if (targetNames.length == 0) { 205 targetNames = null; 206 } 207 if (p.keySet().size() == 0) { 208 p = null; 209 } 210 try { 211 FileObject buildFo = findBuildXml(); 212 if (buildFo == null || !buildFo.isValid()) { 213 NotifyDescriptor nd = new NotifyDescriptor.Message(NbBundle.getMessage(AppClientActionProvider.class, 215 "LBL_No_Build_XML_Found"), NotifyDescriptor.WARNING_MESSAGE); DialogDisplayer.getDefault().notify(nd); 217 } else { 218 ActionUtils.runTarget(buildFo, targetNames, p); 219 } 220 } catch (IOException e) { 221 ErrorManager.getDefault().notify(e); 222 } 223 } 224 }; 225 226 action.run(); 231 } 233 234 237 String [] getTargetNames(String command, Lookup context, Properties p) throws IllegalArgumentException { 238 if (Arrays.asList(platformSensitiveActions).contains(command)) { 239 final String activePlatformId = this.project.evaluator().getProperty(AppClientProjectProperties.JAVA_PLATFORM); if (AppClientProjectUtil.getActivePlatform(activePlatformId) == null) { 241 showPlatformWarning(); 242 return null; 243 } 244 } 245 String [] targetNames = new String [0]; 246 if ( command.equals( COMMAND_COMPILE_SINGLE ) ) { 247 FileObject[] sourceRoots = project.getSourceRoots().getRoots(); 248 FileObject[] files = findSourcesAndPackages( context, sourceRoots); 249 boolean recursive = (context.lookup(NonRecursiveFolder.class) == null); 250 if (files != null) { 251 p.setProperty("javac.includes", ActionUtils.antIncludesList(files, getRoot(sourceRoots,files[0]), recursive)); targetNames = new String [] {"compile-single"}; } else { 254 FileObject[] testRoots = project.getTestSourceRoots().getRoots(); 255 files = findSourcesAndPackages(context, testRoots); 256 p.setProperty("javac.includes", ActionUtils.antIncludesList(files, getRoot(testRoots,files[0]), recursive)); targetNames = new String [] {"compile-test-single"}; } 259 } else if ( command.equals( COMMAND_TEST_SINGLE ) ) { 260 FileObject[] files = findTestSourcesForSources(context); 261 targetNames = setupTestSingle(p, files); 262 } else if ( command.equals( COMMAND_DEBUG_TEST_SINGLE ) ) { 263 FileObject[] files = findTestSourcesForSources(context); 264 targetNames = setupDebugTestSingle(p, files); 265 } else if ( command.equals( JavaProjectConstants.COMMAND_DEBUG_FIX ) ) { 266 FileObject[] files = findSources( context ); 268 String path = null; 269 if (files != null) { 270 path = FileUtil.getRelativePath(getRoot(project.getSourceRoots().getRoots(),files[0]), files[0]); 271 targetNames = new String [] {"debug-fix"}; } else { 273 files = findTestSources(context, false); 274 path = FileUtil.getRelativePath(getRoot(project.getTestSourceRoots().getRoots(),files[0]), files[0]); 275 targetNames = new String [] {"debug-fix-test"}; } 277 if (path.endsWith(".java")) { path = path.substring(0, path.length() - 5); 280 } 281 p.setProperty("fix.includes", path); } else if (command.equals(COMMAND_RUN) || command.equals(EjbProjectConstants.COMMAND_REDEPLOY) || command.equals(COMMAND_DEBUG) ) { 283 EditableProperties ep = updateHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 284 if (!isSelectedServer()) { 286 return null; 287 } 288 289 if (command.equals(COMMAND_DEBUG)) { 291 NotifyDescriptor nd = new NotifyDescriptor.Message(NbBundle.getMessage(AppClientActionProvider.class, "MSG_Server_State_Question"), NotifyDescriptor.QUESTION_MESSAGE); 292 nd.setOptionType(NotifyDescriptor.YES_NO_OPTION); 293 nd.setOptions(new Object [] {NotifyDescriptor.YES_OPTION, NotifyDescriptor.NO_OPTION}); 294 if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.YES_OPTION) { 295 nd = new NotifyDescriptor.Message(NbBundle.getMessage(AppClientActionProvider.class, "MSG_Server_State"), NotifyDescriptor.INFORMATION_MESSAGE); 296 Object o = DialogDisplayer.getDefault().notify(nd); 297 return null; 298 } 299 } 300 301 String mainClass = (String )ep.get("main.class"); MainClassStatus result = isSetMainClass(project.getSourceRoots().getRoots(), mainClass); 304 if (result != MainClassStatus.SET_AND_VALID) { 305 do { 306 if (showMainClassWarning(mainClass, ProjectUtils.getInformation(project).getDisplayName(), ep,result)) { 308 return null; 309 } 310 mainClass = (String )ep.get("main.class"); result=isSetMainClass(project.getSourceRoots().getRoots(), mainClass); 312 } while (result != MainClassStatus.SET_AND_VALID); 313 try { 314 if (updateHelper.requestSave()) { 315 updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,ep); 316 ProjectManager.getDefault().saveProject(project); 317 } else { 318 return null; 319 } 320 } catch (IOException ioe) { 321 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Error while saving project: " + ioe); 322 } 323 } 324 325 if (command.equals (EjbProjectConstants.COMMAND_REDEPLOY)) { 326 p.setProperty("forceRedeploy", "true"); } else { 328 p.setProperty("forceRedeploy", "false"); } 330 331 targetNames = (String [])commands.get(command); 332 if (targetNames == null) { 333 throw new IllegalArgumentException (command); 334 } 335 } else if (command.equals(COMMAND_RUN_SINGLE)) { 336 FileObject[] files = findTestSources(context, false); 337 if (files != null) { 338 targetNames = setupTestSingle(p, files); 339 } else { 340 FileObject file = findSources(context)[0]; 342 String clazz = FileUtil.getRelativePath(getRoot(project.getSourceRoots().getRoots(),file), file); 343 p.setProperty("javac.includes", clazz); if (clazz.endsWith(".java")) { clazz = clazz.substring(0, clazz.length() - 5); 347 } 348 clazz = clazz.replace('/','.'); 349 350 if (!AppClientProjectUtil.hasMainMethod(file)) { 351 NotifyDescriptor nd = new NotifyDescriptor.Message(NbBundle.getMessage(AppClientActionProvider.class, "LBL_No_Main_Classs_Found", clazz), NotifyDescriptor.INFORMATION_MESSAGE); 352 DialogDisplayer.getDefault().notify(nd); 353 return null; 354 } else { 355 p.setProperty("run.class", clazz); targetNames = (String [])commands.get(COMMAND_RUN_SINGLE); 357 363 } 364 } 365 } else if (command.equals(COMMAND_DEBUG_SINGLE)) { 367 if (!isSelectedServer ()) { 368 return null; 369 } 370 if (isDebugged()) { 371 NotifyDescriptor nd; 372 nd = new NotifyDescriptor.Confirmation( 373 NbBundle.getMessage(AppClientActionProvider.class, "MSG_FinishSession"), 374 NotifyDescriptor.OK_CANCEL_OPTION); 375 Object o = DialogDisplayer.getDefault().notify(nd); 376 if (o.equals(NotifyDescriptor.OK_OPTION)) { 377 DebuggerManager.getDebuggerManager().getCurrentSession().kill(); 378 } else { 379 return null; 380 } 381 } 382 } else { 383 targetNames = (String [])commands.get(command); 384 if (targetNames == null) { 385 throw new IllegalArgumentException (command); 386 } 387 } 388 return targetNames; 389 } 390 391 private String [] setupTestSingle(Properties p, FileObject[] files) { 392 FileObject[] testSrcPath = project.getTestSourceRoots().getRoots(); 393 FileObject root = getRoot(testSrcPath, files[0]); 394 p.setProperty("test.includes", ActionUtils.antIncludesList(files, root)); p.setProperty("javac.includes", ActionUtils.antIncludesList(files, root)); return new String [] {"test-single"}; } 398 399 private String [] setupDebugTestSingle(Properties p, FileObject[] files) { 400 FileObject[] testSrcPath = project.getTestSourceRoots().getRoots(); 401 FileObject root = getRoot(testSrcPath, files[0]); 402 String path = FileUtil.getRelativePath(root, files[0]); 403 p.setProperty("test.class", path.substring(0, path.length() - 5).replace('/', '.')); return new String [] {"debug-test"}; } 407 408 public boolean isActionEnabled( String command, Lookup context ) { 409 FileObject buildXml = findBuildXml(); 410 if ( buildXml == null || !buildXml.isValid()) { 411 return false; 412 } 413 if ( command.equals( COMMAND_VERIFY ) ) { 414 return project.getCarModule().hasVerifierSupport(); 415 } 416 if ( command.equals( COMMAND_COMPILE_SINGLE ) ) { 417 return findSourcesAndPackages( context, project.getSourceRoots().getRoots()) != null 418 || findSourcesAndPackages( context, project.getTestSourceRoots().getRoots()) != null; 419 } else if ( command.equals( COMMAND_TEST_SINGLE ) ) { 420 return findTestSourcesForSources(context) != null; 421 } else if ( command.equals( COMMAND_DEBUG_TEST_SINGLE ) ) { 422 FileObject[] files = findTestSourcesForSources(context); 423 return files != null && files.length == 1; 424 } else if (command.equals(COMMAND_RUN_SINGLE) || 425 command.equals(COMMAND_DEBUG_SINGLE) || 426 command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX)) { 427 FileObject fos[] = findSources(context); 428 if (fos != null && fos.length == 1) { 429 return true; 430 } 431 fos = findTestSources(context, false); 432 return fos != null && fos.length == 1; 433 } else { 434 return true; 436 } 437 } 438 439 440 441 443 444 private static final Pattern SRCDIRJAVA = Pattern.compile("\\.java$"); private static final String SUBST = "Test.java"; 447 450 private FileObject[] findSources(Lookup context) { 451 FileObject[] srcPath = project.getSourceRoots().getRoots(); 452 for (int i=0; i< srcPath.length; i++) { 453 FileObject[] files = ActionUtils.findSelectedFiles(context, srcPath[i], ".java", true); if (files != null) { 455 return files; 456 } 457 } 458 return null; 459 } 460 461 private FileObject[] findSourcesAndPackages(Lookup context, FileObject srcDir) { 462 if (srcDir != null) { 463 FileObject[] files = ActionUtils.findSelectedFiles(context, srcDir, null, true); if (files != null) { 466 for (int i = 0; i < files.length; i++) { 467 if (!files[i].isFolder() && !"java".equals(files[i].getExt())) { return null; 469 } 470 } 471 } 472 return files; 473 } else { 474 return null; 475 } 476 } 477 478 private FileObject[] findSourcesAndPackages(Lookup context, FileObject[] srcRoots) { 479 for (int i=0; i<srcRoots.length; i++) { 480 FileObject[] result = findSourcesAndPackages(context, srcRoots[i]); 481 if (result != null) { 482 return result; 483 } 484 } 485 return null; 486 } 487 488 490 private FileObject[] findTestSources(Lookup context, boolean checkInSrcDir) { 491 FileObject[] testSrcPath = project.getTestSourceRoots().getRoots(); 493 for (int i=0; i< testSrcPath.length; i++) { 494 FileObject[] files = ActionUtils.findSelectedFiles(context, testSrcPath[i], ".java", true); if (files != null) { 496 return files; 497 } 498 } 499 if (checkInSrcDir && testSrcPath.length>0) { 500 FileObject[] files = findSources(context); 501 if (files != null) { 502 FileObject srcRoot = getRoot(project.getSourceRoots().getRoots(),files[0]); 504 for (int i=0; i<testSrcPath.length; i++) { 505 FileObject[] files2 = ActionUtils.regexpMapFiles(files,srcRoot, SRCDIRJAVA, testSrcPath[i], SUBST, true); 506 if (files2 != null) { 507 return files2; 508 } 509 } 510 } 511 } 512 return null; 513 } 514 515 516 518 private FileObject[] findTestSourcesForSources(Lookup context) { 519 FileObject[] sourceFiles = findSources(context); 520 if (sourceFiles == null) { 521 return null; 522 } 523 FileObject[] testSrcPath = project.getTestSourceRoots().getRoots(); 524 if (testSrcPath.length == 0) { 525 return null; 526 } 527 FileObject[] srcPath = project.getSourceRoots().getRoots(); 528 FileObject srcDir = getRoot(srcPath, sourceFiles[0]); 529 for (int i=0; i<testSrcPath.length; i++) { 530 FileObject[] files2 = ActionUtils.regexpMapFiles(sourceFiles, srcDir, SRCDIRJAVA, testSrcPath[i], SUBST, true); 531 if (files2 != null) { 532 return files2; 533 } 534 } 535 return null; 536 } 537 538 private FileObject getRoot(FileObject[] roots, FileObject file) { 539 assert file != null : "File can't be null"; FileObject srcDir = null; 541 for (int i=0; i< roots.length; i++) { 542 assert roots[i] != null : "Source Path Root can't be null"; if (FileUtil.isParentOf(roots[i],file) || roots[i].equals(file)) { 544 srcDir = roots[i]; 545 break; 546 } 547 } 548 return srcDir; 549 } 550 551 552 private static enum MainClassStatus { 553 SET_AND_VALID, 554 SET_BUT_INVALID, 555 UNSET 556 } 557 558 564 private MainClassStatus isSetMainClass(FileObject[] sourcesRoots, String mainClass) { 565 566 if (MainClassChooser.unitTestingSupport_hasMainMethodResult != null) { 568 return MainClassChooser.unitTestingSupport_hasMainMethodResult ? MainClassStatus.SET_AND_VALID : MainClassStatus.SET_BUT_INVALID; 569 } 570 571 if (mainClass == null || mainClass.length () == 0) { 572 return MainClassStatus.UNSET; 573 } 574 575 ClassPath bootPath = ClassPath.getClassPath (sourcesRoots[0], ClassPath.BOOT); ClassPath compilePath = ClassPath.getClassPath (sourcesRoots[0], ClassPath.COMPILE); 577 ClassPath sourcePath = ClassPath.getClassPath(sourcesRoots[0], ClassPath.SOURCE); 578 if (AppClientProjectUtil.isMainClass (mainClass, bootPath, compilePath, sourcePath)) { 579 return MainClassStatus.SET_AND_VALID; 580 } 581 return MainClassStatus.SET_BUT_INVALID; 582 } 583 584 589 public static boolean canBeRun(FileObject classFO) { 590 return !SourceUtils.getMainClasses(classFO).isEmpty(); 591 } 592 593 594 602 private boolean showMainClassWarning(String mainClass, String projectName, EditableProperties ep, MainClassStatus messageType) { 603 boolean canceled; 604 final JButton okButton = new JButton (NbBundle.getMessage(MainClassWarning.class, "LBL_MainClassWarning_ChooseMainClass_OK")); okButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(MainClassWarning.class, "AD_MainClassWarning_ChooseMainClass_OK")); 606 607 String message; 609 switch (messageType) { 610 case UNSET: 611 message = MessageFormat.format(NbBundle.getMessage(MainClassWarning.class,"LBL_MainClassNotFound"), new Object [] { 612 projectName 613 }); 614 break; 615 case SET_BUT_INVALID: 616 message = MessageFormat.format(NbBundle.getMessage(MainClassWarning.class,"LBL_MainClassWrong"), new Object [] { 617 mainClass, 618 projectName 619 }); 620 break; 621 default: 622 throw new IllegalArgumentException (); 623 } 624 final MainClassWarning panel = new MainClassWarning(message,project.getSourceRoots().getRoots()); 625 Object [] options = new Object [] { 626 okButton, 627 DialogDescriptor.CANCEL_OPTION 628 }; 629 630 panel.addChangeListener(new ChangeListener () { 631 public void stateChanged(ChangeEvent e) { 632 if (e.getSource() instanceof MouseEvent && MouseUtils.isDoubleClick(((MouseEvent )e.getSource()))) { 633 okButton.doClick(); 635 } else { 636 okButton.setEnabled(panel.getSelectedMainClass() != null); 637 } 638 } 639 }); 640 641 okButton.setEnabled(false); 642 DialogDescriptor desc = new DialogDescriptor(panel, 643 NbBundle.getMessage(MainClassWarning.class, "CTL_MainClassWarning_Title", ProjectUtils.getInformation(project).getDisplayName()), true, options, options[0], DialogDescriptor.BOTTOM_ALIGN, null, null); 645 desc.setMessageType(DialogDescriptor.INFORMATION_MESSAGE); 646 Dialog dlg = DialogDisplayer.getDefault().createDialog(desc); 647 dlg.setVisible(true); 648 if (desc.getValue() != options[0]) { 649 canceled = true; 650 } else { 651 mainClass = panel.getSelectedMainClass(); 652 canceled = false; 653 ep.put("main.class", mainClass == null ? "" : mainClass); } 655 dlg.dispose(); 656 657 return canceled; 658 } 659 660 private void showPlatformWarning() { 661 final JButton closeOption = new JButton (NbBundle.getMessage(AppClientActionProvider.class, "CTL_BrokenPlatform_Close")); 662 closeOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AppClientActionProvider.class, "AD_BrokenPlatform_Close")); 663 final ProjectInformation pi = (ProjectInformation) this.project.getLookup().lookup(ProjectInformation.class); 664 final String projectDisplayName = pi == null ? 665 NbBundle.getMessage(AppClientActionProvider.class,"TEXT_BrokenPlatform_UnknownProjectName") 666 : pi.getDisplayName(); 667 final DialogDescriptor dd = new DialogDescriptor( 668 NbBundle.getMessage(AppClientActionProvider.class, "TEXT_BrokenPlatform", projectDisplayName), 669 NbBundle.getMessage(AppClientActionProvider.class, "MSG_BrokenPlatform_Title"), 670 true, 671 new Object [] {closeOption}, 672 closeOption, 673 DialogDescriptor.DEFAULT_ALIGN, 674 null, 675 null); 676 dd.setMessageType(DialogDescriptor.WARNING_MESSAGE); 677 final Dialog dlg = DialogDisplayer.getDefault().createDialog(dd); 678 dlg.setVisible(true); 679 } 680 681 private boolean isSelectedServer () { 682 String instance = antProjectHelper.getStandardPropertyEvaluator ().getProperty (AppClientProjectProperties.J2EE_SERVER_INSTANCE); 683 if (instance != null) { 684 String id = Deployment.getDefault().getServerID(instance); 685 if (id != null) { 686 return true; 687 } 688 } 689 690 String serverType = antProjectHelper.getStandardPropertyEvaluator ().getProperty (AppClientProjectProperties.J2EE_SERVER_TYPE); 693 if (serverType != null) { 694 String [] servInstIDs = Deployment.getDefault().getInstancesOfServer(serverType); 695 if (servInstIDs.length > 0) { 696 setServerInstance(servInstIDs[0]); 697 return true; 698 } 699 } 700 701 String msg = NbBundle.getMessage(AppClientActionProvider.class, "MSG_No_Server_Selected"); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg, NotifyDescriptor.WARNING_MESSAGE)); 704 return false; 705 } 706 707 private void setServerInstance(final String serverInstanceId) { 708 AppClientProjectProperties.setServerInstance(project, antProjectHelper, serverInstanceId); 709 } 710 711 private boolean isDebugged() { 712 J2eeModuleProvider jmp = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); 713 ServerDebugInfo sdi = jmp.getServerDebugInfo(); 714 if (sdi == null) { 715 return false; 716 } 717 Session[] sessions = DebuggerManager.getDebuggerManager().getSessions(); 718 719 for (int i=0; i < sessions.length; i++) { 720 Session s = sessions[i]; 721 if (s != null) { 722 Object o = s.lookupFirst(null, AttachingDICookie.class); 723 if (o != null) { 724 AttachingDICookie attCookie = (AttachingDICookie)o; 725 if (sdi.getTransport().equals(ServerDebugInfo.TRANSPORT_SHMEM)) { 726 if (attCookie.getSharedMemoryName().equalsIgnoreCase(sdi.getShmemName())) { 727 return true; 728 } 729 } else { 730 if (attCookie.getHostName().equalsIgnoreCase(sdi.getHost()) && 731 attCookie.getPortNumber() == sdi.getPort()) { 732 return true; 733 } 734 } 735 } 736 } 737 } 738 return false; 739 } 740 } 741 | Popular Tags |