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-2007 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.modules.cnd.makeproject.ui;
043:
044: import java.awt.Image;
045: import java.util.Collection;
046: import java.util.Collections;
047: import java.util.Vector;
048: import javax.swing.Action;
049: import javax.swing.event.ChangeEvent;
050: import javax.swing.event.ChangeListener;
051: import org.netbeans.api.project.Project;
052: import org.openide.actions.DeleteAction;
053: import org.openide.actions.PropertiesAction;
054: import org.openide.actions.RenameAction;
055: import org.openide.nodes.AbstractNode;
056: import org.openide.nodes.Children;
057: import org.openide.nodes.Node;
058: import org.openide.util.HelpCtx;
059: import org.openide.util.actions.SystemAction;
060: import org.openide.util.Utilities;
061: import org.openide.util.actions.NodeAction;
062: import org.netbeans.modules.cnd.makeproject.api.ui.LogicalViewNodeProvider;
063:
064: public class ExperimentsLogicalViewNodeProvider implements
065: LogicalViewNodeProvider {
066: public AbstractNode getLogicalViewNode(Project project) {
067: return new ExperimentsRootNode(project);
068: }
069: }
070:
071: class ExperimentsRootNode extends AbstractNode {
072: public ExperimentsRootNode(Project project) {
073: super (new ExperimentsRootNodeChildren(project));
074: setName("Experiments"); // NOI18N
075: setDisplayName("Experiments"); // NOI18N
076: }
077:
078: public Image getIcon(int type) {
079: return Utilities
080: .loadImage("org/netbeans/modules/cnd/makeproject/ui/resources/defaultFolder.gif"); // NOI18N
081: }
082:
083: public Image getOpenedIcon(int type) {
084: return Utilities
085: .loadImage("org/netbeans/modules/cnd/makeproject/ui/resources/defaultFolderOpen.gif"); // NOI18N
086: }
087:
088: public boolean canRename() {
089: return false;
090: }
091: }
092:
093: class ExperimentsRootNodeChildren extends Children.Keys implements
094: ChangeListener {
095: Project project;
096:
097: public ExperimentsRootNodeChildren(Project project) {
098: this .project = project;
099: }
100:
101: protected void addNotify() {
102: super .addNotify();
103: setKeys(getKeys());
104: }
105:
106: protected void removeNotify() {
107: setKeys(Collections.EMPTY_SET);
108: super .removeNotify();
109: }
110:
111: protected Node[] createNodes(Object key) {
112: Node node = null;
113: if (key instanceof ExperimentsGroupNode) {
114: node = (Node) key;
115: } else {
116: ; // FIXUP: error
117: }
118: return new Node[] { node };
119: }
120:
121: public void stateChanged(ChangeEvent e) {
122: setKeys(getKeys());
123: }
124:
125: private Collection getKeys() {
126: Vector v = new Vector();
127: v.add(new ExperimentsGroupNode(project, "Heap Tracing")); // NOI18N
128: v.add(new ExperimentsGroupNode(project, "Data Race Detection")); // NOI18N
129: v.add(new ExperimentsGroupNode(project, "Runtime Checking")); // NOI18N
130: return v;
131: }
132: }
133:
134: class ExperimentsGroupNode extends AbstractNode {
135: public ExperimentsGroupNode(Project project, String name) {
136: super (new ExperimentsGroupNodeChildren(project));
137: setName(name);
138: setDisplayName(name);
139: }
140:
141: public Image getIcon(int type) {
142: return Utilities
143: .loadImage("org/netbeans/modules/cnd/makeproject/ui/resources/defaultFolder.gif"); // NOI18N
144: }
145:
146: public Image getOpenedIcon(int type) {
147: return Utilities
148: .loadImage("org/netbeans/modules/cnd/makeproject/ui/resources/defaultFolderOpen.gif"); // NOI18N
149: }
150:
151: public boolean canRename() {
152: return false;
153: }
154:
155: public Action[] getActions(boolean context) {
156: return new Action[] { new ImportExperimentAction(), };
157: }
158: }
159:
160: class ExperimentsGroupNodeChildren extends Children.Keys implements
161: ChangeListener {
162: Project project;
163:
164: public ExperimentsGroupNodeChildren(Project project) {
165: this .project = project;
166: }
167:
168: protected void addNotify() {
169: super .addNotify();
170: setKeys(getKeys());
171: }
172:
173: protected void removeNotify() {
174: setKeys(Collections.EMPTY_SET);
175: super .removeNotify();
176: }
177:
178: protected Node[] createNodes(Object key) {
179: Node node = null;
180: if (key instanceof Experiment) {
181: node = (Node) key;
182: } else {
183: ; // FIXUP: error
184: }
185: return new Node[] { node };
186: }
187:
188: public void stateChanged(ChangeEvent e) {
189: setKeys(getKeys());
190: }
191:
192: private Collection getKeys() {
193: // FIXUP: add per project...
194: Vector v = new Vector();
195: v.add(new Experiment("Experiment-01212007-1422")); // NOI18N
196: v.add(new Experiment("Experiment-01212007-1427")); // NOI18N
197: v.add(new Experiment("Experiment-01212007-1532")); // NOI18N
198: return v;
199: }
200: }
201:
202: class Experiment extends AbstractNode {
203: public Experiment(String name) {
204: super (Children.LEAF);
205: setName(name);
206: setDisplayName(name);
207: }
208:
209: public Image getIcon(int type) {
210: return Utilities
211: .loadImage("org/netbeans/modules/cnd/makeproject/ui/resources/defaultFolder.gif"); // NOI18N
212: }
213:
214: public boolean canRename() {
215: return true;
216: }
217:
218: public boolean canDestroy() {
219: return true;
220: }
221:
222: public Action[] getActions(boolean context) {
223: return new Action[] { new OpenExperimentAction(),
224: SystemAction.get(DeleteAction.class),
225: SystemAction.get(RenameAction.class), null,
226: SystemAction.get(PropertiesAction.class), };
227: }
228: }
229:
230: class ImportExperimentAction extends DummyAction {
231: public ImportExperimentAction() {
232: super ("Import Experiment..."); // NOI18N
233: }
234: }
235:
236: class OpenExperimentAction extends DummyAction {
237: public OpenExperimentAction() {
238: super ("Open Experiment..."); // NOI18N
239: }
240: }
241:
242: class DummyAction extends NodeAction {
243: private String name;
244:
245: public DummyAction(String name) {
246: this .name = name;
247: }
248:
249: protected boolean enable(Node[] activatedNodes) {
250: return true;
251: }
252:
253: public String getName() {
254: return name;
255: }
256:
257: public void performAction(Node[] activatedNodes) {
258: ;//...
259: }
260:
261: public HelpCtx getHelpCtx() {
262: return null;
263: }
264:
265: protected boolean asynchronous() {
266: return false;
267: }
268: }
|