Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UMLToDoItem |
|
| 2.7;2.7 |
1 | /* $Id: UMLToDoItem.java 17847 2010-01-12 19:37:43Z 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 | * tfmorris | |
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 | ||
40 | /* | |
41 | * UMLToDoItem.java | |
42 | * | |
43 | * Created on December 14, 2003, 4:19 PM | |
44 | */ | |
45 | ||
46 | package org.argouml.uml.cognitive; | |
47 | ||
48 | import java.util.Iterator; | |
49 | ||
50 | import org.argouml.cognitive.Critic; | |
51 | import org.argouml.cognitive.Designer; | |
52 | import org.argouml.cognitive.Highlightable; | |
53 | import org.argouml.cognitive.ListSet; | |
54 | import org.argouml.cognitive.Poster; | |
55 | import org.argouml.cognitive.ToDoItem; | |
56 | import org.argouml.kernel.Project; | |
57 | import org.argouml.kernel.ProjectManager; | |
58 | import org.argouml.model.Model; | |
59 | import org.argouml.ui.ProjectActions; | |
60 | import org.tigris.gef.base.Diagram; | |
61 | import org.tigris.gef.presentation.Fig; | |
62 | ||
63 | ||
64 | /** | |
65 | * UMLToDoItem is the preferred class for newly created ToDoItems within | |
66 | * ArgoUML. It knows more about possible designmaterial and can for example | |
67 | * highlight offenders when they are ModelElements by finding the according Fig | |
68 | * in the current diagram for them. | |
69 | * | |
70 | * @see org.argouml.cognitive.ToDoItem | |
71 | * @since 0.15.3 | |
72 | * @author mkl | |
73 | */ | |
74 | 900 | public class UMLToDoItem extends ToDoItem { |
75 | ||
76 | /** | |
77 | * The constructor. | |
78 | * | |
79 | * @param poster the poster | |
80 | * @param h the headline | |
81 | * @param p the priority | |
82 | * @param d the description | |
83 | * @param m the more-info-url | |
84 | * @param offs the offenders | |
85 | */ | |
86 | public UMLToDoItem(Poster poster, String h, int p, String d, String m, | |
87 | ListSet offs) { | |
88 | 0 | super(poster, h, p, d, m, offs); |
89 | 0 | } |
90 | ||
91 | /** | |
92 | * The constructor. | |
93 | * | |
94 | * @param poster the poster | |
95 | * @param h the headline | |
96 | * @param p the priority | |
97 | * @param d the description | |
98 | * @param m the more-info-url | |
99 | */ | |
100 | public UMLToDoItem(Poster poster, String h, int p, String d, String m) { | |
101 | 0 | super(poster, h, p, d, m); |
102 | 0 | } |
103 | ||
104 | /** | |
105 | * The constructor. | |
106 | * | |
107 | * @param c the poster (critic) | |
108 | * @param dm the offenders | |
109 | * @param dsgr the designer | |
110 | */ | |
111 | public UMLToDoItem(Critic c, Object dm, Designer dsgr) { | |
112 | 94664 | super(c, dm, dsgr); |
113 | 94662 | } |
114 | ||
115 | /** | |
116 | * The constructor. | |
117 | * | |
118 | * @param c the poster (critic) | |
119 | * @param offs the offenders | |
120 | * @param dsgr the designer | |
121 | */ | |
122 | public UMLToDoItem(Critic c, ListSet offs, Designer dsgr) { | |
123 | 0 | super(c, offs, dsgr); |
124 | 0 | } |
125 | ||
126 | /** | |
127 | * The constructor. | |
128 | * | |
129 | * @param c the critic that created this todoitem | |
130 | */ | |
131 | public UMLToDoItem(Critic c) { | |
132 | 0 | super(c); |
133 | 0 | } |
134 | ||
135 | /** | |
136 | * Action jumps to the diagram containing all or most of the | |
137 | * offenders and calls {@link #deselect()}, {@link #select()} | |
138 | * around the call to | |
139 | * {@link ProjectActions#jumpToDiagramShowing(java.util.List)}. | |
140 | */ | |
141 | @Override | |
142 | public void action() { | |
143 | 0 | deselect(); |
144 | // this also sets the target as a convenient side effect | |
145 | 0 | ProjectActions.jumpToDiagramShowing(getOffenders()); |
146 | 0 | select(); |
147 | 0 | } |
148 | ||
149 | /* | |
150 | * @see org.argouml.cognitive.ToDoItem#deselect() | |
151 | */ | |
152 | @Override | |
153 | public void deselect() { | |
154 | 0 | Project p = ProjectManager.getManager().getCurrentProject(); |
155 | 0 | for (Object dm : getOffenders()) { |
156 | 0 | if (dm instanceof Highlightable) { |
157 | 0 | ((Highlightable) dm).setHighlight(false); |
158 | 0 | } else if (p != null) { |
159 | 0 | Iterator iterFigs = p.findFigsForMember(dm).iterator(); |
160 | 0 | while (iterFigs.hasNext()) { |
161 | 0 | Object f = iterFigs.next(); |
162 | 0 | if (f instanceof Highlightable) { |
163 | 0 | ((Highlightable) f).setHighlight(false); |
164 | } | |
165 | 0 | } |
166 | 0 | } |
167 | } | |
168 | 0 | } |
169 | ||
170 | /* | |
171 | * @see org.argouml.cognitive.ToDoItem#select() | |
172 | */ | |
173 | @Override | |
174 | public void select() { | |
175 | 0 | Project p = ProjectManager.getManager().getCurrentProject(); |
176 | 0 | for (Object dm : getOffenders()) { |
177 | 0 | if (dm instanceof Highlightable) { |
178 | 0 | ((Highlightable) dm).setHighlight(true); |
179 | 0 | } else if (p != null) { |
180 | 0 | Iterator iterFigs = p.findFigsForMember(dm).iterator(); |
181 | 0 | while (iterFigs.hasNext()) { |
182 | 0 | Object f = iterFigs.next(); |
183 | 0 | if (f instanceof Highlightable) { |
184 | 0 | ((Highlightable) f).setHighlight(true); |
185 | } | |
186 | 0 | } |
187 | 0 | } |
188 | } | |
189 | 0 | } |
190 | ||
191 | @Override | |
192 | public ListSet getOffenders() { | |
193 | 309743 | final ListSet offenders = super.getOffenders(); |
194 | // TODO: should not be using assert here but I don't want to change to | |
195 | // IllegalStateException at lead up to a release as I don't know how | |
196 | // much testing is done with assert on. | |
197 | 309743 | assert offenders.size() <= 0 |
198 | || Model.getFacade().isAUMLElement(offenders.get(0)) | |
199 | || offenders.get(0) instanceof Fig | |
200 | || offenders.get(0) instanceof Diagram; | |
201 | 309743 | return offenders; |
202 | } | |
203 | ||
204 | @Override | |
205 | protected void checkArgument(Object dm) { | |
206 | 94664 | if (!Model.getFacade().isAUMLElement(dm) |
207 | && !(dm instanceof Fig) | |
208 | && !(dm instanceof Diagram)) { | |
209 | ||
210 | 0 | throw new IllegalArgumentException( |
211 | "The offender must be a model element, " | |
212 | + "a Fig or a Diagram"); | |
213 | } | |
214 | 94664 | } |
215 | ||
216 | } |