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.diagram.ui; |
40 | |
|
41 | |
import static org.argouml.model.Model.getModelManagementFactory; |
42 | |
|
43 | |
import java.awt.event.ActionEvent; |
44 | |
import java.util.ArrayList; |
45 | |
import java.util.Collection; |
46 | |
import java.util.Collections; |
47 | |
import java.util.List; |
48 | |
|
49 | |
import javax.swing.ImageIcon; |
50 | |
import javax.swing.JComboBox; |
51 | |
import javax.swing.JComponent; |
52 | |
import javax.swing.JTextField; |
53 | |
|
54 | |
import org.argouml.i18n.Translator; |
55 | |
import org.argouml.ui.TabModelTarget; |
56 | |
import org.argouml.ui.UndoableAction; |
57 | |
import org.argouml.ui.targetmanager.TargetManager; |
58 | |
import org.argouml.uml.diagram.ArgoDiagram; |
59 | |
import org.argouml.uml.diagram.Relocatable; |
60 | |
import org.argouml.uml.ui.AbstractActionNavigate; |
61 | |
import org.argouml.uml.ui.ActionDeleteModelElements; |
62 | |
import org.argouml.uml.ui.PropPanel; |
63 | |
import org.argouml.uml.ui.UMLComboBox2; |
64 | |
import org.argouml.uml.ui.UMLComboBoxModel2; |
65 | |
import org.argouml.uml.ui.UMLComboBoxNavigator; |
66 | |
import org.argouml.uml.ui.UMLSearchableComboBox; |
67 | |
import org.argouml.uml.util.PathComparator; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public class PropPanelDiagram extends PropPanel implements TabModelTarget { |
74 | |
|
75 | |
private JComboBox homeModelSelector; |
76 | 2289 | private UMLDiagramHomeModelComboBoxModel homeModelComboBoxModel = |
77 | |
new UMLDiagramHomeModelComboBoxModel(); |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
protected PropPanelDiagram(String diagramName, ImageIcon icon) { |
86 | 2289 | super(diagramName, icon); |
87 | |
|
88 | 2289 | JTextField field = new JTextField(); |
89 | |
|
90 | |
|
91 | 2289 | field.getDocument().addDocumentListener(new DiagramNameDocument(field)); |
92 | 2289 | addField("label.name", field); |
93 | |
|
94 | 2289 | addField("label.home-model", getHomeModelSelector()); |
95 | |
|
96 | 2289 | addAction(new ActionNavigateUpFromDiagram()); |
97 | 2289 | addAction(ActionDeleteModelElements.getTargetFollower()); |
98 | 2289 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
public PropPanelDiagram() { |
105 | 0 | this("Diagram", null); |
106 | 0 | } |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
protected JComponent getHomeModelSelector() { |
116 | 2289 | if (homeModelSelector == null) { |
117 | 2289 | homeModelSelector = new UMLSearchableComboBox( |
118 | |
homeModelComboBoxModel, |
119 | |
new ActionSetDiagramHomeModel(), true); |
120 | |
} |
121 | 2289 | return new UMLComboBoxNavigator( |
122 | |
Translator.localize("label.namespace.navigate.tooltip"), |
123 | |
homeModelSelector); |
124 | |
} |
125 | |
|
126 | |
} |
127 | |
|
128 | |
class UMLDiagramHomeModelComboBoxModel extends UMLComboBoxModel2 { |
129 | |
|
130 | |
public UMLDiagramHomeModelComboBoxModel() { |
131 | 2289 | super(ArgoDiagram.NAMESPACE_KEY, false); |
132 | 2289 | } |
133 | |
|
134 | |
@Override |
135 | |
protected void buildModelList() { |
136 | 0 | Object target = getTarget(); |
137 | 0 | List list = new ArrayList(); |
138 | 0 | if (target instanceof Relocatable) { |
139 | 0 | Relocatable diagram = (Relocatable) target; |
140 | 0 | for (Object obj : diagram.getRelocationCandidates( |
141 | |
getModelManagementFactory().getRootModel())) { |
142 | 0 | if (diagram.isRelocationAllowed(obj)) { |
143 | 0 | list.add(obj); |
144 | |
} |
145 | |
} |
146 | |
} |
147 | |
|
148 | |
|
149 | 0 | list.add(getSelectedModelElement()); |
150 | 0 | Collections.sort(list, new PathComparator()); |
151 | 0 | setElements(list); |
152 | 0 | } |
153 | |
|
154 | |
@Override |
155 | |
protected void buildMinimalModelList() { |
156 | 2949 | Collection list = new ArrayList(1); |
157 | 2949 | list.add(getSelectedModelElement()); |
158 | 2949 | setElements(list); |
159 | 2949 | setModelInvalid(); |
160 | 2949 | } |
161 | |
|
162 | |
@Override |
163 | |
protected boolean isLazy() { |
164 | 0 | return true; |
165 | |
} |
166 | |
|
167 | |
@Override |
168 | |
protected Object getSelectedModelElement() { |
169 | 5898 | Object t = getTarget(); |
170 | 5898 | if (t instanceof ArgoDiagram) { |
171 | 5898 | return ((ArgoDiagram) t).getOwner(); |
172 | |
} |
173 | 0 | return null; |
174 | |
} |
175 | |
|
176 | |
@Override |
177 | |
protected boolean isValidElement(Object element) { |
178 | 0 | Object t = getTarget(); |
179 | 0 | if (t instanceof Relocatable) { |
180 | 0 | return ((Relocatable) t).isRelocationAllowed(element); |
181 | |
} |
182 | 0 | return false; |
183 | |
} |
184 | |
} |
185 | |
|
186 | |
class ActionSetDiagramHomeModel extends UndoableAction { |
187 | |
protected ActionSetDiagramHomeModel() { |
188 | 2289 | super(); |
189 | 2289 | } |
190 | |
|
191 | |
public void actionPerformed(ActionEvent e) { |
192 | 0 | Object source = e.getSource(); |
193 | 0 | if (source instanceof UMLComboBox2) { |
194 | 0 | UMLComboBox2 box = (UMLComboBox2) source; |
195 | 0 | Object diagram = box.getTarget(); |
196 | 0 | Object homeModel = box.getSelectedItem(); |
197 | 0 | if (diagram instanceof Relocatable) { |
198 | 0 | Relocatable d = (Relocatable) diagram; |
199 | 0 | if (d.isRelocationAllowed(homeModel)) { |
200 | 0 | d.relocate(homeModel); |
201 | |
} |
202 | |
} |
203 | |
} |
204 | 0 | } |
205 | |
} |
206 | |
|
207 | |
class ActionNavigateUpFromDiagram extends AbstractActionNavigate { |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
public ActionNavigateUpFromDiagram() { |
213 | 2289 | super("button.go-up", true); |
214 | 2289 | } |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
protected Object navigateTo(Object source) { |
220 | 0 | if (source instanceof ArgoDiagram) { |
221 | 0 | return ((ArgoDiagram) source).getNamespace(); |
222 | |
} |
223 | 0 | return null; |
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
@Override |
230 | |
public boolean isEnabled() { |
231 | 14347 | return true; |
232 | |
} |
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
@Override |
238 | |
public void actionPerformed(ActionEvent e) { |
239 | 0 | Object target = TargetManager.getInstance().getTarget(); |
240 | 0 | Object destination = navigateTo(target); |
241 | 0 | if (destination != null) { |
242 | 0 | TargetManager.getInstance().setTarget(destination); |
243 | |
} |
244 | 0 | } |
245 | |
} |