001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.gsfpath.platform.ui;
043:
044: import java.awt.CardLayout;
045: import java.awt.Component;
046: import java.awt.Container;
047: import java.awt.Dialog;
048: import java.awt.GridBagConstraints;
049: import java.awt.GridBagLayout;
050: import java.awt.Image;
051: import java.beans.PropertyChangeListener;
052: import java.beans.PropertyChangeEvent;
053: import java.beans.PropertyVetoException;
054: import java.beans.VetoableChangeListener;
055: import java.io.File;
056: import java.io.IOException;
057: import java.util.ArrayList;
058: import java.util.Collections;
059: import java.util.Comparator;
060: import java.util.HashMap;
061: import java.util.List;
062: import java.util.Locale;
063: import java.util.Set;
064: import javax.swing.JComponent;
065: import javax.swing.UIManager;
066: import org.netbeans.modules.gsfpath.api.platform.JavaPlatform;
067: import org.netbeans.modules.gsfpath.api.platform.JavaPlatformManager;
068: import org.netbeans.modules.gsfpath.platform.wizard.PlatformInstallIterator;
069: import org.openide.DialogDisplayer;
070: import org.openide.ErrorManager;
071: import org.openide.WizardDescriptor;
072: import org.openide.explorer.ExplorerManager;
073: import org.openide.explorer.view.BeanTreeView;
074: import org.openide.filesystems.Repository;
075: import org.openide.filesystems.FileObject;
076: import org.openide.filesystems.FileUtil;
077: import org.openide.loaders.DataObject;
078: import org.openide.loaders.DataFolder;
079: import org.openide.loaders.DataObjectNotFoundException;
080: import org.openide.nodes.AbstractNode;
081: import org.openide.nodes.Node;
082: import org.openide.nodes.FilterNode;
083: import org.openide.nodes.Children;
084: import org.openide.util.NbBundle;
085:
086: /**
087: * @author tom
088: */
089: public class PlatformsCustomizer extends javax.swing.JPanel implements
090: PropertyChangeListener, VetoableChangeListener,
091: ExplorerManager.Provider {
092:
093: private static final String TEMPLATE = "Templates/Services/Platforms/org-netbeans-modules-gsfpath-api-Platform/javaplatform.xml"; //NOI18N
094: private static final String STORAGE = "Services/Platforms/org-netbeans-modules-gsfpath-api-Platform"; //NOI18N
095:
096: private PlatformCategoriesChildren children;
097: private ExplorerManager manager;
098: private final JavaPlatform initialPlatform;
099:
100: /** Creates new form PlatformsCustomizer */
101: public PlatformsCustomizer(JavaPlatform initialPlatform) {
102: this .initialPlatform = (initialPlatform == null) ? JavaPlatformManager
103: .getDefault().getDefaultPlatform()
104: : initialPlatform;
105: initComponents();
106: }
107:
108: public void propertyChange(PropertyChangeEvent evt) {
109: if (ExplorerManager.PROP_SELECTED_NODES.equals(evt
110: .getPropertyName())) {
111: Node[] nodes = (Node[]) evt.getNewValue();
112: if (nodes.length != 1) {
113: selectPlatform(null);
114: } else {
115: selectPlatform(nodes[0]);
116: }
117: }
118: }
119:
120: public void vetoableChange(PropertyChangeEvent evt)
121: throws PropertyVetoException {
122: if (ExplorerManager.PROP_SELECTED_NODES.equals(evt
123: .getPropertyName())) {
124: Node[] nodes = (Node[]) evt.getNewValue();
125: if (nodes.length > 1) {
126: throw new PropertyVetoException("Invalid length", evt); //NOI18N
127: }
128: }
129: }
130:
131: public synchronized ExplorerManager getExplorerManager() {
132: if (this .manager == null) {
133: this .manager = new ExplorerManager();
134: this .manager
135: .setRootContext(new AbstractNode(getChildren()));
136: this .manager.addPropertyChangeListener(this );
137: this .manager.addVetoableChangeListener(this );
138: }
139: return manager;
140: }
141:
142: public @Override
143: void addNotify() {
144: super .addNotify();
145: this .expandPlatforms(this .initialPlatform);
146: }
147:
148: /** This method is called from within the constructor to
149: * initialize the form.
150: * WARNING: Do NOT modify this code. The content of this method is
151: * always regenerated by the Form Editor.
152: */
153: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
154: private void initComponents() {
155: java.awt.GridBagConstraints gridBagConstraints;
156:
157: jPanel3 = new javax.swing.JPanel();
158: platforms = new PlatformsView();
159: addButton = new javax.swing.JButton();
160: removeButton = new javax.swing.JButton();
161: cards = new javax.swing.JPanel();
162: jPanel1 = new javax.swing.JPanel();
163: jLabel1 = new javax.swing.JLabel();
164: platformName = new javax.swing.JTextField();
165: jLabel2 = new javax.swing.JLabel();
166: platformHome = new javax.swing.JTextField();
167: clientArea = new javax.swing.JPanel();
168: messageArea = new javax.swing.JPanel();
169: jLabel3 = new javax.swing.JLabel();
170:
171: setLayout(new java.awt.GridBagLayout());
172:
173: platforms.setPreferredSize(new java.awt.Dimension(200, 334));
174: gridBagConstraints = new java.awt.GridBagConstraints();
175: gridBagConstraints.gridx = 0;
176: gridBagConstraints.gridy = 1;
177: gridBagConstraints.gridwidth = 2;
178: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
179: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
180: gridBagConstraints.weighty = 1.0;
181: gridBagConstraints.insets = new java.awt.Insets(2, 12, 12, 6);
182: add(platforms, gridBagConstraints);
183: java.util.ResourceBundle bundle = java.util.ResourceBundle
184: .getBundle("org/netbeans/modules/gsfpath/platform/ui/Bundle"); // NOI18N
185: platforms.getAccessibleContext().setAccessibleName(
186: bundle.getString("AN_PlatformsCustomizerPlatforms")); // NOI18N
187: platforms.getAccessibleContext().setAccessibleDescription(
188: bundle.getString("AD_PlatformsCustomizerPlatforms")); // NOI18N
189:
190: addButton.setMnemonic(java.util.ResourceBundle.getBundle(
191: "org/netbeans/modules/gsfpath/platform/ui/Bundle")
192: .getString("MNE_AddPlatform").charAt(0));
193: addButton.setText(bundle.getString("CTL_AddPlatform")); // NOI18N
194: addButton
195: .addActionListener(new java.awt.event.ActionListener() {
196: public void actionPerformed(
197: java.awt.event.ActionEvent evt) {
198: addNewPlatform(evt);
199: }
200: });
201: gridBagConstraints = new java.awt.GridBagConstraints();
202: gridBagConstraints.gridx = 0;
203: gridBagConstraints.gridy = 2;
204: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
205: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 6);
206: add(addButton, gridBagConstraints);
207: addButton.getAccessibleContext().setAccessibleDescription(
208: bundle.getString("AD_AddPlatform")); // NOI18N
209:
210: removeButton.setMnemonic(java.util.ResourceBundle.getBundle(
211: "org/netbeans/modules/gsfpath/platform/ui/Bundle")
212: .getString("MNE_Remove").charAt(0));
213: removeButton.setText(bundle.getString("CTL_Remove")); // NOI18N
214: removeButton
215: .addActionListener(new java.awt.event.ActionListener() {
216: public void actionPerformed(
217: java.awt.event.ActionEvent evt) {
218: removePlatform(evt);
219: }
220: });
221: gridBagConstraints = new java.awt.GridBagConstraints();
222: gridBagConstraints.gridx = 1;
223: gridBagConstraints.gridy = 2;
224: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
225: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 6);
226: add(removeButton, gridBagConstraints);
227: removeButton.getAccessibleContext().setAccessibleDescription(
228: bundle.getString("AD_Remove")); // NOI18N
229:
230: cards.setLayout(new java.awt.CardLayout());
231:
232: jPanel1.setLayout(new java.awt.GridBagLayout());
233:
234: jLabel1
235: .setDisplayedMnemonic(java.util.ResourceBundle
236: .getBundle(
237: "org/netbeans/modules/gsfpath/platform/ui/Bundle")
238: .getString("MNE_PlatformName").charAt(0));
239: jLabel1.setLabelFor(platformName);
240: jLabel1.setText(bundle.getString("CTL_PlatformName")); // NOI18N
241: gridBagConstraints = new java.awt.GridBagConstraints();
242: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
243: jPanel1.add(jLabel1, gridBagConstraints);
244:
245: platformName.setColumns(25);
246: platformName.setEditable(false);
247: gridBagConstraints = new java.awt.GridBagConstraints();
248: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
249: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
250: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
251: gridBagConstraints.weightx = 1.0;
252: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
253: jPanel1.add(platformName, gridBagConstraints);
254: platformName.getAccessibleContext().setAccessibleDescription(
255: bundle.getString("AD_PlatformName")); // NOI18N
256:
257: jLabel2
258: .setDisplayedMnemonic(java.util.ResourceBundle
259: .getBundle(
260: "org/netbeans/modules/gsfpath/platform/ui/Bundle")
261: .getString("MNE_PlatformHome").charAt(0));
262: jLabel2.setLabelFor(platformHome);
263: jLabel2.setText(bundle.getString("CTL_PlatformHome")); // NOI18N
264: gridBagConstraints = new java.awt.GridBagConstraints();
265: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
266: gridBagConstraints.insets = new java.awt.Insets(6, 0, 12, 0);
267: jPanel1.add(jLabel2, gridBagConstraints);
268:
269: platformHome.setColumns(25);
270: platformHome.setEditable(false);
271: gridBagConstraints = new java.awt.GridBagConstraints();
272: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
273: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
274: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
275: gridBagConstraints.weightx = 1.0;
276: gridBagConstraints.insets = new java.awt.Insets(6, 6, 12, 0);
277: jPanel1.add(platformHome, gridBagConstraints);
278: platformHome.getAccessibleContext().setAccessibleDescription(
279: bundle.getString("AD_PlatformHome")); // NOI18N
280:
281: clientArea.setLayout(new java.awt.GridBagLayout());
282: gridBagConstraints = new java.awt.GridBagConstraints();
283: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
284: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
285: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
286: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
287: gridBagConstraints.weightx = 1.0;
288: gridBagConstraints.weighty = 1.0;
289: jPanel1.add(clientArea, gridBagConstraints);
290:
291: cards.add(jPanel1, "card2");
292:
293: messageArea.setLayout(new java.awt.GridBagLayout());
294: cards.add(messageArea, "card3");
295:
296: gridBagConstraints = new java.awt.GridBagConstraints();
297: gridBagConstraints.gridx = 2;
298: gridBagConstraints.gridy = 1;
299: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
300: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
301: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
302: gridBagConstraints.weightx = 1.0;
303: gridBagConstraints.weighty = 1.0;
304: gridBagConstraints.insets = new java.awt.Insets(2, 6, 12, 12);
305: add(cards, gridBagConstraints);
306:
307: jLabel3.setLabelFor(platforms);
308: org.openide.awt.Mnemonics.setLocalizedText(jLabel3, bundle
309: .getString("TXT_PlatformsList")); // NOI18N
310: gridBagConstraints = new java.awt.GridBagConstraints();
311: gridBagConstraints.gridx = 0;
312: gridBagConstraints.gridy = 0;
313: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
314: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
315: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
316: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
317: add(jLabel3, gridBagConstraints);
318:
319: getAccessibleContext().setAccessibleDescription(
320: bundle.getString("AD_PlatformsCustomizer")); // NOI18N
321: }// </editor-fold>//GEN-END:initComponents
322:
323: private void removePlatform(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePlatform
324: Node[] nodes = getExplorerManager().getSelectedNodes();
325: if (nodes.length != 1) {
326: assert false : "Illegal number of selected nodes"; //NOI18N
327: return;
328: }
329: DataObject dobj = nodes[0].getLookup().lookup(DataObject.class);
330: if (dobj == null) {
331: assert false : "Can not find platform definition for node: "
332: + nodes[0].getDisplayName(); //NOI18N
333: return;
334: }
335: try {
336: dobj.delete();
337: this .getChildren().refreshPlatforms();
338: this .expandPlatforms(null);
339: } catch (IOException ioe) {
340: ErrorManager.getDefault().notify(ioe);
341: }
342: }//GEN-LAST:event_removePlatform
343:
344: private void addNewPlatform(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addNewPlatform
345: try {
346: WizardDescriptor wiz = new WizardDescriptor(
347: PlatformInstallIterator.create());
348: DataObject template = DataObject.find(Repository
349: .getDefault().getDefaultFileSystem().findResource(
350: TEMPLATE));
351: wiz.putProperty("targetTemplate", template); //NOI18N
352: DataFolder folder = DataFolder.findFolder(Repository
353: .getDefault().getDefaultFileSystem().findResource(
354: STORAGE));
355: wiz.putProperty("targetFolder", folder); //NOI18N
356: wiz
357: .putProperty("WizardPanel_autoWizardStyle",
358: Boolean.TRUE); // NOI18N
359: wiz.putProperty("WizardPanel_contentDisplayed",
360: Boolean.TRUE); // NOI18N
361: wiz
362: .putProperty("WizardPanel_contentNumbered",
363: Boolean.TRUE); // NOI18N
364: wiz.setTitle(NbBundle.getMessage(PlatformsCustomizer.class,
365: "CTL_AddPlatformTitle"));
366: wiz.setTitleFormat(new java.text.MessageFormat("{0}")); // NOI18N
367: Dialog dlg = DialogDisplayer.getDefault().createDialog(wiz);
368: try {
369: dlg.setVisible(true);
370: if (wiz.getValue() == WizardDescriptor.FINISH_OPTION) {
371: this .getChildren().refreshPlatforms();
372: Set result = wiz.getInstantiatedObjects();
373: this .expandPlatforms(result.size() == 0 ? null
374: : (JavaPlatform) result.iterator().next());
375: }
376: } finally {
377: dlg.dispose();
378: }
379: } catch (DataObjectNotFoundException dfne) {
380: ErrorManager.getDefault().notify(dfne);
381: } catch (IOException ioe) {
382: ErrorManager.getDefault().notify(ioe);
383: }
384: }//GEN-LAST:event_addNewPlatform
385:
386: private synchronized PlatformCategoriesChildren getChildren() {
387: if (this .children == null) {
388: this .children = new PlatformCategoriesChildren();
389: }
390: return this .children;
391: }
392:
393: private void selectPlatform(Node pNode) {
394: this .clientArea.removeAll();
395: this .messageArea.removeAll();
396: this .removeButton.setEnabled(false);
397: if (pNode == null) {
398: ((CardLayout) cards.getLayout()).last(cards);
399: return;
400: }
401: JComponent target = messageArea;
402: JavaPlatform platform = pNode.getLookup().lookup(
403: JavaPlatform.class);
404: if (platform != null) {
405: this .removeButton.setEnabled(isDefaultPLatform(platform));
406: if (platform.getInstallFolders().size() != 0) {
407: this .platformName.setText(pNode.getDisplayName());
408: for (FileObject installFolder : platform
409: .getInstallFolders()) {
410: File file = FileUtil.toFile(installFolder);
411: if (file != null) {
412: this .platformHome.setText(file
413: .getAbsolutePath());
414: }
415: }
416: target = clientArea;
417: }
418: }
419: if (pNode.hasCustomizer()) {
420: Component component = pNode.getCustomizer();
421: if (component != null) {
422: addComponent(target, component);
423: }
424: }
425: target.revalidate();
426: CardLayout cl = (CardLayout) cards.getLayout();
427: if (target == clientArea) {
428: cl.first(cards);
429: } else {
430: cl.last(cards);
431: }
432: }
433:
434: private static void addComponent(Container container,
435: Component component) {
436: GridBagConstraints c = new GridBagConstraints();
437: c.gridx = c.gridy = GridBagConstraints.RELATIVE;
438: c.gridheight = c.gridwidth = GridBagConstraints.REMAINDER;
439: c.fill = GridBagConstraints.BOTH;
440: c.anchor = GridBagConstraints.NORTHWEST;
441: c.weightx = c.weighty = 1.0;
442: ((GridBagLayout) container.getLayout()).setConstraints(
443: component, c);
444: container.add(component);
445: }
446:
447: private static boolean isDefaultPLatform(JavaPlatform platform) {
448: JavaPlatform defaultPlatform = JavaPlatformManager.getDefault()
449: .getDefaultPlatform();
450: return defaultPlatform != null
451: && !defaultPlatform.equals(platform);
452: }
453:
454: private void expandPlatforms(JavaPlatform platform) {
455: ExplorerManager mgr = this .getExplorerManager();
456: Node node = mgr.getRootContext();
457: expandAllNodes(this .platforms, node, mgr, platform);
458: }
459:
460: private static void expandAllNodes(BeanTreeView btv, Node node,
461: ExplorerManager mgr, JavaPlatform platform) {
462: btv.expandNode(node);
463: Children ch = node.getChildren();
464: if (ch == Children.LEAF) {
465: if (platform != null
466: && platform.equals(node.getLookup().lookup(
467: JavaPlatform.class))) {
468: try {
469: mgr.setSelectedNodes(new Node[] { node });
470: } catch (PropertyVetoException e) {
471: //Ignore it
472: }
473: }
474: return;
475: }
476: Node nodes[] = ch.getNodes(true);
477: for (int i = 0; i < nodes.length; i++) {
478: expandAllNodes(btv, nodes[i], mgr, platform);
479: }
480:
481: }
482:
483: // Variables declaration - do not modify//GEN-BEGIN:variables
484: private javax.swing.JButton addButton;
485: private javax.swing.JPanel cards;
486: private javax.swing.JPanel clientArea;
487: private javax.swing.JLabel jLabel1;
488: private javax.swing.JLabel jLabel2;
489: private javax.swing.JLabel jLabel3;
490: private javax.swing.JPanel jPanel1;
491: private javax.swing.JPanel jPanel3;
492: private javax.swing.JPanel messageArea;
493: private javax.swing.JTextField platformHome;
494: private javax.swing.JTextField platformName;
495: private org.openide.explorer.view.BeanTreeView platforms;
496: private javax.swing.JButton removeButton;
497:
498: // End of variables declaration//GEN-END:variables
499:
500: private static class PlatformsView extends BeanTreeView {
501:
502: public PlatformsView() {
503: super ();
504: this .setPopupAllowed(false);
505: this .setDefaultActionAllowed(false);
506: this .setRootVisible(false);
507: this .tree.setEditable(false);
508: this .tree.setShowsRootHandles(false);
509: this .setBorder(UIManager.getBorder("Nb.ScrollPane.border")); // NOI18N
510: }
511:
512: }
513:
514: private static class PlatformCategoriesDescriptor implements
515: Comparable<PlatformCategoriesDescriptor> {
516: private final String categoryName;
517: private final List<Node> platforms;
518: private boolean changed = false;
519:
520: public PlatformCategoriesDescriptor(String categoryName) {
521: assert categoryName != null;
522: this .categoryName = categoryName;
523: this .platforms = new ArrayList<Node>();
524: }
525:
526: public String getName() {
527: return this .categoryName;
528: }
529:
530: public List<Node> getPlatform() {
531: if (changed) {
532: //SortedSet can't be used, there can be platforms with the same
533: //display name
534: Collections.sort(platforms,
535: new PlatformNodeComparator());
536: changed = false;
537: }
538: return Collections.unmodifiableList(this .platforms);
539: }
540:
541: public void add(Node node) {
542: this .platforms.add(node);
543: this .changed = true;
544: }
545:
546: public @Override
547: int hashCode() {
548: return this .categoryName.hashCode();
549: }
550:
551: public @Override
552: boolean equals(Object other) {
553: if (other instanceof PlatformCategoriesDescriptor) {
554: PlatformCategoriesDescriptor desc = (PlatformCategoriesDescriptor) other;
555: return this .categoryName.equals(desc.categoryName)
556: && this .platforms.size() == desc.platforms
557: .size();
558: }
559: return false;
560: }
561:
562: public int compareTo(PlatformCategoriesDescriptor desc) {
563: return this .categoryName.compareTo(desc.categoryName);
564: }
565:
566: }
567:
568: private static class PlatformsChildren extends Children.Keys<Node> {
569:
570: private final List<Node> platforms;
571:
572: public PlatformsChildren(List<Node> platforms) {
573: this .platforms = platforms;
574: }
575:
576: protected @Override
577: void addNotify() {
578: super .addNotify();
579: this .setKeys(this .platforms);
580: }
581:
582: protected @Override
583: void removeNotify() {
584: super .removeNotify();
585: this .setKeys(new Node[0]);
586: }
587:
588: protected Node[] createNodes(Node key) {
589: return new Node[] { new FilterNode(key, Children.LEAF) };
590: }
591: }
592:
593: private static class PlatformCategoryNode extends AbstractNode {
594:
595: private final PlatformCategoriesDescriptor desc;
596: private Node iconDelegate;
597:
598: public PlatformCategoryNode(PlatformCategoriesDescriptor desc) {
599: super (new PlatformsChildren(desc.getPlatform()));
600: this .desc = desc;
601: this .iconDelegate = DataFolder.findFolder(
602: Repository.getDefault().getDefaultFileSystem()
603: .getRoot()).getNodeDelegate();
604: }
605:
606: public @Override
607: String getName() {
608: return this .desc.getName();
609: }
610:
611: public @Override
612: String getDisplayName() {
613: return this .getName();
614: }
615:
616: public @Override
617: Image getIcon(int type) {
618: return this .iconDelegate.getIcon(type);
619: }
620:
621: public @Override
622: Image getOpenedIcon(int type) {
623: return this .iconDelegate.getOpenedIcon(type);
624: }
625:
626: }
627:
628: private static class PlatformCategoriesChildren extends
629: Children.Keys<PlatformCategoriesDescriptor> {
630:
631: protected @Override
632: void addNotify() {
633: super .addNotify();
634: this .refreshPlatforms();
635: }
636:
637: protected @Override
638: void removeNotify() {
639: super .removeNotify();
640: }
641:
642: protected Node[] createNodes(PlatformCategoriesDescriptor key) {
643: return new Node[] { new PlatformCategoryNode(key) };
644: }
645:
646: private void refreshPlatforms() {
647: FileObject storage = Repository.getDefault()
648: .getDefaultFileSystem().findResource(STORAGE);
649: if (storage != null) {
650: java.util.Map<String, PlatformCategoriesDescriptor> categories = new HashMap<String, PlatformCategoriesDescriptor>();
651: for (FileObject child : storage.getChildren()) {
652: try {
653: DataObject dobj = DataObject.find(child);
654: Node node = dobj.getNodeDelegate();
655: JavaPlatform platform = node.getLookup()
656: .lookup(JavaPlatform.class);
657: if (platform != null) {
658: String platformType = platform
659: .getSpecification().getName();
660: if (platformType != null) {
661: platformType = platformType
662: .toUpperCase(Locale.ENGLISH);
663: PlatformCategoriesDescriptor platforms = categories
664: .get(platformType);
665: if (platforms == null) {
666: platforms = new PlatformCategoriesDescriptor(
667: platformType);
668: categories.put(platformType,
669: platforms);
670: }
671: platforms.add(node);
672: } else {
673: ErrorManager
674: .getDefault()
675: .log(
676: "Platform: "
677: + platform
678: .getDisplayName()
679: + " has invalid specification."); //NOI18N
680: }
681: } else {
682: ErrorManager
683: .getDefault()
684: .log(
685: "Platform node for : "
686: + node
687: .getDisplayName()
688: + " has no platform in its lookup."); //NOI18N
689: }
690: } catch (DataObjectNotFoundException e) {
691: ErrorManager.getDefault().notify(e);
692: }
693: }
694: List<PlatformCategoriesDescriptor> keys = new ArrayList<PlatformsCustomizer.PlatformCategoriesDescriptor>(
695: categories.values());
696: // if (keys.size() == 1) {
697: // PlatformCategoriesDescriptor desc = (PlatformCategoriesDescriptor) keys.get(0);
698: // this.setKeys (desc.getPlatform());
699: // }
700: // else {
701: Collections.sort(keys);
702: setKeys(keys);
703: // }
704: }
705: }
706:
707: }
708:
709: private static class PlatformNodeComparator implements
710: Comparator<Node> {
711:
712: public int compare(Node n1, Node n2) {
713: return n1.getDisplayName().compareTo(n2.getDisplayName());
714: }
715: }
716:
717: }
|