KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.netbeans.modules.tasklist.usertasks;
2
3 import java.beans.PropertyChangeEvent JavaDoc;
4 import java.beans.PropertyChangeListener JavaDoc;
5 import java.net.URL JavaDoc;
6 import java.util.Comparator JavaDoc;
7 import java.util.Date JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import javax.swing.SwingConstants JavaDoc;
10 import javax.swing.SwingUtilities JavaDoc;
11 import org.netbeans.modules.tasklist.usertasks.treetable.AdvancedTreeTableNode;
12 import org.netbeans.modules.tasklist.usertasks.treetable.FilterIntf;
13 import org.netbeans.modules.tasklist.usertasks.treetable.TreeTableNode;
14 import org.netbeans.modules.tasklist.core.util.ObjectList;
15 import org.netbeans.modules.tasklist.core.util.ObjectListEvent;
16 import org.netbeans.modules.tasklist.core.util.ObjectListListener;
17 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
18
19 /**
20  * Task node
21  *
22  * @author tl
23  */

24 public class UserTaskTreeTableNode extends AdvancedTreeTableNode<UserTask> {
25     /**
26      * Filters a task.
27      *
28      * @return true if the filter accepts <code>ut</code> or one of
29      * it's subtasks
30      */

31     public static boolean acceptsRecursively(UserTask ut, FilterIntf filter) {
32         if (filter.accept(ut))
33             return true;
34         Iterator JavaDoc it = ut.getSubtasks().iterator();
35         while (it.hasNext()) {
36             UserTask child = (UserTask) it.next();
37             if (acceptsRecursively(child, filter))
38                 return true;
39         }
40         return false;
41     }
42     
43     protected boolean unmatched;
44     protected ObjectListListener tl;
45     protected PropertyChangeListener JavaDoc pcl;
46     
47     /**
48      * Creates a new instance of UserTaskTreeTableNode
49      *
50      * @param filter filter to be used or null
51      * @param ut a user task
52      * @param m model for this node
53      * @param comparator comparator to be used or null
54      */

55     public UserTaskTreeTableNode(
56     TreeTableNode parent, FilterIntf filter,
57     UserTasksTreeTableModel m, UserTask ut,
58             Comparator JavaDoc<AdvancedTreeTableNode> comparator) {
59         super(m, parent, ut);
60         
61         this.filter = filter;
62         this.comparator = comparator;
63         pcl = new PropertyChangeListener JavaDoc() {
64             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
65                 SwingUtilities.invokeLater(new Runnable JavaDoc() {
66                     public void run() {
67                         fireObjectChanged();
68                     }
69                 });
70             }
71         };
72         ut.addPropertyChangeListener(pcl);
73         tl = new ObjectListListener() {
74             public void listChanged(ObjectListEvent e) {
75                 switch (e.getType()) {
76                     case ObjectListEvent.EVENT_ADDED: {
77                         Object JavaDoc[] obj = e.getObjects();
78                         for (int i = 0; i < obj.length; i++) {
79                             fireChildObjectAdded(obj[i]);
80                         }
81                         break;
82                     }
83                     case ObjectListEvent.EVENT_REMOVED: {
84                         Object JavaDoc[] obj = e.getObjects();
85                         for (int i = 0; i < obj.length; i++) {
86                             fireChildObjectRemoved(obj[i]);
87                         }
88                         break;
89                     }
90                     case ObjectListEvent.EVENT_REORDERED:
91                         fireChildObjectsReordered();
92                         break;
93                     case ObjectListEvent.EVENT_STRUCTURE_CHANGED:
94                         refreshChildren();
95                         break;
96                     default:
97                         throw new InternalError JavaDoc("unexpected event type"); // NOI18N
98
}
99             }
100         };
101         ut.getSubtasks().addListener(tl);
102     }
103     
104     /**
105      * Returns true if the filter does not accept this node but accepts
106      * some of the children
107      *
108      * @return true = unmatched
109      */

110     public boolean isUnmatched() {
111         return unmatched;
112     }
113     
114     /**
115      * Sets the unmatched attribute
116      *
117      * @param unmatched true = the filter does not accept this node but
118      * some of it's subnodes
119      */

120     public void setUnmatched(boolean unmatched) {
121         this.unmatched = unmatched;
122     }
123     
124     /**
125      * Returns user task associated with this node
126      *
127      * @return user task
128      */

129     public UserTask getUserTask() {
130         return (UserTask) object;
131     }
132     
133     public Object JavaDoc getValueAt(int column) {
134         UserTask ut = getUserTask();
135         switch (column) {
136             case UserTasksTreeTableModel.SUMMARY:
137                 return ut.getSummary();
138             case UserTasksTreeTableModel.PRIORITY:
139                 return new Integer JavaDoc(ut.getPriority());
140             case UserTasksTreeTableModel.DONE:
141                 return Boolean.valueOf(ut.isDone());
142             case UserTasksTreeTableModel.PERCENT_COMPLETE:
143                 return new Integer JavaDoc(ut.getPercentComplete());
144             case UserTasksTreeTableModel.EFFORT:
145                 return ut;
146             case UserTasksTreeTableModel.REMAINING_EFFORT:
147                 return new Integer JavaDoc(ut.getRemainingEffort());
148             case UserTasksTreeTableModel.SPENT_TIME:
149                 return new Integer JavaDoc(ut.getSpentTime());
150             case UserTasksTreeTableModel.DETAILS:
151                 return ut.getDetails();
152             case UserTasksTreeTableModel.FILE_BASE_NAME:
153                 URL JavaDoc url = ut.getUrl();
154                 if (url == null)
155                     return ""; // NOI18N
156
else
157                     return url.toExternalForm();
158             case UserTasksTreeTableModel.LINE_NUMBER:
159                 return new Integer JavaDoc(ut.getLineNumber() + 1);
160             case UserTasksTreeTableModel.CATEGORY:
161                 return ut;
162             case UserTasksTreeTableModel.CREATED:
163                 return new Long JavaDoc(ut.getCreatedDate());
164             case UserTasksTreeTableModel.LAST_EDITED:
165                 return new Long JavaDoc(ut.getLastEditedDate());
166             case UserTasksTreeTableModel.COMPLETED_DATE:
167                 return new Long JavaDoc(ut.getCompletedDate());
168             case UserTasksTreeTableModel.DUE_DATE:
169                 if (ut.getDueDate() == null)
170                     return null;
171                 else
172                     return ut.getDueDate();
173             case UserTasksTreeTableModel.OWNER:
174                 return ut;
175             case UserTasksTreeTableModel.START: {
176                 long start = ut.getStart();
177                 if (start == -1)
178                     return null;
179                 else
180                     return new Date JavaDoc(start);
181             }
182             case UserTasksTreeTableModel.SPENT_TIME_TODAY:
183                 return new Integer JavaDoc(ut.getSpentTimeToday());
184             default:
185                 return "<error>"; // NOI18N
186
}
187     }
188     
189     public void setValueAt(Object JavaDoc aValue, int column) {
190         UserTask ut = getUserTask();
191         switch (column) {
192             case UserTasksTreeTableModel.SUMMARY:
193                 ut.setSummary((String JavaDoc) aValue);
194                 break;
195             case UserTasksTreeTableModel.DONE:
196                 ut.setDone(((Boolean JavaDoc) aValue).booleanValue());
197                 break;
198             case UserTasksTreeTableModel.CATEGORY:
199                 ut.setCategory((String JavaDoc) aValue);
200                 break;
201             case UserTasksTreeTableModel.PRIORITY:
202                 ut.setPriority(((Integer JavaDoc) aValue).intValue());
203                 break;
204             case UserTasksTreeTableModel.PERCENT_COMPLETE:
205                 ut.setPercentComplete(((Integer JavaDoc) aValue).intValue());
206                 break;
207             case UserTasksTreeTableModel.DETAILS:
208                 ut.setDetails((String JavaDoc) aValue);
209                 break;
210             case UserTasksTreeTableModel.OWNER:
211                 ut.setOwner((String JavaDoc) aValue);
212                 break;
213             case UserTasksTreeTableModel.EFFORT:
214                 ut.setEffort(((Integer JavaDoc) aValue).intValue());
215                 break;
216             case UserTasksTreeTableModel.SPENT_TIME:
217                 ut.setSpentTime(((Integer JavaDoc) aValue).intValue());
218                 break;
219             case UserTasksTreeTableModel.START:
220                 ut.setStartDate((Date JavaDoc) aValue);
221                 break;
222             case UserTasksTreeTableModel.DUE_DATE:
223                 ut.setDueDate((Date JavaDoc) aValue);
224                 break;
225         }
226     }
227
228     public String JavaDoc toString() {
229         return super.toString() +
230             "[userTask=" + getUserTask().toString() + "]"; // NOI18N
231
}
232     
233     public void destroy() {
234         super.destroy();
235         getUserTask().getSubtasks().removeListener(tl);
236         getUserTask().removePropertyChangeListener(pcl);
237     }
238     
239     public Iterator JavaDoc getChildrenObjectsIterator() {
240         return getUserTask().getSubtasks().iterator();
241     }
242     
243     public AdvancedTreeTableNode<UserTask> createChildNode(Object JavaDoc child) {
244         UserTaskTreeTableNode n = new UserTaskTreeTableNode(
245             this, filter, (UserTasksTreeTableModel) model,
246             (UserTask) child, comparator);
247         if (getFilter() != null && !getFilter().accept(child))
248             n.unmatched = true;
249         return n;
250     }
251     
252     public boolean accept(Object JavaDoc child) {
253         if (getFilter() == null)
254             return true;
255         
256         return acceptsRecursively((UserTask) child, getFilter());
257     }
258     
259     public boolean isCellEditable(int column) {
260         switch (column) {
261             case UserTasksTreeTableModel.DONE:
262                 return !getUserTask().isValuesComputed() &&
263                         getUserTask().areDependenciesDone();
264             case UserTasksTreeTableModel.PERCENT_COMPLETE:
265                 return !getUserTask().isValuesComputed() &&
266                         getUserTask().areDependenciesDone();
267             case UserTasksTreeTableModel.EFFORT:
268                 return !getUserTask().isValuesComputed();
269             case UserTasksTreeTableModel.SPENT_TIME:
270                 return !getUserTask().isValuesComputed();
271             case UserTasksTreeTableModel.SUMMARY:
272             case UserTasksTreeTableModel.CATEGORY:
273             case UserTasksTreeTableModel.DETAILS:
274             case UserTasksTreeTableModel.PRIORITY:
275             case UserTasksTreeTableModel.OWNER:
276             case UserTasksTreeTableModel.START:
277             case UserTasksTreeTableModel.DUE_DATE:
278                 return true;
279             default:
280                 return false;
281         }
282     }
283 }
284
Popular Tags