1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
package org.argouml.model.euml; |
13 | |
|
14 | |
import org.eclipse.emf.common.notify.impl.NotificationImpl; |
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public class ChangeCommand extends |
27 | |
org.eclipse.uml2.common.edit.command.ChangeCommand { |
28 | |
|
29 | |
private Object objects[]; |
30 | |
|
31 | |
private EUMLModelImplementation modelImpl; |
32 | |
|
33 | |
public ChangeCommand(EUMLModelImplementation modelImplementation, |
34 | |
Runnable runnable, String label) { |
35 | 0 | super(modelImplementation.getEditingDomain(), runnable, label); |
36 | 0 | modelImpl = modelImplementation; |
37 | 0 | } |
38 | |
|
39 | |
public ChangeCommand(EUMLModelImplementation modelImplementation, |
40 | |
Runnable runnable, String label, Object... objects) { |
41 | 0 | super(modelImplementation.getEditingDomain(), runnable, label); |
42 | 0 | if (!isValid(label, objects)) { |
43 | 0 | throw new IllegalArgumentException( |
44 | |
"The label is not compatible with the # of objects"); |
45 | |
} |
46 | 0 | this.objects = objects; |
47 | 0 | modelImpl = modelImplementation; |
48 | 0 | } |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public void setObjects(Object... objects) { |
56 | 0 | if (!isValid(label, objects)) { |
57 | 0 | throw new IllegalArgumentException( |
58 | |
"The label is not compatible with the # of objects"); |
59 | |
} |
60 | 0 | this.objects = objects; |
61 | 0 | modelImpl.getModelEventPump().notifyChanged( |
62 | |
new NotificationImpl( |
63 | |
ModelEventPumpEUMLImpl.COMMAND_STACK_UPDATE, false, |
64 | |
false)); |
65 | 0 | } |
66 | |
|
67 | |
@Override |
68 | |
public String getLabel() { |
69 | 0 | if (objects == null) { |
70 | 0 | return label; |
71 | |
} |
72 | 0 | StringBuilder sb = new StringBuilder(); |
73 | 0 | int j = 0; |
74 | 0 | for (int i = 0; i < label.length(); i++) { |
75 | 0 | if (label.charAt(i) == '#') { |
76 | 0 | sb.append(UMLUtil.toString(objects[j])); |
77 | 0 | j++; |
78 | |
} else { |
79 | 0 | sb.append(label.charAt(i)); |
80 | |
} |
81 | |
} |
82 | 0 | return sb.toString(); |
83 | |
} |
84 | |
|
85 | |
private boolean isValid(String label, Object objects[]) { |
86 | 0 | if (objects == null) { |
87 | 0 | return true; |
88 | |
} |
89 | 0 | int i = 0; |
90 | 0 | for (int j = 0; j < label.length(); j++) { |
91 | 0 | if (label.charAt(j) == '#') { |
92 | 0 | i++; |
93 | |
} |
94 | |
} |
95 | 0 | return i == objects.length; |
96 | |
} |
97 | |
|
98 | |
} |