KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > model > UserTaskObjectList


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.model;
21
22 import java.util.Iterator JavaDoc;
23 import org.netbeans.modules.tasklist.core.util.ObjectList;
24 import org.netbeans.modules.tasklist.usertasks.*;
25
26 /**
27  * List of UserTasks
28  *
29  * @author tl
30  */

31 public class UserTaskObjectList extends ObjectList<UserTask> {
32     private Object JavaDoc parent;
33
34     /**
35      * Creates a new instance of UserTaskObjectList
36      *
37      * @param parent parent for all tasks in this collection. UserTask or
38      * UserTaskList
39      */

40     public UserTaskObjectList(Object JavaDoc parent) {
41         assert parent instanceof UserTask || parent instanceof UserTaskList;
42         this.parent = parent;
43     }
44     
45     /**
46      * Returns the user task with the specified index
47      *
48      * @param index index of the task
49      * @see #get(int)
50      */

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     /**
79      * Removes completed tasks (recursively).
80      */

81     public void purgeCompletedItems() {
82         if (size() == 0)
83             return;
84
85         Iterator JavaDoc 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