1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
package org.argouml.uml.cognitive.critics; |
40 | |
|
41 | |
import java.util.ArrayList; |
42 | |
import java.util.Collection; |
43 | |
import java.util.Iterator; |
44 | |
import java.util.List; |
45 | |
|
46 | |
import javax.swing.JPanel; |
47 | |
|
48 | |
import org.apache.log4j.Logger; |
49 | |
import org.argouml.cognitive.ListSet; |
50 | |
import org.argouml.cognitive.ToDoItem; |
51 | |
import org.argouml.cognitive.ui.WizStepChoice; |
52 | |
import org.argouml.cognitive.ui.WizStepConfirm; |
53 | |
import org.argouml.i18n.Translator; |
54 | |
import org.argouml.model.Model; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
public class WizBreakCircularComp extends UMLWizard { |
61 | 0 | private static final Logger LOG = |
62 | |
Logger.getLogger(WizBreakCircularComp.class); |
63 | |
|
64 | 0 | private String instructions1 = |
65 | |
Translator.localize("critics.WizBreakCircularComp-ins1"); |
66 | |
|
67 | 0 | private String instructions2 = |
68 | |
Translator.localize("critics.WizBreakCircularComp-ins2"); |
69 | |
|
70 | 0 | private String instructions3 = |
71 | |
Translator.localize("critics.WizBreakCircularComp-ins3"); |
72 | |
|
73 | 0 | private WizStepChoice step1 = null; |
74 | 0 | private WizStepChoice step2 = null; |
75 | 0 | private WizStepConfirm step3 = null; |
76 | |
|
77 | 0 | private Object selectedCls = null; |
78 | 0 | private Object selectedAsc = null; |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | 0 | public WizBreakCircularComp() { } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
@Override |
89 | |
public int getNumSteps() { |
90 | 0 | return 3; |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
protected List<String> getOptions1() { |
97 | 0 | List<String> result = new ArrayList<String>(); |
98 | 0 | if (getToDoItem() != null) { |
99 | 0 | ToDoItem item = (ToDoItem) getToDoItem(); |
100 | 0 | for (Object me : item.getOffenders()) { |
101 | 0 | String s = Model.getFacade().getName(me); |
102 | 0 | result.add(s); |
103 | 0 | } |
104 | |
} |
105 | 0 | return result; |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
protected List<String> getOptions2() { |
112 | 0 | List<String> result = new ArrayList<String>(); |
113 | 0 | if (selectedCls != null) { |
114 | 0 | Collection aes = Model.getFacade().getAssociationEnds(selectedCls); |
115 | 0 | Object fromType = selectedCls; |
116 | 0 | String fromName = Model.getFacade().getName(fromType); |
117 | 0 | for (Iterator iter = aes.iterator(); iter.hasNext();) { |
118 | 0 | Object fromEnd = iter.next(); |
119 | 0 | Object asc = Model.getFacade().getAssociation(fromEnd); |
120 | 0 | Object toEnd = |
121 | |
new ArrayList(Model.getFacade().getConnections(asc)).get(0); |
122 | 0 | if (toEnd == fromEnd) { |
123 | 0 | toEnd = new ArrayList( |
124 | |
Model.getFacade().getConnections(asc)).get(1); |
125 | |
} |
126 | 0 | Object toType = Model.getFacade().getType(toEnd); |
127 | 0 | String ascName = Model.getFacade().getName(asc); |
128 | 0 | String toName = Model.getFacade().getName(toType); |
129 | 0 | String s = ascName |
130 | |
+ " " |
131 | |
+ Translator.localize("critics.WizBreakCircularComp-from") |
132 | |
+ fromName |
133 | |
+ " " |
134 | |
+ Translator.localize("critics.WizBreakCircularComp-to") |
135 | |
+ " " |
136 | |
+ toName; |
137 | 0 | result.add(s); |
138 | 0 | } |
139 | |
} |
140 | 0 | return result; |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
public JPanel makePanel(int newStep) { |
147 | 0 | switch (newStep) { |
148 | |
case 1: |
149 | 0 | if (step1 == null) { |
150 | 0 | step1 = new WizStepChoice(this, instructions1, getOptions1()); |
151 | 0 | step1.setTarget(getToDoItem()); |
152 | |
} |
153 | 0 | return step1; |
154 | |
case 2: |
155 | 0 | if (step2 == null) { |
156 | 0 | step2 = new WizStepChoice(this, instructions2, getOptions2()); |
157 | 0 | step2.setTarget(getToDoItem()); |
158 | |
} |
159 | 0 | return step2; |
160 | |
case 3: |
161 | 0 | if (step3 == null) { |
162 | 0 | step3 = new WizStepConfirm(this, instructions3); |
163 | |
} |
164 | 0 | return step3; |
165 | |
} |
166 | 0 | return null; |
167 | |
} |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
public void doAction(int oldStep) { |
173 | 0 | LOG.debug("doAction " + oldStep); |
174 | 0 | int choice = -1; |
175 | 0 | ToDoItem item = (ToDoItem) getToDoItem(); |
176 | 0 | ListSet offs = item.getOffenders(); |
177 | 0 | switch (oldStep) { |
178 | |
case 1: |
179 | 0 | if (step1 != null) { |
180 | 0 | choice = step1.getSelectedIndex(); |
181 | |
} |
182 | 0 | if (choice == -1) { |
183 | 0 | throw new Error("nothing selected, should not get here"); |
184 | |
} |
185 | 0 | selectedCls = offs.get(choice); |
186 | 0 | break; |
187 | |
|
188 | |
case 2: |
189 | 0 | if (step2 != null) { |
190 | 0 | choice = step2.getSelectedIndex(); |
191 | |
} |
192 | 0 | if (choice == -1) { |
193 | 0 | throw new Error("nothing selected, should not get here"); |
194 | |
} |
195 | 0 | Object ae = null; |
196 | 0 | Iterator iter = |
197 | |
Model.getFacade().getAssociationEnds(selectedCls).iterator(); |
198 | 0 | for (int n = 0; n <= choice; n++) { |
199 | 0 | ae = iter.next(); |
200 | |
} |
201 | 0 | selectedAsc = Model.getFacade().getAssociation(ae); |
202 | 0 | break; |
203 | |
|
204 | |
case 3: |
205 | 0 | if (selectedAsc != null) { |
206 | 0 | List conns = new ArrayList( |
207 | |
Model.getFacade().getConnections(selectedAsc)); |
208 | 0 | Object ae0 = conns.get(0); |
209 | 0 | Object ae1 = conns.get(1); |
210 | |
try { |
211 | 0 | Model.getCoreHelper().setAggregation( |
212 | |
ae0, |
213 | |
Model.getAggregationKind().getNone()); |
214 | 0 | Model.getCoreHelper().setAggregation( |
215 | |
ae1, |
216 | |
Model.getAggregationKind().getNone()); |
217 | 0 | } catch (Exception pve) { |
218 | 0 | LOG.error("could not set aggregation", pve); |
219 | 0 | } |
220 | |
} |
221 | |
break; |
222 | |
} |
223 | 0 | } |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
@Override |
229 | |
public boolean canGoNext() { |
230 | 0 | return canFinish(); |
231 | |
} |
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
@Override |
237 | |
public boolean canFinish() { |
238 | 0 | if (!super.canFinish()) { |
239 | 0 | return false; |
240 | |
} |
241 | 0 | if (getStep() == 0) { |
242 | 0 | return true; |
243 | |
} |
244 | 0 | if (getStep() == 1 && step1 != null && step1.getSelectedIndex() != -1) { |
245 | 0 | return true; |
246 | |
} |
247 | 0 | if (getStep() == 2 && step2 != null && step2.getSelectedIndex() != -1) { |
248 | 0 | return true; |
249 | |
} |
250 | 0 | return false; |
251 | |
} |
252 | |
} |