1 19 20 package org.netbeans.modules.apisupport.beanbrowser; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.Collections ; 25 import java.util.LinkedList ; 26 import java.util.List ; 27 import javax.swing.Action ; 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 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 [] getActions(boolean context) { 53 return new Action [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 { 66 return new MainNode(); 67 } 68 } 69 70 private static class MainChildren extends Children.Keys { 72 73 private static final Object LOOKUP_NODE = "lookupNode"; 75 protected void addNotify() { 76 refreshKeys(); 77 } 78 79 private void refreshKeys() { 80 List l = new LinkedList (); 81 l.add(LOOKUP_NODE); 82 l.add(Repository.getDefault().getDefaultFileSystem()); 83 File [] 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 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 (e); 109 } 110 return new Node[] {Wrapper.make(new FilterNode(orig) { 111 public String 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 (e); 122 } 123 return new Node[] {Wrapper.make(new FilterNode(orig) { 124 public String 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 (key); 132 } 133 } 134 135 } 136 137 } 138 | Popular Tags |