Lines 7-26
Link Here
|
7 |
* http://www.sun.com/ |
7 |
* http://www.sun.com/ |
8 |
* |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
12 |
*/ |
13 |
|
13 |
|
14 |
package org.netbeans.modules.apisupport.project.ui.customizer; |
14 |
package org.netbeans.modules.apisupport.project.ui.customizer; |
15 |
|
15 |
|
|
|
16 |
import java.awt.EventQueue; |
16 |
import java.beans.PropertyChangeEvent; |
17 |
import java.beans.PropertyChangeEvent; |
17 |
import java.beans.PropertyChangeListener; |
18 |
import java.beans.PropertyChangeListener; |
18 |
import java.beans.PropertyEditor; |
19 |
import java.beans.PropertyEditor; |
|
|
20 |
import java.io.IOException; |
19 |
import java.lang.reflect.InvocationTargetException; |
21 |
import java.lang.reflect.InvocationTargetException; |
20 |
import java.util.Arrays; |
22 |
import java.util.Arrays; |
21 |
import java.util.Comparator; |
23 |
import java.util.Comparator; |
22 |
import java.util.HashMap; |
24 |
import java.util.HashMap; |
23 |
import java.util.HashSet; |
25 |
import java.util.HashSet; |
|
|
26 |
import java.util.Iterator; |
27 |
import java.util.LinkedHashSet; |
24 |
import java.util.Set; |
28 |
import java.util.Set; |
25 |
import java.util.TreeSet; |
29 |
import java.util.TreeSet; |
26 |
import javax.swing.JButton; |
30 |
import javax.swing.JButton; |
Lines 28-34
Link Here
|
28 |
import javax.swing.event.ChangeListener; |
32 |
import javax.swing.event.ChangeListener; |
29 |
import org.netbeans.api.java.platform.JavaPlatform; |
33 |
import org.netbeans.api.java.platform.JavaPlatform; |
30 |
import org.netbeans.api.java.platform.PlatformsCustomizer; |
34 |
import org.netbeans.api.java.platform.PlatformsCustomizer; |
|
|
35 |
import org.netbeans.api.project.ProjectUtils; |
36 |
import org.netbeans.modules.apisupport.project.ManifestManager; |
31 |
import org.netbeans.modules.apisupport.project.NbModuleProject; |
37 |
import org.netbeans.modules.apisupport.project.NbModuleProject; |
|
|
38 |
import org.netbeans.modules.apisupport.project.NbModuleProjectType; |
39 |
import org.netbeans.modules.apisupport.project.Util; |
32 |
import org.netbeans.modules.apisupport.project.suite.SuiteProject; |
40 |
import org.netbeans.modules.apisupport.project.suite.SuiteProject; |
33 |
import org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory; |
41 |
import org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory; |
34 |
import org.netbeans.modules.apisupport.project.ui.platform.NbPlatformCustomizer; |
42 |
import org.netbeans.modules.apisupport.project.ui.platform.NbPlatformCustomizer; |
Lines 36-49
Link Here
|
36 |
import org.netbeans.modules.apisupport.project.universe.NbPlatform; |
44 |
import org.netbeans.modules.apisupport.project.universe.NbPlatform; |
37 |
import org.openide.DialogDescriptor; |
45 |
import org.openide.DialogDescriptor; |
38 |
import org.openide.DialogDisplayer; |
46 |
import org.openide.DialogDisplayer; |
|
|
47 |
import org.openide.ErrorManager; |
39 |
import org.openide.NotifyDescriptor; |
48 |
import org.openide.NotifyDescriptor; |
40 |
import org.openide.explorer.ExplorerManager; |
49 |
import org.openide.explorer.ExplorerManager; |
|
|
50 |
import org.openide.modules.Dependency; |
51 |
import org.openide.modules.SpecificationVersion; |
41 |
import org.openide.nodes.AbstractNode; |
52 |
import org.openide.nodes.AbstractNode; |
42 |
import org.openide.nodes.Children; |
53 |
import org.openide.nodes.Children; |
43 |
import org.openide.nodes.Node; |
54 |
import org.openide.nodes.Node; |
44 |
import org.openide.nodes.PropertySupport; |
55 |
import org.openide.nodes.PropertySupport; |
45 |
import org.openide.nodes.Sheet; |
56 |
import org.openide.nodes.Sheet; |
46 |
import org.openide.util.NbBundle; |
57 |
import org.openide.util.NbBundle; |
|
|
58 |
import org.openide.util.RequestProcessor; |
59 |
import org.w3c.dom.Element; |
47 |
|
60 |
|
48 |
/** |
61 |
/** |
49 |
* Represents <em>Libraries</em> panel in Suite customizer. |
62 |
* Represents <em>Libraries</em> panel in Suite customizer. |
Lines 53-58
Link Here
|
53 |
final class SuiteCustomizerLibraries extends NbPropertyPanel.Suite |
66 |
final class SuiteCustomizerLibraries extends NbPropertyPanel.Suite |
54 |
implements Comparator, ExplorerManager.Provider, ChangeListener { |
67 |
implements Comparator, ExplorerManager.Provider, ChangeListener { |
55 |
private ExplorerManager manager; |
68 |
private ExplorerManager manager; |
|
|
69 |
private ModuleEntry[] platformModules; |
56 |
|
70 |
|
57 |
/** |
71 |
/** |
58 |
* Creates new form SuiteCustomizerLibraries |
72 |
* Creates new form SuiteCustomizerLibraries |
Lines 88-96
Link Here
|
88 |
} |
102 |
} |
89 |
|
103 |
|
90 |
private void refreshModules() { |
104 |
private void refreshModules() { |
91 |
ModuleEntry[] entry = getProperties().getActivePlatform().getModules(); |
105 |
platformModules = getProperties().getActivePlatform().getModules(); |
92 |
Node root = createModuleNode(entry); |
106 |
Node root = createPlatformModulesNode(); |
93 |
manager.setRootContext(root); |
107 |
manager.setRootContext(root); |
|
|
108 |
universe = null; |
109 |
updateDependencyWarnings(); |
94 |
} |
110 |
} |
95 |
|
111 |
|
96 |
private void refreshJavaPlatforms() { |
112 |
private void refreshJavaPlatforms() { |
Lines 301-307
Link Here
|
301 |
// End of variables declaration//GEN-END:variables |
317 |
// End of variables declaration//GEN-END:variables |
302 |
|
318 |
|
303 |
|
319 |
|
304 |
private Node createModuleNode(ModuleEntry[] entries) { |
320 |
private Node createPlatformModulesNode() { |
305 |
HashSet disabledModuleCNB = new HashSet(Arrays.asList(getProperties().getDisabledModules())); |
321 |
HashSet disabledModuleCNB = new HashSet(Arrays.asList(getProperties().getDisabledModules())); |
306 |
HashSet disabledClusters = new HashSet(Arrays.asList(getProperties().getDisabledClusters())); |
322 |
HashSet disabledClusters = new HashSet(Arrays.asList(getProperties().getDisabledClusters())); |
307 |
|
323 |
|
Lines 313-338
Link Here
|
313 |
n.setName(getMessage("LBL_ModuleListClusters")); |
329 |
n.setName(getMessage("LBL_ModuleListClusters")); |
314 |
n.setDisplayName(getMessage("LBL_ModuleListClustersModules")); |
330 |
n.setDisplayName(getMessage("LBL_ModuleListClustersModules")); |
315 |
|
331 |
|
316 |
for (int i = 0; i < entries.length; i++) { |
332 |
for (int i = 0; i < platformModules.length; i++) { |
317 |
Children clusterChildren = (Children)clusterToChildren.get(entries[i].getClusterDirectory()); |
333 |
Children clusterChildren = (Children)clusterToChildren.get(platformModules[i].getClusterDirectory()); |
318 |
if (clusterChildren == null) { |
334 |
if (clusterChildren == null) { |
319 |
Children.SortedArray modules = new Children.SortedArray(); |
335 |
Children.SortedArray modules = new Children.SortedArray(); |
320 |
modules.setComparator(this); |
336 |
modules.setComparator(this); |
321 |
clusterChildren = modules; |
337 |
clusterChildren = modules; |
322 |
|
338 |
|
323 |
String clusterName = entries[i].getClusterDirectory().getName(); |
339 |
String clusterName = platformModules[i].getClusterDirectory().getName(); |
324 |
Enabled cluster = new Enabled(modules, !disabledClusters.contains(clusterName)); |
340 |
Enabled cluster = new Enabled(modules, !disabledClusters.contains(clusterName)); |
325 |
cluster.setName(clusterName); |
341 |
cluster.setName(clusterName); |
326 |
cluster.setIconBaseWithExtension(SuiteProject.SUITE_ICON_PATH); |
342 |
cluster.setIconBaseWithExtension(SuiteProject.SUITE_ICON_PATH); |
327 |
clusterToChildren.put(entries[i].getClusterDirectory(), modules); |
343 |
clusterToChildren.put(platformModules[i].getClusterDirectory(), modules); |
328 |
n.getChildren().add(new Node[] { cluster }); |
344 |
n.getChildren().add(new Node[] { cluster }); |
329 |
} |
345 |
} |
330 |
|
346 |
|
331 |
String cnb = entries[i].getCodeNameBase(); |
347 |
String cnb = platformModules[i].getCodeNameBase(); |
332 |
AbstractNode module = new Enabled(Children.LEAF, !disabledModuleCNB.contains(cnb)); |
348 |
AbstractNode module = new Enabled(Children.LEAF, !disabledModuleCNB.contains(cnb)); |
333 |
module.setName(cnb); |
349 |
module.setName(cnb); |
334 |
module.setDisplayName(entries[i].getLocalizedName()); |
350 |
module.setDisplayName(platformModules[i].getLocalizedName()); |
335 |
String desc = entries[i].getShortDescription(); |
351 |
String desc = platformModules[i].getShortDescription(); |
336 |
String tooltip; |
352 |
String tooltip; |
337 |
if (desc != null) { |
353 |
if (desc != null) { |
338 |
if (desc.startsWith("<html>")) { // NOI18N |
354 |
if (desc.startsWith("<html>")) { // NOI18N |
Lines 447-453
Link Here
|
447 |
} |
463 |
} |
448 |
} |
464 |
} |
449 |
|
465 |
|
450 |
static final class Enabled extends AbstractNode { |
466 |
final class Enabled extends AbstractNode { |
451 |
private boolean enabled; |
467 |
private boolean enabled; |
452 |
private Children standard; |
468 |
private Children standard; |
453 |
|
469 |
|
Lines 482-487
Link Here
|
482 |
Enabled en = (Enabled)n; |
498 |
Enabled en = (Enabled)n; |
483 |
en.firePropertyChange(null, null, null); |
499 |
en.firePropertyChange(null, null, null); |
484 |
} |
500 |
} |
|
|
501 |
updateDependencyWarnings(); |
485 |
} |
502 |
} |
486 |
|
503 |
|
487 |
public boolean isEnabled() { |
504 |
public boolean isEnabled() { |
Lines 555-560
Link Here
|
555 |
private void initAccessibility() { |
572 |
private void initAccessibility() { |
556 |
managePlafsButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_ManagePlafsButton")); |
573 |
managePlafsButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_ManagePlafsButton")); |
557 |
platformValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_PlatformValue")); |
574 |
platformValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_PlatformValue")); |
|
|
575 |
} |
576 |
|
577 |
// #65924: show warnings if some dependencies cannot be satisfied |
578 |
|
579 |
interface UniverseModule { |
580 |
String getCodeNameBase(); |
581 |
int getReleaseVersion(); |
582 |
SpecificationVersion getSpecificationVersion(); |
583 |
String getImplementationVersion(); |
584 |
Set/*<String>*/ getProvidedTokens(); |
585 |
Set/*<String>*/ getRequiredTokens(); |
586 |
Set/*<Dependency>*/ getModuleDependencies(); |
587 |
String getCluster(); |
588 |
String getDisplayName(); |
589 |
} |
590 |
|
591 |
private static abstract class AbstractUniverseModule implements UniverseModule { |
592 |
protected final ManifestManager mm; |
593 |
protected AbstractUniverseModule(ManifestManager mm) { |
594 |
this.mm = mm; |
595 |
} |
596 |
public int getReleaseVersion() { |
597 |
String s = mm.getReleaseVersion(); |
598 |
return s != null ? Integer.parseInt(s) : -1; |
599 |
} |
600 |
public String getImplementationVersion() { |
601 |
return mm.getImplementationVersion(); |
602 |
} |
603 |
public Set/*<String>*/ getProvidedTokens() { |
604 |
return new HashSet(Arrays.asList(mm.getProvidedTokens())); |
605 |
} |
606 |
public Set/*<String>*/ getRequiredTokens() { |
607 |
return new HashSet(Arrays.asList(mm.getRequiredTokens())); |
608 |
} |
609 |
} |
610 |
|
611 |
private static final class PlatformModule extends AbstractUniverseModule { |
612 |
private final ModuleEntry entry; |
613 |
public PlatformModule(ModuleEntry entry) throws IOException { |
614 |
super(ManifestManager.getInstanceFromJAR(entry.getJarLocation())); |
615 |
this.entry = entry; |
616 |
} |
617 |
public String getCodeNameBase() { |
618 |
return entry.getCodeNameBase(); |
619 |
} |
620 |
public SpecificationVersion getSpecificationVersion() { |
621 |
String s = entry.getSpecificationVersion(); |
622 |
return s != null ? new SpecificationVersion(s) : null; |
623 |
} |
624 |
public Set/*<Dependency>*/ getModuleDependencies() { |
625 |
return mm.getModuleDependencies(); |
626 |
} |
627 |
public String getCluster() { |
628 |
return entry.getClusterDirectory().getName(); |
629 |
} |
630 |
public String getDisplayName() { |
631 |
return entry.getLocalizedName(); |
632 |
} |
633 |
} |
634 |
|
635 |
private static final class SuiteModule extends AbstractUniverseModule { |
636 |
private final NbModuleProject project; |
637 |
private final Set/*<Dependency>*/ dependencies; |
638 |
public SuiteModule(NbModuleProject project) { |
639 |
super(ManifestManager.getInstance(project.getManifest(), false)); |
640 |
this.project = project; |
641 |
dependencies = new HashSet(); |
642 |
// Cannot use ProjectXMLManager since we need to report also deps on nonexistent modules. |
643 |
Element dataE = project.getHelper().getPrimaryConfigurationData(true); |
644 |
Element depsE = Util.findElement(dataE, "module-dependencies", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N |
645 |
Iterator/*<Element>*/ deps = Util.findSubElements(depsE).iterator(); |
646 |
while (deps.hasNext()) { |
647 |
Element dep = (Element) deps.next(); |
648 |
Element run = Util.findElement(dep, "run-dependency", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N |
649 |
if (run == null) { |
650 |
continue; |
651 |
} |
652 |
String text = Util.findText(Util.findElement(dep, "code-name-base", NbModuleProjectType.NAMESPACE_SHARED)); // NOI18N |
653 |
Element relverE = Util.findElement(run, "release-version", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N |
654 |
if (relverE != null) { |
655 |
text += '/' + Util.findText(relverE); |
656 |
} |
657 |
Element specverE = Util.findElement(run, "specification-version", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N |
658 |
if (specverE != null) { |
659 |
text += '>' + Util.findText(specverE); |
660 |
} else { |
661 |
Element implver = Util.findElement(run, "implementation-version", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N |
662 |
if (implver != null) { |
663 |
// Will special-case '*' as an impl version to mean "match anything". |
664 |
text += "=*"; // NOI18N |
665 |
} |
666 |
} |
667 |
dependencies.addAll(Dependency.create(Dependency.TYPE_MODULE, text)); |
668 |
} |
669 |
} |
670 |
public String getCodeNameBase() { |
671 |
return project.getCodeNameBase(); |
672 |
} |
673 |
public SpecificationVersion getSpecificationVersion() { |
674 |
String s = project.getSpecVersion(); |
675 |
return s != null ? new SpecificationVersion(s) : null; |
676 |
} |
677 |
public Set/*<Dependency>*/ getModuleDependencies() { |
678 |
return dependencies; |
679 |
} |
680 |
public String getCluster() { |
681 |
return null; |
682 |
} |
683 |
public String getDisplayName() { |
684 |
return ProjectUtils.getInformation(project).getDisplayName(); |
685 |
} |
686 |
} |
687 |
|
688 |
private RequestProcessor.Task updateDependencyWarningsTask; |
689 |
private void updateDependencyWarnings() { |
690 |
if (updateDependencyWarningsTask == null) { |
691 |
updateDependencyWarningsTask = RequestProcessor.getDefault().create(new Runnable() { |
692 |
public void run() { |
693 |
doUpdateDependencyWarnings(); |
694 |
} |
695 |
}); |
696 |
} |
697 |
updateDependencyWarningsTask.schedule(0); |
698 |
} |
699 |
|
700 |
static Set/*<UniverseModule>*/ loadUniverseModules(ModuleEntry[] platformModules, Set/*<NbModuleProject>*/ suiteModules) throws IOException { |
701 |
Set universe = new LinkedHashSet(); |
702 |
Iterator/*<Project>*/ it = suiteModules.iterator(); |
703 |
while (it.hasNext()) { |
704 |
universe.add(new SuiteModule((NbModuleProject) it.next())); |
705 |
} |
706 |
for (int i = 0; i < platformModules.length; i++) { |
707 |
universe.add(new PlatformModule(platformModules[i])); |
708 |
} |
709 |
return universe; |
710 |
} |
711 |
|
712 |
static String[] findWarning(Set/*<UniverseModule>*/ universeModules, Set/*<String>*/ disabledClusters, Set/*<String>*/ disabledModules) { |
713 |
// XXX |
714 |
return null; |
715 |
} |
716 |
|
717 |
private Set/*<UniverseModule>*/ universe; |
718 |
private void doUpdateDependencyWarnings() { |
719 |
// XXX consider using a PorgressHandle |
720 |
if (universe == null) { |
721 |
try { |
722 |
universe = loadUniverseModules(platformModules, getProperties().getSubModules()); |
723 |
} catch (IOException e) { |
724 |
Util.err.notify(ErrorManager.INFORMATIONAL, e); |
725 |
return; // any warnings would probably be wrong anyway |
726 |
} |
727 |
} |
728 |
|
729 |
Set disabledClusters = new TreeSet(); |
730 |
Set disabledModules = new TreeSet(); |
731 |
|
732 |
Node[] clusters = getExplorerManager().getRootContext().getChildren().getNodes(); |
733 |
for (int i = 0; i < clusters.length; i++) { |
734 |
if (clusters[i] instanceof Enabled) { |
735 |
Enabled e = (Enabled) clusters[i]; |
736 |
if (!e.isEnabled()) { |
737 |
disabledClusters.add(e.getName()); |
738 |
} else { |
739 |
Node[] modules = e.getChildren().getNodes(); |
740 |
for (int j = 0; j < modules.length; j++) { |
741 |
if (modules[j] instanceof Enabled) { |
742 |
Enabled m = (Enabled) modules[j]; |
743 |
if (!m.isEnabled()) { |
744 |
disabledModules.add(m.getName()); |
745 |
} |
746 |
} |
747 |
} |
748 |
} |
749 |
} |
750 |
} |
751 |
|
752 |
final String[] warning = findWarning(universe, disabledClusters, disabledModules); |
753 |
|
754 |
EventQueue.invokeLater(new Runnable() { |
755 |
public void run() { |
756 |
if (warning != null) { |
757 |
String key = warning[0]; |
758 |
String[] args = new String[warning.length - 1]; |
759 |
System.arraycopy(warning, 1, args, 0, args.length); |
760 |
setWarning(NbBundle.getMessage(SuiteCustomizerLibraries.class, key, args)); |
761 |
} else { |
762 |
setWarning(null); |
763 |
} |
764 |
} |
765 |
}); |
766 |
|
558 |
} |
767 |
} |
559 |
|
768 |
|
560 |
} |
769 |
} |