1 19 20 package org.netbeans.modules.j2ee.clientproject.ui; 21 22 import java.awt.Image ; 23 import java.awt.event.ActionEvent ; 24 import java.beans.PropertyChangeEvent ; 25 import java.beans.PropertyChangeListener ; 26 import java.io.CharConversionException ; 27 import java.io.File ; 28 import java.io.IOException ; 29 import java.net.URI ; 30 import java.net.URL ; 31 import java.util.ArrayList ; 32 import java.util.Arrays ; 33 import java.util.Collection ; 34 import java.util.Collections ; 35 import java.util.HashMap ; 36 import java.util.HashSet ; 37 import java.util.Iterator ; 38 import java.util.List ; 39 import java.util.Map ; 40 import java.util.ResourceBundle ; 41 import java.util.Set ; 42 import javax.swing.AbstractAction ; 43 import javax.swing.Action ; 44 import javax.swing.JSeparator ; 45 import javax.swing.SwingUtilities ; 46 import javax.swing.event.ChangeEvent ; 47 import javax.swing.event.ChangeListener ; 48 import org.netbeans.api.java.platform.JavaPlatform; 49 import org.netbeans.api.java.platform.JavaPlatformManager; 50 import org.netbeans.api.java.project.JavaProjectConstants; 51 import org.netbeans.api.project.FileOwnerQuery; 52 import org.netbeans.api.project.Project; 53 import org.netbeans.api.project.ProjectUtils; 54 import org.netbeans.api.project.SourceGroup; 55 import org.netbeans.api.project.Sources; 56 import org.netbeans.modules.j2ee.api.ejbjar.Car; 57 import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants; 58 import org.netbeans.modules.j2ee.clientproject.AppClientProject; 59 import org.netbeans.modules.j2ee.clientproject.AppClientProjectUtil; 60 import org.netbeans.modules.j2ee.clientproject.SourceRoots; 61 import org.netbeans.modules.j2ee.clientproject.UpdateHelper; 62 import org.netbeans.modules.j2ee.clientproject.classpath.ClassPathSupport; 63 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; 64 import org.netbeans.modules.j2ee.clientproject.ui.customizer.CustomizerLibraries; 65 import org.netbeans.modules.j2ee.clientproject.ui.customizer.CustomizerProviderImpl; 66 import org.netbeans.modules.j2ee.clientproject.wsclient.AppClientProjectWebServicesClientSupport; 67 import org.netbeans.modules.j2ee.common.ui.BrokenServerSupport; 68 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 69 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 70 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 71 import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; 72 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 73 import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView; 74 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; 75 import org.netbeans.modules.websvc.api.client.WebServicesClientView; 76 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport; 77 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientView; 78 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 79 import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; 80 import org.netbeans.spi.java.project.support.ui.PackageView; 81 import org.netbeans.spi.project.ActionProvider; 82 import org.netbeans.spi.project.support.ant.AntProjectHelper; 83 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 84 import org.netbeans.spi.project.support.ant.ReferenceHelper; 85 import org.netbeans.spi.project.ui.LogicalViewProvider; 86 import org.netbeans.spi.project.ui.support.CommonProjectActions; 87 import org.netbeans.spi.project.ui.support.DefaultProjectOperations; 88 import org.netbeans.spi.project.ui.support.ProjectSensitiveActions; 89 import org.openide.ErrorManager; 90 import org.openide.actions.FindAction; 91 import org.openide.actions.ToolsAction; 92 import org.openide.filesystems.FileChangeAdapter; 93 import org.openide.filesystems.FileEvent; 94 import org.openide.filesystems.FileObject; 95 import org.openide.filesystems.FileStateInvalidException; 96 import org.openide.filesystems.FileStatusEvent; 97 import org.openide.filesystems.FileStatusListener; 98 import org.openide.filesystems.FileSystem; 99 import org.openide.filesystems.FileUtil; 100 import org.openide.filesystems.Repository; 101 import org.openide.loaders.DataFolder; 102 import org.openide.loaders.DataObject; 103 import org.openide.loaders.DataObjectNotFoundException; 104 import org.openide.loaders.FolderLookup; 105 import org.openide.modules.SpecificationVersion; 106 import org.openide.nodes.AbstractNode; 107 import org.openide.nodes.Children; 108 import org.openide.nodes.FilterNode; 109 import org.openide.nodes.Node; 110 import org.openide.util.Lookup; 111 import org.openide.util.NbBundle; 112 import org.openide.util.RequestProcessor; 113 import org.openide.util.Utilities; 114 import org.openide.util.WeakListeners; 115 import org.openide.util.actions.SystemAction; 116 import org.openide.util.lookup.Lookups; 117 import org.openide.xml.XMLUtil; 118 119 123 public class AppClientLogicalViewProvider implements LogicalViewProvider { 124 125 private static final RequestProcessor BROKEN_LINKS_RP = new RequestProcessor("AppClientLogicalViewProvider.BROKEN_LINKS_RP"); 127 private final AppClientProject project; 128 private final UpdateHelper helper; 129 private final PropertyEvaluator evaluator; 130 private final ReferenceHelper resolver; 131 private List <ChangeListener > changeListeners; 132 133 private static final Object KEY_SERVICE_REFS = "serviceRefs"; private static final String KEY_SETUP_DIR = "setupDir"; private static final String KEY_CONF_DIR = "confDir"; 138 public AppClientLogicalViewProvider(AppClientProject project, UpdateHelper helper, PropertyEvaluator evaluator, ReferenceHelper resolver) { 139 this.project = project; 140 assert project != null; 141 this.helper = helper; 142 assert helper != null; 143 this.evaluator = evaluator; 144 assert evaluator != null; 145 this.resolver = resolver; 146 } 147 148 public Node createLogicalView() { 149 return new AppClientLogicalViewRootNode(); 150 } 151 152 public Node findPath(Node root, Object target) { 153 Project project = (Project) root.getLookup().lookup(Project.class); 154 if (project == null) { 155 return null; 156 } 157 158 if (target instanceof FileObject) { 159 FileObject fo = (FileObject) target; 160 Project owner = FileOwnerQuery.getOwner(fo); 161 if (!project.equals(owner)) { 162 return null; } 164 165 Node[] nodes = root.getChildren().getNodes(true); 166 for (int i = 0; i < nodes.length; i++) { 167 Node result = PackageView.findPath(nodes[i], target); 168 if (result != null) { 169 return result; 170 } 171 } 172 } 173 174 return null; 175 } 176 177 178 179 public synchronized void addChangeListener(ChangeListener l) { 180 if (this.changeListeners == null) { 181 this.changeListeners = new ArrayList <ChangeListener >(); 182 } 183 this.changeListeners.add(l); 184 } 185 186 public synchronized void removeChangeListener(ChangeListener l) { 187 if (this.changeListeners == null) { 188 return; 189 } 190 this.changeListeners.remove(l); 191 } 192 193 197 public void testBroken() { 198 ChangeListener [] _listeners; 199 synchronized (this) { 200 if (this.changeListeners == null) { 201 return; 202 } 203 _listeners = this.changeListeners.toArray(new ChangeListener [this.changeListeners.size()]); 204 } 205 ChangeEvent event = new ChangeEvent (this); 206 for (int i=0; i < _listeners.length; i++) { 207 _listeners[i].stateChanged(event); 208 } 209 } 210 211 213 private static final String [] BREAKABLE_PROPERTIES = new String [] { 214 AppClientProjectProperties.JAVAC_CLASSPATH, 215 AppClientProjectProperties.DEBUG_CLASSPATH, 217 AppClientProjectProperties.RUN_TEST_CLASSPATH, 218 AppClientProjectProperties.DEBUG_TEST_CLASSPATH, 219 AppClientProjectProperties.JAVAC_TEST_CLASSPATH, 220 }; 221 222 public boolean hasBrokenLinks() { 223 return BrokenReferencesSupport.isBroken(helper.getAntProjectHelper(), resolver, getBreakableProperties(), 224 new String [] {AppClientProjectProperties.JAVA_PLATFORM}); 225 } 226 227 public boolean hasInvalidJdkVersion() { 228 String javaSource = this.evaluator.getProperty("javac.source"); String javaTarget = this.evaluator.getProperty("javac.target"); if (javaSource == null && javaTarget == null) { 231 return false; 233 } 234 235 final String platformId = this.evaluator.getProperty(AppClientProjectProperties.JAVA_PLATFORM); final JavaPlatform activePlatform = AppClientProjectUtil.getActivePlatform(platformId); 237 if (activePlatform == null) { 238 return true; 239 } 240 SpecificationVersion platformVersion = activePlatform.getSpecification().getVersion(); 241 try { 242 return (javaSource != null && new SpecificationVersion(javaSource).compareTo(platformVersion)>0) 243 || (javaTarget != null && new SpecificationVersion(javaTarget).compareTo(platformVersion)>0); 244 } catch (NumberFormatException nfe) { 245 ErrorManager.getDefault().log("Invalid javac.source: "+javaSource+" or javac.target: "+javaTarget+" of project:" 246 +this.project.getProjectDirectory().getPath()); 247 return true; 248 } 249 } 250 251 private String [] getBreakableProperties() { 252 SourceRoots roots = this.project.getSourceRoots(); 253 String [] srcRootProps = roots.getRootProperties(); 254 roots = this.project.getTestSourceRoots(); 255 String [] testRootProps = roots.getRootProperties(); 256 String [] result = new String [BREAKABLE_PROPERTIES.length + srcRootProps.length + testRootProps.length]; 257 System.arraycopy(BREAKABLE_PROPERTIES, 0, result, 0, BREAKABLE_PROPERTIES.length); 258 System.arraycopy(srcRootProps, 0, result, BREAKABLE_PROPERTIES.length, srcRootProps.length); 259 System.arraycopy(testRootProps, 0, result, BREAKABLE_PROPERTIES.length + srcRootProps.length, testRootProps.length); 260 return result; 261 } 262 263 private static Image brokenProjectBadge = Utilities.loadImage("org/netbeans/modules/j2ee/clientproject/ui/resources/brokenProjectBadge.gif", true); 264 265 267 private final class AppClientLogicalViewRootNode extends AbstractNode implements Runnable , FileStatusListener, ChangeListener , PropertyChangeListener { 268 269 private Action brokenLinksAction; 270 private BrokenServerAction brokenServerAction; 271 private boolean broken; private boolean illegalState; 274 private Set files; 276 private Map <FileSystem, FileStatusListener> fileSystemListeners; 277 private RequestProcessor.Task task; 278 private final Object privateLock = new Object (); 279 private boolean iconChange; 280 private boolean nameChange; 281 private ChangeListener sourcesListener; 282 private Map <SourceGroup, PropertyChangeListener > groupsListeners; 283 286 public AppClientLogicalViewRootNode() { 287 super(new LogicalViewChildren(project, evaluator, helper, resolver), Lookups.singleton(project)); 288 setIconBaseWithExtension("org/netbeans/modules/j2ee/clientproject/ui/resources/appclient.gif"); super.setName( ProjectUtils.getInformation( project ).getDisplayName() ); 290 if (hasBrokenLinks()) { 291 broken = true; 292 } else if (hasInvalidJdkVersion()) { 293 illegalState = true; 294 } 295 brokenLinksAction = new BrokenLinksAction(); 296 brokenServerAction = new BrokenServerAction(); 297 J2eeModuleProvider moduleProvider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); 298 moduleProvider.addInstanceListener((InstanceListener)WeakListeners.create( 299 InstanceListener.class, brokenServerAction, moduleProvider)); 300 setProjectFiles(project); 301 } 302 303 304 protected void setProjectFiles(Project project) { 305 Sources sources = ProjectUtils.getSources(project); if (sourcesListener == null) { 307 sourcesListener = WeakListeners.change(this, sources); 308 sources.addChangeListener(sourcesListener); 309 } 310 setGroups(Arrays.asList(sources.getSourceGroups(Sources.TYPE_GENERIC))); 311 } 312 313 314 private void setGroups(Collection groups) { 315 if (groupsListeners != null) { 316 Iterator it = groupsListeners.keySet().iterator(); 317 while (it.hasNext()) { 318 SourceGroup group = (SourceGroup) it.next(); 319 PropertyChangeListener pcl = groupsListeners.get(group); 320 group.removePropertyChangeListener(pcl); 321 } 322 } 323 groupsListeners = new HashMap <SourceGroup, PropertyChangeListener >(); 324 Set <FileObject> roots = new HashSet <FileObject>(); 325 Iterator it = groups.iterator(); 326 while (it.hasNext()) { 327 SourceGroup group = (SourceGroup) it.next(); 328 PropertyChangeListener pcl = WeakListeners.propertyChange(this, group); 329 groupsListeners.put(group, pcl); 330 group.addPropertyChangeListener(pcl); 331 FileObject fo = group.getRootFolder(); 332 roots.add(fo); 333 } 334 setFiles(roots); 335 } 336 337 protected void setFiles(Set files) { 338 if (fileSystemListeners != null) { 339 for (FileSystem fs : fileSystemListeners.keySet()) { 340 FileStatusListener fsl = (FileStatusListener) fileSystemListeners.get(fs); 341 fs.removeFileStatusListener(fsl); 342 } 343 } 344 345 fileSystemListeners = new HashMap <FileSystem, FileStatusListener>(); 346 this.files = files; 347 if (files == null) { 348 return; 349 } 350 351 Iterator it = files.iterator(); 352 Set <FileSystem> hookedFileSystems = new HashSet <FileSystem>(); 353 while (it.hasNext()) { 354 FileObject fo = (FileObject) it.next(); 355 try { 356 FileSystem fs = fo.getFileSystem(); 357 if (hookedFileSystems.contains(fs)) { 358 continue; 359 } 360 hookedFileSystems.add(fs); 361 FileStatusListener fsl = FileUtil.weakFileStatusListener(this, fs); 362 fs.addFileStatusListener(fsl); 363 fileSystemListeners.put(fs, fsl); 364 } catch (FileStateInvalidException e) { 365 ErrorManager err = ErrorManager.getDefault(); 366 err.annotate(e, ErrorManager.UNKNOWN, "Cannot get " + fo + " filesystem, ignoring...", null, null, null); err.notify(ErrorManager.INFORMATIONAL, e); 368 } 369 } 370 } 371 372 public String getHtmlDisplayName() { 373 String dispName = super.getDisplayName(); 374 try { 375 dispName = XMLUtil.toElementContent(dispName); 376 } catch (CharConversionException ex) { 377 return dispName; 378 } 379 return broken || illegalState || brokenServerAction.isEnabled() ? "<font color=\"#A40000\">" + dispName + "</font>" : null; } 382 383 public Image getIcon(int type) { 384 Image img = getMyIcon(type); 385 386 if (files != null && files.iterator().hasNext()) { 387 try { 388 FileObject fo = (FileObject) files.iterator().next(); 389 img = fo.getFileSystem().getStatus().annotateIcon(img, type, files); 390 } catch (FileStateInvalidException e) { 391 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 392 } 393 } 394 395 return img; 396 } 397 398 private Image getMyIcon(int type) { 399 Image original = super.getIcon(type); 400 return broken || illegalState || brokenServerAction.isEnabled() 401 ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) 402 : original; 403 } 404 405 public Image getOpenedIcon(int type) { 406 Image img = getMyOpenedIcon(type); 407 408 if (files != null && files.iterator().hasNext()) { 409 try { 410 FileObject fo = (FileObject) files.iterator().next(); 411 img = fo.getFileSystem().getStatus().annotateIcon(img, type, files); 412 } catch (FileStateInvalidException e) { 413 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 414 } 415 } 416 417 return img; 418 } 419 420 private Image getMyOpenedIcon(int type) { 421 Image original = super.getOpenedIcon(type); 422 return broken || illegalState || brokenServerAction.isEnabled() 423 ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) 424 : original; 425 } 426 427 public void run() { 428 boolean fireIcon; 429 boolean fireName; 430 synchronized (privateLock) { 431 fireIcon = iconChange; 432 fireName = nameChange; 433 iconChange = false; 434 nameChange = false; 435 } 436 if (fireIcon) { 437 fireIconChange(); 438 fireOpenedIconChange(); 439 } 440 if (fireName) { 441 fireDisplayNameChange(null, null); 442 } 443 } 444 445 public void annotationChanged(FileStatusEvent event) { 446 if (task == null) { 447 task = RequestProcessor.getDefault().create(this); 448 } 449 450 synchronized (privateLock) { 451 if ((iconChange == false && event.isIconChange()) || (nameChange == false && event.isNameChange())) { 452 Iterator it = files.iterator(); 453 while (it.hasNext()) { 454 FileObject fo = (FileObject) it.next(); 455 if (event.hasChanged(fo)) { 456 iconChange |= event.isIconChange(); 457 nameChange |= event.isNameChange(); 458 } 459 } 460 } 461 } 462 463 task.schedule(50); } 465 466 public void stateChanged(ChangeEvent e) { 468 setProjectFiles(project); 469 } 470 471 public void propertyChange(PropertyChangeEvent evt) { 473 setProjectFiles(project); 474 } 475 476 public Action [] getActions( boolean context ) { 477 return getAdditionalActions(); 478 } 479 480 public boolean canRename() { 481 return true; 482 } 483 484 public void setName(String s) { 485 DefaultProjectOperations.performDefaultRenameOperation(project, s); 486 } 487 488 499 500 502 private Action [] getAdditionalActions() { 503 504 ResourceBundle bundle = NbBundle.getBundle(AppClientLogicalViewProvider.class); 505 506 List <Action > actions = new ArrayList <Action >(30); 507 508 J2eeModuleProvider provider = (J2eeModuleProvider) project.getLookup().lookup(J2eeModuleProvider.class); 509 actions.add(CommonProjectActions.newFileAction()); 510 actions.add(null); 511 actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_BUILD, bundle.getString("LBL_BuildAction_Name"), null)); actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_REBUILD, bundle.getString("LBL_RebuildAction_Name"), null)); actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_CLEAN, bundle.getString("LBL_CleanAction_Name"), null)); if (provider != null && provider.hasVerifierSupport()) { 515 actions.add(ProjectSensitiveActions.projectCommandAction( "verify", bundle.getString( "LBL_VerifyAction_Name" ), null )); } 517 actions.add(ProjectSensitiveActions.projectCommandAction(JavaProjectConstants.COMMAND_JAVADOC, bundle.getString("LBL_JavadocAction_Name"), null)); actions.add(null); 519 actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_RUN, bundle.getString("LBL_RunAction_Name"), null)); actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_DEBUG, bundle.getString("LBL_DebugAction_Name"), null)); actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_TEST, bundle.getString("LBL_TestAction_Name"), null)); actions.add(ProjectSensitiveActions.projectCommandAction(EjbProjectConstants.COMMAND_REDEPLOY, bundle.getString( "LBL_RedeployAction_Name" ), null )); actions.add(null); 524 actions.add(CommonProjectActions.setAsMainProjectAction()); 525 actions.add(CommonProjectActions.openSubprojectsAction()); 526 actions.add(CommonProjectActions.closeProjectAction()); 527 actions.add(null); 528 actions.add(CommonProjectActions.renameProjectAction()); 529 actions.add(CommonProjectActions.moveProjectAction()); 530 actions.add(CommonProjectActions.copyProjectAction()); 531 actions.add(CommonProjectActions.deleteProjectAction()); 532 actions.add(null); 533 actions.add(SystemAction.get(FindAction.class)); 534 535 537 try { 538 FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource("Projects/Actions"); if (fo != null) { 540 DataObject dobj = DataObject.find(fo); 541 FolderLookup actionRegistry = new FolderLookup((DataFolder)dobj); 542 Lookup.Template query = new Lookup.Template(Object .class); 543 Lookup lookup = actionRegistry.getLookup(); 544 Iterator it = lookup.lookup(query).allInstances().iterator(); 545 if (it.hasNext()) { 546 actions.add(null); 547 } 548 while (it.hasNext()) { 549 Object next = it.next(); 550 if (next instanceof Action ) { 551 actions.add((Action ) next); 552 } else if (next instanceof JSeparator ) { 553 actions.add(null); 554 } 555 } 556 } 557 } catch (DataObjectNotFoundException ex) { 558 ErrorManager.getDefault().notify(ex); 560 } 561 562 actions.add(null); 563 actions.add(SystemAction.get(ToolsAction.class)); 564 565 actions.add(null); 566 if (brokenLinksAction != null && brokenLinksAction.isEnabled()) { 567 actions.add(brokenLinksAction); 568 } 569 if (brokenServerAction.isEnabled()) { 570 actions.add(brokenServerAction); 571 } 572 actions.add(CommonProjectActions.customizeProjectAction()); 573 574 return (Action [])actions.toArray(new Action [actions.size()]); 575 } 576 577 private boolean isBroken() { 578 return this.broken; 579 } 580 581 private void setBroken(boolean broken) { 582 this.broken = broken; 583 brokenLinksAction.setEnabled(broken); 584 fireIconChange(); 585 fireOpenedIconChange(); 586 fireDisplayNameChange(null, null); 587 } 588 589 private void setIllegalState(boolean illegalState) { 590 this.illegalState = illegalState; 591 fireIconChange(); 592 fireOpenedIconChange(); 593 fireDisplayNameChange(null, null); 594 } 595 596 599 private class BrokenLinksAction extends AbstractAction implements PropertyChangeListener , ChangeListener , Runnable { 600 601 private RequestProcessor.Task task = null; 602 603 private final PropertyChangeListener weakPCL; 604 605 public BrokenLinksAction() { 606 putValue(Action.NAME, NbBundle.getMessage(AppClientLogicalViewProvider.class, "LBL_Fix_Broken_Links_Action")); 607 setEnabled(broken); 608 evaluator.addPropertyChangeListener(this); 609 weakPCL = WeakListeners.propertyChange(this, JavaPlatformManager.getDefault()); 613 JavaPlatformManager.getDefault().addPropertyChangeListener(weakPCL); 614 AppClientLogicalViewProvider.this.addChangeListener((ChangeListener ) WeakListeners.change(this, AppClientLogicalViewProvider.this)); 615 } 616 617 public void actionPerformed(ActionEvent e) { 618 try { 619 helper.requestSave(); 620 BrokenReferencesSupport.showCustomizer(helper.getAntProjectHelper(), resolver, getBreakableProperties(), new String [] {AppClientProjectProperties.JAVA_PLATFORM}); 621 run(); 622 } catch (IOException ioe) { 623 ErrorManager.getDefault().notify(ioe); 624 } 625 } 626 627 public void propertyChange(PropertyChangeEvent evt) { 628 refsMayChanged(); 629 } 630 631 632 public void stateChanged(ChangeEvent evt) { 633 refsMayChanged(); 634 } 635 636 public synchronized void run() { 637 boolean old = AppClientLogicalViewRootNode.this.broken; 638 boolean broken = hasBrokenLinks(); 639 if (old != broken) { 640 setBroken(broken); 641 } 642 643 old = AppClientLogicalViewRootNode.this.illegalState; 644 broken = hasInvalidJdkVersion(); 645 if (old != broken) { 646 setIllegalState(broken); 647 } 648 } 649 650 private void refsMayChanged() { 651 if (task == null) { 655 task = BROKEN_LINKS_RP.create(this); 656 } 657 task.schedule(100); 658 } 659 660 } 661 662 private class BrokenServerAction extends AbstractAction implements 663 InstanceListener, PropertyChangeListener { 664 665 private RequestProcessor.Task task = null; 666 private boolean brokenServer; 667 668 public BrokenServerAction() { 669 putValue(Action.NAME, NbBundle.getMessage(AppClientLogicalViewProvider.class, "LBL_Fix_Missing_Server_Action")); evaluator.addPropertyChangeListener(this); 671 checkMissingServer(); 672 } 673 674 public boolean isEnabled() { 675 return brokenServer; 676 } 677 678 public void actionPerformed(ActionEvent e) { 679 String j2eeSpec = AppClientProjectProperties.getProperty( 680 AppClientProjectProperties.J2EE_PLATFORM, 681 helper.getAntProjectHelper(), 682 AntProjectHelper.PROJECT_PROPERTIES_PATH); 683 String instance = BrokenServerSupport.selectServer(j2eeSpec, J2eeModule.CLIENT); 684 if (instance != null) { 685 AppClientProjectProperties.setServerInstance( 686 project, helper.getAntProjectHelper(), instance); 687 } 688 checkMissingServer(); 689 } 690 691 public void propertyChange(PropertyChangeEvent evt) { 692 if (AppClientProjectProperties.J2EE_SERVER_INSTANCE.equals(evt.getPropertyName())) { 693 checkMissingServer(); 694 } 695 } 696 697 public void changeDefaultInstance(String oldServerInstanceID, String newServerInstanceID) { 698 } 699 700 public void instanceAdded(String serverInstanceID) { 701 checkMissingServer(); 702 } 703 704 public void instanceRemoved(String serverInstanceID) { 705 checkMissingServer(); 706 } 707 708 private void checkMissingServer() { 709 boolean old = brokenServer; 710 String servInstID = AppClientProjectProperties.getProperty(AppClientProjectProperties.J2EE_SERVER_INSTANCE, helper.getAntProjectHelper(), AntProjectHelper.PRIVATE_PROPERTIES_PATH); 711 brokenServer = BrokenServerSupport.isBroken(servInstID); 712 if (old != brokenServer) { 713 fireIconChange(); 714 fireOpenedIconChange(); 715 fireDisplayNameChange(null, null); 716 } 717 } 718 } 719 } 720 721 private static final class LogicalViewChildren extends Children.Keys implements ChangeListener { 722 723 private static final Object LIBRARIES = "Libs"; private static final Object TEST_LIBRARIES = "TestLibs"; private static final String WSDL_FOLDER=AppClientProjectWebServicesClientSupport.WSDL_FOLDER; 726 727 private final Project project; 728 private final PropertyEvaluator evaluator; 729 private final UpdateHelper helper; 730 private final ReferenceHelper resolver; 731 private final SourceRoots testSources; 732 733 private final WsdlCreationListener wsdlListener; 734 private final MetaInfListener metaInfListener; 735 private FileObject wsdlFolder; 736 private Car jp; 737 738 public LogicalViewChildren(AppClientProject project, PropertyEvaluator evaluator, UpdateHelper helper, ReferenceHelper resolver) { 739 this.project = project; 740 this.evaluator = evaluator; 741 this.helper = helper; 742 this.resolver = resolver; 743 this.testSources = project.getTestSourceRoots(); 744 this.metaInfListener = new MetaInfListener(); 745 this.wsdlListener = new WsdlCreationListener(); 746 Car jps[] = Car.getCars(project); 747 assert jps.length > 0; 748 jp = jps[0]; 749 } 750 751 protected void addNotify() { 752 super.addNotify(); 753 getSources().addChangeListener(this); 754 755 AntProjectHelper projectHelper = helper.getAntProjectHelper(); 756 String prop = evaluator.getProperty(AppClientProjectProperties.META_INF); if (prop!=null) { 758 FileObject metaInf = projectHelper.resolveFileObject(prop); 759 if (metaInf!=null) { 760 metaInf.addFileChangeListener(metaInfListener); 761 } 762 } 763 prop = evaluator.getProperty(AppClientProjectProperties.SRC_DIR); if (prop!=null) { 765 FileObject srcDir = projectHelper.resolveFileObject(prop); 766 if (srcDir!=null) { 767 srcDir.addFileChangeListener(metaInfListener); 768 } 769 } 770 771 WebServicesClientSupport wsClientSupportImpl = WebServicesClientSupport.getWebServicesClientSupport(project.getProjectDirectory()); 773 try { 774 if (wsClientSupportImpl != null) { 775 wsdlFolder = wsClientSupportImpl.getWsdlFolder(false); 776 } 777 } catch (IOException ex) { 778 ErrorManager.getDefault().notify(ex); 779 } 780 if (wsdlFolder != null) { 781 wsdlFolder.addFileChangeListener(wsdlListener); 782 } 783 setKeys(getKeys()); 784 } 785 786 protected void removeNotify() { 787 setKeys(Collections.EMPTY_SET); 788 getSources().removeChangeListener(this); 789 790 AntProjectHelper projectHelper = helper.getAntProjectHelper(); 791 String prop = evaluator.getProperty(AppClientProjectProperties.META_INF); if (prop!=null) { 793 FileObject metaInf = projectHelper.resolveFileObject(prop); 794 if (metaInf!=null) { 795 metaInf.addFileChangeListener(metaInfListener); 796 } 797 } 798 prop = evaluator.getProperty(AppClientProjectProperties.SRC_DIR); if (prop!=null) { 800 FileObject srcDir = projectHelper.resolveFileObject(prop); 801 if (srcDir!=null) { 802 srcDir.removeFileChangeListener(metaInfListener); 803 } 804 } 805 if (wsdlFolder != null) { 806 wsdlFolder.removeFileChangeListener(wsdlListener); 807 } 808 809 super.removeNotify(); 810 } 811 812 protected Node[] createNodes(Object key) { 813 Node[] result; 814 if (key == LIBRARIES) { 815 result = new Node[] { 817 new LibrariesNode( 818 NbBundle.getMessage(AppClientLogicalViewProvider.class,"CTL_LibrariesNode"), 819 project, 820 evaluator, 821 helper, 822 resolver, 823 AppClientProjectProperties.RUN_CLASSPATH, 824 new String [] {AppClientProjectProperties.BUILD_CLASSES_DIR}, 825 AppClientProjectProperties.JAVA_PLATFORM, AppClientProjectProperties.J2EE_SERVER_INSTANCE, 827 new Action [] { 828 LibrariesNode.createAddProjectAction(project, AppClientProjectProperties.JAVAC_CLASSPATH, 829 ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES), 830 LibrariesNode.createAddLibraryAction(project, helper.getAntProjectHelper(), AppClientProjectProperties.JAVAC_CLASSPATH, 831 ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES), 832 LibrariesNode.createAddFolderAction(project, AppClientProjectProperties.JAVAC_CLASSPATH, 833 ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES), 834 null, 835 new PreselectPropertiesAction(project, "Libraries", CustomizerLibraries.COMPILE) }, 837 ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES) 838 }; 839 } else if (key == TEST_LIBRARIES) { 840 result = new Node[] { 841 new LibrariesNode( 842 NbBundle.getMessage(AppClientLogicalViewProvider.class,"CTL_TestLibrariesNode"), 843 project, 844 evaluator, 845 helper, 846 resolver, 847 AppClientProjectProperties.RUN_TEST_CLASSPATH, 848 new String [] { 849 AppClientProjectProperties.BUILD_TEST_CLASSES_DIR, 850 AppClientProjectProperties.JAVAC_CLASSPATH, 851 AppClientProjectProperties.BUILD_CLASSES_DIR, 852 }, 853 null, 854 null, 855 new Action [] { 856 LibrariesNode.createAddProjectAction(project, AppClientProjectProperties.JAVAC_TEST_CLASSPATH, null), 857 LibrariesNode.createAddLibraryAction(project, helper.getAntProjectHelper(), AppClientProjectProperties.JAVAC_TEST_CLASSPATH, null), 858 LibrariesNode.createAddFolderAction(project, AppClientProjectProperties.JAVAC_TEST_CLASSPATH, null), 859 null, 860 new PreselectPropertiesAction(project, "Libraries", CustomizerLibraries.COMPILE_TESTS), }, 862 null 863 ), 864 }; 865 } 866 else if (key instanceof SourceGroupKey) { 868 result = new Node[] {PackageView.createPackageView(((SourceGroupKey) key).group)}; 871 } else if (key == KEY_SETUP_DIR) { 872 result = new Node[] {J2eeProjectView.createServerResourcesNode(project)}; 873 } else if (key == KEY_CONF_DIR) { 874 result = new Node[] {J2eeProjectView.createConfigFilesView(jp.getMetaInf())}; 875 } else if (key == KEY_SERVICE_REFS) { 876 java.util.Map properties = ((AppClientProject) project).getAntProjectHelper().getStandardPropertyEvaluator().getProperties(); 877 String serverInstance = (String )properties.get(AppClientProjectProperties.J2EE_SERVER_INSTANCE); 878 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstance); 879 880 Car wm = Car.getCar(project.getProjectDirectory()); 881 result = null; 882 if (wm!=null && (J2eeModule.JAVA_EE_5.equals(wm.getJ2eePlatformVersion()))) { 883 JAXWSClientView view = JAXWSClientView.getJAXWSClientView(); 884 result = view == null ? new Node[0] : new Node[] {view.createJAXWSClientView(project)}; 885 } else { 886 FileObject clientRoot = project.getProjectDirectory(); 887 WebServicesClientView clientView = WebServicesClientView.getWebServicesClientView(clientRoot); 888 if (clientView != null) { 889 WebServicesClientSupport wss = WebServicesClientSupport.getWebServicesClientSupport(clientRoot); 890 if (wss!=null) { 891 FileObject wsdlFolder = wss.getWsdlFolder(); 892 if (wsdlFolder!=null) { 893 FileObject[] children = wsdlFolder.getChildren(); 894 boolean foundWsdl = false; 895 for (int i=0;i<children.length;i++) { 896 if (children[i].getExt().equalsIgnoreCase(WSDL_FOLDER)) { foundWsdl=true; 898 break; 899 } 900 } 901 if (foundWsdl) { 902 result = new Node[] {clientView.createWebServiceClientView(wsdlFolder)}; 903 } 904 } 905 } 906 } 907 } 908 } else { 909 assert false : "Unknown key type"; result = new Node[0]; 911 } 912 return result; 913 } 914 915 public void stateChanged(ChangeEvent e) { 916 SwingUtilities.invokeLater(new Runnable () { 919 public void run() { 920 setKeys(getKeys()); 921 } 922 }); 923 } 924 925 927 private Collection getKeys() { 928 if (this.project.getProjectDirectory() == null || !this.project.getProjectDirectory().isValid()) { 931 return Collections.EMPTY_LIST; 932 } 933 Sources sources = getSources(); 934 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 935 936 List <Object > result = new ArrayList <Object >(groups.length); 937 result.add(KEY_CONF_DIR); 938 result.add(KEY_SETUP_DIR); 939 for( int i = 0; i < groups.length; i++ ) { 940 result.add(new SourceGroupKey(groups[i])); 941 } 942 result.add(LIBRARIES); 943 URL [] testRoots = this.testSources.getRootURLs(); 944 boolean addTestSources = false; 945 for (int i = 0; i < testRoots.length; i++) { 946 File f = new File (URI.create(testRoots[i].toExternalForm())); 947 if (f.exists()) { 948 addTestSources = true; 949 break; 950 } 951 } 952 if (addTestSources) { 953 result.add(TEST_LIBRARIES); 954 } 955 956 JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class); 958 JAXWSClientSupport jwcss = JAXWSClientSupport.getJaxWsClientSupport(project.getProjectDirectory()); 959 if ((jwcss != null) && (jaxWsModel != null) && (jaxWsModel.getClients().length > 0)) { 960 result.add(KEY_SERVICE_REFS); 961 } else { 962 WebServicesClientSupport wscs = WebServicesClientSupport.getWebServicesClientSupport(project.getProjectDirectory()); 963 List wsClients = wscs.getServiceClients(); 964 if ((wsClients != null) && (!wsClients.isEmpty())) { 965 result.add(KEY_SERVICE_REFS); 966 } 967 } 968 969 return result; 970 } 971 972 private Sources getSources() { 973 return ProjectUtils.getSources(project); 974 } 975 976 private static class SourceGroupKey { 977 978 public final SourceGroup group; 979 public final FileObject fileObject; 980 981 SourceGroupKey(SourceGroup group) { 982 this.group = group; 983 this.fileObject = group.getRootFolder(); 984 } 985 986 public int hashCode() { 987 return fileObject.hashCode(); 988 } 989 990 public boolean equals(Object obj) { 991 if (!(obj instanceof SourceGroupKey)) { 992 return false; 993 } else { 994 SourceGroupKey otherKey = (SourceGroupKey) obj; 995 String thisDisplayName = this.group.getDisplayName(); 996 String otherDisplayName = otherKey.group.getDisplayName(); 997 return fileObject.equals(otherKey.fileObject) && 999 thisDisplayName == null ? otherDisplayName == null : thisDisplayName.equals(otherDisplayName); 1000 } 1001 } 1002 1003 } 1004 1005 private final class WsdlCreationListener extends FileChangeAdapter { 1006 1007 public void fileDataCreated(FileEvent fe) { 1008 if (WSDL_FOLDER.equalsIgnoreCase(fe.getFile().getExt())) { 1009 SwingUtilities.invokeLater(new Runnable () { 1010 public void run() { 1011 refreshKey(KEY_SERVICE_REFS); 1012 } 1013 }); 1014 } 1015 } 1016 1017 public void fileDeleted(FileEvent fe) { 1018 if (WSDL_FOLDER.equalsIgnoreCase(fe.getFile().getExt())) { 1019 SwingUtilities.invokeLater(new Runnable () { 1020 public void run() { 1021 refreshKey(KEY_SERVICE_REFS); 1022 } 1023 }); 1024 } else if (fe.getFile().isFolder() && WSDL_FOLDER.equals(fe.getFile().getName())) { 1025 SwingUtilities.invokeLater(new Runnable () { 1026 public void run() { 1027 refreshKey(KEY_SERVICE_REFS); 1028 } 1029 }); 1030 } 1031 } 1032 } 1033 1034 private final class MetaInfListener extends FileChangeAdapter { 1035 1036 public void fileFolderCreated(FileEvent fe) { 1037 if (fe.getFile().isFolder() && WSDL_FOLDER.equals(fe.getFile().getName())) { 1038 fe.getFile().addFileChangeListener(wsdlListener); 1039 } else if (fe.getFile().isFolder() && "META-INF".equals(fe.getFile().getName())) { fe.getFile().addFileChangeListener(metaInfListener); 1041 } 1042 } 1043 1044 public void fileDeleted(FileEvent fe) { 1045 if (fe.getFile().isFolder() && WSDL_FOLDER.equals(fe.getFile().getName())) { 1046 fe.getFile().removeFileChangeListener(wsdlListener); 1047 SwingUtilities.invokeLater(new Runnable () { 1048 public void run() { 1049 refreshKey(KEY_SERVICE_REFS); 1050 } 1051 }); 1052 } else if (fe.getFile().isFolder() && "META-INF".equals(fe.getFile().getName())) { fe.getFile().removeFileChangeListener(metaInfListener); 1054 } 1055 } 1056 } 1057 } 1058 1059 1061 private static class PackageViewFilterNode extends FilterNode { 1062 1063 private final String nodeName; 1064 private final Project project; 1065 1066 Action [] actions; 1067 1068 public PackageViewFilterNode(SourceGroup sourceGroup, Project project) { 1069 super(PackageView.createPackageView(sourceGroup)); 1070 this.project = project; 1071 this.nodeName = "Sources"; } 1073 1074 1075 public Action [] getActions(boolean context) { 1076 if (!context) { 1077 if (actions == null) { 1078 Action superActions[] = super.getActions(context); 1079 actions = new Action [superActions.length + 2]; 1080 System.arraycopy(superActions, 0, actions, 0, superActions.length); 1081 actions[superActions.length] = null; 1082 actions[superActions.length + 1] = new PreselectPropertiesAction(project, nodeName); 1083 } 1084 return actions; 1085 } else { 1086 return super.getActions(context); 1087 } 1088 } 1089 1090 } 1091 1092 1093 1095 private static class PreselectPropertiesAction extends AbstractAction { 1096 1097 private final Project project; 1098 private final String nodeName; 1099 private final String panelName; 1100 1101 public PreselectPropertiesAction(Project project, String nodeName) { 1102 this(project, nodeName, null); 1103 } 1104 1105 public PreselectPropertiesAction(Project project, String nodeName, String panelName) { 1106 super(NbBundle.getMessage(AppClientLogicalViewProvider.class, "LBL_Properties_Action")); 1107 this.project = project; 1108 this.nodeName = nodeName; 1109 this.panelName = panelName; 1110 } 1111 1112 public void actionPerformed(ActionEvent e) { 1113 CustomizerProviderImpl cp = (CustomizerProviderImpl) project.getLookup().lookup(CustomizerProviderImpl.class); 1115 if (cp != null) { 1116 cp.showCustomizer(nodeName, panelName); 1117 } 1118 1119 } 1120 } 1121 1122} 1123 | Popular Tags |