KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > timerwin > AllUserTasksTreeModel


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  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.timerwin;
21
22 import javax.swing.tree.TreeModel JavaDoc;
23 import org.netbeans.modules.tasklist.core.util.ObjectList;
24 import org.netbeans.modules.tasklist.usertasks.UserTaskView;
25 import org.netbeans.modules.tasklist.usertasks.UserTaskViewRegistry;
26 import org.netbeans.modules.tasklist.usertasks.model.UserTaskList;
27
28 /**
29  * TreeModel for user tasks
30  *
31  * @author tl
32  */

33 public class AllUserTasksTreeModel implements TreeModel JavaDoc {
34     private Object JavaDoc root = new Object JavaDoc();
35     private UserTaskList[] utl;
36
37     /**
38      * Creates a new model for a task list.
39      *
40      * @param utl a task list
41      */

42     public AllUserTasksTreeModel() {
43         UserTaskView[] all = UserTaskViewRegistry.getInstance().getAll();
44         utl = new UserTaskList[all.length];
45         for (int i = 0; i < all.length; i++) {
46             utl[i] = all[i].getUserTaskList();
47         }
48     }
49
50     public boolean isLeaf(Object JavaDoc node) {
51         if (node == root)
52             return false;
53         else
54             return ((ObjectList.Owner) node).getObjectList().size() == 0;
55     }
56
57     public int getChildCount(Object JavaDoc parent) {
58         if (parent == root)
59             return utl.length;
60         else
61             return ((ObjectList.Owner) parent).getObjectList().size();
62     }
63
64     public void valueForPathChanged(javax.swing.tree.TreePath JavaDoc path, Object JavaDoc newValue) {
65     }
66
67     public void removeTreeModelListener(javax.swing.event.TreeModelListener JavaDoc l) {
68     }
69
70     public void addTreeModelListener(javax.swing.event.TreeModelListener JavaDoc l) {
71     }
72
73     public Object JavaDoc getChild(Object JavaDoc parent, int index) {
74         if (parent == root)
75             return utl[index];
76         else
77             return ((ObjectList.Owner) parent).getObjectList().get(index);
78     }
79
80     public Object JavaDoc getRoot() {
81         return root;
82     }
83
84     public int getIndexOfChild(Object JavaDoc parent, Object JavaDoc child) {
85         return -1;
86     }
87 }
88
Popular Tags