KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > suggestions > SuggestionNode


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.modules.tasklist.suggestions;
21
22 import org.netbeans.modules.tasklist.client.Suggestion;
23 import org.netbeans.modules.tasklist.client.SuggestionPriority;
24 import org.netbeans.modules.tasklist.core.Task;
25 import org.netbeans.modules.tasklist.core.TaskListView;
26 import org.netbeans.modules.tasklist.core.TaskNode;
27 import org.netbeans.modules.tasklist.core.editors.LocationPropertyEditor;
28 import org.netbeans.modules.tasklist.core.editors.PriorityPropertyEditor;
29 import org.netbeans.modules.tasklist.core.editors.StringPropertyEditor;
30 import org.netbeans.modules.tasklist.core.filter.FilterAction;
31 import org.openide.ErrorManager;
32 import org.openide.actions.PropertiesAction;
33 import org.openide.loaders.DataObject;
34 import org.openide.nodes.Node;
35 import org.openide.nodes.PropertySupport;
36 import org.openide.nodes.PropertySupport.Reflection;
37 import org.openide.nodes.Sheet;
38 import org.openide.nodes.Sheet.Set;
39 import org.openide.text.DataEditorSupport;
40 import org.openide.text.Line;
41 import org.openide.util.NbBundle;
42 import org.openide.util.actions.SystemAction;
43
44 import javax.swing.*;
45 import org.openide.nodes.Children;
46 import java.awt.datatransfer.Transferable JavaDoc;
47 import java.util.ArrayList JavaDoc;
48 import java.util.Collections JavaDoc;
49 import java.util.Iterator JavaDoc;
50 import java.util.List JavaDoc;
51 import org.netbeans.modules.tasklist.core.TaskChildren;
52 import org.netbeans.modules.tasklist.core.SuggestionNodeProperty;
53
54
55 /**
56  * A node in the Suggestions View, representing a Suggestion
57  *
58  * @author Tor Norbye
59  */

60
61 public class SuggestionNode extends TaskNode {
62
63     // the node is displayed in given view
64
private TaskListView view;
65
66
67     public SuggestionNode(SuggestionImpl item) {
68       this(item, Children.LEAF);
69     }
70
71     /**
72      * @param subtasks show subtasks as children ?
73      */

74     protected SuggestionNode(SuggestionImpl item, Children children) {
75         super(item, children);
76     }
77
78     public Action getPreferredAction() {
79         if (item.getAction() == null) {
80             return SystemAction.get(ShowSuggestionAction.class);
81         } else {
82             return SystemAction.get(FixAction.class);
83         }
84     }
85
86
87     public Node cloneNode () {
88       SuggestionNode clon = new SuggestionNode((SuggestionImpl)this.item);
89       if (!clon.isLeaf())
90     clon.setChildren((Children)getTaskChildren().clone());
91       return clon;
92     }
93
94     protected TaskChildren createChildren() {
95       return new SuggestionChildren((SuggestionImpl)this.item);
96     }
97
98
99
100     protected void updateIcon() {
101         setIconBase("org/netbeans/modules/tasklist/suggestions/suggTask"); // NOI18N
102
}
103     
104     protected SystemAction[] createActions() {
105         ArrayList JavaDoc actions = new ArrayList JavaDoc(20);
106         if (item.getAction() != null) {
107             actions.add(SystemAction.get(FixAction.class));
108         }
109         //actions.add(SystemAction.get(GoToTaskAction.class);
110
actions.add(SystemAction.get(ShowSuggestionAction.class));
111         List JavaDoc typeActions =
112             ((SuggestionImpl)item).getSType().getActions();
113         if ((typeActions != null) && (typeActions.size() > 0)) {
114             actions.add(null);
115             Iterator JavaDoc it = typeActions.iterator();
116             while (it.hasNext()) {
117                 actions.add(it.next());
118             }
119         }
120
121         // "Global" (not node specific) actions moved to toolbar
122
// actions.add(null);
123
// actions.add(SystemAction.get(ShowCategoryAction.class));
124
// actions.add(SystemAction.get(EditTypesAction.class));
125
// actions.add(SystemAction.get(DisableAction.class));
126
// actions.add(null);
127
// actions.add(SystemAction.get(FilterAction.class));
128
// actions.add(SystemAction.get(ExpandAllAction.class));
129
// actions.add(null);
130
// actions.add(SystemAction.get(ExportAction.class));
131

132         // Property: node specific, but by convention last in menu
133
// #38642 do not show for TODOs, its confusing XXX
134
if ("nb-tasklist-scannedtask".equals(item.getType()) == false ) { // NOI18N
135
actions.add(null);
136             actions.add(SystemAction.get(PropertiesAction.class));
137         }
138
139         return (SystemAction[])actions.toArray(
140              new SystemAction[actions.size()]);
141     }
142
143     public Action[] getActions(boolean empty) {
144         if (empty) {
145             return new SystemAction[] {
146                 SystemAction.get(FilterAction.class),
147                 SystemAction.get(EditTypesAction.class)
148             };
149         } else {
150             return super.getActions(false);
151         }
152     }
153
154     /** Creates properties.
155      */

156     protected Sheet createSheet() {
157         Sheet s = Sheet.createDefault();
158         Set ss = s.get(Sheet.PROPERTIES);
159         
160
161     ss.put(new SuggestionNodeProperty(item, SuggestionImplProperties.PROP_SUMMARY));
162     ss.put(new SuggestionNodeProperty(item, SuggestionImplProperties.PROP_DETAILS));
163     ss.put(new SuggestionNodeProperty(item, SuggestionImplProperties.PROP_PRIORITY, PriorityPropertyEditor.class));
164     ss.put(new SuggestionNodeProperty(item, SuggestionImplProperties.PROP_FILENAME, StringPropertyEditor.class));
165     ss.put(new SuggestionNodeProperty(item, SuggestionImplProperties.PROP_LINE_NUMBER, StringPropertyEditor.class));
166     ss.put(new SuggestionNodeProperty(item, SuggestionImplProperties.PROP_CATEGORY));
167     ss.put(new SuggestionNodeProperty(item, SuggestionImplProperties.PROP_LOCATION, LocationPropertyEditor.class));
168
169         return s;
170     }
171
172     static String JavaDoc getCategoryLabel() {
173         return NbBundle.getMessage(SuggestionNode.class, "Category"); // NOI18N
174
}
175     
176     public boolean canRename() {
177         return false;
178     }
179
180     public boolean canDestroy() {
181         // No point since it gets recreated after every edit
182
return false;
183     }
184
185     /** Can this node be copied?
186     * @return <code>true</code>
187     */

188     public boolean canCopy () {
189         return true;
190     }
191
192     /** Can this node be cut?
193     * @return <code>false</code>
194     */

195     public boolean canCut () {
196         // No point since it gets recreated after every edit
197
return false;
198     }
199
200     /** Don't allow pastes */
201     protected void createPasteTypes(Transferable JavaDoc t, List JavaDoc s) {
202     }
203
204
205     /** Get a cookie. Call super first, but if null, also
206      * check the data object associated with the line number
207      * if any.
208      * @todo Should this be done in TaskNode (for all tasklist
209      * tasks) or just here?
210      */

211     public Node.Cookie getCookie(Class JavaDoc cl) {
212         Node.Cookie c = super.getCookie(cl);
213         if (c != null) {
214             return c;
215         }
216         if (cl.isAssignableFrom(Suggestion.class)) {
217             return (SuggestionImpl)item;
218         }
219         Line l = item.getLine();
220         if (l != null) {
221             DataObject dao = DataEditorSupport.findDataObject(l);
222             if (dao != null)
223                 return dao.getCookie(cl);
224             else
225                 return null;
226         }
227         return null;
228     }
229 }
230
231
Popular Tags