KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > customizer > SuiteCustomizerLibraries


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.apisupport.project.ui.customizer;
21
22 import java.awt.EventQueue JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.beans.PropertyEditor JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.lang.reflect.InvocationTargetException JavaDoc;
28 import java.text.Collator JavaDoc;
29 import java.util.Arrays JavaDoc;
30 import java.util.Comparator JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.HashSet JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.LinkedHashSet JavaDoc;
35 import java.util.Map JavaDoc;
36 import java.util.Set JavaDoc;
37 import java.util.SortedMap JavaDoc;
38 import java.util.SortedSet JavaDoc;
39 import java.util.TreeMap JavaDoc;
40 import java.util.TreeSet JavaDoc;
41 import javax.swing.event.ChangeEvent JavaDoc;
42 import javax.swing.event.ChangeListener JavaDoc;
43 import org.netbeans.api.java.platform.JavaPlatform;
44 import org.netbeans.api.java.platform.PlatformsCustomizer;
45 import org.netbeans.api.project.ProjectUtils;
46 import org.netbeans.modules.apisupport.project.ManifestManager;
47 import org.netbeans.modules.apisupport.project.NbModuleProject;
48 import org.netbeans.modules.apisupport.project.NbModuleProjectType;
49 import org.netbeans.modules.apisupport.project.Util;
50 import org.netbeans.modules.apisupport.project.suite.SuiteProject;
51 import org.netbeans.modules.apisupport.project.ui.UIUtil;
52 import org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory;
53 import org.netbeans.modules.apisupport.project.ui.platform.NbPlatformCustomizer;
54 import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
55 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
56 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
57 import org.openide.ErrorManager;
58 import org.openide.NotifyDescriptor;
59 import org.openide.explorer.ExplorerManager;
60 import org.openide.modules.Dependency;
61 import org.openide.modules.SpecificationVersion;
62 import org.openide.nodes.AbstractNode;
63 import org.openide.nodes.Children;
64 import org.openide.nodes.Node;
65 import org.openide.nodes.PropertySupport;
66 import org.openide.nodes.Sheet;
67 import org.openide.util.NbBundle;
68 import org.openide.util.RequestProcessor;
69 import org.w3c.dom.Element JavaDoc;
70
71 /**
72  * Represents <em>Libraries</em> panel in Suite customizer.
73  *
74  * @author Martin Krauskopf
75  */

76 final class SuiteCustomizerLibraries extends NbPropertyPanel.Suite
77         implements Comparator JavaDoc, ExplorerManager.Provider, ChangeListener JavaDoc {
78     private ExplorerManager manager;
79     private ModuleEntry[] platformModules;
80     private ProjectCustomizer.Category cat;
81     
82     /**
83      * Creates new form SuiteCustomizerLibraries
84      */

85     public SuiteCustomizerLibraries(final SuiteProperties suiteProps, ProjectCustomizer.Category cat) {
86         super(suiteProps, SuiteCustomizerLibraries.class);
87         initComponents();
88         this.cat = cat;
89         initAccessibility();
90         manager = new ExplorerManager();
91         refresh();
92         
93         
94         view.setProperties(new Node.Property[] { ENABLED_PROP_TEMPLATE });
95         view.setRootVisible(false);
96         view.setDefaultActionAllowed(false);
97         
98         suiteProps.getBrandingModel().addChangeListener(this);
99         suiteProps.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
100             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
101                 if (SuiteProperties.NB_PLATFORM_PROPERTY.equals(evt.getPropertyName())) {
102                     refresh();
103                 }
104             }
105         });
106         
107         javaPlatformCombo.setRenderer(JavaPlatformComponentFactory.javaPlatformListCellRenderer());
108     }
109     
110     void refresh() {
111         refreshJavaPlatforms();
112         refreshPlatforms();
113         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
114             public void run() {
115                 refreshModules();
116             }
117         });
118         updateJavaPlatformEnabled();
119     }
120     
121     private void refreshModules() {
122         platformModules = getProperties().getActivePlatform().getModules();
123         Node root = createPlatformModulesNode();
124         manager.setRootContext(root);
125         synchronized (this) {
126             universe = null;
127         }
128         updateDependencyWarnings();
129     }
130     
131     private void refreshJavaPlatforms() {
132         javaPlatformCombo.setModel(JavaPlatformComponentFactory.javaPlatformListModel());
133         javaPlatformCombo.setSelectedItem(getProperties().getActiveJavaPlatform());
134     }
135     
136     private void refreshPlatforms() {
137         platformValue.setModel(new PlatformComponentFactory.NbPlatformListModel()); // refresh
138
platformValue.setSelectedItem(getProperties().getActivePlatform());
139         platformValue.requestFocus();
140     }
141     
142     public void store() {
143         Set JavaDoc enabledClusters = new TreeSet JavaDoc();
144         Set JavaDoc disabledModules = new TreeSet JavaDoc();
145         
146         Node[] clusters = getExplorerManager().getRootContext().getChildren().getNodes();
147         for (int i = 0; i < clusters.length; i++) {
148             if (clusters[i] instanceof Enabled) {
149                 Enabled e = (Enabled)clusters[i];
150                 if (e.isEnabled()) {
151                     enabledClusters.add(e.getName());
152                     Node[] modules = e.getChildren().getNodes();
153                     for (int j = 0; j < modules.length; j++) {
154                         if (modules[j] instanceof Enabled) {
155                             Enabled m = (Enabled)modules[j];
156                             if (!m.isEnabled()) {
157                                 disabledModules.add(m.getName());
158                             }
159                         }
160                     }
161                 }
162             }
163         }
164         
165         getProperties().setEnabledClusters((String JavaDoc[]) enabledClusters.toArray(new String JavaDoc[enabledClusters.size()]));
166         getProperties().setDisabledModules((String JavaDoc[]) disabledModules.toArray(new String JavaDoc[disabledModules.size()]));
167     }
168     
169     /** This method is called from within the constructor to
170      * initialize the form.
171      * WARNING: Do NOT modify this code. The content of this method is
172      * always regenerated by the Form Editor.
173      */

174     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
175
private void initComponents() {
176         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
177
178         platformsPanel = new javax.swing.JPanel JavaDoc();
179         platformValue = org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory.getNbPlatformsComboxBox();
180         platform = new javax.swing.JLabel JavaDoc();
181         managePlafsButton = new javax.swing.JButton JavaDoc();
182         javaPlatformLabel = new javax.swing.JLabel JavaDoc();
183         javaPlatformCombo = new javax.swing.JComboBox JavaDoc();
184         javaPlatformButton = new javax.swing.JButton JavaDoc();
185         filler = new javax.swing.JLabel JavaDoc();
186         view = new org.openide.explorer.view.TreeTableView();
187         viewLabel = new javax.swing.JLabel JavaDoc();
188
189         setLayout(new java.awt.GridBagLayout JavaDoc());
190
191         platformsPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
192
193         platformValue.addItemListener(new java.awt.event.ItemListener JavaDoc() {
194             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
195                 platformValueItemStateChanged(evt);
196             }
197         });
198
199         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
200         gridBagConstraints.gridx = 1;
201         gridBagConstraints.gridy = 1;
202         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
203         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
204         gridBagConstraints.weightx = 1.0;
205         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 12);
206         platformsPanel.add(platformValue, gridBagConstraints);
207
208         platform.setLabelFor(platformValue);
209         org.openide.awt.Mnemonics.setLocalizedText(platform, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_NetBeansPlatform"));
210         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
211         gridBagConstraints.gridx = 0;
212         gridBagConstraints.gridy = 1;
213         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
214         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 12);
215         platformsPanel.add(platform, gridBagConstraints);
216
217         org.openide.awt.Mnemonics.setLocalizedText(managePlafsButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "CTL_ManagePlatform_a"));
218         managePlafsButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
219             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
220                 managePlatforms(evt);
221             }
222         });
223
224         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
225         gridBagConstraints.gridx = 2;
226         gridBagConstraints.gridy = 1;
227         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
228         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
229         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
230         platformsPanel.add(managePlafsButton, gridBagConstraints);
231
232         javaPlatformLabel.setLabelFor(javaPlatformCombo);
233         org.openide.awt.Mnemonics.setLocalizedText(javaPlatformLabel, NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_Java_Platform"));
234         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
235         gridBagConstraints.gridx = 0;
236         gridBagConstraints.gridy = 0;
237         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
238         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
239         platformsPanel.add(javaPlatformLabel, gridBagConstraints);
240
241         javaPlatformCombo.addItemListener(new java.awt.event.ItemListener JavaDoc() {
242             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
243                 javaPlatformComboItemStateChanged(evt);
244             }
245         });
246
247         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
248         gridBagConstraints.gridx = 1;
249         gridBagConstraints.gridy = 0;
250         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
251         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
252         gridBagConstraints.weightx = 1.0;
253         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
254         platformsPanel.add(javaPlatformCombo, gridBagConstraints);
255
256         org.openide.awt.Mnemonics.setLocalizedText(javaPlatformButton, NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_Manage_Java_Platforms"));
257         javaPlatformButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
258             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
259                 javaPlatformButtonActionPerformed(evt);
260             }
261         });
262
263         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
264         gridBagConstraints.gridx = 2;
265         gridBagConstraints.gridy = 0;
266         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
267         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
268         platformsPanel.add(javaPlatformButton, gridBagConstraints);
269
270         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
271         gridBagConstraints.gridx = 0;
272         gridBagConstraints.gridy = 0;
273         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
274         gridBagConstraints.weightx = 1.0;
275         add(platformsPanel, gridBagConstraints);
276
277         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
278         gridBagConstraints.gridx = 0;
279         gridBagConstraints.gridy = 1;
280         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
281         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
282         gridBagConstraints.weighty = 1.0;
283         add(filler, gridBagConstraints);
284
285         view.setBorder(javax.swing.UIManager.getBorder("ScrollPane.border"));
286         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
287         gridBagConstraints.gridx = 0;
288         gridBagConstraints.gridy = 2;
289         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
290         gridBagConstraints.weightx = 1.0;
291         gridBagConstraints.weighty = 1.0;
292         add(view, gridBagConstraints);
293
294         viewLabel.setLabelFor(view);
295         org.openide.awt.Mnemonics.setLocalizedText(viewLabel, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_PlatformModules"));
296         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
297         gridBagConstraints.gridx = 0;
298         gridBagConstraints.gridy = 1;
299         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
300         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 2, 0);
301         add(viewLabel, gridBagConstraints);
302
303     }// </editor-fold>//GEN-END:initComponents
304

305     private void javaPlatformButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_javaPlatformButtonActionPerformed
306
PlatformsCustomizer.showCustomizer((JavaPlatform) javaPlatformCombo.getSelectedItem());
307     }//GEN-LAST:event_javaPlatformButtonActionPerformed
308

309     private void javaPlatformComboItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_javaPlatformComboItemStateChanged
310
getProperties().setActiveJavaPlatform((JavaPlatform) javaPlatformCombo.getSelectedItem());
311     }//GEN-LAST:event_javaPlatformComboItemStateChanged
312

313     private void platformValueItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_platformValueItemStateChanged
314
getProperties().setActivePlatform((NbPlatform) platformValue.getSelectedItem());
315         refreshModules();
316         updateJavaPlatformEnabled();
317     }//GEN-LAST:event_platformValueItemStateChanged
318

319     private void managePlatforms(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_managePlatforms
320
NbPlatformCustomizer.showCustomizer();
321         refreshPlatforms();
322     }//GEN-LAST:event_managePlatforms
323

324     // Variables declaration - do not modify//GEN-BEGIN:variables
325
private javax.swing.JLabel JavaDoc filler;
326     private javax.swing.JButton JavaDoc javaPlatformButton;
327     private javax.swing.JComboBox JavaDoc javaPlatformCombo;
328     private javax.swing.JLabel JavaDoc javaPlatformLabel;
329     private javax.swing.JButton JavaDoc managePlafsButton;
330     private javax.swing.JLabel JavaDoc platform;
331     private javax.swing.JComboBox JavaDoc platformValue;
332     private javax.swing.JPanel JavaDoc platformsPanel;
333     private org.openide.explorer.view.TreeTableView view;
334     private javax.swing.JLabel JavaDoc viewLabel;
335     // End of variables declaration//GEN-END:variables
336

337     
338     private Node createPlatformModulesNode() {
339         HashSet JavaDoc disabledModuleCNB = new HashSet JavaDoc(Arrays.asList(getProperties().getDisabledModules()));
340         HashSet JavaDoc enabledClusters = new HashSet JavaDoc(Arrays.asList(getProperties().getEnabledClusters()));
341         
342         HashMap JavaDoc clusterToChildren = new HashMap JavaDoc();
343         
344         Children.SortedArray clusters = new Children.SortedArray();
345         clusters.setComparator(this);
346         AbstractNode n = new AbstractNode(clusters);
347         n.setName(getMessage("LBL_ModuleListClusters"));
348         n.setDisplayName(getMessage("LBL_ModuleListClustersModules"));
349         
350         for (int i = 0; i < platformModules.length; i++) {
351             Children clusterChildren = (Children)clusterToChildren.get(platformModules[i].getClusterDirectory());
352             if (clusterChildren == null) {
353                 Children.SortedArray modules = new Children.SortedArray();
354                 modules.setComparator(this);
355                 clusterChildren = modules;
356                 
357                 String JavaDoc clusterName = platformModules[i].getClusterDirectory().getName();
358                 Enabled cluster = new Enabled(modules, enabledClusters.contains(clusterName));
359                 cluster.setName(clusterName);
360                 cluster.setIconBaseWithExtension(SuiteProject.SUITE_ICON_PATH);
361                 clusterToChildren.put(platformModules[i].getClusterDirectory(), modules);
362                 n.getChildren().add(new Node[] { cluster });
363             }
364             
365             String JavaDoc cnb = platformModules[i].getCodeNameBase();
366             AbstractNode module = new Enabled(Children.LEAF, !disabledModuleCNB.contains(cnb));
367             module.setName(cnb);
368             module.setDisplayName(platformModules[i].getLocalizedName());
369             String JavaDoc desc = platformModules[i].getShortDescription();
370             String JavaDoc tooltip;
371             if (desc != null) {
372                 if (desc.startsWith("<html>")) { // NOI18N
373
tooltip = "<html>" + NbBundle.getMessage(SuiteCustomizerLibraries.class, "SuiteCustomizerLibraries.HINT_module_desc", cnb, desc.substring(6));
374                 } else {
375                     tooltip = NbBundle.getMessage(SuiteCustomizerLibraries.class, "SuiteCustomizerLibraries.HINT_module_desc", cnb, desc);
376                 }
377             } else {
378                 tooltip = NbBundle.getMessage(SuiteCustomizerLibraries.class, "SuiteCustomizerLibraries.HINT_module_no_desc", cnb);
379             }
380             module.setShortDescription(tooltip);
381             module.setIconBaseWithExtension(NbModuleProject.NB_PROJECT_ICON_PATH);
382             
383             clusterChildren.add(new Node[] { module });
384         }
385         
386         return n;
387     }
388     
389     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
390         Node n1 = (Node)o1;
391         Node n2 = (Node)o2;
392         
393         return n1.getDisplayName().compareTo(n2.getDisplayName());
394     }
395     
396     public ExplorerManager getExplorerManager() {
397         return manager;
398     }
399     
400     private static final Set JavaDoc<String JavaDoc> DISABLED_PLATFORM_MODULES = new HashSet JavaDoc();
401     
402     static {
403         // Probably not needed for most platform apps, and won't even work under JNLP.
404
DISABLED_PLATFORM_MODULES.add("org.netbeans.modules.autoupdate"); // NOI18N
405
// XXX the following would not be shown in regular apps anyway, because they are autoloads,
406
// but they *are* shown in JNLP apps because currently even unused autoloads are enabled under JNLP:
407
// Just annoying; e.g. shows Runtime tab prominently.
408
DISABLED_PLATFORM_MODULES.add("org.openide.execution"); // NOI18N
409
DISABLED_PLATFORM_MODULES.add("org.netbeans.core.execution"); // NOI18N
410
// Similar - unlikely to really be wanted by typical platform apps, and show some GUI.
411
DISABLED_PLATFORM_MODULES.add("org.openide.io"); // NOI18N
412
DISABLED_PLATFORM_MODULES.add("org.netbeans.core.output2"); // NOI18N
413
DISABLED_PLATFORM_MODULES.add("org.netbeans.core.multiview"); // NOI18N
414
// this one is useful only for writers of apps showing local disk
415
DISABLED_PLATFORM_MODULES.add("org.netbeans.modules.favorites"); // NOI18N
416
// And these are deprecated:
417
DISABLED_PLATFORM_MODULES.add("org.openide.compat"); // NOI18N
418
DISABLED_PLATFORM_MODULES.add("org.openide.util.enumerations"); // NOI18N
419
}
420     
421     public void stateChanged(ChangeEvent JavaDoc ev) {
422         if (getProperties().getBrandingModel().isBrandingEnabled()) {
423             // User is turning on branded mode. Let's take a guess: they want to
424
// exclude the usual suspects from the module list. We do not want to set
425
// these excludes on a new suite because user might want to use real IDE as the platform
426
// (i.e. not be creating an app, but rather be creating some modules for the IDE).
427
// Only do this if there are no existing exclusions.
428
Node[] clusters = getExplorerManager().getRootContext().getChildren().getNodes();
429             for (int i = 0; i < clusters.length; i++) {
430                 if (clusters[i] instanceof Enabled) {
431                     Enabled e = (Enabled) clusters[i];
432                     if (!e.isEnabled()) {
433                         return;
434                     } else {
435                         Node[] modules = e.getChildren().getNodes();
436                         for (int j = 0; j < modules.length; j++) {
437                             if (modules[j] instanceof Enabled) {
438                                 Enabled m = (Enabled) modules[j];
439                                 if (!m.isEnabled()) {
440                                     return;
441                                 }
442                             }
443                         }
444                     }
445                 }
446             }
447             // #64443: prompt first.
448
if (!UIUtil.showAcceptCancelDialog(
449                     getMessage("SuiteCustomizerLibraries.title.exclude_ide_modules"),
450                     getMessage("SuiteCustomizerLibraries.text.exclude_ide_modules"),
451                     getMessage("SuiteCustomizerLibraries.button.exclude"),
452                     getMessage("SuiteCustomizerLibraries.button.skip"),
453                     NotifyDescriptor.QUESTION_MESSAGE)) {
454                 return;
455             }
456             // OK, continue.
457
for (int i = 0; i < clusters.length; i++) {
458                 if (clusters[i] instanceof Enabled) {
459                     Enabled e = (Enabled) clusters[i];
460                     if (e.getName().startsWith("platform")) { // NOI18N
461
Node[] modules = e.getChildren().getNodes();
462                         for (int j = 0; j < modules.length; j++) {
463                             if (modules[j] instanceof Enabled) {
464                                 Enabled m = (Enabled) modules[j];
465                                 if (DISABLED_PLATFORM_MODULES.contains(m.getName())) {
466                                     m.setEnabled(false);
467                                 }
468                             }
469                         }
470                     } else {
471                         e.setEnabled(false);
472                     }
473                 }
474             }
475         }
476     }
477     
478     final class Enabled extends AbstractNode {
479         private boolean enabled;
480         private Children standard;
481         
482         public Enabled(Children ch, boolean enabled) {
483             super(ch);
484             this.standard = ch;
485             this.enabled = enabled;
486             
487             Sheet s = Sheet.createDefault();
488             Sheet.Set ss = s.get(Sheet.PROPERTIES);
489             ss.put(new EnabledProp(this));
490             setSheet(s);
491         }
492         
493         public void setEnabled(boolean s) {
494             if (s == enabled) {
495                 return;
496             }
497             enabled = s;
498             //refresh childern
499
Node[] all = standard.getNodes();
500             for (int i = 0; i < all.length; i++) {
501                 Node nn = all[i];
502                 if (nn instanceof Enabled) {
503                     Enabled en = (Enabled)nn;
504                     en.firePropertyChange(null, null, null);
505                 }
506             }
507             //refresh parent
508
Node n = getParentNode();
509             if (n instanceof Enabled) {
510                 Enabled en = (Enabled)n;
511                 en.firePropertyChange(null, null, null);
512             }
513             updateDependencyWarnings();
514         }
515         
516         public boolean isEnabled() {
517             return enabled;
518         }
519     }
520     
521     private static final EnabledProp ENABLED_PROP_TEMPLATE = new EnabledProp(null);
522     private static final class EnabledProp extends PropertySupport.ReadWrite {
523         
524         private Enabled node;
525         private PropertyEditor JavaDoc editor;
526         
527         public EnabledProp(Enabled node) {
528             super("enabled", Boolean.TYPE, getMessage("LBL_ModuleListEnabled"), getMessage("LBL_ModuleListEnabledShortDescription"));
529             this.node = node;
530         }
531         
532         public void setValue(Object JavaDoc val) throws IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
533             node.setEnabled(((Boolean JavaDoc)val).booleanValue());
534         }
535         
536         public Object JavaDoc getValue() throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
537             Children ch = node.getChildren();
538             if (ch == Children.LEAF) {
539                 return Boolean.valueOf(node.isEnabled());
540             } else {
541                 Node[] arr = ch.getNodes();
542                 boolean on = false;
543                 boolean off = false;
544                 for (int i = 0; i < arr.length; i++) {
545                     Enabled n = (Enabled)arr[i];
546                     if (n.isEnabled()) {
547                         on = true;
548                     } else {
549                         off = true;
550                     }
551                     
552                     if (on && off && node.isEnabled()) {
553                         return null;
554                     }
555                 }
556                 
557                 return Boolean.valueOf(on && node.isEnabled());
558             }
559         }
560         
561         public boolean canWrite() {
562             Node parent = node.getParentNode();
563             if (parent instanceof Enabled) {
564                 // cluster node
565
return ((Enabled)parent).isEnabled();
566             }
567             return true;
568         }
569         
570         public PropertyEditor JavaDoc getPropertyEditor() {
571             if (editor == null) {
572                 editor = super.getPropertyEditor();
573             }
574             return editor;
575         }
576         
577     }
578     
579     private static String JavaDoc getMessage(String JavaDoc key) {
580         return NbBundle.getMessage(CustomizerDisplay.class, key);
581     }
582     
583     private void initAccessibility() {
584         managePlafsButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_ManagePlafsButton"));
585         platformValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_PlatformValue"));
586         javaPlatformCombo.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_JavaPlatformCombo"));
587         javaPlatformButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_JavaPlatformButton"));
588     }
589     
590     // #65924: show warnings if some dependencies cannot be satisfied
591

592     interface UniverseModule {
593         String JavaDoc getCodeNameBase();
594         int getReleaseVersion();
595         SpecificationVersion getSpecificationVersion();
596         String JavaDoc getImplementationVersion();
597         Set JavaDoc<String JavaDoc> getProvidedTokens();
598         Set JavaDoc<String JavaDoc> getRequiredTokens();
599         Set JavaDoc<Dependency> getModuleDependencies();
600         String JavaDoc getCluster();
601         String JavaDoc getDisplayName();
602     }
603     
604     private static abstract class AbstractUniverseModule implements UniverseModule {
605         protected final ManifestManager mm;
606         protected AbstractUniverseModule(ManifestManager mm) {
607             this.mm = mm;
608         }
609         public int getReleaseVersion() {
610             String JavaDoc s = mm.getReleaseVersion();
611             return s != null ? Integer.parseInt(s) : -1;
612         }
613         public String JavaDoc getImplementationVersion() {
614             return mm.getImplementationVersion();
615         }
616         public Set JavaDoc<String JavaDoc> getProvidedTokens() {
617             return new HashSet JavaDoc(Arrays.asList(mm.getProvidedTokens()));
618         }
619         public Set JavaDoc<String JavaDoc> getRequiredTokens() {
620             Set JavaDoc s = new HashSet JavaDoc(Arrays.asList(mm.getRequiredTokens()));
621             Iterator JavaDoc it = s.iterator();
622             while (it.hasNext()) {
623                 String JavaDoc tok = (String JavaDoc) it.next();
624                 if (tok.startsWith("org.openide.modules.ModuleFormat") || tok.startsWith("org.openide.modules.os.")) { // NOI18N
625
it.remove();
626                 }
627             }
628             s.addAll(Arrays.asList(mm.getNeededTokens()));
629             return s;
630         }
631         public String JavaDoc toString() {
632             return getCodeNameBase();
633         }
634     }
635     
636     private static final class PlatformModule extends AbstractUniverseModule {
637         private final ModuleEntry entry;
638         public PlatformModule(ModuleEntry entry) throws IOException JavaDoc {
639             super(ManifestManager.getInstanceFromJAR(entry.getJarLocation()));
640             this.entry = entry;
641         }
642         public String JavaDoc getCodeNameBase() {
643             return entry.getCodeNameBase();
644         }
645         public SpecificationVersion getSpecificationVersion() {
646             String JavaDoc s = entry.getSpecificationVersion();
647             return s != null ? new SpecificationVersion(s) : null;
648         }
649         public Set JavaDoc<Dependency> getModuleDependencies() {
650             return mm.getModuleDependencies();
651         }
652         public String JavaDoc getCluster() {
653             return entry.getClusterDirectory().getName();
654         }
655         public String JavaDoc getDisplayName() {
656             return entry.getLocalizedName();
657         }
658     }
659     
660     private static final class SuiteModule extends AbstractUniverseModule {
661         private final NbModuleProject project;
662         private final Set JavaDoc<Dependency> dependencies;
663         public SuiteModule(NbModuleProject project) {
664             super(ManifestManager.getInstance(project.getManifest(), false));
665             this.project = project;
666             dependencies = new HashSet JavaDoc();
667             // Cannot use ProjectXMLManager since we need to report also deps on nonexistent modules.
668
Element JavaDoc dataE = project.getPrimaryConfigurationData();
669             Element JavaDoc depsE = Util.findElement(dataE, "module-dependencies", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
670
Iterator JavaDoc<Element JavaDoc> deps = Util.findSubElements(depsE).iterator();
671             while (deps.hasNext()) {
672                 Element JavaDoc dep = (Element JavaDoc) deps.next();
673                 Element JavaDoc run = Util.findElement(dep, "run-dependency", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
674
if (run == null) {
675                     continue;
676                 }
677                 String JavaDoc text = Util.findText(Util.findElement(dep, "code-name-base", NbModuleProjectType.NAMESPACE_SHARED)); // NOI18N
678
Element JavaDoc relverE = Util.findElement(run, "release-version", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
679
if (relverE != null) {
680                     text += '/' + Util.findText(relverE);
681                 }
682                 Element JavaDoc specverE = Util.findElement(run, "specification-version", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
683
if (specverE != null) {
684                     text += " > " + Util.findText(specverE);
685                 } else {
686                     Element JavaDoc implver = Util.findElement(run, "implementation-version", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
687
if (implver != null) {
688                         // Will special-case '*' as an impl version to mean "match anything".
689
text += " = *"; // NOI18N
690
}
691                 }
692                 dependencies.addAll(Dependency.create(Dependency.TYPE_MODULE, text));
693             }
694         }
695         public String JavaDoc getCodeNameBase() {
696             return project.getCodeNameBase();
697         }
698         public SpecificationVersion getSpecificationVersion() {
699             String JavaDoc s = project.getSpecVersion();
700             return s != null ? new SpecificationVersion(s) : null;
701         }
702         public Set JavaDoc<Dependency> getModuleDependencies() {
703             return dependencies;
704         }
705         public String JavaDoc getCluster() {
706             return null;
707         }
708         public String JavaDoc getDisplayName() {
709             return ProjectUtils.getInformation(project).getDisplayName();
710         }
711     }
712
713     private RequestProcessor.Task updateDependencyWarningsTask;
714     private void updateDependencyWarnings() {
715         // XXX avoid running unless and until we become visible, perhaps
716
if (updateDependencyWarningsTask == null) {
717             updateDependencyWarningsTask = RequestProcessor.getDefault().create(new Runnable JavaDoc() {
718                 public void run() {
719                     doUpdateDependencyWarnings();
720                 }
721             });
722         }
723         updateDependencyWarningsTask.schedule(0);
724     }
725     
726     static Set JavaDoc<UniverseModule> loadUniverseModules(ModuleEntry[] platformModules, Set JavaDoc<NbModuleProject> suiteModules) throws IOException JavaDoc {
727         Set JavaDoc universe = new LinkedHashSet JavaDoc();
728         Iterator JavaDoc<NbModuleProject> it = suiteModules.iterator();
729         while (it.hasNext()) {
730             universe.add(new SuiteModule((NbModuleProject) it.next()));
731         }
732         for (int i = 0; i < platformModules.length; i++) {
733             universe.add(new PlatformModule(platformModules[i]));
734         }
735         return universe;
736     }
737     
738     static String JavaDoc[] findWarning(Set JavaDoc<UniverseModule> universeModules, Set JavaDoc<String JavaDoc> enabledClusters, Set JavaDoc<String JavaDoc> disabledModules) {
739         SortedMap JavaDoc<String JavaDoc,UniverseModule> sortedModules = new TreeMap JavaDoc();
740         Set JavaDoc<UniverseModule> excluded = new HashSet JavaDoc();
741         Map JavaDoc<String JavaDoc,Set JavaDoc<UniverseModule>> providers = new HashMap JavaDoc();
742         Iterator JavaDoc it = universeModules.iterator();
743         while (it.hasNext()) {
744             UniverseModule m = (UniverseModule) it.next();
745             String JavaDoc cnb = m.getCodeNameBase();
746             String JavaDoc cluster = m.getCluster();
747             if (cluster != null && (!enabledClusters.contains(cluster) || disabledModules.contains(cnb))) {
748                 excluded.add(m);
749             }
750             sortedModules.put(cnb, m);
751             Iterator JavaDoc<String JavaDoc> provides = m.getProvidedTokens().iterator();
752             while (provides.hasNext()) {
753                 String JavaDoc tok = (String JavaDoc) provides.next();
754                 Set JavaDoc<UniverseModule> providersOf = (Set JavaDoc) providers.get(tok);
755                 if (providersOf == null) {
756                     providersOf = new TreeSet JavaDoc(UNIVERSE_MODULE_COMPARATOR);
757                     providers.put(tok, providersOf);
758                 }
759                 providersOf.add(m);
760             }
761         }
762         it = sortedModules.values().iterator();
763         while (it.hasNext()) {
764             UniverseModule m = (UniverseModule) it.next();
765             if (excluded.contains(m)) {
766                 continue;
767             }
768             String JavaDoc[] warning = findWarning(m, sortedModules, providers, excluded);
769             if (warning != null) {
770                 return warning;
771             }
772         }
773         return null;
774     }
775     private static final Comparator JavaDoc<UniverseModule> UNIVERSE_MODULE_COMPARATOR = new Comparator JavaDoc() {
776         Collator JavaDoc COLL = Collator.getInstance();
777         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
778             return COLL.compare(((UniverseModule) o1).getDisplayName(), ((UniverseModule) o2).getDisplayName());
779         }
780     };
781     
782     private Set JavaDoc<UniverseModule> universe;
783     private /* #71791 */ synchronized void doUpdateDependencyWarnings() {
784         if (universe == null) {
785             try {
786                 Set JavaDoc<NbModuleProject> suiteModules = getProperties().getSubModules();
787                 universe = loadUniverseModules(platformModules, suiteModules);
788             } catch (IOException JavaDoc e) {
789                 Util.err.notify(ErrorManager.INFORMATIONAL, e);
790                 return; // any warnings would probably be wrong anyway
791
}
792         }
793         
794         Set JavaDoc enabledClusters = new TreeSet JavaDoc();
795         Set JavaDoc disabledModules = new TreeSet JavaDoc();
796         
797         Node[] clusters = getExplorerManager().getRootContext().getChildren().getNodes();
798         for (int i = 0; i < clusters.length; i++) {
799             if (clusters[i] instanceof Enabled) {
800                 Enabled e = (Enabled) clusters[i];
801                 if (e.isEnabled()) {
802                     enabledClusters.add(e.getName());
803                     Node[] modules = e.getChildren().getNodes();
804                     for (int j = 0; j < modules.length; j++) {
805                         if (modules[j] instanceof Enabled) {
806                             Enabled m = (Enabled) modules[j];
807                             if (!m.isEnabled()) {
808                                 disabledModules.add(m.getName());
809                             }
810                         }
811                     }
812                 }
813             }
814         }
815         
816         final String JavaDoc[] warning = findWarning(universe, enabledClusters, disabledModules);
817         
818         EventQueue.invokeLater(new Runnable JavaDoc() {
819             public void run() {
820                 if (warning != null) {
821                     String JavaDoc key = warning[0];
822                     String JavaDoc[] args = new String JavaDoc[warning.length - 1];
823                     System.arraycopy(warning, 1, args, 0, args.length);
824                     cat.setErrorMessage(NbBundle.getMessage(SuiteCustomizerLibraries.class, key, args));
825                 } else {
826                     cat.setErrorMessage(null);
827                 }
828             }
829         });
830         
831     }
832
833     private static String JavaDoc[] findWarning(UniverseModule m, Map JavaDoc<String JavaDoc,UniverseModule> modules, Map JavaDoc<String JavaDoc,Set JavaDoc<UniverseModule>> providers, Set JavaDoc<UniverseModule> excluded) {
834         // Check module dependencies:
835
SortedSet JavaDoc<Dependency> deps = new TreeSet JavaDoc(new Comparator JavaDoc() {
836             public int compare(Object JavaDoc o1, Object JavaDoc o2) {
837                 Dependency d1 = (Dependency) o1;
838                 Dependency d2 = (Dependency) o2;
839                 return d1.getName().compareTo(d2.getName());
840             }
841         });
842         deps.addAll(m.getModuleDependencies());
843         Iterator JavaDoc it = deps.iterator();
844         while (it.hasNext()) {
845             Dependency d = (Dependency) it.next();
846             String JavaDoc codename = d.getName();
847             String JavaDoc cnb;
848             int mrvLo, mrvHi;
849             int slash = codename.lastIndexOf('/');
850             if (slash == -1) {
851                 cnb = codename;
852                 mrvLo = -1;
853                 mrvHi = -1;
854             } else {
855                 cnb = codename.substring(0, slash);
856                 String JavaDoc mrv = codename.substring(slash + 1);
857                 int dash = mrv.lastIndexOf('-');
858                 if (dash == -1) {
859                     mrvLo = mrvHi = Integer.parseInt(mrv);
860                 } else {
861                     mrvLo = Integer.parseInt(mrv.substring(0, dash));
862                     mrvHi = Integer.parseInt(mrv.substring(dash + 1));
863                 }
864             }
865             UniverseModule dep = (UniverseModule) modules.get(cnb);
866             if (dep == null) {
867                 if (m.getCluster() != null) {
868                     return new String JavaDoc[] {"ERR_platform_no_dep", m.getDisplayName(), m.getCluster(), cnb};
869                 } else {
870                     return new String JavaDoc[] {"ERR_suite_no_dep", m.getDisplayName(), cnb};
871                 }
872             }
873             if (excluded.contains(dep)) {
874                 assert dep.getCluster() != null;
875                 if (m.getCluster() != null) {
876                     return new String JavaDoc[] {"ERR_platform_excluded_dep", m.getDisplayName(), m.getCluster(), dep.getDisplayName(), dep.getCluster()};
877                 } else {
878                     return new String JavaDoc[] {"ERR_suite_excluded_dep", m.getDisplayName(), dep.getDisplayName(), dep.getCluster()};
879                 }
880             }
881             if (dep.getReleaseVersion() < mrvLo || dep.getReleaseVersion() > mrvHi) {
882                 if (m.getCluster() != null) {
883                     return new String JavaDoc[] {"ERR_platform_bad_dep_mrv", m.getDisplayName(), m.getCluster(), dep.getDisplayName()};
884                 } else {
885                     return new String JavaDoc[] {"ERR_suite_bad_dep_mrv", m.getDisplayName(), dep.getDisplayName()};
886                 }
887             }
888             if (d.getComparison() == Dependency.COMPARE_SPEC) {
889                 SpecificationVersion needed = new SpecificationVersion(d.getVersion());
890                 SpecificationVersion found = dep.getSpecificationVersion();
891                 if (found == null || found.compareTo(needed) < 0) {
892                     if (m.getCluster() != null) {
893                         return new String JavaDoc[] {"ERR_platform_bad_dep_spec", m.getDisplayName(), m.getCluster(), dep.getDisplayName()};
894                     } else {
895                         return new String JavaDoc[] {"ERR_suite_bad_dep_spec", m.getDisplayName(), dep.getDisplayName()};
896                     }
897                 }
898             } else if (d.getComparison() == Dependency.COMPARE_IMPL) {
899                 String JavaDoc needed = d.getVersion();
900                 if (!needed.equals("*") && !needed.equals(dep.getImplementationVersion())) { // NOI18N
901
assert m.getCluster() != null;
902                     return new String JavaDoc[] {"ERR_platform_bad_dep_impl", m.getDisplayName(), m.getCluster(), dep.getDisplayName()};
903                 }
904             }
905         }
906         // Now check token availability:
907
Iterator JavaDoc toks = new TreeSet JavaDoc(m.getRequiredTokens()).iterator();
908         while (toks.hasNext()) {
909             String JavaDoc tok = (String JavaDoc) toks.next();
910             UniverseModule wouldBeProvider = null;
911             boolean found = false;
912             Set JavaDoc<UniverseModule> possibleProviders = (Set JavaDoc) providers.get(tok);
913             if (possibleProviders != null) {
914                 it = possibleProviders.iterator();
915                 while (it.hasNext()) {
916                     UniverseModule p = (UniverseModule) it.next();
917                     if (excluded.contains(p)) {
918                         if (wouldBeProvider == null) {
919                             wouldBeProvider = p;
920                         }
921                     } else {
922                         found = true;
923                         break;
924                     }
925                 }
926             }
927             if (!found) {
928                 if (wouldBeProvider != null) {
929                     assert wouldBeProvider.getCluster() != null;
930                     if (m.getCluster() != null) {
931                         return new String JavaDoc[] {"ERR_platform_only_excluded_providers", tok, m.getDisplayName(), m.getCluster(), wouldBeProvider.getDisplayName(), wouldBeProvider.getCluster()}; // NOI18N
932
} else {
933                         return new String JavaDoc[] {"ERR_suite_only_excluded_providers", tok, m.getDisplayName(), wouldBeProvider.getDisplayName(), wouldBeProvider.getCluster()}; // NOI18N
934
}
935                 } else {
936                     if (m.getCluster() != null) {
937                         return new String JavaDoc[] {"ERR_platform_no_providers", tok, m.getDisplayName(), m.getCluster()}; // NOI18N
938
} else {
939                         return new String JavaDoc[] {"ERR_suite_no_providers", tok, m.getDisplayName()}; // NOI18N
940
}
941                 }
942             }
943         }
944         // All clear for this module.
945
return null;
946     }
947
948     private void updateJavaPlatformEnabled() { // #71631
949
boolean enabled = ((NbPlatform) platformValue.getSelectedItem()).getHarnessVersion() >= NbPlatform.HARNESS_VERSION_50u1;
950         javaPlatformCombo.setEnabled(enabled);
951         javaPlatformButton.setEnabled(enabled); // #72061
952
}
953     
954 }
955
Popular Tags