Lines 48-63
Link Here
|
48 |
import java.io.CharConversionException; |
48 |
import java.io.CharConversionException; |
49 |
import java.io.IOException; |
49 |
import java.io.IOException; |
50 |
import java.net.URL; |
50 |
import java.net.URL; |
51 |
import java.util.ArrayList; |
51 |
import java.util.Collection; |
52 |
import java.util.List; |
|
|
53 |
import java.util.ResourceBundle; |
54 |
import javax.swing.AbstractAction; |
52 |
import javax.swing.AbstractAction; |
55 |
import javax.swing.Action; |
53 |
import javax.swing.Action; |
56 |
import javax.swing.event.ChangeEvent; |
54 |
import javax.swing.event.ChangeEvent; |
57 |
import javax.swing.event.ChangeListener; |
55 |
import javax.swing.event.ChangeListener; |
58 |
import org.netbeans.api.java.platform.JavaPlatform; |
56 |
import org.netbeans.api.java.platform.JavaPlatform; |
59 |
import org.netbeans.api.java.platform.JavaPlatformManager; |
57 |
import org.netbeans.api.java.platform.JavaPlatformManager; |
60 |
import org.netbeans.api.java.project.JavaProjectConstants; |
|
|
61 |
import org.netbeans.api.project.FileOwnerQuery; |
58 |
import org.netbeans.api.project.FileOwnerQuery; |
62 |
import org.netbeans.api.project.Project; |
59 |
import org.netbeans.api.project.Project; |
63 |
import org.netbeans.api.project.ProjectUtils; |
60 |
import org.netbeans.api.project.ProjectUtils; |
Lines 70-98
Link Here
|
70 |
import org.netbeans.modules.java.j2seproject.J2SEProject; |
67 |
import org.netbeans.modules.java.j2seproject.J2SEProject; |
71 |
import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; |
68 |
import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; |
72 |
import org.netbeans.spi.java.project.support.ui.PackageView; |
69 |
import org.netbeans.spi.java.project.support.ui.PackageView; |
73 |
import org.netbeans.spi.project.ActionProvider; |
|
|
74 |
import org.netbeans.spi.project.SubprojectProvider; |
75 |
import org.netbeans.spi.project.support.ant.PropertyEvaluator; |
70 |
import org.netbeans.spi.project.support.ant.PropertyEvaluator; |
76 |
import org.netbeans.spi.project.support.ant.ReferenceHelper; |
71 |
import org.netbeans.spi.project.support.ant.ReferenceHelper; |
77 |
import org.netbeans.spi.project.ui.support.CommonProjectActions; |
72 |
import org.netbeans.spi.project.ui.support.CommonProjectActions; |
78 |
import org.netbeans.spi.project.ui.support.NodeFactorySupport; |
73 |
import org.netbeans.spi.project.ui.support.NodeFactorySupport; |
79 |
import org.netbeans.spi.project.ui.support.DefaultProjectOperations; |
74 |
import org.netbeans.spi.project.ui.support.DefaultProjectOperations; |
80 |
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions; |
|
|
81 |
import org.openide.ErrorManager; |
75 |
import org.openide.ErrorManager; |
82 |
import org.openide.actions.FindAction; |
76 |
import org.openide.awt.DynamicMenuContent; |
83 |
import org.openide.filesystems.FileObject; |
77 |
import org.openide.filesystems.FileObject; |
84 |
import org.openide.filesystems.FileUtil; |
78 |
import org.openide.filesystems.FileUtil; |
85 |
import org.openide.modules.SpecificationVersion; |
79 |
import org.openide.modules.SpecificationVersion; |
86 |
import org.openide.nodes.AbstractNode; |
80 |
import org.openide.nodes.AbstractNode; |
87 |
import org.openide.nodes.Node; |
81 |
import org.openide.nodes.Node; |
88 |
import org.openide.util.ChangeSupport; |
82 |
import org.openide.util.ChangeSupport; |
|
|
83 |
import org.openide.util.ContextAwareAction; |
89 |
import org.openide.util.HelpCtx; |
84 |
import org.openide.util.HelpCtx; |
90 |
import org.openide.util.ImageUtilities; |
85 |
import org.openide.util.ImageUtilities; |
|
|
86 |
import org.openide.util.Lookup; |
91 |
import org.openide.util.NbBundle; |
87 |
import org.openide.util.NbBundle; |
92 |
import org.openide.util.RequestProcessor; |
88 |
import org.openide.util.RequestProcessor; |
93 |
import org.openide.util.Utilities; |
|
|
94 |
import org.openide.util.WeakListeners; |
89 |
import org.openide.util.WeakListeners; |
95 |
import org.openide.util.actions.SystemAction; |
|
|
96 |
import org.openide.util.lookup.Lookups; |
90 |
import org.openide.util.lookup.Lookups; |
97 |
import org.openide.xml.XMLUtil; |
91 |
import org.openide.xml.XMLUtil; |
98 |
|
92 |
|
Lines 107-127
Link Here
|
107 |
private final J2SEProject project; |
101 |
private final J2SEProject project; |
108 |
private final UpdateHelper helper; |
102 |
private final UpdateHelper helper; |
109 |
private final PropertyEvaluator evaluator; |
103 |
private final PropertyEvaluator evaluator; |
110 |
private final SubprojectProvider spp; |
|
|
111 |
private final ReferenceHelper resolver; |
104 |
private final ReferenceHelper resolver; |
112 |
private final ChangeSupport changeSupport = new ChangeSupport(this); |
105 |
private final ChangeSupport changeSupport = new ChangeSupport(this); |
|
|
106 |
private final PropertyChangeListener pcl; |
113 |
|
107 |
|
114 |
public J2SELogicalViewProvider(J2SEProject project, UpdateHelper helper, PropertyEvaluator evaluator, SubprojectProvider spp, ReferenceHelper resolver) { |
108 |
public J2SELogicalViewProvider(J2SEProject project, UpdateHelper helper, PropertyEvaluator evaluator, ReferenceHelper resolver) { |
115 |
this.project = project; |
109 |
this.project = project; |
116 |
assert project != null; |
110 |
assert project != null; |
117 |
this.helper = helper; |
111 |
this.helper = helper; |
118 |
assert helper != null; |
112 |
assert helper != null; |
119 |
this.evaluator = evaluator; |
113 |
this.evaluator = evaluator; |
120 |
assert evaluator != null; |
114 |
assert evaluator != null; |
121 |
this.spp = spp; |
|
|
122 |
assert spp != null; |
123 |
this.resolver = resolver; |
115 |
this.resolver = resolver; |
124 |
assert resolver != null; |
116 |
assert resolver != null; |
|
|
117 |
pcl = new PropertyChangeListener() { |
118 |
public @Override void propertyChange(PropertyChangeEvent evt) { |
119 |
testBroken(); |
120 |
} |
121 |
}; |
122 |
evaluator.addPropertyChangeListener(pcl); |
123 |
// When evaluator fires changes that platform properties were |
124 |
// removed the platform still exists in JavaPlatformManager. |
125 |
// That's why I have to listen here also on JPM: |
126 |
JavaPlatformManager.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(pcl, JavaPlatformManager.getDefault())); |
125 |
} |
127 |
} |
126 |
|
128 |
|
127 |
public Node createLogicalView() { |
129 |
public Node createLogicalView() { |
Lines 174-186
Link Here
|
174 |
changeSupport.removeChangeListener(l); |
176 |
changeSupport.removeChangeListener(l); |
175 |
} |
177 |
} |
176 |
|
178 |
|
|
|
179 |
private final RequestProcessor.Task task = RP.create(new Runnable() { |
180 |
public @Override void run() { |
181 |
boolean old = broken; |
182 |
boolean _broken = hasBrokenLinks(); |
183 |
if (old != _broken) { |
184 |
setBroken(_broken); |
185 |
} |
186 |
old = illegalState; |
187 |
boolean _illegalState = hasInvalidJdkVersion(); |
188 |
if (old != _illegalState) { |
189 |
setIllegalState(_illegalState); |
190 |
} |
191 |
old = compileOnSaveDisabled; |
192 |
boolean _compileOnSaveDisabled = isCompileOnSaveDisabled(); |
193 |
if (old != _compileOnSaveDisabled) { |
194 |
setCompileOnSaveDisabled(_compileOnSaveDisabled); |
195 |
} |
196 |
} |
197 |
}); |
198 |
|
177 |
/** |
199 |
/** |
178 |
* Used by J2SEProjectCustomizer to mark the project as broken when it warns user |
200 |
* Used by J2SEProjectCustomizer 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. |
201 |
* about project's broken references and advises him to use BrokenLinksAction to correct it. |
180 |
* |
|
|
181 |
*/ |
202 |
*/ |
182 |
public void testBroken() { |
203 |
public @Override void testBroken() { |
183 |
changeSupport.fireChange(); |
204 |
task.schedule(100); |
184 |
} |
205 |
} |
185 |
|
206 |
|
186 |
|
207 |
|
Lines 201-207
Link Here
|
201 |
new String[] {J2SEProjectProperties.JAVA_PLATFORM}); |
222 |
new String[] {J2SEProjectProperties.JAVA_PLATFORM}); |
202 |
} |
223 |
} |
203 |
|
224 |
|
204 |
public boolean hasInvalidJdkVersion () { |
225 |
private boolean hasInvalidJdkVersion () { |
205 |
String javaSource = this.evaluator.getProperty("javac.source"); //NOI18N |
226 |
String javaSource = this.evaluator.getProperty("javac.source"); //NOI18N |
206 |
String javaTarget = this.evaluator.getProperty("javac.target"); //NOI18N |
227 |
String javaTarget = this.evaluator.getProperty("javac.target"); //NOI18N |
207 |
if (javaSource == null && javaTarget == null) { |
228 |
if (javaSource == null && javaTarget == null) { |
Lines 250-265
Link Here
|
250 |
String compileOnSaveDisabledTP = "<img src=\"" + errorBadgeIconURL + "\"> " + NbBundle.getMessage(J2SELogicalViewProvider.class, "TP_CompileOnSaveDisabled"); |
271 |
String compileOnSaveDisabledTP = "<img src=\"" + errorBadgeIconURL + "\"> " + NbBundle.getMessage(J2SELogicalViewProvider.class, "TP_CompileOnSaveDisabled"); |
251 |
compileOnSaveDisabledBadge = ImageUtilities.assignToolTipToImage(ImageUtilities.loadImage(COMPILE_ON_SAVE_DISABLED_BADGE_PATH), compileOnSaveDisabledTP); // NOI18N |
272 |
compileOnSaveDisabledBadge = ImageUtilities.assignToolTipToImage(ImageUtilities.loadImage(COMPILE_ON_SAVE_DISABLED_BADGE_PATH), compileOnSaveDisabledTP); // NOI18N |
252 |
} |
273 |
} |
253 |
|
274 |
|
254 |
/** Filter node containin additional features for the J2SE physical |
275 |
private final class J2SELogicalViewRootNode extends AbstractNode implements ChangeListener { |
255 |
*/ |
|
|
256 |
private final class J2SELogicalViewRootNode extends AbstractNode { |
257 |
|
276 |
|
258 |
private Action brokenLinksAction; |
277 |
@SuppressWarnings("LeakingThisInConstructor") |
259 |
private boolean broken; //Represents a state where project has a broken reference repairable by broken reference support |
|
|
260 |
private boolean illegalState; //Represents a state where project is not in legal state, eg invalid source/target level |
261 |
private boolean compileOnSaveDisabled; //true iff Compile-on-Save is disabled |
262 |
|
263 |
public J2SELogicalViewRootNode() { |
278 |
public J2SELogicalViewRootNode() { |
264 |
super(NodeFactorySupport.createCompositeChildren(project, "Projects/org-netbeans-modules-java-j2seproject/Nodes"), |
279 |
super(NodeFactorySupport.createCompositeChildren(project, "Projects/org-netbeans-modules-java-j2seproject/Nodes"), |
265 |
Lookups.singleton(project)); |
280 |
Lookups.singleton(project)); |
Lines 272-278
Link Here
|
272 |
illegalState = true; |
287 |
illegalState = true; |
273 |
} |
288 |
} |
274 |
compileOnSaveDisabled = isCompileOnSaveDisabled(); |
289 |
compileOnSaveDisabled = isCompileOnSaveDisabled(); |
275 |
brokenLinksAction = new BrokenLinksAction(); |
290 |
addChangeListener(WeakListeners.change(this, J2SELogicalViewProvider.this)); |
276 |
} |
291 |
} |
277 |
|
292 |
|
278 |
@Override |
293 |
@Override |
Lines 315-323
Link Here
|
315 |
} |
330 |
} |
316 |
} |
331 |
} |
317 |
|
332 |
|
|
|
333 |
public @Override void stateChanged(ChangeEvent e) { |
334 |
fireIconChange(); |
335 |
fireOpenedIconChange(); |
336 |
fireDisplayNameChange(null, null); |
337 |
} |
338 |
|
318 |
@Override |
339 |
@Override |
319 |
public Action[] getActions( boolean context ) { |
340 |
public Action[] getActions( boolean context ) { |
320 |
return getAdditionalActions(); |
341 |
return CommonProjectActions.forType("org-netbeans-modules-java-j2seproject"); // NOI18N |
321 |
} |
342 |
} |
322 |
|
343 |
|
323 |
@Override |
344 |
@Override |
Lines 334-478
Link Here
|
334 |
public HelpCtx getHelpCtx() { |
355 |
public HelpCtx getHelpCtx() { |
335 |
return new HelpCtx(J2SELogicalViewRootNode.class); |
356 |
return new HelpCtx(J2SELogicalViewRootNode.class); |
336 |
} |
357 |
} |
337 |
|
358 |
|
338 |
// Private methods ------------------------------------------------- |
359 |
} |
339 |
|
360 |
|
340 |
private Action[] getAdditionalActions() { |
361 |
private boolean broken; //Represents a state where project has a broken reference repairable by broken reference support |
341 |
|
362 |
private boolean illegalState; //Represents a state where project is not in legal state, eg invalid source/target level |
342 |
ResourceBundle bundle = NbBundle.getBundle(J2SELogicalViewProvider.class); |
363 |
private boolean compileOnSaveDisabled; //true iff Compile-on-Save is disabled |
343 |
|
364 |
|
344 |
List<Action> actions = new ArrayList<Action>(); |
365 |
// Private methods ------------------------------------------------- |
345 |
|
366 |
|
346 |
actions.add(CommonProjectActions.newFileAction()); |
367 |
private void setBroken(boolean broken) { |
347 |
actions.add(null); |
368 |
this.broken = broken; |
348 |
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_BUILD, bundle.getString("LBL_BuildAction_Name"), null)); // NOI18N |
369 |
changeSupport.fireChange(); |
349 |
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_REBUILD, bundle.getString("LBL_RebuildAction_Name"), null)); // NOI18N |
370 |
} |
350 |
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_CLEAN, bundle.getString("LBL_CleanAction_Name"), null)); // NOI18N |
371 |
|
351 |
actions.add(ProjectSensitiveActions.projectCommandAction(JavaProjectConstants.COMMAND_JAVADOC, bundle.getString("LBL_JavadocAction_Name"), null)); // NOI18N |
372 |
private void setIllegalState (boolean illegalState) { |
352 |
actions.add(null); |
373 |
this.illegalState = illegalState; |
353 |
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_RUN, bundle.getString("LBL_RunAction_Name"), null)); // NOI18N |
374 |
changeSupport.fireChange(); |
354 |
actions.addAll(Utilities.actionsForPath("Projects/Debugger_Actions_temporary")); //NOI18N |
375 |
} |
355 |
actions.addAll(Utilities.actionsForPath("Projects/Profiler_Actions_temporary")); //NOI18N |
376 |
|
356 |
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_TEST, bundle.getString("LBL_TestAction_Name"), null)); // NOI18N |
377 |
private void setCompileOnSaveDisabled (boolean value) { |
357 |
actions.add(CommonProjectActions.setProjectConfigurationAction()); |
378 |
this.compileOnSaveDisabled = value; |
358 |
actions.add(null); |
379 |
changeSupport.fireChange(); |
359 |
actions.add(CommonProjectActions.setAsMainProjectAction()); |
380 |
} |
360 |
actions.add(CommonProjectActions.openSubprojectsAction()); |
381 |
|
361 |
actions.add(CommonProjectActions.closeProjectAction()); |
382 |
public static final class BrokenLinksActionFactory extends AbstractAction implements ContextAwareAction { |
362 |
actions.add(null); |
383 |
|
363 |
actions.add(CommonProjectActions.renameProjectAction()); |
384 |
/** for layer registration */ |
364 |
actions.add(CommonProjectActions.moveProjectAction()); |
385 |
public BrokenLinksActionFactory() { |
365 |
actions.add(CommonProjectActions.copyProjectAction()); |
386 |
setEnabled(false); |
366 |
actions.add(CommonProjectActions.deleteProjectAction()); |
387 |
putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true); |
367 |
actions.add(null); |
|
|
368 |
actions.add(SystemAction.get(FindAction.class)); |
369 |
|
370 |
// honor 57874 contact |
371 |
actions.addAll(Utilities.actionsForPath("Projects/Actions")); //NOI18N |
372 |
|
373 |
actions.add(null); |
374 |
if (broken) { |
375 |
actions.add(brokenLinksAction); |
376 |
} |
377 |
actions.add(CommonProjectActions.customizeProjectAction()); |
378 |
|
379 |
return actions.toArray(new Action[actions.size()]); |
380 |
|
381 |
} |
382 |
|
383 |
private void setBroken(boolean broken) { |
384 |
this.broken = broken; |
385 |
brokenLinksAction.setEnabled(broken); |
386 |
fireIconChange(); |
387 |
fireOpenedIconChange(); |
388 |
fireDisplayNameChange(null, null); |
389 |
} |
390 |
|
391 |
private void setIllegalState (boolean illegalState) { |
392 |
this.illegalState = illegalState; |
393 |
fireIconChange(); |
394 |
fireOpenedIconChange(); |
395 |
fireDisplayNameChange(null, null); |
396 |
} |
397 |
|
398 |
private void setCompileOnSaveDisabled (boolean value) { |
399 |
this.compileOnSaveDisabled = value; |
400 |
fireIconChange(); |
401 |
fireOpenedIconChange(); |
402 |
fireDisplayNameChange(null, null); |
403 |
} |
388 |
} |
404 |
|
389 |
|
405 |
/** This action is created only when project has broken references. |
390 |
public @Override void actionPerformed(ActionEvent e) { |
406 |
* Once these are resolved the action is disabled. |
391 |
assert false; |
407 |
*/ |
392 |
} |
408 |
private class BrokenLinksAction extends AbstractAction implements PropertyChangeListener, ChangeListener, Runnable { |
393 |
|
409 |
|
394 |
public @Override Action createContextAwareInstance(Lookup actionContext) { |
410 |
private RequestProcessor.Task task = null; |
395 |
Collection<? extends Project> p = actionContext.lookupAll(Project.class); |
411 |
|
396 |
if (p.size() != 1) { |
412 |
private PropertyChangeListener weakPCL; |
397 |
return this; |
413 |
|
|
|
414 |
public BrokenLinksAction() { |
415 |
putValue(Action.NAME, NbBundle.getMessage(J2SELogicalViewProvider.class, "LBL_Fix_Broken_Links_Action")); |
416 |
setEnabled(broken); |
417 |
evaluator.addPropertyChangeListener(this); |
418 |
// When evaluator fires changes that platform properties were |
419 |
// removed the platform still exists in JavaPlatformManager. |
420 |
// That's why I have to listen here also on JPM: |
421 |
weakPCL = WeakListeners.propertyChange(this, JavaPlatformManager.getDefault()); |
422 |
JavaPlatformManager.getDefault().addPropertyChangeListener(weakPCL); |
423 |
J2SELogicalViewProvider.this.addChangeListener(WeakListeners.change(this, J2SELogicalViewProvider.this)); |
424 |
} |
398 |
} |
425 |
|
399 |
J2SELogicalViewProvider lvp = p.iterator().next().getLookup().lookup(J2SELogicalViewProvider.class); |
426 |
public void actionPerformed(ActionEvent e) { |
400 |
if (lvp == null) { |
427 |
try { |
401 |
return this; |
428 |
helper.requestUpdate(); |
|
|
429 |
BrokenReferencesSupport.showCustomizer(helper.getAntProjectHelper(), resolver, getBreakableProperties(), new String[] {J2SEProjectProperties.JAVA_PLATFORM}); |
430 |
run(); |
431 |
} catch (IOException ioe) { |
432 |
ErrorManager.getDefault().notify(ioe); |
433 |
} |
434 |
} |
402 |
} |
435 |
|
403 |
return lvp.new BrokenLinksAction(); |
436 |
public void propertyChange(PropertyChangeEvent evt) { |
404 |
} |
437 |
refsMayChanged(); |
405 |
|
|
|
406 |
} |
407 |
|
408 |
/** This action is created only when project has broken references. |
409 |
* Once these are resolved the action is disabled. |
410 |
*/ |
411 |
private class BrokenLinksAction extends AbstractAction { |
412 |
|
413 |
public BrokenLinksAction() { |
414 |
putValue(Action.NAME, NbBundle.getMessage(J2SELogicalViewProvider.class, "LBL_Fix_Broken_Links_Action")); |
415 |
setEnabled(broken); |
416 |
putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true); |
417 |
} |
418 |
|
419 |
public void actionPerformed(ActionEvent e) { |
420 |
try { |
421 |
helper.requestUpdate(); |
422 |
BrokenReferencesSupport.showCustomizer(helper.getAntProjectHelper(), resolver, getBreakableProperties(), new String[] {J2SEProjectProperties.JAVA_PLATFORM}); |
423 |
testBroken(); |
424 |
} catch (IOException ioe) { |
425 |
ErrorManager.getDefault().notify(ioe); |
438 |
} |
426 |
} |
439 |
|
|
|
440 |
|
441 |
public void stateChanged(ChangeEvent evt) { |
442 |
refsMayChanged(); |
443 |
} |
444 |
|
445 |
public synchronized void run() { |
446 |
boolean old = J2SELogicalViewRootNode.this.broken; |
447 |
boolean broken = hasBrokenLinks(); |
448 |
if (old != broken) { |
449 |
setBroken(broken); |
450 |
} |
451 |
|
452 |
old = J2SELogicalViewRootNode.this.illegalState; |
453 |
broken = hasInvalidJdkVersion (); |
454 |
if (old != broken) { |
455 |
setIllegalState(broken); |
456 |
} |
457 |
old = J2SELogicalViewRootNode.this.compileOnSaveDisabled; |
458 |
boolean cosDisabled = isCompileOnSaveDisabled(); |
459 |
if (old != cosDisabled) { |
460 |
setCompileOnSaveDisabled(cosDisabled); |
461 |
} |
462 |
} |
463 |
|
464 |
private void refsMayChanged() { |
465 |
// check project state whenever there was a property change |
466 |
// or change in list of platforms. |
467 |
// Coalesce changes since they can come quickly: |
468 |
if (task == null) { |
469 |
task = RP.create(this); |
470 |
} |
471 |
task.schedule(100); |
472 |
} |
473 |
|
474 |
} |
427 |
} |
475 |
|
428 |
|
476 |
} |
429 |
} |
477 |
|
430 |
|
478 |
} |
431 |
} |