KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.netbeans.modules.tasklist.usertasks;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Comparator JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7 import org.netbeans.modules.tasklist.usertasks.model.Dependency;
8
9 import org.netbeans.modules.tasklist.usertasks.treetable.AdvancedTreeTableNode;
10 import org.netbeans.modules.tasklist.usertasks.treetable.FilterIntf;
11 import org.netbeans.modules.tasklist.usertasks.treetable.TreeTableNode;
12 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
13
14 /**
15  * Task node
16  */

17 public class UTDependenciesTreeTableNode extends UserTaskTreeTableNode {
18     /**
19      * Filters a task.
20      *
21      * @return true if the filter accepts <code>ut</code> or one of
22      * it's subtasks
23      */

24     public static boolean acceptsRecursivelyDep(UserTask ut, FilterIntf filter) {
25         if (filter.accept(ut))
26             return true;
27         Iterator JavaDoc it = ut.getDependencies().iterator();
28         while (it.hasNext()) {
29             Dependency child = (Dependency) it.next();
30             if (acceptsRecursivelyDep(child.getDependsOn(), filter))
31                 return true;
32         }
33         return false;
34     }
35     
36     /**
37      * Creates a new instance of UserTaskTreeTableNode
38      *
39      * @param filter filter to be used or null
40      * @param ut a user task
41      * @param m model for this node
42      * @param comparator comparator to be used or null
43      */

44     public UTDependenciesTreeTableNode(
45     TreeTableNode parent, FilterIntf filter,
46             UserTasksTreeTableModel m, UserTask ut,
47             Comparator JavaDoc<AdvancedTreeTableNode> comparator) {
48         super(parent, filter, m, ut, comparator);
49         
50         /*this.filter = filter;
51         this.comparator = comparator;
52         pcl = new PropertyChangeListener() {
53             public void propertyChange(PropertyChangeEvent evt) {
54                 fireObjectChanged();
55             }
56         };
57         ut.addPropertyChangeListener(pcl);*/

58         /* TODO: add listener tl = new ObjectList.Listener() {
59             public void listChanged(ObjectList.Event e) {
60                 switch (e.getType()) {
61                     case ObjectList.Event.EVENT_ADDED: {
62                         Object[] obj = e.getObjects();
63                         for (int i = 0; i < obj.length; i++) {
64                             fireChildObjectAdded(obj[i]);
65                         }
66                         break;
67                     }
68                     case ObjectList.Event.EVENT_REMOVED: {
69                         Object[] obj = e.getObjects();
70                         for (int i = 0; i < obj.length; i++) {
71                             fireChildObjectRemoved(obj[i]);
72                         }
73                         break;
74                     }
75                     case ObjectList.Event.EVENT_REORDERED:
76                         fireChildObjectsReordered();
77                         break;
78                     case ObjectList.Event.EVENT_STRUCTURE_CHANGED:
79                         refreshChildren();
80                         break;
81                     default:
82                         throw new InternalError("unexpected event type"); // NOI18N
83                 }
84             }
85         };
86         ut.getSubtasks().addListener(tl);*/

87     }
88     
89     public boolean isLeaf() {
90         return getUserTask().getDependencies().isEmpty();
91     }
92     
93     /* TODO: remove registered listeners public void destroy() {
94         super.destroy();
95         getUserTask().getSubtasks().removeListener(tl);
96         getUserTask().removePropertyChangeListener(pcl);
97     } */

98     
99     public Iterator JavaDoc getChildrenObjectsIterator() {
100         List JavaDoc<UserTask> tasks = new ArrayList JavaDoc<UserTask>(
101                 getUserTask().getDependencies().size());
102         for (int i = 0; i < getUserTask().getDependencies().size(); i++) {
103             Dependency d = (Dependency) getUserTask().getDependencies().get(i);
104             tasks.add(d.getDependsOn());
105         }
106         return tasks.iterator();
107     }
108     
109     public UTDependenciesTreeTableNode createChildNode(Object JavaDoc child) {
110         UTDependenciesTreeTableNode n = new UTDependenciesTreeTableNode(
111             this, filter, (UserTasksTreeTableModel) model,
112             (UserTask) child, comparator);
113         if (getFilter() != null && !getFilter().accept(child))
114             n.unmatched = true;
115         return n;
116     }
117     
118     public boolean accept(Object JavaDoc child) {
119         if (getFilter() == null)
120             return true;
121         
122         return acceptsRecursivelyDep((UserTask) child, getFilter());
123     }
124 }
125
Popular Tags