Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
GoListToGoalsToItems |
|
| 4.125;4.125 |
1 | /* $Id: GoListToGoalsToItems.java 17818 2010-01-12 18:39:46Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * linus | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2008 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.cognitive.ui; | |
40 | ||
41 | import java.util.ArrayList; | |
42 | import java.util.List; | |
43 | ||
44 | import javax.swing.event.TreeModelListener; | |
45 | import javax.swing.tree.TreePath; | |
46 | ||
47 | import org.argouml.cognitive.Designer; | |
48 | import org.argouml.cognitive.Goal; | |
49 | import org.argouml.cognitive.ToDoItem; | |
50 | import org.argouml.cognitive.ToDoList; | |
51 | ||
52 | ||
53 | /** | |
54 | * Rule for sorting the ToDo list: Goal -> Item. | |
55 | * | |
56 | */ | |
57 | 1800 | public class GoListToGoalsToItems extends AbstractGoList2 { |
58 | ||
59 | //////////////////////////////////////////////////////////////// | |
60 | // TreeModel implementation | |
61 | ||
62 | ||
63 | /* | |
64 | * @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int) | |
65 | */ | |
66 | public Object getChild(Object parent, int index) { | |
67 | 0 | if (parent instanceof ToDoList) { |
68 | 0 | return getGoalList().get(index); |
69 | } | |
70 | 0 | if (parent instanceof Goal) { |
71 | 0 | Goal g = (Goal) parent; |
72 | 0 | List<ToDoItem> itemList = |
73 | Designer.theDesigner().getToDoList().getToDoItemList(); | |
74 | 0 | synchronized (itemList) { |
75 | 0 | for (ToDoItem item : itemList) { |
76 | 0 | if (item.getPoster().supports(g)) { |
77 | 0 | if (index == 0) { |
78 | 0 | return item; |
79 | } | |
80 | 0 | index--; |
81 | } | |
82 | } | |
83 | 0 | } |
84 | } | |
85 | 0 | throw new IndexOutOfBoundsException("getChild shouldnt get here " |
86 | + "GoListToGoalsToItems"); | |
87 | } | |
88 | ||
89 | /* | |
90 | * @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object) | |
91 | */ | |
92 | public int getChildCount(Object parent) { | |
93 | 0 | if (parent instanceof ToDoList) { |
94 | 0 | return getGoalList().size(); |
95 | } | |
96 | 0 | if (parent instanceof Goal) { |
97 | 0 | Goal g = (Goal) parent; |
98 | 0 | int count = 0; |
99 | 0 | List<ToDoItem> itemList = |
100 | Designer.theDesigner().getToDoList().getToDoItemList(); | |
101 | 0 | synchronized (itemList) { |
102 | 0 | for (ToDoItem item : itemList) { |
103 | 0 | if (item.getPoster().supports(g)) { |
104 | 0 | count++; |
105 | } | |
106 | } | |
107 | 0 | } |
108 | 0 | return count; |
109 | } | |
110 | 0 | return 0; |
111 | } | |
112 | ||
113 | /* | |
114 | * @see javax.swing.tree.TreeModel#getIndexOfChild( | |
115 | * java.lang.Object, java.lang.Object) | |
116 | */ | |
117 | public int getIndexOfChild(Object parent, Object child) { | |
118 | 0 | if (parent instanceof ToDoList) { |
119 | 0 | return getGoalList().indexOf(child); |
120 | } | |
121 | 0 | if (parent instanceof Goal) { |
122 | // instead of making a new list, decrement index, return when | |
123 | // found and index == 0 | |
124 | 0 | List<ToDoItem> candidates = new ArrayList<ToDoItem>(); |
125 | 0 | Goal g = (Goal) parent; |
126 | 0 | List<ToDoItem> itemList = |
127 | Designer.theDesigner().getToDoList().getToDoItemList(); | |
128 | 0 | synchronized (itemList) { |
129 | 0 | for (ToDoItem item : itemList) { |
130 | 0 | if (item.getPoster().supports(g)) { |
131 | 0 | candidates.add(item); |
132 | } | |
133 | } | |
134 | 0 | } |
135 | 0 | return candidates.indexOf(child); |
136 | } | |
137 | 0 | return -1; |
138 | } | |
139 | ||
140 | /* | |
141 | * @see javax.swing.tree.TreeModel#isLeaf(java.lang.Object) | |
142 | */ | |
143 | public boolean isLeaf(Object node) { | |
144 | 0 | if (node instanceof ToDoList) { |
145 | 0 | return false; |
146 | } | |
147 | 0 | if (node instanceof Goal && getChildCount(node) > 0) { |
148 | 0 | return false; |
149 | } | |
150 | 0 | return true; |
151 | } | |
152 | ||
153 | /* | |
154 | * @see javax.swing.tree.TreeModel#valueForPathChanged( | |
155 | * javax.swing.tree.TreePath, java.lang.Object) | |
156 | */ | |
157 | 0 | public void valueForPathChanged(TreePath path, Object newValue) { } |
158 | ||
159 | /* | |
160 | * @see javax.swing.tree.TreeModel#addTreeModelListener(javax.swing.event.TreeModelListener) | |
161 | */ | |
162 | 0 | public void addTreeModelListener(TreeModelListener l) { } |
163 | ||
164 | /* | |
165 | * @see javax.swing.tree.TreeModel#removeTreeModelListener(javax.swing.event.TreeModelListener) | |
166 | */ | |
167 | 0 | public void removeTreeModelListener(TreeModelListener l) { } |
168 | ||
169 | ||
170 | /** | |
171 | * @return the goals | |
172 | */ | |
173 | public List<Goal> getGoalList() { | |
174 | 0 | return Designer.theDesigner().getGoalModel().getGoalList(); |
175 | } | |
176 | ||
177 | } |