KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > ActionsPoolNode


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.core;
21
22 import java.awt.datatransfer.Transferable JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.openide.nodes.*;
26 import org.openide.actions.*;
27 import org.openide.loaders.DataFolder;
28 import org.openide.util.datatransfer.NewType;
29 import org.openide.util.actions.SystemAction;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32
33 /** The node for the actions pool folder representation.
34 * Delegates most of its functionality to the original data folder node.
35 * Final only for better performance, can be unfinaled.
36 *
37 * @author Ian Formanek
38 */

39 public final class ActionsPoolNode extends DataFolder.FolderNode {
40
41     /** Actions of this node when it is top level actions node */
42     static SystemAction[] topStaticActions;
43
44     private static final Node.PropertySet[] NO_PROPERTIES = new Node.PropertySet[0];
45
46     public ActionsPoolNode () {
47         this (NbPlaces.getDefault().actions ());
48     }
49
50     /** Constructs this node with given node to filter.
51     */

52     ActionsPoolNode (DataFolder folder) {
53         folder.super(new ActionsPoolChildren(folder));
54         //JST: it displays only Menu as name! super.setDisplayName(NbBundle.getBundle (ActionsPoolNode.class).getString("CTL_Actions_name"));
55
super.setShortDescription(NbBundle.getBundle (ActionsPoolNode.class).getString("CTL_Actions_hint"));
56
57         super.setIconBaseWithExtension ("org/netbeans/core/resources/actions.gif"); // NOI18N
58
}
59
60     public HelpCtx getHelpCtx () {
61         return new HelpCtx (ActionsPoolNode.class);
62     }
63
64     /** Support for new types that can be created in this node.
65     * @return array of new type operations that are allowed
66     */

67     public NewType[] getNewTypes () {
68         return new NewType[0];
69     }
70
71     protected void createPasteTypes (Transferable JavaDoc t, List JavaDoc s) {
72         s.clear ();
73     }
74
75     /** Actions.
76     * @return array of actions for this node
77     */

78     public SystemAction[] getActions () {
79         if (topStaticActions == null)
80             topStaticActions = new SystemAction [] {
81                                    SystemAction.get (FileSystemAction.class),
82                                    null,
83                                    SystemAction.get(ToolsAction.class),
84                                    SystemAction.get(PropertiesAction.class),
85                                };
86         return topStaticActions;
87     }
88
89     /** Creates properties for this node */
90     public Node.PropertySet[] getPropertySets () {
91         return NO_PROPERTIES;
92     }
93
94     public boolean canDestroy () {
95         return false;
96     }
97
98     public boolean canCut () {
99         return false;
100     }
101
102     public boolean canRename () {
103         return false;
104     }
105
106     /** Children for the ActionsPoolNode. Creates ActionsPoolNodes or
107     * ItemNodes as filter subnodes...
108     */

109     static final class ActionsPoolChildren extends FilterNode.Children {
110
111         /** @param or original node to take children from */
112         public ActionsPoolChildren (DataFolder folder) {
113             super(folder.getNodeDelegate ());
114         }
115
116         /** Overriden, returns ActionsPoolNode filters of original nodes.
117         *
118         * @param node node to create copy of
119         * @return ActionsPoolNode filter of the original node
120         */

121         protected Node copyNode (Node node) {
122             DataFolder df = (DataFolder)node.getCookie(DataFolder.class);
123             if (df != null) {
124                 return new ActionsPoolNode(df);
125             }
126             return new ActionItemNode(node);
127         }
128
129     }
130
131     static final class ActionItemNode extends FilterNode {
132
133         /** Actions which this node supports */
134         static SystemAction[] staticActions;
135
136         /** Constructs new filter node for Action item */
137         ActionItemNode (Node filter) {
138             super(filter, Children.LEAF);
139         }
140
141         /** Actions.
142         * @return array of actions for this node
143         */

144         public SystemAction[] getActions () {
145             if (staticActions == null) {
146                 staticActions = new SystemAction [] {
147                                     SystemAction.get(CopyAction.class),
148                                     null,
149                                     SystemAction.get(ToolsAction.class),
150                                     SystemAction.get(PropertiesAction.class),
151                                 };
152             }
153             return staticActions;
154         }
155
156         /** Disallows renaming.
157         */

158         public boolean canRename () {
159             return false;
160         }
161
162         public boolean canDestroy () {
163             return false;
164         }
165
166         public boolean canCut () {
167             return false;
168         }
169
170         /** Creates properties for this node */
171         public Node.PropertySet[] getPropertySets () {
172             /*
173             ResourceBundle bundle = NbBundle.getBundle(ActionsPoolNode.class);
174             // default sheet with "properties" property set // NOI18N
175             Sheet sheet = Sheet.createDefault();
176             sheet.get(Sheet.PROPERTIES).put(
177                 new PropertySupport.Name(
178                     this,
179                     bundle.getString("PROP_ActionItemName"),
180                     bundle.getString("HINT_ActionItemName")
181                 )
182             );
183             return sheet.toArray();
184              */

185             return new Node.PropertySet[] { };
186         }
187
188     } // end of ActionItemNode
189

190 }
191
Popular Tags