Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ToDoByPoster |
|
| 4.2;4.2 |
1 | /* $Id: ToDoByPoster.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 | * bobtarling | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2006 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.List; | |
42 | ||
43 | import org.apache.log4j.Logger; | |
44 | import org.argouml.cognitive.Designer; | |
45 | import org.argouml.cognitive.ListSet; | |
46 | import org.argouml.cognitive.Poster; | |
47 | import org.argouml.cognitive.ToDoItem; | |
48 | import org.argouml.cognitive.ToDoListEvent; | |
49 | import org.argouml.cognitive.ToDoListListener; | |
50 | ||
51 | /** | |
52 | * Represents a perspective for ToDo items: grouping by poster type. | |
53 | * | |
54 | */ | |
55 | public class ToDoByPoster extends ToDoPerspective | |
56 | implements ToDoListListener { | |
57 | 900 | private static final Logger LOG = |
58 | Logger.getLogger(ToDoByPoster.class); | |
59 | ||
60 | /** | |
61 | * The constructor. | |
62 | * | |
63 | */ | |
64 | public ToDoByPoster() { | |
65 | 900 | super("combobox.todo-perspective-poster"); |
66 | 900 | addSubTreeModel(new GoListToPosterToItem()); |
67 | 900 | } |
68 | ||
69 | //////////////////////////////////////////////////////////////// | |
70 | // ToDoListListener implementation | |
71 | ||
72 | /* | |
73 | * @see org.argouml.cognitive.ToDoListListener#toDoItemsChanged(org.argouml.cognitive.ToDoListEvent) | |
74 | */ | |
75 | public void toDoItemsChanged(ToDoListEvent tde) { | |
76 | 0 | LOG.debug("toDoItemsChanged"); |
77 | 0 | List<ToDoItem> items = tde.getToDoItemList(); |
78 | 0 | Object[] path = new Object[2]; |
79 | 0 | path[0] = Designer.theDesigner().getToDoList(); |
80 | ||
81 | 0 | ListSet<Poster> allPosters = |
82 | Designer.theDesigner().getToDoList().getPosters(); | |
83 | 0 | synchronized (allPosters) { |
84 | 0 | for (Poster p : allPosters) { |
85 | 0 | path[1] = p; |
86 | 0 | int nMatchingItems = 0; |
87 | 0 | for (ToDoItem item : items) { |
88 | 0 | Poster post = item.getPoster(); |
89 | 0 | if (post != p) { |
90 | 0 | continue; |
91 | } | |
92 | 0 | nMatchingItems++; |
93 | 0 | } |
94 | 0 | if (nMatchingItems == 0) { |
95 | 0 | continue; |
96 | } | |
97 | 0 | int[] childIndices = new int[nMatchingItems]; |
98 | 0 | Object[] children = new Object[nMatchingItems]; |
99 | 0 | nMatchingItems = 0; |
100 | 0 | for (ToDoItem item : items) { |
101 | 0 | Poster post = item.getPoster(); |
102 | 0 | if (post != p) { |
103 | 0 | continue; |
104 | } | |
105 | 0 | childIndices[nMatchingItems] = getIndexOfChild(p, item); |
106 | 0 | children[nMatchingItems] = item; |
107 | 0 | nMatchingItems++; |
108 | 0 | } |
109 | 0 | fireTreeNodesChanged(this, path, childIndices, children); |
110 | 0 | } |
111 | 0 | } |
112 | 0 | } |
113 | ||
114 | /* | |
115 | * @see org.argouml.cognitive.ToDoListListener#toDoItemsAdded(org.argouml.cognitive.ToDoListEvent) | |
116 | */ | |
117 | public void toDoItemsAdded(ToDoListEvent tde) { | |
118 | 0 | LOG.debug("toDoItemAdded"); |
119 | 0 | List<ToDoItem> items = tde.getToDoItemList(); |
120 | 0 | Object[] path = new Object[2]; |
121 | 0 | path[0] = Designer.theDesigner().getToDoList(); |
122 | ||
123 | 0 | ListSet<Poster> allPosters = |
124 | Designer.theDesigner().getToDoList().getPosters(); | |
125 | 0 | synchronized (allPosters) { |
126 | 0 | for (Poster p : allPosters) { |
127 | 0 | path[1] = p; |
128 | 0 | int nMatchingItems = 0; |
129 | 0 | for (ToDoItem item : items) { |
130 | 0 | Poster post = item.getPoster(); |
131 | 0 | if (post != p) { |
132 | 0 | continue; |
133 | } | |
134 | 0 | nMatchingItems++; |
135 | 0 | } |
136 | 0 | if (nMatchingItems == 0) { |
137 | 0 | continue; |
138 | } | |
139 | 0 | int[] childIndices = new int[nMatchingItems]; |
140 | 0 | Object[] children = new Object[nMatchingItems]; |
141 | 0 | nMatchingItems = 0; |
142 | 0 | for (ToDoItem item : items) { |
143 | 0 | Poster post = item.getPoster(); |
144 | 0 | if (post != p) { |
145 | 0 | continue; |
146 | } | |
147 | 0 | childIndices[nMatchingItems] = getIndexOfChild(p, item); |
148 | 0 | children[nMatchingItems] = item; |
149 | 0 | nMatchingItems++; |
150 | 0 | } |
151 | 0 | fireTreeNodesInserted(this, path, childIndices, children); |
152 | 0 | } |
153 | 0 | } |
154 | 0 | } |
155 | ||
156 | /* | |
157 | * @see org.argouml.cognitive.ToDoListListener#toDoItemsRemoved(org.argouml.cognitive.ToDoListEvent) | |
158 | */ | |
159 | public void toDoItemsRemoved(ToDoListEvent tde) { | |
160 | 0 | LOG.debug("toDoItemRemoved"); |
161 | 0 | List<ToDoItem> items = tde.getToDoItemList(); |
162 | ||
163 | 0 | Object[] path = new Object[2]; |
164 | 0 | path[0] = Designer.theDesigner().getToDoList(); |
165 | ||
166 | 0 | ListSet<Poster> allPosters = Designer.theDesigner().getToDoList() |
167 | .getPosters(); | |
168 | 0 | synchronized (allPosters) { |
169 | 0 | for (Poster p : allPosters) { |
170 | 0 | boolean anyInPoster = false; |
171 | 0 | for (ToDoItem item : items) { |
172 | 0 | Poster post = item.getPoster(); |
173 | 0 | if (post == p) { |
174 | 0 | anyInPoster = true; |
175 | 0 | break; |
176 | } | |
177 | 0 | } |
178 | 0 | if (!anyInPoster) { |
179 | 0 | continue; |
180 | } | |
181 | 0 | path[1] = p; |
182 | 0 | fireTreeStructureChanged(path); |
183 | 0 | } |
184 | 0 | } |
185 | 0 | } |
186 | ||
187 | /* | |
188 | * @see org.argouml.cognitive.ToDoListListener#toDoListChanged(org.argouml.cognitive.ToDoListEvent) | |
189 | */ | |
190 | public void toDoListChanged(ToDoListEvent tde) { | |
191 | 0 | } |
192 | ||
193 | } | |
194 | ||
195 |