Lines 19-82
Link Here
|
19 |
|
19 |
|
20 |
package org.netbeans.modules.apisupport.project.ui; |
20 |
package org.netbeans.modules.apisupport.project.ui; |
21 |
|
21 |
|
22 |
import java.awt.EventQueue; |
|
|
23 |
import java.awt.Image; |
22 |
import java.awt.Image; |
24 |
import java.awt.event.ActionEvent; |
|
|
25 |
import java.beans.PropertyChangeEvent; |
23 |
import java.beans.PropertyChangeEvent; |
26 |
import java.beans.PropertyChangeListener; |
24 |
import java.beans.PropertyChangeListener; |
27 |
import java.io.IOException; |
|
|
28 |
import java.util.ArrayList; |
29 |
import java.util.Collections; |
30 |
import java.util.Enumeration; |
25 |
import java.util.Enumeration; |
31 |
import java.util.HashSet; |
26 |
import java.util.HashSet; |
32 |
import java.util.Iterator; |
|
|
33 |
import java.util.LinkedHashMap; |
34 |
import java.util.List; |
35 |
import java.util.Set; |
27 |
import java.util.Set; |
36 |
import java.util.SortedSet; |
|
|
37 |
import java.util.TreeSet; |
38 |
import javax.swing.AbstractAction; |
39 |
import javax.swing.Action; |
28 |
import javax.swing.Action; |
40 |
import javax.swing.event.ChangeEvent; |
|
|
41 |
import javax.swing.event.ChangeListener; |
42 |
import org.netbeans.api.project.FileOwnerQuery; |
29 |
import org.netbeans.api.project.FileOwnerQuery; |
43 |
import org.netbeans.api.project.Project; |
|
|
44 |
import org.netbeans.api.project.ProjectInformation; |
30 |
import org.netbeans.api.project.ProjectInformation; |
45 |
import org.netbeans.api.project.ProjectManager; |
|
|
46 |
import org.netbeans.api.project.ProjectUtils; |
31 |
import org.netbeans.api.project.ProjectUtils; |
47 |
import org.netbeans.api.project.ui.OpenProjects; |
|
|
48 |
import org.netbeans.modules.apisupport.project.NbModuleProject; |
49 |
import org.netbeans.modules.apisupport.project.Util; |
50 |
import org.netbeans.modules.apisupport.project.suite.SuiteProject; |
32 |
import org.netbeans.modules.apisupport.project.suite.SuiteProject; |
51 |
import org.netbeans.modules.apisupport.project.ui.customizer.SuiteUtils; |
|
|
52 |
import org.netbeans.modules.apisupport.project.ui.wizard.NewNbModuleWizardIterator; |
53 |
import org.netbeans.spi.project.SubprojectProvider; |
54 |
import org.netbeans.spi.project.ui.LogicalViewProvider; |
33 |
import org.netbeans.spi.project.ui.LogicalViewProvider; |
55 |
import org.netbeans.spi.project.ui.support.DefaultProjectOperations; |
34 |
import org.netbeans.spi.project.ui.support.DefaultProjectOperations; |
56 |
import org.openide.DialogDisplayer; |
35 |
import org.netbeans.spi.project.ui.support.NodeFactorySupport; |
57 |
import org.openide.ErrorManager; |
|
|
58 |
import org.openide.NotifyDescriptor; |
59 |
import org.openide.awt.StatusDisplayer; |
60 |
import org.openide.filesystems.FileChangeAdapter; |
61 |
import org.openide.filesystems.FileObject; |
36 |
import org.openide.filesystems.FileObject; |
62 |
import org.openide.filesystems.FileUtil; |
37 |
import org.openide.filesystems.FileUtil; |
63 |
import org.openide.filesystems.FileChangeListener; |
|
|
64 |
import org.openide.filesystems.FileEvent; |
65 |
import org.openide.filesystems.FileStateInvalidException; |
66 |
import org.openide.loaders.DataObject; |
38 |
import org.openide.loaders.DataObject; |
67 |
import org.openide.loaders.DataObjectNotFoundException; |
39 |
import org.openide.loaders.DataObjectNotFoundException; |
68 |
import org.openide.nodes.AbstractNode; |
|
|
69 |
import org.openide.nodes.Children; |
70 |
import org.openide.nodes.Node; |
40 |
import org.openide.nodes.Node; |
71 |
import org.openide.util.HelpCtx; |
|
|
72 |
import org.openide.util.NbBundle; |
41 |
import org.openide.util.NbBundle; |
73 |
import org.openide.util.RequestProcessor; |
|
|
74 |
import org.openide.util.Utilities; |
42 |
import org.openide.util.Utilities; |
75 |
import org.openide.util.WeakListeners; |
43 |
import org.openide.util.WeakListeners; |
76 |
import org.openide.util.actions.CookieAction; |
|
|
77 |
import org.openide.util.actions.NodeAction; |
78 |
import org.openide.util.lookup.Lookups; |
44 |
import org.openide.util.lookup.Lookups; |
79 |
import org.openide.windows.WindowManager; |
|
|
80 |
|
45 |
|
81 |
/** |
46 |
/** |
82 |
* Provides a logical view of a NetBeans suite project. |
47 |
* Provides a logical view of a NetBeans suite project. |
Lines 128-137
Link Here
|
128 |
return null; |
93 |
return null; |
129 |
} |
94 |
} |
130 |
|
95 |
|
131 |
private static String getMessage(final String key) { |
|
|
132 |
return NbBundle.getMessage(SuiteLogicalView.class, key); |
133 |
} |
134 |
|
135 |
/** Package private for unit test only. */ |
96 |
/** Package private for unit test only. */ |
136 |
static final class SuiteRootNode extends AnnotatedNode |
97 |
static final class SuiteRootNode extends AnnotatedNode |
137 |
implements PropertyChangeListener { |
98 |
implements PropertyChangeListener { |
Lines 142-148
Link Here
|
142 |
private final ProjectInformation info; |
103 |
private final ProjectInformation info; |
143 |
|
104 |
|
144 |
SuiteRootNode(final SuiteProject suite) { |
105 |
SuiteRootNode(final SuiteProject suite) { |
145 |
super(createRootChildren(suite), Lookups.fixed(new Object[] {suite})); |
106 |
super(NodeFactorySupport.createCompositeChildren(suite, "Projects/org-netbeans-modules-apisupport-project-suite/Nodes"), |
|
|
107 |
Lookups.fixed(new Object[] {suite})); |
146 |
this.suite = suite; |
108 |
this.suite = suite; |
147 |
info = ProjectUtils.getInformation(suite); |
109 |
info = ProjectUtils.getInformation(suite); |
148 |
info.addPropertyChangeListener(WeakListeners.propertyChange(this, info)); |
110 |
info.addPropertyChangeListener(WeakListeners.propertyChange(this, info)); |
Lines 204-602
Link Here
|
204 |
} |
166 |
} |
205 |
|
167 |
|
206 |
} |
168 |
} |
207 |
|
|
|
208 |
private static Children createRootChildren(final SuiteProject suite) { |
209 |
ImportantFilesChildren ch = new ImportantFilesChildren(suite); |
210 |
Node ifn = ModuleLogicalView.createImportantFilesNode(ch); |
211 |
|
212 |
Node[] nodes = new Node[] { new ModulesNode(suite), ifn, }; |
213 |
Children children = new Children.Array(); |
214 |
children.add(nodes); |
215 |
return children; |
216 |
} |
217 |
|
218 |
/** Represent <em>Modules</em> node in the Suite Logical View. */ |
219 |
static final class ModulesNode extends AbstractNode { |
220 |
|
221 |
private SuiteProject suite; |
222 |
|
223 |
ModulesNode(final SuiteProject suite) { |
224 |
super(new ModuleChildren(suite)); |
225 |
this.suite = suite; |
226 |
setName("modules"); // NOI18N |
227 |
setDisplayName(getMessage("CTL_Modules")); |
228 |
} |
229 |
|
230 |
public Action[] getActions(boolean context) { |
231 |
return new Action[] { |
232 |
new AddNewSuiteComponentAction(suite), |
233 |
new AddNewLibraryWrapperAction(suite), |
234 |
new AddSuiteComponentAction(suite), |
235 |
}; |
236 |
} |
237 |
|
238 |
private Image getIcon(boolean opened) { |
239 |
Image badge = Utilities.loadImage("org/netbeans/modules/apisupport/project/suite/resources/module-badge.gif", true); |
240 |
return Utilities.mergeImages(UIUtil.getTreeFolderIcon(opened), badge, 9, 9); |
241 |
} |
242 |
|
243 |
public Image getIcon(int type) { |
244 |
return getIcon(false); |
245 |
} |
246 |
|
247 |
public Image getOpenedIcon(int type) { |
248 |
return getIcon(true); |
249 |
} |
250 |
|
251 |
static final class ModuleChildren extends Children.Keys<NbModuleProject> implements ChangeListener { |
252 |
|
253 |
private final SuiteProject suite; |
254 |
|
255 |
public ModuleChildren(SuiteProject suite) { |
256 |
suite.getLookup().lookup(SubprojectProvider.class).addChangeListener(this); |
257 |
this.suite = suite; |
258 |
} |
259 |
|
260 |
protected void addNotify() { |
261 |
updateKeys(); |
262 |
} |
263 |
|
264 |
private void updateKeys() { |
265 |
// e.g.(?) Explorer view under Children.MUTEX subsequently calls e.g. |
266 |
// SuiteProject$Info.getSimpleName() which acquires ProjectManager.mutex(). And |
267 |
// since this method might be called under ProjectManager.mutex() write access |
268 |
// and updateKeys() --> setKeys() in turn calls Children.MUTEX write access, |
269 |
// deadlock is here, so preventing it... (also got this under read access) |
270 |
EventQueue.invokeLater(new Runnable() { |
271 |
public void run() { |
272 |
// #70112: sort them. |
273 |
SortedSet<NbModuleProject> subModules = new TreeSet(Util.projectDisplayNameComparator()); |
274 |
subModules.addAll(SuiteUtils.getSubProjects(suite)); |
275 |
setKeys(subModules); |
276 |
} |
277 |
}); |
278 |
} |
279 |
|
280 |
protected void removeNotify() { |
281 |
suite.getLookup().lookup(SubprojectProvider.class).removeChangeListener(this); |
282 |
setKeys(Collections.EMPTY_SET); |
283 |
} |
284 |
|
285 |
protected Node[] createNodes(NbModuleProject p) { |
286 |
return new Node[] {new SuiteComponentNode(p)}; |
287 |
} |
288 |
|
289 |
public void stateChanged(ChangeEvent ev) { |
290 |
updateKeys(); |
291 |
} |
292 |
|
293 |
} |
294 |
|
295 |
} |
296 |
|
297 |
private static final class AddSuiteComponentAction extends AbstractAction { |
298 |
|
299 |
private final SuiteProject suite; |
300 |
|
301 |
public AddSuiteComponentAction(final SuiteProject suite) { |
302 |
super(getMessage("CTL_AddModule")); |
303 |
this.suite = suite; |
304 |
} |
305 |
|
306 |
public void actionPerformed(ActionEvent evt) { |
307 |
NbModuleProject project = UIUtil.chooseSuiteComponent( |
308 |
WindowManager.getDefault().getMainWindow(), |
309 |
suite); |
310 |
if (project != null) { |
311 |
if (!SuiteUtils.contains(suite, project)) { |
312 |
try { |
313 |
SuiteUtils.addModule(suite, (NbModuleProject) project); |
314 |
ProjectManager.getDefault().saveProject(suite); |
315 |
} catch (IOException ex) { |
316 |
ErrorManager.getDefault().notify(ex); |
317 |
} |
318 |
} else { |
319 |
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( |
320 |
NbBundle.getMessage(SuiteLogicalView.class, "MSG_SuiteAlreadyContainsCNB", project.getCodeNameBase()))); |
321 |
} |
322 |
} |
323 |
} |
324 |
|
325 |
} |
326 |
|
327 |
private static final class AddNewSuiteComponentAction extends AbstractAction { |
328 |
|
329 |
private final SuiteProject suite; |
330 |
|
331 |
public AddNewSuiteComponentAction(final SuiteProject suite) { |
332 |
super(getMessage("CTL_AddNewModule")); |
333 |
this.suite = suite; |
334 |
} |
335 |
|
336 |
public void actionPerformed(ActionEvent evt) { |
337 |
NewNbModuleWizardIterator iterator = NewNbModuleWizardIterator.createSuiteComponentIterator(suite); |
338 |
UIUtil.runProjectWizard(iterator, "CTL_NewModuleProject"); // NOI18N |
339 |
} |
340 |
|
341 |
} |
342 |
|
343 |
static final class AddNewLibraryWrapperAction extends AbstractAction { |
344 |
|
345 |
private final Project suiteProvider; |
346 |
private final NbModuleProject target; |
347 |
|
348 |
public AddNewLibraryWrapperAction(final Project suiteProvider, final NbModuleProject target) { |
349 |
super(getMessage("CTL_AddNewLibrary")); |
350 |
this.suiteProvider = suiteProvider; |
351 |
this.target = target; |
352 |
} |
353 |
|
354 |
public AddNewLibraryWrapperAction(final Project suiteProvider) { |
355 |
this(suiteProvider, null); |
356 |
} |
357 |
|
358 |
public void actionPerformed(ActionEvent evt) { |
359 |
NbModuleProject project = UIUtil.runLibraryWrapperWizard(suiteProvider); |
360 |
if (project != null && target != null) { |
361 |
try { |
362 |
Util.addDependency(target, project); |
363 |
ProjectManager.getDefault().saveProject(target); |
364 |
} catch (IOException e) { |
365 |
assert false : e; |
366 |
} |
367 |
} |
368 |
} |
369 |
|
370 |
} |
371 |
|
372 |
/** Represent one module (a suite component) node. */ |
373 |
private static final class SuiteComponentNode extends AbstractNode { |
374 |
|
375 |
private final static Action REMOVE_ACTION = new RemoveSuiteComponentAction(); |
376 |
private final static Action OPEN_ACTION = new OpenProjectAction(); |
377 |
|
378 |
public SuiteComponentNode(final NbModuleProject suiteComponent) { |
379 |
super(Children.LEAF, Lookups.fixed(new Object[] {suiteComponent})); |
380 |
ProjectInformation info = ProjectUtils.getInformation(suiteComponent); |
381 |
setName(info.getName()); |
382 |
setDisplayName(info.getDisplayName()); |
383 |
setIconBaseWithExtension(NbModuleProject.NB_PROJECT_ICON_PATH); |
384 |
info.addPropertyChangeListener(new PropertyChangeListener() { |
385 |
public void propertyChange(PropertyChangeEvent evt) { |
386 |
if (evt.getPropertyName() == ProjectInformation.PROP_DISPLAY_NAME) { |
387 |
SuiteComponentNode.this.setDisplayName((String) evt.getNewValue()); |
388 |
} else if (evt.getPropertyName() == ProjectInformation.PROP_NAME) { |
389 |
SuiteComponentNode.this.setName((String) evt.getNewValue()); |
390 |
} |
391 |
} |
392 |
}); |
393 |
} |
394 |
|
395 |
public Action[] getActions(boolean context) { |
396 |
return new Action[] { |
397 |
OPEN_ACTION, REMOVE_ACTION |
398 |
}; |
399 |
} |
400 |
|
401 |
public Action getPreferredAction() { |
402 |
return OPEN_ACTION; |
403 |
} |
404 |
|
405 |
} |
406 |
|
407 |
private static final class RemoveSuiteComponentAction extends NodeAction { |
408 |
|
409 |
protected void performAction(Node[] activatedNodes) { |
410 |
for (int i = 0; i < activatedNodes.length; i++) { |
411 |
final NbModuleProject suiteComponent = |
412 |
(NbModuleProject) activatedNodes[i].getLookup().lookup(NbModuleProject.class); |
413 |
assert suiteComponent != null : "NbModuleProject in lookup"; // NOI18N |
414 |
try { |
415 |
NbModuleProject[] modules = SuiteUtils.getDependentModules(suiteComponent); |
416 |
boolean remove = true; |
417 |
if (modules.length > 0) { |
418 |
StringBuffer sb = new StringBuffer("<ul>"); // NOI18N |
419 |
for (int j = 0; j < modules.length; j++) { |
420 |
sb.append("<li>" + ProjectUtils.getInformation(modules[j]).getDisplayName() + "</li>"); // NOI18N |
421 |
} |
422 |
sb.append("</ul>"); // NOI18N |
423 |
String displayName = ProjectUtils.getInformation(suiteComponent).getDisplayName(); |
424 |
String confirmMessage = NbBundle.getMessage(SuiteLogicalView.class, |
425 |
"MSG_RemovingModuleMessage", displayName, sb.toString()); // NOI18N |
426 |
remove = UIUtil.showAcceptCancelDialog( |
427 |
NbBundle.getMessage(SuiteLogicalView.class, "CTL_RemovingModuleTitle", displayName), |
428 |
confirmMessage, getMessage("CTL_RemoveDependency"), null, NotifyDescriptor.QUESTION_MESSAGE); |
429 |
} |
430 |
if (remove) { |
431 |
SuiteUtils.removeModuleFromSuiteWithDependencies(suiteComponent); |
432 |
} |
433 |
} catch (IOException ex) { |
434 |
ErrorManager.getDefault().notify(ex); |
435 |
} |
436 |
} |
437 |
} |
438 |
|
439 |
protected boolean enable(Node[] activatedNodes) { |
440 |
return true; |
441 |
} |
442 |
|
443 |
public String getName() { |
444 |
return getMessage("CTL_RemoveModule"); |
445 |
} |
446 |
|
447 |
public HelpCtx getHelpCtx() { |
448 |
return HelpCtx.DEFAULT_HELP; |
449 |
} |
450 |
|
451 |
protected boolean asynchronous() { |
452 |
return false; |
453 |
} |
454 |
|
455 |
} |
456 |
|
457 |
private static final class OpenProjectAction extends CookieAction { |
458 |
|
459 |
protected void performAction(Node[] activatedNodes) { |
460 |
final Project[] projects = new Project[activatedNodes.length]; |
461 |
for (int i = 0; i < activatedNodes.length; i++) { |
462 |
Project project = (Project) activatedNodes[i].getLookup().lookup(Project.class); |
463 |
projects[i] = project; |
464 |
} |
465 |
RequestProcessor.getDefault().post(new Runnable() { |
466 |
public void run() { |
467 |
StatusDisplayer.getDefault().setStatusText(getMessage("MSG_OpeningProjects")); |
468 |
OpenProjects.getDefault().open(projects, false); |
469 |
} |
470 |
}); |
471 |
} |
472 |
|
473 |
public String getName() { |
474 |
return getMessage("CTL_OpenProject"); |
475 |
} |
476 |
|
477 |
public HelpCtx getHelpCtx() { |
478 |
return HelpCtx.DEFAULT_HELP; |
479 |
} |
480 |
|
481 |
protected boolean asynchronous() { |
482 |
return false; |
483 |
} |
484 |
|
485 |
protected int mode() { |
486 |
return CookieAction.MODE_ALL; |
487 |
} |
488 |
|
489 |
protected Class[] cookieClasses() { |
490 |
return new Class[] { Project.class }; |
491 |
} |
492 |
|
493 |
} |
494 |
|
495 |
/** |
496 |
* Actual list of important files. |
497 |
*/ |
498 |
private static final class ImportantFilesChildren extends Children.Keys<String> { |
499 |
|
500 |
private List<String> visibleFiles = new ArrayList(); |
501 |
private FileChangeListener fcl; |
502 |
|
503 |
/** Abstract location to display name. */ |
504 |
private static final java.util.Map<String,String> FILES = new LinkedHashMap(); |
505 |
static { |
506 |
FILES.put("master.jnlp", getMessage("LBL_jnlp_master")); |
507 |
FILES.put("build.xml", getMessage("LBL_build.xml")); |
508 |
FILES.put("nbproject/project.properties", getMessage("LBL_project.properties")); |
509 |
FILES.put("nbproject/private/private.properties", getMessage("LBL_private.properties")); |
510 |
FILES.put("nbproject/platform.properties", getMessage("LBL_platform.properties")); |
511 |
FILES.put("nbproject/private/platform-private.properties", getMessage("LBL_platform-private.properties")); |
512 |
} |
513 |
|
514 |
private final SuiteProject project; |
515 |
|
516 |
public ImportantFilesChildren(SuiteProject project) { |
517 |
this.project = project; |
518 |
} |
519 |
|
520 |
protected void addNotify() { |
521 |
super.addNotify(); |
522 |
attachListeners(); |
523 |
refreshKeys(); |
524 |
} |
525 |
|
526 |
protected void removeNotify() { |
527 |
setKeys(Collections.EMPTY_SET); |
528 |
removeListeners(); |
529 |
super.removeNotify(); |
530 |
} |
531 |
|
532 |
protected Node[] createNodes(String loc) { |
533 |
String locEval = project.getEvaluator().evaluate(loc); |
534 |
FileObject file = project.getHelper().resolveFileObject(locEval); |
535 |
|
536 |
try { |
537 |
Node orig = DataObject.find(file).getNodeDelegate(); |
538 |
return new Node[] {new ModuleLogicalView.SpecialFileNode(orig, (String) FILES.get(loc))}; |
539 |
} catch (DataObjectNotFoundException e) { |
540 |
throw new AssertionError(e); |
541 |
} |
542 |
} |
543 |
|
544 |
private void refreshKeys() { |
545 |
List<String> newVisibleFiles = new ArrayList(); |
546 |
Iterator it = FILES.keySet().iterator(); |
547 |
Set files = new HashSet(); |
548 |
while (it.hasNext()) { |
549 |
String loc = (String) it.next(); |
550 |
String locEval = project.getEvaluator().evaluate(loc); |
551 |
if (locEval == null) { |
552 |
continue; |
553 |
} |
554 |
FileObject file = project.getHelper().resolveFileObject(locEval); |
555 |
if (file != null) { |
556 |
newVisibleFiles.add(loc); |
557 |
files.add(file); |
558 |
} |
559 |
} |
560 |
if (!isInitialized() || !newVisibleFiles.equals(visibleFiles)) { |
561 |
visibleFiles = newVisibleFiles; |
562 |
RequestProcessor.getDefault().post(new Runnable() { // #72471 |
563 |
public void run() { |
564 |
setKeys(visibleFiles); |
565 |
} |
566 |
}); |
567 |
((ModuleLogicalView.ImportantFilesNode) getNode()).setFiles(files); // #72439 |
568 |
} |
569 |
} |
570 |
|
571 |
private void attachListeners() { |
572 |
try { |
573 |
if (fcl == null) { |
574 |
fcl = new FileChangeAdapter() { |
575 |
public void fileDataCreated(FileEvent fe) { |
576 |
refreshKeys(); |
577 |
} |
578 |
public void fileDeleted(FileEvent fe) { |
579 |
refreshKeys(); |
580 |
} |
581 |
}; |
582 |
project.getProjectDirectory().getFileSystem().addFileChangeListener(fcl); |
583 |
} |
584 |
} catch (FileStateInvalidException e) { |
585 |
assert false : e; |
586 |
} |
587 |
} |
588 |
|
589 |
private void removeListeners() { |
590 |
if (fcl != null) { |
591 |
try { |
592 |
project.getProjectDirectory().getFileSystem().removeFileChangeListener(fcl); |
593 |
} catch (FileStateInvalidException e) { |
594 |
assert false : e; |
595 |
} |
596 |
fcl = null; |
597 |
} |
598 |
} |
599 |
|
600 |
} |
601 |
|
602 |
} |
169 |
} |