1 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 ; 47 import java.util.ArrayList ; 48 import java.util.Collections ; 49 import java.util.Iterator ; 50 import java.util.List ; 51 import org.netbeans.modules.tasklist.core.TaskChildren; 52 import org.netbeans.modules.tasklist.core.SuggestionNodeProperty; 53 54 55 60 61 public class SuggestionNode extends TaskNode { 62 63 private TaskListView view; 65 66 67 public SuggestionNode(SuggestionImpl item) { 68 this(item, Children.LEAF); 69 } 70 71 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"); } 103 104 protected SystemAction[] createActions() { 105 ArrayList actions = new ArrayList (20); 106 if (item.getAction() != null) { 107 actions.add(SystemAction.get(FixAction.class)); 108 } 109 actions.add(SystemAction.get(ShowSuggestionAction.class)); 111 List typeActions = 112 ((SuggestionImpl)item).getSType().getActions(); 113 if ((typeActions != null) && (typeActions.size() > 0)) { 114 actions.add(null); 115 Iterator it = typeActions.iterator(); 116 while (it.hasNext()) { 117 actions.add(it.next()); 118 } 119 } 120 121 132 if ("nb-tasklist-scannedtask".equals(item.getType()) == false ) { 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 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 getCategoryLabel() { 173 return NbBundle.getMessage(SuggestionNode.class, "Category"); } 175 176 public boolean canRename() { 177 return false; 178 } 179 180 public boolean canDestroy() { 181 return false; 183 } 184 185 188 public boolean canCopy () { 189 return true; 190 } 191 192 195 public boolean canCut () { 196 return false; 198 } 199 200 201 protected void createPasteTypes(Transferable t, List s) { 202 } 203 204 205 211 public Node.Cookie getCookie(Class 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 |