KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > UserTaskNode


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  * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.usertasks;
21
22 import java.awt.datatransfer.DataFlavor JavaDoc;
23 import java.awt.datatransfer.Transferable JavaDoc;
24 import java.awt.datatransfer.UnsupportedFlavorException JavaDoc;
25 import java.beans.PropertyChangeEvent JavaDoc;
26 import java.beans.PropertyChangeListener JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.lang.reflect.InvocationTargetException JavaDoc;
29 import java.net.MalformedURLException JavaDoc;
30 import java.net.URL JavaDoc;
31 import java.util.Date JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.logging.Level JavaDoc;
34
35 import javax.swing.Action JavaDoc;
36 import javax.swing.SwingUtilities JavaDoc;
37 import javax.swing.tree.TreePath JavaDoc;
38
39 import org.netbeans.modules.tasklist.core.TaskNode;
40 import org.netbeans.modules.tasklist.core.export.ExportAction;
41 import org.netbeans.modules.tasklist.core.export.ImportAction;
42 import org.netbeans.modules.tasklist.core.filter.FilterAction;
43 import org.netbeans.modules.tasklist.core.filter.RemoveFilterAction;
44 import org.netbeans.modules.tasklist.usertasks.actions.CollapseAllAction;
45 import org.netbeans.modules.tasklist.usertasks.actions.ExpandAllUserTasksAction;
46 import org.netbeans.modules.tasklist.usertasks.actions.GoToUserTaskAction;
47 import org.netbeans.modules.tasklist.usertasks.actions.PauseAction;
48 import org.netbeans.modules.tasklist.usertasks.actions.ScheduleAction;
49 import org.netbeans.modules.tasklist.usertasks.actions.StartTaskAction;
50 import org.netbeans.modules.tasklist.usertasks.editors.DateEditor;
51 import org.netbeans.modules.tasklist.usertasks.editors.DurationPropertyEditor;
52 import org.netbeans.modules.tasklist.usertasks.editors.PercentsPropertyEditor;
53 import org.netbeans.modules.tasklist.usertasks.editors.PriorityPropertyEditor;
54 import org.netbeans.modules.tasklist.usertasks.transfer.UserTasksTransferable;
55 import org.netbeans.modules.tasklist.usertasks.treetable.AdvancedTreeTableNode;
56 import org.netbeans.modules.tasklist.usertasks.util.UTUtils;
57 import org.openide.actions.CopyAction;
58 import org.openide.actions.CutAction;
59 import org.openide.actions.PasteAction;
60 import org.openide.nodes.AbstractNode;
61 import org.openide.nodes.Children;
62 import org.openide.nodes.PropertySupport;
63 import org.openide.nodes.Sheet;
64 import org.openide.nodes.Sheet.Set;
65 import org.openide.util.HelpCtx;
66 import org.openide.util.NbBundle;
67 import org.openide.util.actions.SystemAction;
68 import org.openide.util.datatransfer.ExTransferable;
69 import org.openide.util.datatransfer.MultiTransferObject;
70 import org.openide.util.datatransfer.PasteType;
71 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
72 import org.netbeans.modules.tasklist.usertasks.model.UserTaskList;
73 import org.openide.actions.DeleteAction;
74 import org.openide.nodes.Node;
75
76 /**
77  * Node for a user task
78  *
79  * @author tl
80  */

81 public final class UserTaskNode extends AbstractNode {
82     private UserTask item;
83     private UserTaskList utl;
84     private UserTaskTreeTableNode node;
85     private UserTasksTreeTable tt;
86     
87     /**
88      * Constructor
89      *
90      * @param node node in the tree associated with this one
91      * @param item an user task that will be represented by this node.
92      * @param utl user task list that this task belongs to. Should be != null
93      * for root tasks
94      * @param tt TreeTable
95      */

96     public UserTaskNode(UserTaskTreeTableNode node, UserTask item, UserTaskList utl,
97     UserTasksTreeTable tt) {
98         super(Children.LEAF);
99         assert item != null;
100         
101         this.utl = utl;
102         this.item = item;
103         this.node = node;
104         this.tt = tt;
105         
106         setName(item.getSummary());
107         
108         item.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
109             public void propertyChange(PropertyChangeEvent JavaDoc e) {
110                 String JavaDoc n = e.getPropertyName();
111                 if (n == UserTask.PROP_PROGRESS) { // NOI18N
112
int old = Math.round(((Float JavaDoc) e.getOldValue()).floatValue());
113                     int new_ = Math.round(((Float JavaDoc) e.getNewValue()).floatValue());
114                     UserTaskNode.this.firePropertyChange(
115                         "percentComplete", // NOI18N
116
new Integer JavaDoc(old), new Integer JavaDoc(new_));
117                 } else if (n == UserTask.PROP_LINE ||
118                         n == "started") { // NOI18N
119
// nothing
120
// TODO: strange property "started"??
121
} else {
122                     UserTaskNode.this.firePropertyChange(e.getPropertyName(),
123                         e.getOldValue(), e.getNewValue());
124                 }
125                 if (n == "started" || // NOI18N
126
n == UserTask.PROP_VALUES_COMPUTED ||
127                         n == UserTask.PROP_LINE) { // NOI18N
128
fireCookieChange();
129                 }
130             }
131         });
132     }
133
134     /**
135      * Returns the task associated with this node
136      * @return
137      */

138     public UserTask getTask() {
139         return item;
140     }
141     
142     public Action JavaDoc[] getActions(boolean empty) {
143         UserTaskView utv = (UserTaskView)
144                 SwingUtilities.getAncestorOfClass(UserTaskView.class, tt);
145         if (empty) {
146             return new Action JavaDoc[] {
147                 // TODO: SystemAction.get(NewTaskAction.class),
148
null,
149                 PauseAction.getInstance(),
150                 null,
151                 SystemAction.get(PasteAction.class),
152                 null,
153                 SystemAction.get(FilterAction.class),
154                 utv.purgeTasksAction,
155                 SystemAction.get(ScheduleAction.class),
156                 null,
157                 SystemAction.get(ExpandAllUserTasksAction.class),
158                 SystemAction.get(CollapseAllAction.class),
159                 null,
160                 SystemAction.get(ImportAction.class),
161                 SystemAction.get(ExportAction.class),
162             };
163         } else {
164             return new Action JavaDoc[] {
165                 utv.newTaskAction,
166                 //SystemAction.get(ShowScheduleViewAction.class),
167
null,
168                 new StartTaskAction(utv),
169                 PauseAction.getInstance(),
170                 null,
171                 utv.showTaskAction,
172                 new GoToUserTaskAction(utv),
173                 null,
174                 SystemAction.get(CutAction.class),
175                 SystemAction.get(CopyAction.class),
176                 SystemAction.get(PasteAction.class),
177                 null,
178                 SystemAction.get(DeleteAction.class),
179                 null,
180                 utv.moveUpAction,
181                 utv.moveDownAction,
182                 utv.moveLeftAction,
183                 utv.moveRightAction,
184                 null,
185                 SystemAction.get(FilterAction.class),
186                 SystemAction.get(RemoveFilterAction.class),
187                 null,
188                 utv.purgeTasksAction,
189                 utv.clearCompletedAction,
190                 SystemAction.get(ScheduleAction.class),
191                 null,
192                 SystemAction.get(ExpandAllUserTasksAction.class),
193                 SystemAction.get(CollapseAllAction.class),
194                 null,
195                 SystemAction.get(ImportAction.class),
196                 SystemAction.get(ExportAction.class),
197
198                 // Property: node specific, but by convention last in menu
199
null,
200                 utv.propertiesAction
201             };
202         }
203     }
204
205     protected Sheet createSheet() {
206         Sheet s = Sheet.createDefault();
207         Set ss = s.get(Sheet.PROPERTIES);
208
209         try {
210             PropertySupport.Reflection p;
211             p = new PropertySupport.Reflection(item, String JavaDoc.class, "getSummary", "setSummary"); // NOI18N
212
p.setName(UserTask.PROP_SUMMARY);
213             p.setDisplayName(NbBundle.getMessage(TaskNode.class, "Description")); // NOI18N
214
p.setShortDescription(NbBundle.getMessage(TaskNode.class, "DescriptionHint")); // NOI18N
215
ss.put(p);
216             
217             p = new PropertySupport.Reflection(item, Integer.TYPE, "getPriority", "setPriority"); // NOI18N
218
p.setName(UserTask.PROP_PRIORITY);
219             p.setPropertyEditorClass(PriorityPropertyEditor.class);
220             p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_priorityProperty")); // NOI18N
221
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_priorityProperty")); // NOI18N
222
ss.put(p);
223             
224             
225             p = new PropertySupport.Reflection(item, Boolean.TYPE, "isDone", "setDone"); // NOI18N
226
p.setName("done"); // NOI18N
227
p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_doneProperty")); // NOI18N
228
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_doneProperty")); // NOI18N
229
ss.put(p);
230             
231             p = new PropertySupport.Reflection(item, Integer.TYPE,
232                 "getPercentComplete", "setPercentComplete"); // NOI18N
233
p.setName("percentComplete"); // NOI18N
234
p.setPropertyEditorClass(PercentsPropertyEditor.class);
235             p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_percentCompleteProperty")); // NOI18N
236
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_percentCompleteProperty")); // NOI18N
237
ss.put(p);
238             
239             p = new PropertySupport.Reflection(item, Boolean.TYPE,
240                 "isValuesComputed", "setValuesComputed"); // NOI18N
241
p.setName("valuesComputed"); // NOI18N
242
p.setDisplayName(org.openide.util.NbBundle.getMessage(UserTaskNode.class, "LBL_valuesComputed")); // NOI18N
243
p.setShortDescription(org.openide.util.NbBundle.getMessage(UserTaskNode.class, "HNT_valuesComputed")); // NOI18N
244
ss.put(p);
245             
246             p = new PropertySupport.Reflection(item, Integer.TYPE, "getEffort", "setEffort"); // NOI18N
247
p.setName("effort"); // NOI18N
248
p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_effortProperty")); // NOI18N
249
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_effortProperty")); // NOI18N
250
p.setPropertyEditorClass(DurationPropertyEditor.class);
251             ss.put(p);
252
253             p = new PropertySupport.Reflection(item, Integer.TYPE, "getRemainingEffort", null); // NOI18N
254
p.setName("remainingEffort"); // NOI18N
255
p.setValue("canEditAsText", Boolean.FALSE); // NOI18N
256
p.setValue("suppressCustomEditor", Boolean.TRUE); // NOI18N
257
p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_remainingEffortProperty")); // NOI18N
258
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_remainingEffortProperty")); // NOI18N
259
p.setPropertyEditorClass(DurationPropertyEditor.class);
260             ss.put(p);
261
262             p = new PropertySupport.Reflection(item, Integer.TYPE, "getSpentTime", "setSpentTime"); // NOI18N
263
p.setName("spentTime"); // NOI18N
264
p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_spentTimeProperty")); // NOI18N
265
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_spentTimeProperty")); // NOI18N
266
p.setPropertyEditorClass(DurationPropertyEditor.class);
267             ss.put(p);
268
269             p = new PropertySupport.Reflection(item, Integer.TYPE, "getSpentTimeToday", null); // NOI18N
270
p.setName("spentTimeToday"); // NOI18N
271
p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_spentTimeTodayProperty")); // NOI18N
272
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_spentTimeTodayProperty")); // NOI18N
273
p.setPropertyEditorClass(DurationPropertyEditor.class);
274             ss.put(p);
275
276             p = new PropertySupport.Reflection(item, String JavaDoc.class, "getDetails", "setDetails"); // NOI18N
277
p.setName(UserTask.PROP_DETAILS);
278             p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_detailsProperty")); // NOI18N
279
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_detailsProperty")); // NOI18N
280
ss.put(p);
281             
282             p = new PropertySupport.Reflection(item, String JavaDoc.class, (String JavaDoc) null, null) { // NOI18N
283
public boolean canRead() {
284                     return true;
285                 }
286                 public boolean canWrite() {
287                     return true;
288                 }
289                 public Object JavaDoc getValue () throws
290                     IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
291                     URL JavaDoc url = ((UserTask) instance).getUrl();
292                     if (url == null)
293                         return ""; // NOI18N
294
else
295                         return url.toExternalForm();
296                 }
297                 public void setValue (Object JavaDoc val) throws
298                     IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
299                     try {
300                         URL JavaDoc url = new URL JavaDoc((String JavaDoc) val);
301                         ((UserTask) instance).setUrl(url);
302                     } catch (MalformedURLException JavaDoc e) {
303                         throw new IllegalArgumentException JavaDoc(e.getMessage());
304                     }
305                 }
306             };
307             p.setName(UserTask.PROP_URL);
308             p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_urlProperty")); // NOI18N
309
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_urlProperty")); // NOI18N
310
//p.setValue("suppressCustomEditor", Boolean.TRUE); // NOI18N
311
ss.put(p);
312
313             p = new PropertySupport.Reflection(item, Integer.TYPE, (String JavaDoc) null, null) { // NOI18N
314
public boolean canRead() {
315                     return true;
316                 }
317                 public boolean canWrite() {
318                     return true;
319                 }
320                 public Object JavaDoc getValue () throws
321                     IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
322                     return new Integer JavaDoc(((UserTask) instance).getLineNumber() + 1);
323                 }
324                 public void setValue (Object JavaDoc val) throws
325                     IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
326                     int n = ((Integer JavaDoc) val).intValue();
327                     if (n < 1)
328                         throw new IllegalArgumentException JavaDoc();
329                     ((UserTask) instance).setLineNumber(n - 1);
330                 }
331             };
332             p.setName(UserTask.PROP_LINE_NUMBER);
333             p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_lineProperty")); // NOI18N
334
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_lineProperty")); // NOI18N
335
ss.put(p);
336             
337             p = new PropertySupport.Reflection(item, String JavaDoc.class, "getCategory", "setCategory"); // NOI18N
338
p.setName(UserTask.PROP_CATEGORY);
339             p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_categoryProperty")); // NOI18N
340
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_categoryProperty")); // NOI18N
341
p.setValue("canEditAsText", Boolean.TRUE); // NOI18N
342
p.setValue("suppressCustomEditor", Boolean.TRUE); // NOI18N
343
ss.put(p);
344
345             p = new PropertySupport.Reflection(item, Date JavaDoc.class, "getCreatedDate", null); // NOI18N
346
p.setPropertyEditorClass(DateEditor.class);
347             p.setName("created"); // NOI18N
348
p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_createdProperty")); // NOI18N
349
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_createdProperty")); // NOI18N
350
p.setValue("suppressCustomEditor", Boolean.TRUE); // NOI18N
351
ss.put(p);
352
353             p = new PropertySupport.Reflection(item, Date JavaDoc.class, "getLastEditedDate", null); // NOI18N
354
p.setPropertyEditorClass(DateEditor.class);
355             p.setName("edited"); // NOI18N
356
p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_editedProperty")); // NOI18N
357
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_editedProperty")); // NOI18N
358
p.setValue("suppressCustomEditor", Boolean.TRUE); // NOI18N
359
ss.put(p);
360
361             p = new PropertySupport.Reflection(item, Date JavaDoc.class, "getCompletedDate", null); // NOI18N
362
p.setPropertyEditorClass(DateEditor.class);
363             p.setName("completedDate"); // NOI18N
364
p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_completedDateProperty")); // NOI18N
365
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_completedDateProperty")); // NOI18N
366
p.setValue("suppressCustomEditor", Boolean.TRUE); // NOI18N
367
ss.put(p);
368
369             p = new PropertySupport.Reflection(item, Date JavaDoc.class, "getDueDate", "setDueDate"); // NOI18N
370
p.setPropertyEditorClass(DateEditor.class);
371             p.setName(UserTask.PROP_DUE_DATE);
372             p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_dueDateProperty")); // NOI18N
373
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_dueDateProperty")); // NOI18N
374
ss.put(p);
375
376             p = new PropertySupport.Reflection(item, String JavaDoc.class, "getOwner", "setOwner"); // NOI18N
377
p.setName(UserTask.PROP_OWNER);
378             p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_ownerProperty")); // NOI18N
379
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_ownerProperty")); // NOI18N
380
ss.put(p);
381
382             p = new PropertySupport.Reflection(item, Date JavaDoc.class, "getStartDate", "setStartDate"); // NOI18N
383
p.setPropertyEditorClass(DateEditor.class);
384             p.setName(UserTask.PROP_START);
385             p.setDisplayName(NbBundle.getMessage(UserTaskNode.class, "LBL_startProperty")); // NOI18N
386
p.setShortDescription(NbBundle.getMessage(UserTaskNode.class, "HNT_startProperty")); // NOI18N
387
ss.put(p);
388         } catch (NoSuchMethodException JavaDoc nsme) {
389             UTUtils.LOGGER.log(Level.WARNING, "", nsme); // NOI18N
390
}
391         return s;
392     }
393
394     public boolean canDestroy() {
395         return true;
396     }
397
398     /** Can this node be copied?
399     * @return <code>true</code>
400     */

401     public boolean canCopy () {
402         return true;
403     }
404
405     /** Can this node be cut?
406     * @return <code>false</code>
407     */

408     public boolean canCut () {
409         return true;
410     }
411     
412     public javax.swing.Action JavaDoc getPreferredAction() {
413         return null; // TODO SystemAction.get(ShowTaskAction.class);
414
}
415     
416     public boolean canRename() {
417         return true;
418     }
419     
420     @SuppressWarnings JavaDoc("unchecked")
421     protected void createPasteTypes(java.awt.datatransfer.Transferable JavaDoc t,
422             List JavaDoc s) {
423         super.createPasteTypes(t, s);
424         PasteType p = createTodoPasteType(this, t);
425         if (p != null) {
426             s.add(p); // generates a warning
427
}
428     }
429
430     /**
431      * Create a paste type from a transferable.
432      *
433      * @param t the transferable to check
434      * @param target parent for the pasted task
435      * @return an appropriate paste type, or null if not appropriate
436      */

437     public static PasteType createTodoPasteType(
438     Node target, Transferable JavaDoc t) {
439         if (t.isDataFlavorSupported(ExTransferable.multiFlavor)) {
440             try {
441                 // Multiselection
442
final MultiTransferObject mto = (MultiTransferObject)
443                     t.getTransferData(ExTransferable.multiFlavor);
444                 if (mto.areDataFlavorsSupported(
445                     new DataFlavor JavaDoc[] {UserTasksTransferable.USER_TASKS_FLAVOR})) {
446                     return new UserTaskNode.TodoPaste(target, t);
447                 }
448             } catch (UnsupportedFlavorException JavaDoc e) {
449                 UTUtils.LOGGER.log(Level.WARNING, "", e); // NOI18N
450
} catch (IOException JavaDoc e) {
451                 UTUtils.LOGGER.log(Level.WARNING, "", e); // NOI18N
452
}
453         }
454         
455         if (t.isDataFlavorSupported(UserTasksTransferable.USER_TASKS_FLAVOR)) {
456             return new TodoPaste(target, t);
457         }
458         return null;
459     }
460
461     public org.openide.nodes.Node.Cookie getCookie(Class JavaDoc type) {
462         UserTask uitem = (UserTask) item;
463         if (type == UserTask.class) {
464             return item;
465         } else {
466             return super.getCookie(type);
467         }
468     }
469     
470     public void setName(String JavaDoc nue) {
471         super.setName(nue);
472         if (!nue.equals(item.getSummary())) {
473             item.setSummary(nue);
474         }
475     }
476     
477     public Transferable JavaDoc clipboardCopy() throws IOException JavaDoc {
478         final UserTask copy = (UserTask) item.clone();
479         return new ExTransferable.Single(UserTasksTransferable.USER_TASKS_FLAVOR) {
480             protected Object JavaDoc getData() {
481                 return copy;
482             }
483         };
484     }
485     
486     public Transferable JavaDoc clipboardCut() throws IOException JavaDoc {
487         destroy();
488         return clipboardCopy();
489     }
490
491     public void destroy() throws IOException JavaDoc {
492         AdvancedTreeTableNode n =
493             (AdvancedTreeTableNode) this.node.findNextNodeAfterDelete();
494         item.destroy();
495         if (item.getParent() != null)
496             item.getParent().getSubtasks().remove(item);
497         else
498             utl.getSubtasks().remove(item);
499         super.destroy();
500         if (n != null) {
501             TreePath JavaDoc tp = new TreePath JavaDoc(n.getPathToRoot());
502             tt.select(tp);
503             tt.scrollTo(tp);
504         }
505     }
506     
507     /**
508      * Performs "Paste" for the specified task on this node
509      *
510      * @param t task to be pasted
511      */

512     public void pasteTask(UserTask t) {
513         t = (UserTask) t.clone();
514         item.getSubtasks().add(t);
515         int index = this.node.getIndexOfObject(t);
516         if (index >= 0) {
517             AdvancedTreeTableNode n =
518                 (AdvancedTreeTableNode) this.node.getChildAt(index);
519             TreePath JavaDoc tp = new TreePath JavaDoc(n.getPathToRoot());
520             tt.expandAllPath(tp);
521             tt.select(tp);
522             tt.scrollTo(tp);
523         }
524     }
525     
526     /**
527      * Paste type for a pasted task
528      */

529     private static final class TodoPaste extends PasteType {
530         private final Transferable JavaDoc t;
531         private final Node target;
532         
533         /**
534          * Creates a paste type for a UserTask
535          *
536          * @param t a transferable object
537          * @param target parent for the pasted task
538          */

539         public TodoPaste(Node target, Transferable JavaDoc t) {
540             this.t = t;
541             this.target = target;
542         }
543         
544         public String JavaDoc getName() {
545             return NbBundle.getMessage(UserTasksTransferable.class,
546                 "LBL_todo_paste_as_subtask"); // NOI18N
547
}
548         
549         public HelpCtx getHelpCtx() {
550             return new HelpCtx("org.netbeans.modules.todo"); // NOI18N
551
}
552         
553         public Transferable JavaDoc paste() throws IOException JavaDoc {
554             try {
555                 if (t.isDataFlavorSupported(ExTransferable.multiFlavor)) {
556                     // Multiselection
557
final MultiTransferObject mto = (MultiTransferObject)
558                         t.getTransferData(ExTransferable.multiFlavor);
559                     if (mto.areDataFlavorsSupported(
560                         new DataFlavor JavaDoc[] {UserTasksTransferable.USER_TASKS_FLAVOR})) {
561                         for (int i = 0; i < mto.getCount(); i++) {
562                             UserTask item = (UserTask)
563                                 mto.getTransferData(i, UserTasksTransferable.USER_TASKS_FLAVOR);
564                             addTask(item);
565                         }
566                         return null;
567                     }
568                 }
569                 
570                 if (t.isDataFlavorSupported(UserTasksTransferable.USER_TASKS_FLAVOR)) {
571                     UserTask item =
572                         (UserTask) t.getTransferData(UserTasksTransferable.USER_TASKS_FLAVOR);
573                     addTask(item);
574                 }
575             } catch (UnsupportedFlavorException JavaDoc ufe) {
576                 // Should not happen.
577
IOException JavaDoc ioe = (IOException JavaDoc) new IOException JavaDoc(
578                         ufe.toString()).initCause(ufe);
579                 throw ioe;
580             }
581             return null;
582         }
583         
584         /**
585          * Adds a task
586          *
587          * @param item a task
588          */

589         private void addTask(UserTask item) {
590             UserTask ut;
591             if (item instanceof UserTask) {
592                 ut = (UserTask) item;
593             } else {
594                 ut = new UserTask(item.getSummary(), item.getList());
595                 ut.setDetails(item.getDetails());
596                 ut.setLine(item.getLine());
597                 ut.setPriority(item.getPriority());
598             }
599             ((UserTaskNode) target).pasteTask(ut);
600         }
601     }
602 }
603
604
Popular Tags