KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > rubyproject > ui > RubyLogicalViewProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ruby.rubyproject.ui;
21
22 import java.awt.Image JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.beans.PropertyChangeEvent JavaDoc;
25 import java.beans.PropertyChangeListener JavaDoc;
26 import java.io.CharConversionException JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Arrays JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.HashSet JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.Map JavaDoc;
36 import java.util.ResourceBundle JavaDoc;
37 import java.util.Set JavaDoc;
38 import javax.swing.AbstractAction JavaDoc;
39 import javax.swing.Action JavaDoc;
40 import javax.swing.JSeparator JavaDoc;
41 import javax.swing.event.ChangeEvent JavaDoc;
42 import javax.swing.event.ChangeListener JavaDoc;
43 import org.netbeans.modules.ruby.rubyproject.RubyActionProvider;
44 import org.netbeans.api.project.FileOwnerQuery;
45 import org.netbeans.api.project.Project;
46 import org.netbeans.api.project.ProjectUtils;
47 import org.netbeans.api.project.SourceGroup;
48 import org.netbeans.api.project.Sources;
49 import org.netbeans.modules.ruby.rubyproject.RubyProjectUtil;
50 import org.netbeans.modules.ruby.rubyproject.ui.customizer.RubyProjectProperties;
51 import org.netbeans.modules.ruby.rubyproject.RubyProject;
52 import org.netbeans.modules.ruby.rubyproject.SourceRoots;
53 import org.netbeans.modules.ruby.rubyproject.UpdateHelper;
54 import org.netbeans.spi.project.ActionProvider;
55 import org.netbeans.spi.project.SubprojectProvider;
56 import org.netbeans.modules.ruby.spi.project.support.rake.PropertyEvaluator;
57 import org.netbeans.modules.ruby.spi.project.support.rake.ReferenceHelper;
58 import org.netbeans.spi.project.ui.LogicalViewProvider;
59 import org.netbeans.spi.project.ui.support.CommonProjectActions;
60 import org.netbeans.spi.project.ui.support.NodeFactorySupport;
61 import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
62 import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
63 import org.openide.ErrorManager;
64 import org.openide.actions.FindAction;
65 import org.openide.actions.ToolsAction;
66 import org.openide.filesystems.FileObject;
67 import org.openide.filesystems.FileStateInvalidException;
68 import org.openide.filesystems.FileStatusEvent;
69 import org.openide.filesystems.FileStatusListener;
70 import org.openide.filesystems.FileSystem;
71 import org.openide.filesystems.FileUtil;
72 import org.openide.filesystems.Repository;
73 import org.openide.loaders.DataFolder;
74 import org.openide.loaders.DataObject;
75 import org.openide.loaders.DataObjectNotFoundException;
76 import org.openide.loaders.FolderLookup;
77 import org.openide.modules.SpecificationVersion;
78 import org.openide.nodes.AbstractNode;
79 import org.openide.nodes.Node;
80 import org.openide.util.HelpCtx;
81 import org.openide.util.Lookup;
82 import org.openide.util.NbBundle;
83 import org.openide.util.RequestProcessor;
84 import org.openide.util.Utilities;
85 import org.openide.util.WeakListeners;
86 import org.openide.util.actions.SystemAction;
87 import org.openide.util.lookup.Lookups;
88 import org.openide.xml.XMLUtil;
89
90 /**
91  * Support for creating logical views.
92  * @author Petr Hrebejk
93  */

94 public class RubyLogicalViewProvider implements LogicalViewProvider {
95     
96     //private static final RequestProcessor BROKEN_LINKS_RP = new RequestProcessor("RubyPhysicalViewProvider.BROKEN_LINKS_RP"); // NOI18N
97

98     private final RubyProject project;
99     private final UpdateHelper helper;
100     private final PropertyEvaluator evaluator;
101     private final SubprojectProvider spp;
102     private final ReferenceHelper resolver;
103     private List JavaDoc changeListeners;
104     
105     public RubyLogicalViewProvider(RubyProject project, UpdateHelper helper, PropertyEvaluator evaluator, SubprojectProvider spp, ReferenceHelper resolver) {
106         this.project = project;
107         assert project != null;
108         this.helper = helper;
109         assert helper != null;
110         this.evaluator = evaluator;
111         assert evaluator != null;
112         this.spp = spp;
113         assert spp != null;
114         this.resolver = resolver;
115     }
116     
117     public Node createLogicalView() {
118         return new RubyLogicalViewRootNode();
119     }
120     
121     public PropertyEvaluator getEvaluator() {
122         return evaluator;
123     }
124     
125     public ReferenceHelper getRefHelper() {
126         return resolver;
127     }
128     
129     public UpdateHelper getUpdateHelper() {
130         return helper;
131     }
132     
133     public Node findPath(Node root, Object JavaDoc target) {
134         Project project = (Project) root.getLookup().lookup(Project.class);
135         if (project == null) {
136             return null;
137         }
138         
139         if (target instanceof FileObject) {
140             FileObject fo = (FileObject) target;
141             Project owner = FileOwnerQuery.getOwner(fo);
142             if (!project.equals(owner)) {
143                 return null; // Don't waste time if project does not own the fo
144
}
145             
146             Node[] nodes = root.getChildren().getNodes(true);
147             for (int i = 0; i < nodes.length; i++) {
148                 TreeRootNode.PathFinder pf2 = (TreeRootNode.PathFinder) nodes[i].getLookup().lookup(TreeRootNode.PathFinder.class);
149                 if (pf2 != null) {
150                     Node n = pf2.findPath(nodes[i], target);
151                     if (n != null) {
152                         return n;
153                     }
154                 }
155             }
156         }
157         
158         return null;
159     }
160     
161     
162     
163     public synchronized void addChangeListener(ChangeListener JavaDoc l) {
164         if (this.changeListeners == null) {
165             this.changeListeners = new ArrayList JavaDoc();
166         }
167         this.changeListeners.add(l);
168     }
169     
170     public synchronized void removeChangeListener(ChangeListener JavaDoc l) {
171         if (this.changeListeners == null) {
172             return;
173         }
174         this.changeListeners.remove(l);
175     }
176     
177     /**
178      * Used by RubyProjectCustomizer to mark the project as broken when it warns user
179      * about project's broken references and advices him to use BrokenLinksAction to correct it.
180      *
181      */

182     public void testBroken() {
183         ChangeListener JavaDoc[] _listeners;
184         synchronized (this) {
185             if (this.changeListeners == null) {
186                 return;
187             }
188             _listeners = (ChangeListener JavaDoc[]) this.changeListeners.toArray(
189                     new ChangeListener JavaDoc[this.changeListeners.size()]);
190         }
191         ChangeEvent JavaDoc event = new ChangeEvent JavaDoc(this);
192         for (int i=0; i < _listeners.length; i++) {
193             _listeners[i].stateChanged(event);
194         }
195     }
196     
197 // private static Lookup createLookup( Project project ) {
198
// DataFolder rootFolder = DataFolder.findFolder(project.getProjectDirectory());
199
// // XXX Remove root folder after FindAction rewrite
200
// return Lookups.fixed(new Object[] {project, rootFolder});
201
// }
202

203     
204     // Private innerclasses ----------------------------------------------------------------
205

206     private static final String JavaDoc[] BREAKABLE_PROPERTIES = new String JavaDoc[] {
207         RubyProjectProperties.JAVAC_CLASSPATH,
208         RubyProjectProperties.RUN_CLASSPATH,
209         RubyProjectProperties.DEBUG_CLASSPATH,
210         RubyProjectProperties.RUN_TEST_CLASSPATH,
211         RubyProjectProperties.DEBUG_TEST_CLASSPATH,
212         RubyProjectProperties.JAVAC_TEST_CLASSPATH,
213     };
214     
215     public boolean hasBrokenLinks () {
216 // return BrokenReferencesSupport.isBroken(helper.getRakeProjectHelper(), resolver, getBreakableProperties(),
217
// new String[] {RubyProjectProperties.JAVA_PLATFORM});
218
return false;
219     }
220     
221     public boolean hasInvalidJdkVersion () {
222 // String javaSource = this.evaluator.getProperty("javac.source"); //NOI18N
223
// String javaTarget = this.evaluator.getProperty("javac.target"); //NOI18N
224
// if (javaSource == null && javaTarget == null) {
225
// //No need to check anything
226
// return false;
227
// }
228
//
229
// final String platformId = this.evaluator.getProperty("platform.active"); //NOI18N
230
// final JavaPlatform activePlatform = RubyProjectUtil.getActivePlatform (platformId);
231
// if (activePlatform == null) {
232
// return true;
233
// }
234
// SpecificationVersion platformVersion = activePlatform.getSpecification().getVersion();
235
// try {
236
// return (javaSource != null && new SpecificationVersion (javaSource).compareTo(platformVersion)>0)
237
// || (javaTarget != null && new SpecificationVersion (javaTarget).compareTo(platformVersion)>0);
238
// } catch (NumberFormatException nfe) {
239
// ErrorManager.getDefault().log("Invalid javac.source: "+javaSource+" or javac.target: "+javaTarget+" of project:"
240
// +this.project.getProjectDirectory().getPath());
241
// return true;
242
// }
243
return false;
244     }
245     
246 // private String[] getBreakableProperties() {
247
// SourceRoots roots = this.project.getSourceRoots();
248
// String[] srcRootProps = roots.getRootProperties();
249
// roots = this.project.getTestSourceRoots();
250
// String[] testRootProps = roots.getRootProperties();
251
// String[] result = new String [BREAKABLE_PROPERTIES.length + srcRootProps.length + testRootProps.length];
252
// System.arraycopy(BREAKABLE_PROPERTIES, 0, result, 0, BREAKABLE_PROPERTIES.length);
253
// System.arraycopy(srcRootProps, 0, result, BREAKABLE_PROPERTIES.length, srcRootProps.length);
254
// System.arraycopy(testRootProps, 0, result, BREAKABLE_PROPERTIES.length + srcRootProps.length, testRootProps.length);
255
// return result;
256
// }
257

258     private static Image JavaDoc brokenProjectBadge = Utilities.loadImage("org/netbeans/modules/ruby/rubyproject/ui/resources/brokenProjectBadge.gif", true);
259     
260     /** Filter node containin additional features for the Ruby physical
261      */

262     private final class RubyLogicalViewRootNode extends AbstractNode implements Runnable JavaDoc, FileStatusListener, ChangeListener JavaDoc, PropertyChangeListener JavaDoc {
263         
264         private Image JavaDoc icon;
265         private Lookup lookup;
266         //private Action brokenLinksAction;
267
private boolean broken; //Represents a state where project has a broken reference repairable by broken reference support
268
private boolean illegalState; //Represents a state where project is not in legal state, eg invalid source/target level
269

270         // icon badging >>>
271
private Set JavaDoc files;
272         private Map JavaDoc fileSystemListeners;
273         private RequestProcessor.Task task;
274         private final Object JavaDoc privateLock = new Object JavaDoc();
275         private boolean iconChange;
276         private boolean nameChange;
277         private ChangeListener JavaDoc sourcesListener;
278         private Map JavaDoc groupsListeners;
279         //private Project project;
280
// icon badging <<<
281

282         public RubyLogicalViewRootNode() {
283             super(NodeFactorySupport.createCompositeChildren(project, "Projects/org-netbeans-modules-ruby-rubyproject/Nodes"),
284                   Lookups.singleton(project));
285             setIconBaseWithExtension("org/netbeans/modules/ruby/rubyproject/ui/resources/jruby.png");
286             super.setName( ProjectUtils.getInformation( project ).getDisplayName() );
287             if (hasBrokenLinks()) {
288                 broken = true;
289             }
290             else if (hasInvalidJdkVersion ()) {
291                 illegalState = true;
292             }
293             //brokenLinksAction = new BrokenLinksAction();
294
setProjectFiles(project);
295         }
296         
297         
298         protected final void setProjectFiles(Project project) {
299             Sources sources = ProjectUtils.getSources(project); // returns singleton
300
if (sourcesListener == null) {
301                 sourcesListener = WeakListeners.change(this, sources);
302                 sources.addChangeListener(sourcesListener);
303             }
304             setGroups(Arrays.asList(sources.getSourceGroups(Sources.TYPE_GENERIC)));
305         }
306         
307         
308         private final void setGroups(Collection JavaDoc groups) {
309             if (groupsListeners != null) {
310                 Iterator JavaDoc it = groupsListeners.keySet().iterator();
311                 while (it.hasNext()) {
312                     SourceGroup group = (SourceGroup) it.next();
313                     PropertyChangeListener JavaDoc pcl = (PropertyChangeListener JavaDoc) groupsListeners.get(group);
314                     group.removePropertyChangeListener(pcl);
315                 }
316             }
317             groupsListeners = new HashMap JavaDoc();
318             Set JavaDoc roots = new HashSet JavaDoc();
319             Iterator JavaDoc it = groups.iterator();
320             while (it.hasNext()) {
321                 SourceGroup group = (SourceGroup) it.next();
322                 PropertyChangeListener JavaDoc pcl = WeakListeners.propertyChange(this, group);
323                 groupsListeners.put(group, pcl);
324                 group.addPropertyChangeListener(pcl);
325                 FileObject fo = group.getRootFolder();
326                 roots.add(fo);
327             }
328             setFiles(roots);
329         }
330         
331         protected final void setFiles(Set JavaDoc files) {
332             if (fileSystemListeners != null) {
333                 Iterator JavaDoc it = fileSystemListeners.keySet().iterator();
334                 while (it.hasNext()) {
335                     FileSystem fs = (FileSystem) it.next();
336                     FileStatusListener fsl = (FileStatusListener) fileSystemListeners.get(fs);
337                     fs.removeFileStatusListener(fsl);
338                 }
339             }
340             
341             fileSystemListeners = new HashMap JavaDoc();
342             this.files = files;
343             if (files == null) {
344                 return;
345             }
346             
347             Iterator JavaDoc it = files.iterator();
348             Set JavaDoc hookedFileSystems = new HashSet JavaDoc();
349             while (it.hasNext()) {
350                 FileObject fo = (FileObject) it.next();
351                 try {
352                     FileSystem fs = fo.getFileSystem();
353                     if (hookedFileSystems.contains(fs)) {
354                         continue;
355                     }
356                     hookedFileSystems.add(fs);
357                     FileStatusListener fsl = FileUtil.weakFileStatusListener(this, fs);
358                     fs.addFileStatusListener(fsl);
359                     fileSystemListeners.put(fs, fsl);
360                 } catch (FileStateInvalidException e) {
361                     ErrorManager err = ErrorManager.getDefault();
362                     err.annotate(e, ErrorManager.UNKNOWN, "Cannot get " + fo + " filesystem, ignoring...", null, null, null); // NO18N
363
err.notify(ErrorManager.INFORMATIONAL, e);
364                 }
365             }
366         }
367         
368         public String JavaDoc getHtmlDisplayName() {
369             String JavaDoc dispName = super.getDisplayName();
370             try {
371                 dispName = XMLUtil.toElementContent(dispName);
372             } catch (CharConversionException JavaDoc ex) {
373                 return dispName;
374             }
375             // XXX text colors should be taken from UIManager, not hard-coded!
376
return broken || illegalState ? "<font color=\"#A40000\">" + dispName + "</font>" : null; //NOI18N
377
}
378         
379         public Image JavaDoc getIcon(int type) {
380             Image JavaDoc img = getMyIcon(type);
381             
382             if (files != null && files.iterator().hasNext()) {
383                 try {
384                     FileObject fo = (FileObject) files.iterator().next();
385                     img = fo.getFileSystem().getStatus().annotateIcon(img, type, files);
386                 } catch (FileStateInvalidException e) {
387                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
388                 }
389             }
390             
391             return img;
392         }
393         
394         private Image JavaDoc getMyIcon(int type) {
395             Image JavaDoc original = super.getIcon(type);
396             return broken || illegalState ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original;
397         }
398         
399         public Image JavaDoc getOpenedIcon(int type) {
400             Image JavaDoc img = getMyOpenedIcon(type);
401             
402             if (files != null && files.iterator().hasNext()) {
403                 try {
404                     FileObject fo = (FileObject) files.iterator().next();
405                     img = fo.getFileSystem().getStatus().annotateIcon(img, type, files);
406                 } catch (FileStateInvalidException e) {
407                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
408                 }
409             }
410             
411             return img;
412         }
413         
414         private Image JavaDoc getMyOpenedIcon(int type) {
415             Image JavaDoc original = super.getOpenedIcon(type);
416             return broken || illegalState ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original;
417         }
418         
419         public void run() {
420             boolean fireIcon;
421             boolean fireName;
422             synchronized (privateLock) {
423                 fireIcon = iconChange;
424                 fireName = nameChange;
425                 iconChange = false;
426                 nameChange = false;
427             }
428             if (fireIcon) {
429                 fireIconChange();
430                 fireOpenedIconChange();
431             }
432             if (fireName) {
433                 fireDisplayNameChange(null, null);
434             }
435         }
436         
437         public void annotationChanged(FileStatusEvent event) {
438             if (task == null) {
439                 task = RequestProcessor.getDefault().create(this);
440             }
441             
442             synchronized (privateLock) {
443                 if ((iconChange == false && event.isIconChange()) || (nameChange == false && event.isNameChange())) {
444                     Iterator JavaDoc it = files.iterator();
445                     while (it.hasNext()) {
446                         FileObject fo = (FileObject) it.next();
447                         if (event.hasChanged(fo)) {
448                             iconChange |= event.isIconChange();
449                             nameChange |= event.isNameChange();
450                         }
451                     }
452                 }
453             }
454             
455             task.schedule(50); // batch by 50 ms
456
}
457         
458         // sources change
459
public void stateChanged(ChangeEvent JavaDoc e) {
460             setProjectFiles(project);
461         }
462         
463         // group change
464
public void propertyChange(PropertyChangeEvent JavaDoc evt) {
465             setProjectFiles(project);
466         }
467         
468         public Action JavaDoc[] getActions( boolean context ) {
469             return getAdditionalActions();
470         }
471         
472         public boolean canRename() {
473             return true;
474         }
475         
476         public void setName(String JavaDoc s) {
477             DefaultProjectOperations.performDefaultRenameOperation(project, s);
478         }
479         
480         public HelpCtx getHelpCtx() {
481             return new HelpCtx(RubyLogicalViewRootNode.class);
482         }
483         
484         /*
485         public boolean canDestroy() {
486             return true;
487         }
488          
489         public void destroy() throws IOException {
490             System.out.println("Destroy " + project.getProjectDirectory());
491             LogicalViews.closeProjectAction().actionPerformed(new ActionEvent(this, 0, ""));
492             project.getProjectDirectory().delete();
493         }
494          */

495         
496         // Private methods -------------------------------------------------------------
497

498         private Action JavaDoc[] getAdditionalActions() {
499             
500             ResourceBundle JavaDoc bundle = NbBundle.getBundle(RubyLogicalViewProvider.class);
501             
502             List JavaDoc actions = new ArrayList JavaDoc();
503             
504             actions.add(CommonProjectActions.newFileAction());
505             actions.add(null);
506             actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_BUILD, bundle.getString("LBL_BuildAction_Name"), null)); // NOI18N
507
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_REBUILD, bundle.getString("LBL_RebuildAction_Name"), null)); // NOI18N
508
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_CLEAN, bundle.getString("LBL_CleanAction_Name"), null)); // NOI18N
509
actions.add(null);
510             actions.add(ProjectSensitiveActions.projectCommandAction(RubyActionProvider.COMMAND_RDOC, bundle.getString("LBL_RDocAction_Name"), null)); // NOI18N
511
actions.add(null);
512             actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_RUN, bundle.getString("LBL_RunAction_Name"), null)); // NOI18N
513
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_DEBUG, bundle.getString("LBL_DebugAction_Name"), null)); // NOI18N
514
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_TEST, bundle.getString("LBL_TestAction_Name"), null)); // NOI18N
515
actions.add(CommonProjectActions.setProjectConfigurationAction());
516             actions.add(null);
517             actions.add(CommonProjectActions.setAsMainProjectAction());
518             actions.add(CommonProjectActions.openSubprojectsAction());
519             actions.add(CommonProjectActions.closeProjectAction());
520             actions.add(null);
521             actions.add(CommonProjectActions.renameProjectAction());
522             actions.add(CommonProjectActions.moveProjectAction());
523             actions.add(CommonProjectActions.copyProjectAction());
524             actions.add(CommonProjectActions.deleteProjectAction());
525             actions.add(null);
526             actions.add(SystemAction.get(FindAction.class));
527             
528             // honor 57874 contact
529

530             try {
531                 FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource("Projects/Actions"); // NOI18N
532
if (fo != null) {
533                     DataObject dobj = DataObject.find(fo);
534                     FolderLookup actionRegistry = new FolderLookup((DataFolder)dobj);
535                     Lookup.Template query = new Lookup.Template(Object JavaDoc.class);
536                     Lookup lookup = actionRegistry.getLookup();
537                     Iterator JavaDoc it = lookup.lookup(query).allInstances().iterator();
538                     if (it.hasNext()) {
539                         actions.add(null);
540                     }
541                     while (it.hasNext()) {
542                         Object JavaDoc next = it.next();
543                         if (next instanceof Action JavaDoc) {
544                             actions.add(next);
545                         } else if (next instanceof JSeparator JavaDoc) {
546                             actions.add(null);
547                         }
548                     }
549                 }
550             } catch (DataObjectNotFoundException ex) {
551                 // data folder for existing fileobject expected
552
ErrorManager.getDefault().notify(ex);
553             }
554             
555             actions.add(null);
556             actions.add(SystemAction.get(ToolsAction.class));
557             actions.add(null);
558 // if (broken) {
559
// actions.add(brokenLinksAction);
560
// }
561
actions.add(CommonProjectActions.customizeProjectAction());
562             
563             return (Action JavaDoc[]) actions.toArray(new Action JavaDoc[actions.size()]);
564             
565         }
566         
567 // private boolean isBroken() {
568
// return this.broken;
569
// }
570
//
571
// private void setBroken(boolean broken) {
572
// this.broken = broken;
573
// //brokenLinksAction.setEnabled(broken);
574
// fireIconChange();
575
// fireOpenedIconChange();
576
// fireDisplayNameChange(null, null);
577
// }
578
//
579
// private void setIllegalState (boolean illegalState) {
580
// this.illegalState = illegalState;
581
// fireIconChange();
582
// fireOpenedIconChange();
583
// fireDisplayNameChange(null, null);
584
// }
585
//
586
// /** This action is created only when project has broken references.
587
// * Once these are resolved the action is disabled.
588
// */
589
// private class BrokenLinksAction extends AbstractAction implements PropertyChangeListener, ChangeListener, Runnable {
590
//
591
// private RequestProcessor.Task task = null;
592
//
593
// private PropertyChangeListener weakPCL;
594
//
595
// public BrokenLinksAction() {
596
// putValue(Action.NAME, NbBundle.getMessage(RubyLogicalViewProvider.class, "LBL_Fix_Broken_Links_Action"));
597
// setEnabled(broken);
598
// evaluator.addPropertyChangeListener(this);
599
// // When evaluator fires changes that platform properties were
600
// // removed the platform still exists in JavaPlatformManager.
601
// // That's why I have to listen here also on JPM:
602
// weakPCL = WeakListeners.propertyChange(this, JavaPlatformManager.getDefault());
603
// JavaPlatformManager.getDefault().addPropertyChangeListener(weakPCL);
604
// RubyLogicalViewProvider.this.addChangeListener((ChangeListener) WeakListeners.change(this, RubyLogicalViewProvider.this));
605
// }
606
//
607
// public void actionPerformed(ActionEvent e) {
608
// try {
609
// helper.requestSave();
610
// BrokenReferencesSupport.showCustomizer(helper.getRakeProjectHelper(), resolver, getBreakableProperties(), new String[] {RubyProjectProperties.JAVA_PLATFORM});
611
// run();
612
// } catch (IOException ioe) {
613
// ErrorManager.getDefault().notify(ioe);
614
// }
615
// }
616
//
617
// public void propertyChange(PropertyChangeEvent evt) {
618
// refsMayChanged();
619
// }
620
//
621
//
622
// public void stateChanged(ChangeEvent evt) {
623
// refsMayChanged();
624
// }
625
//
626
// public synchronized void run() {
627
// boolean old = RubyLogicalViewRootNode.this.broken;
628
// boolean broken = hasBrokenLinks();
629
// if (old != broken) {
630
// setBroken(broken);
631
// }
632
//
633
// old = RubyLogicalViewRootNode.this.illegalState;
634
// broken = hasInvalidJdkVersion ();
635
// if (old != broken) {
636
// setIllegalState(broken);
637
// }
638
// }
639
//
640
// private void refsMayChanged() {
641
// // check project state whenever there was a property change
642
// // or change in list of platforms.
643
// // Coalesce changes since they can come quickly:
644
// if (task == null) {
645
// task = BROKEN_LINKS_RP.create(this);
646
// }
647
// task.schedule(100);
648
// }
649
//
650
// }
651
//
652
}
653     
654 }
655
Popular Tags