422
|
1 |
/*
|
|
2 |
* Copyright (c) 2007, 2008 Borland Software Corporation
|
|
3 |
*
|
|
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 |
* Artem Tikhomirov (Borland) - initial API and implementation
|
|
11 |
*/
|
|
12 |
«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
|
|
13 |
«IMPORT "http://www.eclipse.org/emf/2002/GenModel"»
|
|
14 |
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
|
|
15 |
«EXTENSION xpt::editor::GenDiagram»
|
|
16 |
«EXTENSION xpt::GenModelUtils»
|
|
17 |
«EXTENSION xpt::editor::Utils»
|
|
18 |
|
|
19 |
«DEFINE DiagramEditorUtil FOR gmfgen::GenDiagram-»
|
|
20 |
«EXPAND xpt::Common::copyright FOR editorGen-»
|
|
21 |
package «editorGen.editor.packageName»;
|
|
22 |
|
|
23 |
«EXPAND xpt::Common::generatedClassComment»
|
|
24 |
public class «diagramEditorUtilClassName» {
|
|
25 |
|
|
26 |
«EXPAND saveOptions-»
|
|
27 |
|
|
28 |
«EXPAND openDiagramMethod-»
|
|
29 |
«IF editorGen.application == null-»
|
|
30 |
|
|
31 |
«EXPAND setCharsetMethods-»
|
|
32 |
«ENDIF-»
|
|
33 |
|
|
34 |
«EXPAND getUniqueFileNameMethod-»
|
|
35 |
|
|
36 |
«IF editorGen.application != null»
|
|
37 |
/**
|
|
38 |
* Allows user to select file and loads it as a model.
|
|
39 |
*
|
|
40 |
* @generated
|
|
41 |
*/
|
|
42 |
public static org.eclipse.emf.ecore.resource.Resource openModel(
|
|
43 |
org.eclipse.swt.widgets.Shell shell, String description, org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain) {
|
|
44 |
org.eclipse.swt.widgets.FileDialog fileDialog = new org.eclipse.swt.widgets.FileDialog(shell, org.eclipse.swt.SWT.OPEN);
|
|
45 |
if (description != null) {
|
|
46 |
fileDialog.setText(description);
|
|
47 |
}
|
|
48 |
fileDialog.open();
|
|
49 |
String fileName = fileDialog.getFileName();
|
|
50 |
if (fileName == null || fileName.length() == 0) {
|
|
51 |
return null;
|
|
52 |
}
|
|
53 |
if (fileDialog.getFilterPath() != null) {
|
|
54 |
fileName = fileDialog.getFilterPath() + java.io.File.separator + fileName;
|
|
55 |
}
|
|
56 |
org.eclipse.emf.common.util.URI uri = org.eclipse.emf.common.util.URI.createFileURI(fileName);
|
|
57 |
org.eclipse.emf.ecore.resource.Resource resource = null;
|
|
58 |
try {
|
|
59 |
resource = editingDomain.getResourceSet().getResource(uri, true);
|
|
60 |
} catch (org.eclipse.emf.common.util.WrappedException we) {
|
|
61 |
«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Unable to load resource: " + uri, we); «EXPAND xpt::Common::nonNLS»
|
|
62 |
org.eclipse.jface.dialogs.MessageDialog.openError(shell,
|
|
63 |
«EXPAND xpt::Externalizer::accessorCall(i18nKeyForOpenModelResourceErrorDialog().titleKey()) FOR editorGen»,
|
|
64 |
org.eclipse.osgi.util.NLS.bind(
|
|
65 |
«EXPAND xpt::Externalizer::accessorCall(i18nKeyForOpenModelResourceErrorDialog().messageKey()) FOR editorGen»,
|
|
66 |
fileName));
|
|
67 |
}
|
|
68 |
return resource;
|
|
69 |
}
|
|
70 |
«ENDIF»
|
|
71 |
|
|
72 |
/**
|
|
73 |
* Runs the wizard in a dialog.
|
|
74 |
*
|
|
75 |
* @generated
|
|
76 |
*/
|
|
77 |
public static void runWizard(org.eclipse.swt.widgets.Shell shell, org.eclipse.jface.wizard.Wizard wizard, String settingsKey) {
|
|
78 |
org.eclipse.jface.dialogs.IDialogSettings pluginDialogSettings = «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getDialogSettings();
|
|
79 |
org.eclipse.jface.dialogs.IDialogSettings wizardDialogSettings = pluginDialogSettings.getSection(settingsKey);
|
|
80 |
if (wizardDialogSettings == null) {
|
|
81 |
wizardDialogSettings = pluginDialogSettings.addNewSection(settingsKey);
|
|
82 |
}
|
|
83 |
wizard.setDialogSettings(wizardDialogSettings);
|
|
84 |
org.eclipse.jface.wizard.WizardDialog dialog = new org.eclipse.jface.wizard.WizardDialog(shell, wizard);
|
|
85 |
dialog.create();
|
|
86 |
dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x), 500);
|
|
87 |
dialog.open();
|
|
88 |
}
|
|
89 |
|
|
90 |
«EXPAND createDiagramMethod-»
|
|
91 |
«IF domainDiagramElement != null»
|
|
92 |
«EXPAND createInitialModelMethod»
|
|
93 |
«EXPAND attachModelMethod»
|
|
94 |
«IF hasDocumentRoot()»«EXPAND createDocumentRootMethod»«ENDIF»
|
|
95 |
«ENDIF»
|
|
96 |
|
|
97 |
«EXPAND selectElementsMethod»
|
|
98 |
«EXPAND findElementsMethod»
|
|
99 |
«EXPAND findViewMethod»
|
|
100 |
|
|
101 |
«EXPAND additions»
|
|
102 |
}
|
|
103 |
«ENDDEFINE»
|
|
104 |
|
|
105 |
«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»
|
|
106 |
|
|
107 |
«DEFINE saveOptions FOR gmfgen::GenDiagram-»
|
|
108 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
109 |
public static java.util.Map getSaveOptions() {
|
|
110 |
java.util.Map saveOptions = new java.util.HashMap();
|
|
111 |
saveOptions.put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_ENCODING, "UTF-8"); «EXPAND xpt::Common::nonNLS»
|
|
112 |
saveOptions.put(org.eclipse.emf.ecore.resource.Resource.OPTION_SAVE_ONLY_IF_CHANGED, org.eclipse.emf.ecore.resource.Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
|
|
113 |
return saveOptions;
|
|
114 |
}
|
|
115 |
«ENDDEFINE»
|
|
116 |
|
|
117 |
«DEFINE openDiagramMethod FOR gmfgen::GenDiagram-»
|
|
118 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
119 |
public static boolean openDiagram(org.eclipse.emf.ecore.resource.Resource diagram) throws org.eclipse.ui.PartInitException {
|
|
120 |
«IF editorGen.application == null-»
|
|
121 |
String path = diagram.getURI().toPlatformString(true);
|
|
122 |
org.eclipse.core.resources.IResource workspaceResource = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().findMember(new org.eclipse.core.runtime.Path(path));
|
|
123 |
if (workspaceResource instanceof org.eclipse.core.resources.IFile) {
|
|
124 |
org.eclipse.ui.IWorkbenchPage page = org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
|
125 |
return null != page.openEditor(new org.eclipse.ui.part.FileEditorInput((org.eclipse.core.resources.IFile) workspaceResource), «editorGen.editor.getQualifiedClassName()».ID);
|
|
126 |
}
|
|
127 |
return false;
|
|
128 |
«ELSE-»
|
|
129 |
org.eclipse.ui.IWorkbenchPage page = org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
|
130 |
page.openEditor(new org.eclipse.emf.common.ui.URIEditorInput(diagram.getURI()), «editorGen.editor.getQualifiedClassName()».ID);
|
|
131 |
return true;
|
|
132 |
«ENDIF-»
|
|
133 |
}
|
|
134 |
«ENDDEFINE»
|
|
135 |
|
|
136 |
«DEFINE setCharsetMethods FOR gmfgen::GenDiagram-»
|
|
137 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
138 |
public static void setCharset(org.eclipse.core.resources.IFile file) {
|
|
139 |
if (file == null) {
|
|
140 |
return;
|
|
141 |
}
|
|
142 |
try {
|
|
143 |
file.setCharset("UTF-8", new org.eclipse.core.runtime.NullProgressMonitor()); «EXPAND xpt::Common::nonNLS»
|
|
144 |
} catch (org.eclipse.core.runtime.CoreException e) {
|
|
145 |
«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Unable to set charset for file " + file.getFullPath(), e); «EXPAND xpt::Common::nonNLS»
|
|
146 |
}
|
|
147 |
}
|
|
148 |
«ENDDEFINE»
|
|
149 |
|
|
150 |
«DEFINE getUniqueFileNameMethod FOR gmfgen::GenDiagram-»
|
|
151 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
152 |
public static String getUniqueFileName(org.eclipse.core.runtime.IPath containerFullPath, String fileName, String extension) {
|
|
153 |
if (containerFullPath == null) {
|
|
154 |
containerFullPath = new org.eclipse.core.runtime.Path(""); «EXPAND xpt::Common::nonNLS»
|
|
155 |
}
|
|
156 |
if (fileName == null || fileName.trim().length() == 0) {
|
|
157 |
fileName = "default"; «EXPAND xpt::Common::nonNLS»
|
|
158 |
}
|
|
159 |
org.eclipse.core.runtime.IPath filePath = containerFullPath.append(fileName);
|
|
160 |
if (extension != null && !extension.equals(filePath.getFileExtension())) {
|
|
161 |
filePath = filePath.addFileExtension(extension);
|
|
162 |
}
|
|
163 |
extension = filePath.getFileExtension();
|
|
164 |
fileName = filePath.removeFileExtension().lastSegment();
|
|
165 |
int i = 1;
|
|
166 |
while (
|
|
167 |
«IF editorGen.application == null-»
|
|
168 |
org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().exists(filePath)
|
|
169 |
«ELSE-»
|
|
170 |
filePath.toFile().exists()
|
|
171 |
«ENDIF-»
|
|
172 |
) {
|
|
173 |
i++;
|
|
174 |
filePath = containerFullPath.append(fileName + i);
|
|
175 |
if (extension != null) {
|
|
176 |
filePath = filePath.addFileExtension(extension);
|
|
177 |
}
|
|
178 |
}
|
|
179 |
return filePath.lastSegment();
|
|
180 |
}
|
|
181 |
«ENDDEFINE»
|
|
182 |
|
|
183 |
«DEFINE createDiagramMethod FOR gmfgen::GenDiagram-»
|
|
184 |
«EXPAND xpt::Common::generatedMemberComment(editorGen.application == null ? "This method should be called within a workspace modify operation since it creates resources." : "")»
|
|
185 |
public static org.eclipse.emf.ecore.resource.Resource createDiagram(org.eclipse.emf.common.util.URI diagramURI,«IF standaloneDomainModel()» org.eclipse.emf.common.util.URI modelURI,«ENDIF» org.eclipse.core.runtime.IProgressMonitor progressMonitor) {
|
|
186 |
org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain = org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory.INSTANCE.createEditingDomain();
|
|
187 |
progressMonitor.beginTask(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForCreateDiagramProgressTask()) FOR editorGen», 3);
|
|
188 |
final org.eclipse.emf.ecore.resource.Resource diagramResource = editingDomain.getResourceSet().createResource(diagramURI);
|
|
189 |
«IF standaloneDomainModel()-»
|
|
190 |
final org.eclipse.emf.ecore.resource.Resource modelResource = editingDomain.getResourceSet().createResource(modelURI);
|
|
191 |
«ELSEIF domainDiagramElement != null && hasDocumentRoot() /*for standalone models, we assume its resourcefactory would be able to set extendedMetaData option*/-»
|
|
192 |
((org.eclipse.emf.ecore.xmi.XMLResource) diagramResource).getDefaultSaveOptions().put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
|
|
193 |
((org.eclipse.emf.ecore.xmi.XMLResource) diagramResource).getDefaultLoadOptions().put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
|
|
194 |
«ENDIF-»
|
|
195 |
final String diagramName = diagramURI.lastSegment();
|
|
196 |
org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand command = new org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand(editingDomain, «EXPAND xpt::Externalizer::accessorCall(i18nKeyForCreateDiagramCommandLabel()) FOR editorGen», java.util.Collections.EMPTY_LIST) {
|
|
197 |
protected org.eclipse.gmf.runtime.common.core.command.CommandResult doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor monitor, org.eclipse.core.runtime.IAdaptable info) throws org.eclipse.core.commands.ExecutionException {
|
|
198 |
«IF domainDiagramElement != null-»
|
|
199 |
«EXPAND MetaModel::QualifiedClassName FOR domainDiagramElement» model = createInitialModel();
|
|
200 |
attachModelToResource(model, «IF standaloneDomainModel()»model«ELSE»diagram«ENDIF»Resource);
|
|
201 |
«ENDIF»
|
|
202 |
org.eclipse.gmf.runtime.notation.Diagram diagram = org.eclipse.gmf.runtime.diagram.core.services.ViewService.createDiagram(
|
|
203 |
«IF domainDiagramElement != null-»
|
|
204 |
«IF domainDiagramElement.isExternalInterface()»(org.eclipse.emf.ecore.EObject) «ENDIF»model,
|
|
205 |
«ENDIF-»
|
|
206 |
«EXPAND xpt::editor::VisualIDRegistry::modelID», «editorGen.plugin.getActivatorQualifiedClassName()».DIAGRAM_PREFERENCES_HINT);
|
|
207 |
if (diagram != null) {
|
|
208 |
diagramResource.getContents().add(diagram);
|
|
209 |
diagram.setName(diagramName);
|
|
210 |
«IF domainDiagramElement != null-»
|
|
211 |
diagram.setElement(«IF domainDiagramElement.isExternalInterface()»(org.eclipse.emf.ecore.EObject) «ENDIF»model);
|
|
212 |
«ENDIF-»
|
|
213 |
}
|
|
214 |
|
|
215 |
try {
|
|
216 |
«IF standaloneDomainModel()»modelResource.save(«EXPAND xpt::Common::getSaveOptions»);«ENDIF»
|
|
217 |
diagramResource.save(«EXPAND xpt::Common::getSaveOptions»);
|
|
218 |
} catch (java.io.IOException e) {
|
|
219 |
«/* TODO CommandResult.newErrorCommandResult(e) would be better? Or even throw ExecutionEx?*/»
|
|
220 |
«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Unable to store model and diagram resources", e); «EXPAND xpt::Common::nonNLS»
|
|
221 |
}
|
|
222 |
return org.eclipse.gmf.runtime.common.core.command.CommandResult.newOKCommandResult();
|
|
223 |
}
|
|
224 |
};
|
|
225 |
try {
|
|
226 |
org.eclipse.core.commands.operations.OperationHistoryFactory.getOperationHistory().execute(command, new org.eclipse.core.runtime.SubProgressMonitor(progressMonitor, 1), null);
|
|
227 |
} catch (org.eclipse.core.commands.ExecutionException e) {
|
|
228 |
«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Unable to create model and diagram", e); «EXPAND xpt::Common::nonNLS»
|
|
229 |
}
|
|
230 |
«IF editorGen.application == null-»
|
|
231 |
«IF standaloneDomainModel()»setCharset(org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(modelResource));«ENDIF»
|
|
232 |
setCharset(org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(diagramResource));
|
|
233 |
«ENDIF-»
|
|
234 |
return diagramResource;
|
|
235 |
}
|
|
236 |
«ENDDEFINE»
|
|
237 |
|
|
238 |
«DEFINE createInitialModelMethod FOR gmfgen::GenDiagram»
|
|
239 |
«EXPAND xpt::Common::generatedMemberComment("Create a new instance of domain element associated with canvas.\n<!-- begin-user-doc -->\n<!-- end-user-doc -->")»
|
|
240 |
private static «EXPAND MetaModel::QualifiedClassName FOR domainDiagramElement» createInitialModel() {
|
|
241 |
return «EXPAND MetaModel::NewInstance FOR domainDiagramElement»;
|
|
242 |
}
|
|
243 |
«ENDDEFINE»
|
|
244 |
|
|
245 |
«DEFINE attachModelMethod FOR gmfgen::GenDiagram»
|
|
246 |
«EXPAND xpt::Common::generatedMemberComment("Store model element in the resource.\n<!-- begin-user-doc -->\n<!-- end-user-doc -->")»
|
|
247 |
private static void attachModelToResource(«EXPAND MetaModel::QualifiedClassName FOR domainDiagramElement» model, org.eclipse.emf.ecore.resource.Resource resource) {
|
|
248 |
resource.getContents().add(«IF hasDocumentRoot()»createDocumentRoot(model)«ELSE»«IF domainDiagramElement.isExternalInterface()»(org.eclipse.emf.ecore.EObject) «ENDIF»model«ENDIF»);
|
|
249 |
}
|
|
250 |
«ENDDEFINE»
|
|
251 |
|
|
252 |
// invoke only when there's DocumentRoot in the domain model
|
|
253 |
«DEFINE createDocumentRootMethod FOR gmfgen::GenDiagram»
|
|
254 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
255 |
private static «EXPAND MetaModel::QualifiedClassName FOR getDocumentRoot()» createDocumentRoot(«EXPAND MetaModel::QualifiedClassName FOR domainDiagramElement» model) {
|
|
256 |
«EXPAND MetaModel::NewInstance("docRoot") FOR getDocumentRoot()»
|
|
257 |
«LET getDocumentRootSetFeature() AS f»«IF f == null-»
|
|
258 |
docRoot.set«domainDiagramElement.ecoreClass.name»(model); // FIXME name of the set method is pure guess«ELSE-»
|
|
259 |
«EXPAND MetaModel::setFeatureValue("docRoot", getDocumentRoot(), "model") FOR f»;«ENDIF»
|
|
260 |
«ENDLET-»
|
|
261 |
return docRoot;
|
|
262 |
}
|
|
263 |
«ENDDEFINE»
|
|
264 |
|
|
265 |
«DEFINE selectElementsMethod FOR gmfgen::GenDiagram»
|
|
266 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
267 |
public static void selectElementsInDiagram(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart diagramPart, java.util.List/*EditPart*/ editParts) {
|
|
268 |
diagramPart.getDiagramGraphicalViewer().deselectAll();
|
|
269 |
|
|
270 |
org.eclipse.gef.EditPart firstPrimary = null;
|
|
271 |
for (java.util.Iterator it = editParts.iterator(); it.hasNext();) {
|
|
272 |
org.eclipse.gef.EditPart nextPart = (org.eclipse.gef.EditPart) it.next();
|
|
273 |
diagramPart.getDiagramGraphicalViewer().appendSelection(nextPart);
|
|
274 |
if(firstPrimary == null && nextPart instanceof org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart) {
|
|
275 |
firstPrimary = nextPart;
|
|
276 |
}
|
|
277 |
}
|
|
278 |
|
|
279 |
if(!editParts.isEmpty()) {
|
|
280 |
diagramPart.getDiagramGraphicalViewer().reveal(firstPrimary != null ? firstPrimary : (org.eclipse.gef.EditPart)editParts.get(0));
|
|
281 |
}
|
|
282 |
}
|
|
283 |
«ENDDEFINE»
|
|
284 |
|
|
285 |
«DEFINE findElementsMethod FOR gmfgen::GenDiagram»
|
|
286 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
287 |
private static int findElementsInDiagramByID(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart diagramPart, org.eclipse.emf.ecore.EObject element, java.util.List editPartCollector) {
|
|
288 |
org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer viewer = (org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer) diagramPart.getViewer();
|
|
289 |
final int intialNumOfEditParts = editPartCollector.size();
|
|
290 |
|
|
291 |
if (element instanceof org.eclipse.gmf.runtime.notation.View) { // support notation element lookup
|
|
292 |
org.eclipse.gef.EditPart editPart = (org.eclipse.gef.EditPart) viewer.getEditPartRegistry().get(element);
|
|
293 |
if (editPart != null) {
|
|
294 |
editPartCollector.add(editPart);
|
|
295 |
return 1;
|
|
296 |
}
|
|
297 |
}
|
|
298 |
|
|
299 |
String elementID = org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil.getProxyID(element);
|
|
300 |
java.util.List associatedParts = viewer.findEditPartsForElement(elementID, org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.class);
|
|
301 |
// perform the possible hierarchy disjoint -> take the top-most parts only
|
|
302 |
for (java.util.Iterator editPartIt = associatedParts.iterator(); editPartIt.hasNext();) {
|
|
303 |
org.eclipse.gef.EditPart nextPart = (org.eclipse.gef.EditPart) editPartIt.next();
|
|
304 |
org.eclipse.gef.EditPart parentPart = nextPart.getParent();
|
|
305 |
while (parentPart != null && !associatedParts.contains(parentPart)) {
|
|
306 |
parentPart = parentPart.getParent();
|
|
307 |
}
|
|
308 |
if (parentPart == null) {
|
|
309 |
editPartCollector.add(nextPart);
|
|
310 |
}
|
|
311 |
}
|
|
312 |
|
|
313 |
if (intialNumOfEditParts == editPartCollector.size()) {
|
|
314 |
if (!associatedParts.isEmpty()) {
|
|
315 |
editPartCollector.add(associatedParts.iterator().next());
|
|
316 |
} else {
|
|
317 |
if (element.eContainer() != null) {
|
|
318 |
return findElementsInDiagramByID(diagramPart, element.eContainer(), editPartCollector);
|
|
319 |
}
|
|
320 |
}
|
|
321 |
}
|
|
322 |
return editPartCollector.size() - intialNumOfEditParts;
|
|
323 |
}
|
|
324 |
«ENDDEFINE»
|
|
325 |
|
|
326 |
«DEFINE findViewMethod FOR gmfgen::GenDiagram»
|
|
327 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
328 |
public static org.eclipse.gmf.runtime.notation.View findView(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart diagramEditPart, org.eclipse.emf.ecore.EObject targetElement, LazyElement2ViewMap lazyElement2ViewMap) {
|
|
329 |
boolean hasStructuralURI = false;
|
|
330 |
if(targetElement.eResource() instanceof org.eclipse.emf.ecore.xmi.XMLResource) {
|
|
331 |
hasStructuralURI = ((org.eclipse.emf.ecore.xmi.XMLResource)targetElement.eResource()).getID(targetElement) == null;
|
|
332 |
}
|
|
333 |
|
|
334 |
org.eclipse.gmf.runtime.notation.View view = null;
|
|
335 |
if(hasStructuralURI && !lazyElement2ViewMap.getElement2ViewMap().isEmpty()) {
|
|
336 |
view = (org.eclipse.gmf.runtime.notation.View)lazyElement2ViewMap.getElement2ViewMap().get(targetElement);
|
|
337 |
} else if (findElementsInDiagramByID(diagramEditPart, targetElement, lazyElement2ViewMap.editPartTmpHolder) > 0) {
|
|
338 |
org.eclipse.gef.EditPart editPart = (org.eclipse.gef.EditPart) lazyElement2ViewMap.editPartTmpHolder.get(0);
|
|
339 |
lazyElement2ViewMap.editPartTmpHolder.clear();
|
|
340 |
view = editPart.getModel() instanceof org.eclipse.gmf.runtime.notation.View ? (org.eclipse.gmf.runtime.notation.View) editPart.getModel() : null;
|
|
341 |
}
|
|
342 |
|
|
343 |
return (view == null) ? diagramEditPart.getDiagramView() : view;
|
|
344 |
}
|
|
345 |
|
|
346 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
347 |
public static class LazyElement2ViewMap {
|
|
348 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
349 |
private java.util.Map element2ViewMap;
|
|
350 |
|
|
351 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
352 |
private org.eclipse.gmf.runtime.notation.View scope;
|
|
353 |
|
|
354 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
355 |
private java.util.Set elementSet;
|
|
356 |
|
|
357 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
358 |
public final java.util.List editPartTmpHolder = new java.util.ArrayList();
|
|
359 |
|
|
360 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
361 |
public LazyElement2ViewMap(org.eclipse.gmf.runtime.notation.View scope, java.util.Set elements) {
|
|
362 |
this.scope = scope;
|
|
363 |
this.elementSet = elements;
|
|
364 |
}
|
|
365 |
|
|
366 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
367 |
public final java.util.Map getElement2ViewMap() {
|
|
368 |
if(element2ViewMap == null) {
|
|
369 |
element2ViewMap = new java.util.HashMap();
|
|
370 |
// map possible notation elements to itself as these can't be found by view.getElement()
|
|
371 |
for (java.util.Iterator it = elementSet.iterator(); it.hasNext();) {
|
|
372 |
org.eclipse.emf.ecore.EObject element = (org.eclipse.emf.ecore.EObject) it.next();
|
|
373 |
if(element instanceof org.eclipse.gmf.runtime.notation.View) {
|
|
374 |
org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) element;
|
|
375 |
if(view.getDiagram() == scope.getDiagram()) {
|
|
376 |
element2ViewMap.put(element, element); // take only those that part of our diagram
|
|
377 |
}
|
|
378 |
}
|
|
379 |
}
|
|
380 |
|
|
381 |
buildElement2ViewMap(scope, element2ViewMap, elementSet);
|
|
382 |
}
|
|
383 |
return element2ViewMap;
|
|
384 |
}
|
|
385 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
386 |
static java.util.Map buildElement2ViewMap(org.eclipse.gmf.runtime.notation.View parentView, java.util.Map element2ViewMap, java.util.Set elements) {
|
|
387 |
if(elements.size() == element2ViewMap.size()) return element2ViewMap;
|
|
388 |
|
|
389 |
if(parentView.isSetElement() && !element2ViewMap.containsKey(parentView.getElement()) && elements.contains(parentView.getElement())) {
|
|
390 |
element2ViewMap.put(parentView.getElement(), parentView);
|
|
391 |
if(elements.size() == element2ViewMap.size()) return element2ViewMap;
|
|
392 |
}
|
|
393 |
|
|
394 |
for (java.util.Iterator it = parentView.getChildren().iterator(); it.hasNext();) {
|
|
395 |
buildElement2ViewMap((org.eclipse.gmf.runtime.notation.View) it.next(), element2ViewMap, elements);
|
|
396 |
if(elements.size() == element2ViewMap.size()) return element2ViewMap;
|
|
397 |
}
|
|
398 |
for (java.util.Iterator it = parentView.getSourceEdges().iterator(); it.hasNext();) {
|
|
399 |
buildElement2ViewMap((org.eclipse.gmf.runtime.notation.View) it.next(), element2ViewMap, elements);
|
|
400 |
if(elements.size() == element2ViewMap.size()) return element2ViewMap;
|
|
401 |
}
|
|
402 |
for (java.util.Iterator it = parentView.getSourceEdges().iterator(); it.hasNext();) {
|
|
403 |
buildElement2ViewMap((org.eclipse.gmf.runtime.notation.View) it.next(), element2ViewMap, elements);
|
|
404 |
if(elements.size() == element2ViewMap.size()) return element2ViewMap;
|
|
405 |
}
|
|
406 |
return element2ViewMap;
|
|
407 |
}
|
|
408 |
} //LazyElement2ViewMap
|
|
409 |
«ENDDEFINE»
|
|
410 |
|
|
411 |
«DEFINE i18nAccessors FOR gmfgen::GenDiagram-»
|
|
412 |
«EXPAND xpt::Externalizer::accessorField(i18nKeyForOpenModelResourceErrorDialog().titleKey())-»
|
|
413 |
«EXPAND xpt::Externalizer::accessorField(i18nKeyForOpenModelResourceErrorDialog().messageKey())-»
|
|
414 |
«EXPAND xpt::Externalizer::accessorField(i18nKeyForCreateDiagramProgressTask())-»
|
|
415 |
«EXPAND xpt::Externalizer::accessorField(i18nKeyForCreateDiagramCommandLabel())-»
|
|
416 |
«ENDDEFINE»
|
|
417 |
|
|
418 |
«DEFINE i18nValues FOR gmfgen::GenDiagram-»
|
|
419 |
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForOpenModelResourceErrorDialog().titleKey(), "Error")-»
|
|
420 |
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForOpenModelResourceErrorDialog().messageKey(), "Failed to load model file {0}")-»
|
|
421 |
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForCreateDiagramProgressTask(), "Creating diagram and model files")-»
|
|
422 |
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForCreateDiagramCommandLabel(), "Creating diagram and model")-»
|
|
423 |
«ENDDEFINE»
|