1 package org.netbeans.modules.tasklist.usertasks; 2 3 import java.beans.PropertyChangeEvent ; 4 import java.beans.PropertyChangeListener ; 5 import java.net.URL ; 6 import java.util.Comparator ; 7 import java.util.Date ; 8 import java.util.Iterator ; 9 import javax.swing.SwingConstants ; 10 import javax.swing.SwingUtilities ; 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 24 public class UserTaskTreeTableNode extends AdvancedTreeTableNode<UserTask> { 25 31 public static boolean acceptsRecursively(UserTask ut, FilterIntf filter) { 32 if (filter.accept(ut)) 33 return true; 34 Iterator 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 pcl; 46 47 55 public UserTaskTreeTableNode( 56 TreeTableNode parent, FilterIntf filter, 57 UserTasksTreeTableModel m, UserTask ut, 58 Comparator <AdvancedTreeTableNode> comparator) { 59 super(m, parent, ut); 60 61 this.filter = filter; 62 this.comparator = comparator; 63 pcl = new PropertyChangeListener () { 64 public void propertyChange(PropertyChangeEvent evt) { 65 SwingUtilities.invokeLater(new Runnable () { 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 [] 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 [] 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 ("unexpected event type"); } 99 } 100 }; 101 ut.getSubtasks().addListener(tl); 102 } 103 104 110 public boolean isUnmatched() { 111 return unmatched; 112 } 113 114 120 public void setUnmatched(boolean unmatched) { 121 this.unmatched = unmatched; 122 } 123 124 129 public UserTask getUserTask() { 130 return (UserTask) object; 131 } 132 133 public Object 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 (ut.getPriority()); 140 case UserTasksTreeTableModel.DONE: 141 return Boolean.valueOf(ut.isDone()); 142 case UserTasksTreeTableModel.PERCENT_COMPLETE: 143 return new Integer (ut.getPercentComplete()); 144 case UserTasksTreeTableModel.EFFORT: 145 return ut; 146 case UserTasksTreeTableModel.REMAINING_EFFORT: 147 return new Integer (ut.getRemainingEffort()); 148 case UserTasksTreeTableModel.SPENT_TIME: 149 return new Integer (ut.getSpentTime()); 150 case UserTasksTreeTableModel.DETAILS: 151 return ut.getDetails(); 152 case UserTasksTreeTableModel.FILE_BASE_NAME: 153 URL url = ut.getUrl(); 154 if (url == null) 155 return ""; else 157 return url.toExternalForm(); 158 case UserTasksTreeTableModel.LINE_NUMBER: 159 return new Integer (ut.getLineNumber() + 1); 160 case UserTasksTreeTableModel.CATEGORY: 161 return ut; 162 case UserTasksTreeTableModel.CREATED: 163 return new Long (ut.getCreatedDate()); 164 case UserTasksTreeTableModel.LAST_EDITED: 165 return new Long (ut.getLastEditedDate()); 166 case UserTasksTreeTableModel.COMPLETED_DATE: 167 return new Long (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 (start); 181 } 182 case UserTasksTreeTableModel.SPENT_TIME_TODAY: 183 return new Integer (ut.getSpentTimeToday()); 184 default: 185 return "<error>"; } 187 } 188 189 public void setValueAt(Object aValue, int column) { 190 UserTask ut = getUserTask(); 191 switch (column) { 192 case UserTasksTreeTableModel.SUMMARY: 193 ut.setSummary((String ) aValue); 194 break; 195 case UserTasksTreeTableModel.DONE: 196 ut.setDone(((Boolean ) aValue).booleanValue()); 197 break; 198 case UserTasksTreeTableModel.CATEGORY: 199 ut.setCategory((String ) aValue); 200 break; 201 case UserTasksTreeTableModel.PRIORITY: 202 ut.setPriority(((Integer ) aValue).intValue()); 203 break; 204 case UserTasksTreeTableModel.PERCENT_COMPLETE: 205 ut.setPercentComplete(((Integer ) aValue).intValue()); 206 break; 207 case UserTasksTreeTableModel.DETAILS: 208 ut.setDetails((String ) aValue); 209 break; 210 case UserTasksTreeTableModel.OWNER: 211 ut.setOwner((String ) aValue); 212 break; 213 case UserTasksTreeTableModel.EFFORT: 214 ut.setEffort(((Integer ) aValue).intValue()); 215 break; 216 case UserTasksTreeTableModel.SPENT_TIME: 217 ut.setSpentTime(((Integer ) aValue).intValue()); 218 break; 219 case UserTasksTreeTableModel.START: 220 ut.setStartDate((Date ) aValue); 221 break; 222 case UserTasksTreeTableModel.DUE_DATE: 223 ut.setDueDate((Date ) aValue); 224 break; 225 } 226 } 227 228 public String toString() { 229 return super.toString() + 230 "[userTask=" + getUserTask().toString() + "]"; } 232 233 public void destroy() { 234 super.destroy(); 235 getUserTask().getSubtasks().removeListener(tl); 236 getUserTask().removePropertyChangeListener(pcl); 237 } 238 239 public Iterator getChildrenObjectsIterator() { 240 return getUserTask().getSubtasks().iterator(); 241 } 242 243 public AdvancedTreeTableNode<UserTask> createChildNode(Object 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 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 |