1 19 20 package org.netbeans.modules.tasklist.suggestions; 21 22 import java.awt.Image ; 23 import org.openide.filesystems.FileObject; 24 import org.openide.util.Utilities; 25 import org.netbeans.modules.tasklist.core.Task; 26 import org.netbeans.modules.tasklist.client.SuggestionPerformer; 27 import org.netbeans.modules.tasklist.client.SuggestionPriority; 28 import org.openide.loaders.DataObject; 29 import org.openide.nodes.Node; 30 import org.openide.text.Line; 31 import org.openide.text.DataEditorSupport; 32 33 35 40 public class SuggestionImpl extends Task implements Node.Cookie { 41 private Object seed = null; 42 private SuggestionType stype = null; 43 44 protected SuggestionImpl() { 45 } 46 47 50 public SuggestionImpl(FileObject fo, 51 String summary, SuggestionType stype, 52 SuggestionPerformer action, Object data) { 53 super(summary, null); 54 setFileObject(fo); 55 this.seed = data; 56 this.stype = stype; 57 setAction(action); 58 if (stype != null) { 59 setType(stype.getName()); 60 } 61 } 62 63 69 public String getFileBaseName() { 70 Line l = getLine(); 71 if (l != null) { 72 DataObject dobj = (DataObject) l.getLookup().lookup(DataObject.class); 73 if (dobj != null) { 74 return dobj.getPrimaryFile().getNameExt(); 75 } 76 } 77 return ""; 78 } 79 80 87 public int getLineNumber() { 88 Line l = getLine(); 89 if (l == null) { 90 return 0; 91 } else { 92 return l.getLineNumber()+1; 93 } 94 } 95 96 100 public static class Location implements Comparable { 101 public String filename; 102 public int line; 103 104 public Location(String filename, int line) { 105 this.filename = filename; 106 this.line = line; 107 } 108 109 public int compareTo(Object o) { 110 Location rhs = (Location)o; 111 int c1 = this.filename.compareTo(rhs.filename); 112 if (c1 != 0) return c1; 113 else return (this.line < rhs.line)? -1 : ((this.line == rhs.line)?0:1); 114 } 115 116 public String toString() { 117 return filename + ":" + (line+1); 118 } 119 } 120 121 122 public Location getLocation() { 123 Line l = getLine(); 124 if (l != null) { 125 DataObject dobj = (DataObject) l.getLookup().lookup(DataObject.class); 126 if (dobj != null) { 127 return new Location(dobj.getPrimaryFile().getPath(),l.getLineNumber()); 128 } 129 } 130 return null; 131 } 132 133 140 public String toString() { 141 return "SuggestionImpl#" + System.identityHashCode(this) + "[\"" + getSummary() + "\", " + getFileBaseName() + ":" + getLineNumber() + "]"; } 143 144 147 public Node [] createNode() { 148 if (hasSubtasks()) { 149 return new Node[] {new SuggestionNode(this, new SuggestionChildren(this))}; 150 } else { 151 return new Node[] {new SuggestionNode(this)}; 152 } 153 } 154 155 159 protected Object clone() { 160 SuggestionImpl t = new SuggestionImpl(); 161 t.copyFrom(this); 162 return t; 163 } 164 165 178 protected void copyFrom(SuggestionImpl from) { 179 super.copyFrom(from); 180 181 seed = from.seed; 182 stype = from.stype; 183 185 } 187 188 189 public String getCategory() { 190 if (stype != null) { 191 return stype.getLocalizedName(); 192 } else { 193 return ""; 194 } 195 } 196 197 198 public int getPriorityNumber() { 199 return getPriority().intValue(); 200 } 201 202 206 protected void setType(String type) { 207 super.setType(type); 208 } 209 210 public SuggestionType getSType() { 211 return stype; 212 } 213 214 void setSType(SuggestionType stype) { 215 this.stype = stype; 216 setType(stype.getName()); 217 } 218 219 public Image getIcon() { 220 if (super.getIcon() != null) { 221 return super.getIcon(); 222 } else if ((stype != null) && (stype.getIconImage() != null)) { 223 return stype.getIconImage(); 224 } else { 225 return null; 226 } 227 228 } 229 230 235 public Object getSeed() { 236 return seed; 237 } 238 239 245 public SuggestionPriority getPriority() { 246 if (seed == SuggestionList.CATEGORY_NODE_SEED) 247 return null; 248 else 249 return super.getPriority(); 250 } 251 252 269 270 public void setIcon(Image image) { 272 super.setIcon(image); 273 } 274 } 275 276 277 278 | Popular Tags |