1 19 20 package org.netbeans.core; 21 22 import org.netbeans.core.ui.LookupNode; 23 import org.openide.actions.PropertiesAction; 24 import org.openide.actions.ToolsAction; 25 import org.openide.loaders.DataFolder; 26 import org.openide.nodes.AbstractNode; 27 import org.openide.nodes.Children; 28 import org.openide.nodes.Node; 29 import org.openide.util.HelpCtx; 30 import org.openide.util.Mutex; 31 import org.openide.util.NbBundle; 32 import org.openide.util.actions.SystemAction; 33 34 40 final class EnvironmentNode extends AbstractNode { 41 42 static final long serialVersionUID = 4782447107972624693L; 43 44 private String filter; 45 46 private static final String EN_ICON_BASE = "org/netbeans/core/resources/"; 48 private static java.util.HashMap <String , Node> types = new java.util.HashMap <String , Node> (11); 49 50 private static final Object lock = new Object (); 51 52 53 public static final String TYPE_ROOTS = "roots"; 55 public static final String TYPE_ENVIRONMENT = "environment"; 57 public static final String TYPE_SESSION = "session"; 59 60 private EnvironmentNode (String filter, Children children) { 61 super (children); 62 this.filter = filter; 63 decorateNode(filter, this); 64 } 65 66 67 69 public static Node find (final String name) { 70 Node retValue = 72 Children.MUTEX.readAccess(new Mutex.Action<Node>() { 73 public Node run() { 74 synchronized (lock) { 75 Node n = types.get (name); 76 if (n == null) { 77 DataFolder folder = null; 78 if (TYPE_ENVIRONMENT.equals(name)) { 79 folder = NbPlaces.getDefault().findSessionFolder("UI/Runtime"); } else if (TYPE_ROOTS.equals(name)) { 81 folder = NbPlaces.getDefault().findSessionFolder("UI/Roots"); 82 } else { 83 assert TYPE_SESSION.equals(name) : name; 84 folder = NbPlaces.getDefault().findSessionFolder("UI/Services"); } 86 87 n = new PersistentLookupNode(name, folder); 88 types.put (name, n); 89 } 90 return n; 91 } 92 } 93 }); 94 if (retValue != null) { 95 return retValue; 96 } 97 throw new IllegalStateException (); 98 } 99 100 private static void decorateNode (String name, AbstractNode node) { 101 String resourceName = "CTL_" + name + "_name"; String iconBase = EN_ICON_BASE + name.toLowerCase () + ".gif"; 103 104 node.setDisplayName(NbBundle.getMessage (EnvironmentNode.class, resourceName)); 105 node.setIconBaseWithExtension(iconBase); 106 } 107 108 109 public HelpCtx getHelpCtx () { 110 return new HelpCtx (EnvironmentNode.class); 111 } 112 113 120 public SystemAction[] createActions () { 121 return new SystemAction[] { 122 SystemAction.get(ToolsAction.class), 123 SystemAction.get(PropertiesAction.class) 124 }; 125 } 126 127 128 public Node.Handle getHandle () { 129 return new EnvironmentHandle (filter); 130 } 131 132 133 private static final class PersistentLookupNode extends LookupNode 134 implements java.beans.PropertyChangeListener { 135 136 private String filter; 137 138 public PersistentLookupNode (String filter, DataFolder folder) { 139 super(folder); 140 this.filter = filter; 141 142 if (TYPE_ROOTS.equals(filter)) { 143 folder.addPropertyChangeListener( 144 org.openide.util.WeakListeners.propertyChange(this, folder)); 145 } 146 } 147 148 public Node.Handle getHandle () { 149 return new EnvironmentHandle (filter); 150 } 151 152 153 public void propertyChange(java.beans.PropertyChangeEvent evt) { 154 if(DataFolder.PROP_CHILDREN.equals(evt.getPropertyName())) { 155 NbPlaces.getDefault().fireChange(); 156 } 157 } 158 } 160 static final class EnvironmentHandle implements Node.Handle { 161 static final long serialVersionUID =-850350968366553370L; 162 163 164 private String filter; 165 166 167 public EnvironmentHandle (String filter) { 168 this.filter = filter; 169 } 170 public Node getNode () { 171 String f = filter; 172 if (f == null) { 173 f = TYPE_ENVIRONMENT; 175 } 176 177 return find (f); 178 } 179 } 180 } 181 | Popular Tags |