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.core;
043:
044: import java.awt.datatransfer.Transferable;
045: import java.util.List;
046:
047: import org.openide.nodes.*;
048: import org.openide.actions.*;
049: import org.openide.loaders.DataFolder;
050: import org.openide.util.datatransfer.NewType;
051: import org.openide.util.actions.SystemAction;
052: import org.openide.util.HelpCtx;
053: import org.openide.util.NbBundle;
054:
055: /** The node for the actions pool folder representation.
056: * Delegates most of its functionality to the original data folder node.
057: * Final only for better performance, can be unfinaled.
058: *
059: * @author Ian Formanek
060: */
061: public final class ActionsPoolNode extends DataFolder.FolderNode {
062:
063: /** Actions of this node when it is top level actions node */
064: static SystemAction[] topStaticActions;
065:
066: private static final Node.PropertySet[] NO_PROPERTIES = new Node.PropertySet[0];
067:
068: public ActionsPoolNode() {
069: this (NbPlaces.getDefault().actions());
070: }
071:
072: /** Constructs this node with given node to filter.
073: */
074: ActionsPoolNode(DataFolder folder) {
075: folder.super (new ActionsPoolChildren(folder));
076: //JST: it displays only Menu as name! super.setDisplayName(NbBundle.getBundle (ActionsPoolNode.class).getString("CTL_Actions_name"));
077: super .setShortDescription(NbBundle.getBundle(
078: ActionsPoolNode.class).getString("CTL_Actions_hint"));
079:
080: super
081: .setIconBaseWithExtension("org/netbeans/core/resources/actions.gif"); // NOI18N
082: }
083:
084: public HelpCtx getHelpCtx() {
085: return new HelpCtx(ActionsPoolNode.class);
086: }
087:
088: /** Support for new types that can be created in this node.
089: * @return array of new type operations that are allowed
090: */
091: public NewType[] getNewTypes() {
092: return new NewType[0];
093: }
094:
095: protected void createPasteTypes(Transferable t, List s) {
096: s.clear();
097: }
098:
099: /** Actions.
100: * @return array of actions for this node
101: */
102: public SystemAction[] getActions() {
103: if (topStaticActions == null)
104: topStaticActions = new SystemAction[] {
105: SystemAction.get(FileSystemAction.class), null,
106: SystemAction.get(ToolsAction.class),
107: SystemAction.get(PropertiesAction.class), };
108: return topStaticActions;
109: }
110:
111: /** Creates properties for this node */
112: public Node.PropertySet[] getPropertySets() {
113: return NO_PROPERTIES;
114: }
115:
116: public boolean canDestroy() {
117: return false;
118: }
119:
120: public boolean canCut() {
121: return false;
122: }
123:
124: public boolean canRename() {
125: return false;
126: }
127:
128: /** Children for the ActionsPoolNode. Creates ActionsPoolNodes or
129: * ItemNodes as filter subnodes...
130: */
131: static final class ActionsPoolChildren extends FilterNode.Children {
132:
133: /** @param or original node to take children from */
134: public ActionsPoolChildren(DataFolder folder) {
135: super (folder.getNodeDelegate());
136: }
137:
138: /** Overriden, returns ActionsPoolNode filters of original nodes.
139: *
140: * @param node node to create copy of
141: * @return ActionsPoolNode filter of the original node
142: */
143: protected Node copyNode(Node node) {
144: DataFolder df = (DataFolder) node
145: .getCookie(DataFolder.class);
146: if (df != null) {
147: return new ActionsPoolNode(df);
148: }
149: return new ActionItemNode(node);
150: }
151:
152: }
153:
154: static final class ActionItemNode extends FilterNode {
155:
156: /** Actions which this node supports */
157: static SystemAction[] staticActions;
158:
159: /** Constructs new filter node for Action item */
160: ActionItemNode(Node filter) {
161: super (filter, Children.LEAF);
162: }
163:
164: /** Actions.
165: * @return array of actions for this node
166: */
167: public SystemAction[] getActions() {
168: if (staticActions == null) {
169: staticActions = new SystemAction[] {
170: SystemAction.get(CopyAction.class), null,
171: SystemAction.get(ToolsAction.class),
172: SystemAction.get(PropertiesAction.class), };
173: }
174: return staticActions;
175: }
176:
177: /** Disallows renaming.
178: */
179: public boolean canRename() {
180: return false;
181: }
182:
183: public boolean canDestroy() {
184: return false;
185: }
186:
187: public boolean canCut() {
188: return false;
189: }
190:
191: /** Creates properties for this node */
192: public Node.PropertySet[] getPropertySets() {
193: /*
194: ResourceBundle bundle = NbBundle.getBundle(ActionsPoolNode.class);
195: // default sheet with "properties" property set // NOI18N
196: Sheet sheet = Sheet.createDefault();
197: sheet.get(Sheet.PROPERTIES).put(
198: new PropertySupport.Name(
199: this,
200: bundle.getString("PROP_ActionItemName"),
201: bundle.getString("HINT_ActionItemName")
202: )
203: );
204: return sheet.toArray();
205: */
206: return new Node.PropertySet[] {};
207: }
208:
209: } // end of ActionItemNode
210:
211: }
|