1 19 20 package org.netbeans.modules.j2ee.ejbjarproject.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.util.ArrayList ; 28 import java.util.Arrays ; 29 import java.util.Collection ; 30 import java.util.Enumeration ; 31 import java.util.HashMap ; 32 import java.util.HashSet ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 import java.util.Map ; 36 import java.util.ResourceBundle ; 37 import java.util.Set ; 38 39 import javax.swing.AbstractAction ; 40 import javax.swing.Action ; 41 import javax.swing.JSeparator ; 42 import javax.swing.event.ChangeEvent ; 43 import javax.swing.event.ChangeListener ; 44 import org.netbeans.api.java.platform.JavaPlatformManager; 45 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 46 import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; 47 import org.netbeans.modules.j2ee.ejbjarproject.ui.logicalview.LogicalViewChildren; 48 import org.openide.actions.ToolsAction; 49 50 import org.openide.nodes.*; 51 import org.openide.util.*; 52 import org.openide.util.actions.SystemAction; 53 import org.openide.xml.XMLUtil; 54 55 import org.netbeans.api.project.FileOwnerQuery; 56 import org.netbeans.api.project.Project; 57 import org.netbeans.api.project.ProjectUtils; 58 import org.netbeans.spi.java.project.support.ui.PackageView; 59 import org.netbeans.spi.project.ui.support.CommonProjectActions; 60 import org.netbeans.spi.project.ActionProvider; 61 import org.netbeans.spi.project.SubprojectProvider; 62 import org.netbeans.spi.project.support.ant.AntProjectHelper; 63 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 64 import org.netbeans.spi.project.support.ant.ReferenceHelper; 65 import org.netbeans.spi.project.ui.LogicalViewProvider; 66 import org.netbeans.spi.project.ui.support.ProjectSensitiveActions; 67 import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; 68 import org.netbeans.api.java.project.JavaProjectConstants; 69 import org.netbeans.api.project.SourceGroup; 70 import org.netbeans.api.project.Sources; 71 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; 72 import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; 73 import org.openide.filesystems.FileObject; 74 import org.openide.loaders.DataFolder; 75 import org.openide.util.lookup.Lookups; 76 77 78 import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants; 79 import org.netbeans.modules.j2ee.common.ui.BrokenServerSupport; 80 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 81 import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; 82 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; 83 import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView; 84 import org.netbeans.spi.project.ui.support.DefaultProjectOperations; 85 import org.openide.ErrorManager; 86 import org.openide.filesystems.FileStateInvalidException; 87 import org.openide.filesystems.FileStatusEvent; 88 import org.openide.filesystems.FileStatusListener; 89 import org.openide.filesystems.FileSystem; 90 import org.openide.filesystems.FileUtil; 91 import org.openide.filesystems.Repository; 92 import org.openide.loaders.DataObject; 93 import org.openide.loaders.DataObjectNotFoundException; 94 import org.openide.loaders.FolderLookup; 95 96 100 public class EjbJarLogicalViewProvider implements LogicalViewProvider { 101 private static final RequestProcessor BROKEN_LINKS_RP = new RequestProcessor("EjbJarLogicalViewProvider.BROKEN_LINKS_RP"); 103 private final EjbJarProject project; 104 private final AntProjectHelper helper; 105 private final UpdateHelper updateHelper; 106 private final PropertyEvaluator evaluator; 107 private final SubprojectProvider spp; 108 private final ReferenceHelper resolver; 109 private List changeListeners; 110 111 public EjbJarLogicalViewProvider(EjbJarProject project, UpdateHelper updateHelper, PropertyEvaluator evaluator, SubprojectProvider spp, ReferenceHelper resolver) { 112 this.project = project; 113 assert project != null; 114 this.updateHelper = updateHelper; 115 assert updateHelper != null; 116 this.helper = updateHelper.getAntProjectHelper(); 117 this.evaluator = evaluator; 118 assert evaluator != null; 119 this.spp = spp; 120 assert spp != null; 121 this.resolver = resolver; 122 } 123 124 public Node createLogicalView() { 125 return new WebLogicalViewRootNode(); 126 } 127 128 public Node findPath( Node root, Object target ) { 129 Project project = (Project)root.getLookup().lookup( Project.class ); 130 if ( project == null ) { 131 return null; 132 } 133 134 if ( target instanceof FileObject ) { 135 FileObject fo = (FileObject)target; 136 Project owner = FileOwnerQuery.getOwner( fo ); 137 if ( !project.equals( owner ) ) { 138 return null; } 140 141 Node[] nodes = root.getChildren().getNodes( true ); 142 for ( int i = 0; i < nodes.length; i++ ) { 143 Node result = PackageView.findPath( nodes[i], target ); 144 if ( result != null ) { 145 return result; 146 } 147 } 148 return findNodeInConfigFiles(root, fo); 149 } 150 151 return null; 152 } 153 154 private Node findNodeInConfigFiles(Node root, FileObject fo) { 155 String nodeName; 158 try { 159 DataObject dobj = DataObject.find(fo); 160 nodeName = dobj.getName(); 161 } catch (DataObjectNotFoundException e) { 162 nodeName = fo.getName(); 163 } 164 Node configFiles = root.getChildren().findChild(J2eeProjectView.CONFIG_FILES_VIEW_NAME); if (configFiles == null) { 166 return null; 167 } 168 return NodeOp.findChild(configFiles, nodeName); 169 } 170 171 public synchronized void addChangeListener (ChangeListener l) { 172 if (this.changeListeners == null) { 173 this.changeListeners = new ArrayList (); 174 } 175 this.changeListeners.add (l); 176 } 177 178 public synchronized void removeChangeListener (ChangeListener l) { 179 if (this.changeListeners == null) { 180 return; 181 } 182 this.changeListeners.remove (l); 183 } 184 185 190 public void testBroken () { 191 ChangeListener [] _listeners; 192 synchronized (this) { 193 if (this.changeListeners == null) { 194 return; 195 } 196 _listeners = (ChangeListener []) this.changeListeners.toArray( 197 new ChangeListener [this.changeListeners.size()]); 198 } 199 ChangeEvent event = new ChangeEvent (this); 200 for (int i=0; i<_listeners.length; i++) { 201 _listeners[i].stateChanged(event); 202 } 203 } 204 205 private static Lookup createLookup( Project project ) { 206 DataFolder rootFolder = DataFolder.findFolder( project.getProjectDirectory() ); 207 return Lookups.fixed( new Object [] { project, rootFolder } ); 209 } 210 211 213 private static final String [] BREAKABLE_PROPERTIES = new String [] { 214 EjbJarProjectProperties.JAVAC_CLASSPATH, 215 EjbJarProjectProperties.DEBUG_CLASSPATH, 216 EjbJarProjectProperties.RUN_TEST_CLASSPATH, 217 EjbJarProjectProperties.DEBUG_TEST_CLASSPATH, 218 EjbJarProjectProperties.JAVAC_TEST_CLASSPATH, 219 }; 220 221 public boolean hasBrokenLinks() { 222 return BrokenReferencesSupport.isBroken(helper, resolver, getBreakableProperties(), 223 new String [] {EjbJarProjectProperties.JAVA_PLATFORM}); 224 } 225 226 private String [] getBreakableProperties() { 227 SourceRoots roots = this.project.getSourceRoots(); 228 String [] srcRootProps = roots.getRootProperties(); 229 roots = this.project.getTestSourceRoots(); 230 String [] testRootProps = roots.getRootProperties(); 231 String [] result = new String [BREAKABLE_PROPERTIES.length + srcRootProps.length + testRootProps.length]; 232 System.arraycopy(BREAKABLE_PROPERTIES, 0, result, 0, BREAKABLE_PROPERTIES.length); 233 System.arraycopy(srcRootProps, 0, result, BREAKABLE_PROPERTIES.length, srcRootProps.length); 234 System.arraycopy(testRootProps, 0, result, BREAKABLE_PROPERTIES.length + srcRootProps.length, testRootProps.length); 235 return result; 236 } 237 238 240 private final class WebLogicalViewRootNode extends AbstractNode implements Runnable , FileStatusListener, ChangeListener , PropertyChangeListener { 241 242 private Action brokenLinksAction; 243 private BrokenServerAction brokenServerAction; 244 private boolean broken; 245 private static final String BROKEN_PROJECT_BADGE = "org/netbeans/modules/j2ee/ejbjarproject/ui/resources/brokenProjectBadge.gif"; 247 private Set files; 249 private Map fileSystemListeners; 250 private RequestProcessor.Task task; 251 private final Object privateLock = new Object (); 252 private boolean iconChange; 253 private boolean nameChange; 254 private ChangeListener sourcesListener; 255 private Map groupsListeners; 256 258 public WebLogicalViewRootNode() { 259 super( new LogicalViewChildren( project, updateHelper, evaluator, resolver ), createLookup( project ) ); 260 setIconBase( "org/netbeans/modules/j2ee/ejbjarproject/ui/resources/ejbjarProjectIcon" ); super.setName( ProjectUtils.getInformation( project ).getDisplayName() ); 262 if (hasBrokenLinks()) { 263 broken = true; 264 } 265 brokenLinksAction = new BrokenLinksAction(); 266 brokenServerAction = new BrokenServerAction(); 267 J2eeModuleProvider moduleProvider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); 268 moduleProvider.addInstanceListener((InstanceListener)WeakListeners.create( 269 InstanceListener.class, brokenServerAction, moduleProvider)); 270 setProjectFiles(project); 271 } 272 273 protected final void setProjectFiles(Project project) { 274 Sources sources = ProjectUtils.getSources(project); if (sourcesListener == null) { 276 sourcesListener = WeakListeners.change(this, sources); 277 sources.addChangeListener(sourcesListener); 278 } 279 setGroups(Arrays.asList(sources.getSourceGroups(Sources.TYPE_GENERIC))); 280 } 281 282 283 private final void setGroups(Collection groups) { 284 if (groupsListeners != null) { 285 Iterator it = groupsListeners.keySet().iterator(); 286 while (it.hasNext()) { 287 SourceGroup group = (SourceGroup) it.next(); 288 PropertyChangeListener pcl = (PropertyChangeListener ) groupsListeners.get(group); 289 group.removePropertyChangeListener(pcl); 290 } 291 } 292 groupsListeners = new HashMap (); 293 Set roots = new HashSet (); 294 Iterator it = groups.iterator(); 295 while (it.hasNext()) { 296 SourceGroup group = (SourceGroup) it.next(); 297 PropertyChangeListener pcl = WeakListeners.propertyChange(this, group); 298 groupsListeners.put(group, pcl); 299 group.addPropertyChangeListener(pcl); 300 FileObject fo = group.getRootFolder(); 301 if (project.getProjectDirectory().equals(fo)) { 302 Enumeration en = project.getProjectDirectory().getChildren(false); 305 while (en.hasMoreElements()) { 306 FileObject child = (FileObject) en.nextElement(); 307 if (FileOwnerQuery.getOwner(child) == project) { 308 roots.add(child); 309 } 310 } 311 } else { 312 roots.add(fo); 313 } 314 } 315 setFiles(roots); 316 } 317 318 protected final void setFiles(Set files) { 319 if (fileSystemListeners != null) { 320 Iterator it = fileSystemListeners.keySet().iterator(); 321 while (it.hasNext()) { 322 FileSystem fs = (FileSystem) it.next(); 323 FileStatusListener fsl = (FileStatusListener) fileSystemListeners.get(fs); 324 fs.removeFileStatusListener(fsl); 325 } 326 } 327 328 fileSystemListeners = new HashMap (); 329 this.files = files; 330 if (files == null) return; 331 332 Iterator it = files.iterator(); 333 Set hookedFileSystems = new HashSet (); 334 while (it.hasNext()) { 335 FileObject fo = (FileObject) it.next(); 336 try { 337 FileSystem fs = fo.getFileSystem(); 338 if (hookedFileSystems.contains(fs)) { 339 continue; 340 } 341 hookedFileSystems.add(fs); 342 FileStatusListener fsl = FileUtil.weakFileStatusListener(this, fs); 343 fs.addFileStatusListener(fsl); 344 fileSystemListeners.put(fs, fsl); 345 } catch (FileStateInvalidException e) { 346 ErrorManager err = ErrorManager.getDefault(); 347 err.annotate(e, "Can not get " + fo + " filesystem, ignoring..."); err.notify(ErrorManager.INFORMATIONAL, e); 349 } 350 } 351 } 352 353 public java.awt.Image getIcon (int type) { 354 java.awt.Image img = getMyIcon (type); 355 356 if (files != null && files.iterator().hasNext()) { 357 try { 358 FileObject fo = (FileObject) files.iterator().next(); 359 img = fo.getFileSystem ().getStatus ().annotateIcon (img, type, files); 360 } catch (FileStateInvalidException e) { 361 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 362 } 363 } 364 365 return img; 366 } 367 368 public java.awt.Image getOpenedIcon (int type) { 369 java.awt.Image img = getMyOpenedIcon(type); 370 371 if (files != null && files.iterator().hasNext()) { 372 try { 373 FileObject fo = (FileObject) files.iterator().next(); 374 img = fo.getFileSystem ().getStatus ().annotateIcon (img, type, files); 375 } catch (FileStateInvalidException e) { 376 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 377 } 378 } 379 380 return img; 381 } 382 383 public void run() { 384 boolean fireIcon; 385 boolean fireName; 386 synchronized (privateLock) { 387 fireIcon = iconChange; 388 fireName = nameChange; 389 iconChange = false; 390 nameChange = false; 391 } 392 if (fireIcon) { 393 fireIconChange(); 394 fireOpenedIconChange(); 395 } 396 if (fireName) { 397 fireDisplayNameChange(null, null); 398 } 399 } 400 401 public void annotationChanged(FileStatusEvent event) { 402 if (task == null) { 403 task = RequestProcessor.getDefault().create(this); 404 } 405 406 synchronized (privateLock) { 407 if ((iconChange == false && event.isIconChange()) || (nameChange == false && event.isNameChange())) { 408 Iterator it = files.iterator(); 409 while (it.hasNext()) { 410 FileObject fo = (FileObject) it.next(); 411 if (event.hasChanged(fo)) { 412 iconChange |= event.isIconChange(); 413 nameChange |= event.isNameChange(); 414 } 415 } 416 } 417 } 418 419 task.schedule(50); } 421 422 public void stateChanged(ChangeEvent e) { 424 setProjectFiles(project); 425 } 426 427 public void propertyChange(PropertyChangeEvent evt) { 429 setProjectFiles(project); 430 } 431 432 public Image getMyIcon(int type) { 433 Image original = super.getIcon( type ); 434 return broken || brokenServerAction.isEnabled() 435 ? Utilities.mergeImages(original, Utilities.loadImage(BROKEN_PROJECT_BADGE), 8, 0) 436 : original; 437 } 438 439 public Image getMyOpenedIcon(int type) { 440 Image original = super.getOpenedIcon(type); 441 return broken || brokenServerAction.isEnabled() 442 ? Utilities.mergeImages(original, Utilities.loadImage(BROKEN_PROJECT_BADGE), 8, 0) 443 : original; 444 } 445 446 public String getHtmlDisplayName() { 447 String dispName = super.getDisplayName(); 448 try { 449 dispName = XMLUtil.toElementContent(dispName); 450 } catch (CharConversionException ex) { 451 } 453 return broken || brokenServerAction.isEnabled() ? "<font color=\"#A40000\">" + dispName + "</font>" : null; } 455 456 public Action [] getActions( boolean context ) { 457 if ( context ) 458 return super.getActions( true ); 459 else 460 return getAdditionalActions(); 461 } 462 463 public boolean canRename() { 464 return true; 465 } 466 467 public void setName(String s) { 468 DefaultProjectOperations.performDefaultRenameOperation(project, s); 469 } 470 471 public HelpCtx getHelpCtx() { 472 return new HelpCtx(WebLogicalViewRootNode.class); 473 } 474 475 477 private Action [] getAdditionalActions() { 478 479 ResourceBundle bundle = NbBundle.getBundle(EjbJarLogicalViewProvider.class); 480 481 J2eeModuleProvider provider = (J2eeModuleProvider) project.getLookup().lookup(J2eeModuleProvider.class); 482 List actions = new ArrayList (30); 483 actions.add(CommonProjectActions.newFileAction()); 484 actions.add(null); 485 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()) { 489 actions.add(ProjectSensitiveActions.projectCommandAction( "verify", bundle.getString( "LBL_VerifyAction_Name" ), null )); } 491 actions.add(ProjectSensitiveActions.projectCommandAction( JavaProjectConstants.COMMAND_JAVADOC, bundle.getString( "LBL_JavadocAction_Name" ), null )); actions.add(null); 493 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( EjbProjectConstants.COMMAND_REDEPLOY, bundle.getString( "LBL_RedeployAction_Name" ), null )); actions.add(null); 497 actions.add(CommonProjectActions.setAsMainProjectAction()); 498 actions.add(CommonProjectActions.openSubprojectsAction()); 499 actions.add(CommonProjectActions.closeProjectAction()); 500 actions.add(null); 501 actions.add(CommonProjectActions.renameProjectAction()); 502 actions.add(CommonProjectActions.moveProjectAction()); 503 actions.add(CommonProjectActions.copyProjectAction()); 504 actions.add(CommonProjectActions.deleteProjectAction()); 505 actions.add(null); 506 actions.add(SystemAction.get( org.openide.actions.FindAction.class )); 507 508 510 try { 511 Repository repository = Repository.getDefault(); 512 FileSystem sfs = repository.getDefaultFileSystem(); 513 FileObject fo = sfs.findResource("Projects/Actions"); if (fo != null) { 515 DataObject dobj = DataObject.find(fo); 516 FolderLookup actionRegistry = new FolderLookup((DataFolder)dobj); 517 Lookup.Template query = new Lookup.Template(Object .class); 518 Lookup lookup = actionRegistry.getLookup(); 519 Iterator it = lookup.lookup(query).allInstances().iterator(); 520 if (it.hasNext()) { 521 actions.add(null); 522 } 523 while (it.hasNext()) { 524 Object next = it.next(); 525 if (next instanceof Action ) { 526 actions.add(next); 527 } else if (next instanceof JSeparator ) { 528 actions.add(null); 529 } 530 } 531 } 532 } catch (DataObjectNotFoundException ex) { 533 ErrorManager.getDefault().notify(ex); 535 } 536 537 actions.add(null); 538 actions.add(SystemAction.get(ToolsAction.class)); 539 actions.add(null); 540 541 if (brokenLinksAction != null && brokenLinksAction.isEnabled()) { 542 actions.add(brokenLinksAction); 543 } 544 if (brokenServerAction.isEnabled()) { 545 actions.add(brokenServerAction); 546 } 547 actions.add(CommonProjectActions.customizeProjectAction()); 548 549 return (Action [])actions.toArray(new Action [actions.size()]); 550 } 551 552 555 private class BrokenLinksAction extends AbstractAction implements PropertyChangeListener , ChangeListener , Runnable { 556 557 private RequestProcessor.Task task = null; 558 559 private PropertyChangeListener weakPCL; 560 561 public BrokenLinksAction() { 562 putValue(Action.NAME, NbBundle.getMessage(EjbJarLogicalViewProvider.class, "LBL_Fix_Broken_Links_Action")); 563 setEnabled(broken); 564 evaluator.addPropertyChangeListener(this); 565 566 weakPCL = WeakListeners.propertyChange( this, JavaPlatformManager.getDefault() ); 570 JavaPlatformManager.getDefault().addPropertyChangeListener( weakPCL ); 571 EjbJarLogicalViewProvider.this.addChangeListener ((ChangeListener )WeakListeners.change(this, EjbJarLogicalViewProvider.this)); 572 } 573 574 public void actionPerformed(ActionEvent e) { 575 BrokenReferencesSupport.showCustomizer(helper, resolver, getBreakableProperties(), new String []{EjbJarProjectProperties.JAVA_PLATFORM}); 576 run(); 577 } 578 579 public void propertyChange(PropertyChangeEvent evt) { 580 refsMayChanged(); 581 } 582 583 public void stateChanged (ChangeEvent evt) { 584 refsMayChanged (); 585 } 586 587 public synchronized void run() { 588 boolean old = broken; 589 broken = hasBrokenLinks(); 590 if (old != broken) { 591 setEnabled(broken); 592 fireIconChange(); 593 fireOpenedIconChange(); 594 fireDisplayNameChange(null, null); 595 new EjbJarProjectProperties (project, updateHelper, evaluator, resolver).save(); 597 } 598 } 599 600 public void refsMayChanged() { 601 if (task == null) { 605 task = BROKEN_LINKS_RP.create(this); 606 } 607 task.schedule(100); 608 } 609 610 } 611 612 private class BrokenServerAction extends AbstractAction implements 613 InstanceListener, PropertyChangeListener { 614 615 private RequestProcessor.Task task = null; 616 private boolean brokenServer; 617 618 public BrokenServerAction() { 619 putValue(Action.NAME, NbBundle.getMessage(EjbJarLogicalViewProvider.class, "LBL_Fix_Missing_Server_Action")); evaluator.addPropertyChangeListener(this); 621 checkMissingServer(); 622 } 623 624 public boolean isEnabled() { 625 return brokenServer; 626 } 627 628 public void actionPerformed(ActionEvent e) { 629 String j2eeSpec = EjbJarProjectProperties.getProperty( 630 EjbJarProjectProperties.J2EE_PLATFORM, 631 helper, 632 AntProjectHelper.PROJECT_PROPERTIES_PATH); 633 String instance = BrokenServerSupport.selectServer(j2eeSpec, J2eeModule.EJB); 634 if (instance != null) { 635 EjbJarProjectProperties.setServerInstance( 636 project, helper, instance); 637 } 638 checkMissingServer(); 639 } 640 641 public void propertyChange(PropertyChangeEvent evt) { 642 if (EjbJarProjectProperties.J2EE_SERVER_INSTANCE.equals(evt.getPropertyName())) { 643 checkMissingServer(); 644 } 645 } 646 647 public void changeDefaultInstance(String oldServerInstanceID, String newServerInstanceID) { 648 } 649 650 public void instanceAdded(String serverInstanceID) { 651 checkMissingServer(); 652 } 653 654 public void instanceRemoved(String serverInstanceID) { 655 checkMissingServer(); 656 } 657 658 private void checkMissingServer() { 659 boolean old = brokenServer; 660 String servInstID = EjbJarProjectProperties.getProperty(EjbJarProjectProperties.J2EE_SERVER_INSTANCE, helper, AntProjectHelper.PRIVATE_PROPERTIES_PATH); 661 brokenServer = BrokenServerSupport.isBroken(servInstID); 662 if (old != brokenServer) { 663 fireIconChange(); 664 fireOpenedIconChange(); 665 fireDisplayNameChange(null, null); 666 } 667 } 668 } 669 670 } 671 672 675 public static class Actions { 676 677 private Actions() {} 679 public static Action createAction( String key, String name, boolean global ) { 680 return new ActionImpl( key, name, global ? Utilities.actionsGlobalContext() : null ); 681 } 682 683 private static class ActionImpl extends AbstractAction implements ContextAwareAction { 684 685 Lookup context; 686 String name; 687 String command; 688 689 public ActionImpl( String command, String name, Lookup context ) { 690 super( name ); 691 this.context = context; 692 this.command = command; 693 this.name = name; 694 } 695 696 public void actionPerformed( ActionEvent e ) { 697 698 Project project = (Project)context.lookup( Project.class ); 699 ActionProvider ap = (ActionProvider)project.getLookup().lookup( ActionProvider.class); 700 701 ap.invokeAction( command, context ); 702 703 } 704 705 public Action createContextAwareInstance( Lookup lookup ) { 706 return new ActionImpl( command, name, lookup ); 707 } 708 } 709 710 } 711 712 } 713 | Popular Tags |