1 19 20 package org.netbeans.modules.tasklist.usertasks.model; 21 22 import java.util.Iterator ; 23 import org.netbeans.modules.tasklist.core.util.ObjectList; 24 import org.netbeans.modules.tasklist.usertasks.*; 25 26 31 public class UserTaskObjectList extends ObjectList<UserTask> { 32 private Object parent; 33 34 40 public UserTaskObjectList(Object parent) { 41 assert parent instanceof UserTask || parent instanceof UserTaskList; 42 this.parent = parent; 43 } 44 45 51 public UserTask getUserTask(int index) { 52 return (UserTask) get(index); 53 } 54 55 public void add(int index, UserTask element) { 56 UserTask ut = (UserTask) element; 57 if (ut.getParent() != null) 58 ut.getParent().getSubtasks().remove(ut); 59 else if (ut.getList() != null) 60 ut.getList().getSubtasks().remove(ut); 61 if (parent instanceof UserTask) { 62 ut.setParent((UserTask) parent); 63 ut.setList(((UserTask) parent).getList()); 64 } else { 65 ut.setParent(null); 66 ut.setList((UserTaskList) parent); 67 } 68 super.add(index, element); 69 } 70 71 public UserTask remove(int index) { 72 UserTask element = super.remove(index); 73 ((UserTask) element).setParent(null); 74 ((UserTask) element).setList(null); 75 return element; 76 } 77 78 81 public void purgeCompletedItems() { 82 if (size() == 0) 83 return; 84 85 Iterator it = iterator(); 86 while (it.hasNext()) { 87 UserTask task = (UserTask) it.next(); 88 if (task.isDone()) 89 it.remove(); 90 else 91 task.getSubtasks().purgeCompletedItems(); 92 } 93 } 94 } 95 | Popular Tags |