1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package org.argouml.model.euml; |
16 | |
|
17 | |
import java.util.ArrayList; |
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.argouml.model.AbstractModelFactory; |
21 | |
import org.argouml.model.ModelManagementFactory; |
22 | |
import org.argouml.model.NotImplementedException; |
23 | |
import org.eclipse.emf.ecore.EObject; |
24 | |
import org.eclipse.emf.ecore.resource.Resource; |
25 | |
import org.eclipse.emf.ecore.util.EcoreUtil; |
26 | |
import org.eclipse.emf.edit.domain.EditingDomain; |
27 | |
import org.eclipse.uml2.common.edit.command.ChangeCommand; |
28 | |
import org.eclipse.uml2.uml.ElementImport; |
29 | |
import org.eclipse.uml2.uml.Model; |
30 | |
import org.eclipse.uml2.uml.Namespace; |
31 | |
import org.eclipse.uml2.uml.PackageableElement; |
32 | |
import org.eclipse.uml2.uml.Profile; |
33 | |
import org.eclipse.uml2.uml.UMLFactory; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | class ModelManagementFactoryEUMLImpl implements ModelManagementFactory, |
40 | |
AbstractModelFactory { |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
private EUMLModelImplementation modelImpl; |
46 | |
|
47 | |
private EditingDomain editingDomain; |
48 | |
|
49 | |
private org.eclipse.uml2.uml.Package theRootModel; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public ModelManagementFactoryEUMLImpl( |
58 | 0 | EUMLModelImplementation implementation) { |
59 | 0 | modelImpl = implementation; |
60 | 0 | editingDomain = implementation.getEditingDomain(); |
61 | 0 | } |
62 | |
|
63 | |
public ElementImport buildElementImport(final Object pack, |
64 | |
final Object me) { |
65 | 0 | UMLUtil.checkArgs(new Object[] {pack, me}, |
66 | |
new Class[] {Namespace.class, PackageableElement.class}); |
67 | |
|
68 | 0 | RunnableClass run = new RunnableClass() { |
69 | |
public void run() { |
70 | 0 | ElementImport elementImport = createElementImport(); |
71 | 0 | elementImport.setImportingNamespace((Namespace) pack); |
72 | 0 | elementImport.setImportedElement((PackageableElement) me); |
73 | 0 | getParams().add(elementImport); |
74 | 0 | } |
75 | |
}; |
76 | 0 | editingDomain.getCommandStack().execute( |
77 | |
new ChangeCommand(editingDomain, run)); |
78 | |
|
79 | 0 | return (ElementImport) run.getParams().get(0); |
80 | |
} |
81 | |
|
82 | |
|
83 | |
public org.eclipse.uml2.uml.Package buildPackage(final String name) { |
84 | 0 | RunnableClass run = new RunnableClass() { |
85 | |
public void run() { |
86 | 0 | org.eclipse.uml2.uml.Package pkg = |
87 | |
(org.eclipse.uml2.uml.Package) createPackage(); |
88 | 0 | if (name != null) { |
89 | 0 | pkg.setName(name); |
90 | |
} |
91 | 0 | getParams().add(pkg); |
92 | 0 | } |
93 | |
}; |
94 | 0 | editingDomain.getCommandStack().execute( |
95 | |
new ChangeCommand(editingDomain, run)); |
96 | 0 | return (org.eclipse.uml2.uml.Package) run.getParams().get(0); |
97 | |
} |
98 | |
|
99 | |
public Object copyPackage(Object source, Object ns) { |
100 | |
|
101 | 0 | return null; |
102 | |
} |
103 | |
|
104 | |
public ElementImport createElementImport() { |
105 | 0 | RunnableClass run = new RunnableClass() { |
106 | |
public void run() { |
107 | 0 | getParams().add(UMLFactory.eINSTANCE.createElementImport()); |
108 | 0 | } |
109 | |
}; |
110 | 0 | editingDomain.getCommandStack().execute( |
111 | |
new ChangeCommand(editingDomain, run)); |
112 | 0 | return (ElementImport) run.getParams().get(0); |
113 | |
} |
114 | |
|
115 | |
public Model createModel() { |
116 | |
|
117 | |
|
118 | |
|
119 | 0 | RunnableClass run = new RunnableClass() { |
120 | |
public void run() { |
121 | 0 | getParams().add(UMLFactory.eINSTANCE.createModel()); |
122 | 0 | } |
123 | |
}; |
124 | 0 | editingDomain.getCommandStack().execute( |
125 | |
new ChangeCommand(editingDomain, run)); |
126 | 0 | return (Model) run.getParams().get(0); |
127 | |
} |
128 | |
|
129 | |
public org.eclipse.uml2.uml.Package createPackage() { |
130 | 0 | RunnableClass run = new RunnableClass() { |
131 | |
public void run() { |
132 | 0 | getParams().add(UMLFactory.eINSTANCE.createPackage()); |
133 | 0 | } |
134 | |
}; |
135 | 0 | editingDomain.getCommandStack().execute( |
136 | |
new ChangeCommand(editingDomain, run)); |
137 | 0 | return (org.eclipse.uml2.uml.Package) run.getParams().get(0); |
138 | |
} |
139 | |
|
140 | |
public Profile createProfile() { |
141 | 0 | RunnableClass run = new RunnableClass() { |
142 | |
public void run() { |
143 | 0 | getParams().add(UMLFactory.eINSTANCE.createProfile()); |
144 | 0 | } |
145 | |
}; |
146 | 0 | editingDomain.getCommandStack().execute( |
147 | |
new ChangeCommand(editingDomain, run)); |
148 | 0 | return (Profile) run.getParams().get(0); |
149 | |
} |
150 | |
|
151 | |
@Deprecated |
152 | |
public Object createSubsystem() { |
153 | |
|
154 | 0 | throw new NotImplementedException(); |
155 | |
} |
156 | |
|
157 | |
|
158 | |
|
159 | |
@Deprecated |
160 | |
public void setRootModel(Object rootModel) { |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | 0 | if (rootModel != null |
166 | |
&& !(rootModel instanceof org.eclipse.uml2.uml.Package)) { |
167 | 0 | throw new IllegalArgumentException( |
168 | |
"The rootModel supplied must be a Package. Got a " |
169 | |
+ rootModel.getClass().getName()); |
170 | |
} |
171 | 0 | List<EObject> restoreList = new ArrayList<EObject>(); |
172 | 0 | if (theRootModel != null && theRootModel.eResource() != null) { |
173 | 0 | if (theRootModel.eResource().getContents().contains(theRootModel) |
174 | |
&& rootModel == theRootModel) { |
175 | 0 | for (EObject o : theRootModel.eResource().getContents()) { |
176 | 0 | if (o != theRootModel) { |
177 | 0 | restoreList.add(o); |
178 | |
} |
179 | |
} |
180 | |
} |
181 | 0 | EcoreUtil.remove(theRootModel); |
182 | |
} |
183 | 0 | theRootModel = (org.eclipse.uml2.uml.Package) rootModel; |
184 | 0 | if (rootModel != null && theRootModel.eResource() == null) { |
185 | 0 | restoreList.add(0, theRootModel); |
186 | 0 | Resource r = UMLUtil.getResource(modelImpl, UMLUtil.DEFAULT_URI, |
187 | |
Boolean.FALSE); |
188 | 0 | r.getContents().addAll(restoreList); |
189 | |
} |
190 | 0 | modelImpl.getModelEventPump().setRootContainer(theRootModel); |
191 | 0 | } |
192 | |
|
193 | |
@Deprecated |
194 | |
public org.eclipse.uml2.uml.Package getRootModel() { |
195 | 0 | return theRootModel; |
196 | |
} |
197 | |
|
198 | |
} |