KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > beanbrowser > MainNode


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.beanbrowser;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.LinkedList JavaDoc;
26 import java.util.List JavaDoc;
27 import javax.swing.Action JavaDoc;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileSystem;
30 import org.openide.filesystems.FileUtil;
31 import org.openide.filesystems.Repository;
32 import org.openide.loaders.DataObject;
33 import org.openide.loaders.DataObjectNotFoundException;
34 import org.openide.nodes.AbstractNode;
35 import org.openide.nodes.Children;
36 import org.openide.nodes.FilterNode;
37 import org.openide.nodes.Node;
38 import org.openide.util.HelpCtx;
39 import org.openide.windows.TopComponent;
40
41 /** Node to browse various important stuff. */
42 public class MainNode extends AbstractNode {
43     
44     public MainNode() {
45         super(new MainChildren());
46         setName("BeanBrowserMainNode");
47         setDisplayName("NetBeans Runtime");
48         setIconBaseWithExtension("org/netbeans/modules/apisupport/beanbrowser/BeanBrowserIcon.gif");
49         getCookieSet().add(new LookupNode.BbMarker());
50     }
51     
52     public Action JavaDoc[] getActions(boolean context) {
53         return new Action JavaDoc[0];
54     }
55     
56     public HelpCtx getHelpCtx() {
57         return new HelpCtx("org.netbeans.modules.apisupport.beanbrowser");
58     }
59     
60     public Node.Handle getHandle() {
61         return new MainNodeHandle();
62     }
63     private static final class MainNodeHandle implements Node.Handle {
64         private static final long serialVersionUID = 1L;
65         public Node getNode() throws IOException JavaDoc {
66             return new MainNode();
67         }
68     }
69     
70     // Key class: DataObject (for a folder to show), or LOOKUP_NODE, or REPOSITORY
71
private static class MainChildren extends Children.Keys {
72         
73         private static final Object JavaDoc LOOKUP_NODE = "lookupNode"; // NOI18N
74

75         protected void addNotify() {
76             refreshKeys();
77         }
78         
79         private void refreshKeys() {
80             List JavaDoc l = new LinkedList JavaDoc();
81             l.add(LOOKUP_NODE);
82             l.add(Repository.getDefault().getDefaultFileSystem());
83             File JavaDoc[] roots = File.listRoots();
84             if (roots != null) {
85                 for (int i = 0; i < roots.length; i++) {
86                     FileObject f = FileUtil.toFileObject(roots[i]);
87                     if (f != null) {
88                         l.add(f);
89                     }
90                 }
91             }
92             l.add(TopComponent.getRegistry());
93             setKeys(l);
94         }
95         
96         protected void removeNotify() {
97             setKeys(Collections.EMPTY_SET);
98         }
99         
100         protected Node[] createNodes(Object JavaDoc key) {
101             if (key == LOOKUP_NODE) {
102                 return new Node[] {LookupNode.globalLookupNode(), LookupNode.actionsGlobalContextLookupNode()};
103             } else if (key instanceof FileSystem) {
104                 Node orig;
105                 try {
106                     orig = DataObject.find(((FileSystem) key).getRoot()).getNodeDelegate();
107                 } catch (DataObjectNotFoundException e) {
108                     throw new AssertionError JavaDoc(e);
109                 }
110                 return new Node[] {Wrapper.make(new FilterNode(orig) {
111                     public String JavaDoc getDisplayName() {
112                         return "System FS (All Layers)";
113                     }
114                 })};
115             } else if (key instanceof FileObject) {
116                 final FileObject f = (FileObject) key;
117                 Node orig;
118                 try {
119                     orig = DataObject.find(f).getNodeDelegate();
120                 } catch (DataObjectNotFoundException e) {
121                     throw new AssertionError JavaDoc(e);
122                 }
123                 return new Node[] {Wrapper.make(new FilterNode(orig) {
124                     public String JavaDoc getDisplayName() {
125                         return FileUtil.getFileDisplayName(f);
126                     }
127                 })};
128             } else if (key instanceof TopComponent.Registry) {
129                 return new Node[] {new TopComponentsNode((TopComponent.Registry) key)};
130             } else {
131                 throw new AssertionError JavaDoc(key);
132             }
133         }
134         
135     }
136     
137 }
138
Popular Tags