Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e71bd7fdbe6cb301ce6b908a07fe6c5da5e25c7a (plain) (blame)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
 * Copyright (c) 2007, 2008 Borland Software Corporation
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Alexander Shatalin (Borland) - initial API and implementation
 *    Dmitry Stadnik (Borland) - rewritten in xpand
 */

«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»

«EXTENSION xpt::editor::Utils»

«DEFINE className FOR gmfgen::GenDiagram»«newDiagramFileWizardClassName»«ENDDEFINE»

«DEFINE qualifiedClassName FOR gmfgen::GenDiagram»«editorGen.editor.packageName».«EXPAND className»«ENDDEFINE»

«DEFINE NewDiagramFileWizard FOR gmfgen::GenDiagram-»
«EXPAND xpt::Common::copyright FOR editorGen-»
package «editorGen.editor.packageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «EXPAND className» extends org.eclipse.jface.wizard.Wizard {

	«EXPAND xpt::Common::generatedMemberComment»
	private «EXPAND creationPage» myFileCreationPage;

	«EXPAND xpt::Common::generatedMemberComment»
	private «EXPAND xpt::editor::ModelElementSelectionPage::qualifiedClassName» diagramRootElementSelectionPage;

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.emf.transaction.TransactionalEditingDomain myEditingDomain;

	«EXPAND xpt::Common::generatedMemberComment»
	public «EXPAND className»(org.eclipse.emf.common.util.URI domainModelURI,
			org.eclipse.emf.ecore.EObject diagramRoot,
			org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain) {
		«EXPAND xpt::Common::_assert('domainModelURI != null : \"Domain model uri must be specified\"')-»
	    «EXPAND xpt::Common::_assert('diagramRoot != null : \"Doagram root element must be specified\"')-»
	    «EXPAND xpt::Common::_assert('editingDomain != null : \"Editing domain must be specified\"')-»

		myFileCreationPage = new «EXPAND creationPage»(«EXPAND xpt::Externalizer::accessorCall(nameKey(i18nKeyForNewDiagramFileWizardCreationPage(self))) FOR editorGen», org.eclipse.jface.viewers.StructuredSelection.EMPTY);
		myFileCreationPage.setTitle(«EXPAND xpt::Externalizer::accessorCall(titleKey(i18nKeyForNewDiagramFileWizardCreationPage(self))) FOR editorGen»);
		myFileCreationPage.setDescription(org.eclipse.osgi.util.NLS.bind(
				«EXPAND xpt::Externalizer::accessorCall(descriptionKey(i18nKeyForNewDiagramFileWizardCreationPage(self))) FOR editorGen», 
				«EXPAND xpt::editor::VisualIDRegistry::modelID»));
		org.eclipse.core.runtime.IPath filePath;
		String fileName = org.eclipse.emf.common.util.URI.decode(domainModelURI.trimFileExtension().lastSegment());
		if (domainModelURI.isPlatformResource()) {
			filePath = new org.eclipse.core.runtime.Path(domainModelURI.trimSegments(1).toPlatformString(true));
		} else if (domainModelURI.isFile()) {
			filePath = new org.eclipse.core.runtime.Path(domainModelURI.trimSegments(1).toFileString());
		} else {
			// TODO : use some default path
			throw new IllegalArgumentException("Unsupported URI: " + domainModelURI); «EXPAND xpt::Common::nonNLS»
		}
		myFileCreationPage.setContainerFullPath(filePath);
		myFileCreationPage.setFileName(«getDiagramEditorUtilQualifiedClassName()».getUniqueFileName(
				filePath, fileName, "«editorGen.diagramFileExtension»")); «EXPAND xpt::Common::nonNLS»

		diagramRootElementSelectionPage = new DiagramRootElementSelectionPage(«EXPAND xpt::Externalizer::accessorCall(nameKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self))) FOR editorGen»);
		diagramRootElementSelectionPage.setTitle(«EXPAND xpt::Externalizer::accessorCall(titleKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self))) FOR editorGen»);
		diagramRootElementSelectionPage.setDescription(«EXPAND xpt::Externalizer::accessorCall(descriptionKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self))) FOR editorGen»);
		diagramRootElementSelectionPage.setModelElement(diagramRoot);

	   	myEditingDomain = editingDomain;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public void addPages() {
		addPage(myFileCreationPage);
		addPage(diagramRootElementSelectionPage);
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public boolean performFinish() {
		java.util.List affectedFiles = new java.util.LinkedList();
		«IF null = editorGen.application-»
		org.eclipse.core.resources.IFile diagramFile = myFileCreationPage.createNewFile();
		«EXPAND xpt::Common::setCharset('diagramFile')-»
		affectedFiles.add(diagramFile);
		org.eclipse.emf.common.util.URI diagramModelURI = org.eclipse.emf.common.util.URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
		«ELSE-»
		org.eclipse.core.runtime.IPath diagramModelPath = myFileCreationPage.getContainerFullPath().append(myFileCreationPage.getFileName());
		org.eclipse.emf.common.util.URI diagramModelURI = org.eclipse.emf.common.util.URI.createFileURI(diagramModelPath.toString());
		«ENDIF-»
		org.eclipse.emf.ecore.resource.ResourceSet resourceSet = myEditingDomain.getResourceSet();
		final org.eclipse.emf.ecore.resource.Resource diagramResource = resourceSet.createResource(diagramModelURI);
		org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand command =
			new org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand(
				myEditingDomain, «EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardInitDiagramCommand(self)) FOR editorGen», affectedFiles) {

			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 {
				int diagramVID = «EXPAND xpt::editor::VisualIDRegistry::getDiagramVisualIDMethodCall»(diagramRootElementSelectionPage.getModelElement());
				if (diagramVID != «EXPAND xpt::editor::VisualIDRegistry::visualID») {
					return org.eclipse.gmf.runtime.common.core.command.CommandResult.newErrorCommandResult(
						«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardIncorrectRootError(self)) FOR editorGen»);
				}
				org.eclipse.gmf.runtime.notation.Diagram diagram =
					org.eclipse.gmf.runtime.diagram.core.services.ViewService.createDiagram(
						diagramRootElementSelectionPage.getModelElement(), «EXPAND xpt::editor::VisualIDRegistry::modelID»,
						«EXPAND xpt::plugin::Activator::preferenceHintAccess FOR editorGen»);
				diagramResource.getContents().add(diagram);
				«IF editorGen.sameFileForDiagramAndModel-»
				diagramResource.getContents().add(diagram.getElement());
				«ENDIF-»
				«IF not synchronized-»
				new «getDiagramContentInitializerQualifiedClassName()»().initDiagramContent(diagram);			
				«ENDIF-»
				return org.eclipse.gmf.runtime.common.core.command.CommandResult.newOKCommandResult();
			}
		};
		try {
			org.eclipse.core.commands.operations.OperationHistoryFactory.getOperationHistory().execute(
				command, new org.eclipse.core.runtime.NullProgressMonitor(), null);
			diagramResource.save(«EXPAND xpt::Common::getSaveOptions»);
			«getDiagramEditorUtilQualifiedClassName()».openDiagram(diagramResource);
		} catch (org.eclipse.core.commands.ExecutionException e) {
			«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
				"Unable to create model and diagram", e); «EXPAND xpt::Common::nonNLS»
		} catch (java.io.IOException ex) {
			«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
				"Save operation failed for: " + diagramModelURI, ex); «EXPAND xpt::Common::nonNLS»
		} catch (org.eclipse.ui.PartInitException ex) {
			«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
				"Unable to open editor", ex); «EXPAND xpt::Common::nonNLS»
		}			
		return true;
	}

	«EXPAND xpt::Common::generatedClassComment»
	private static class DiagramRootElementSelectionPage extends «EXPAND xpt::editor::ModelElementSelectionPage::qualifiedClassName» {

		«EXPAND xpt::Common::generatedMemberComment»
		protected DiagramRootElementSelectionPage(String pageName) {
			super(pageName);
		}

		«EXPAND xpt::Common::generatedMemberComment»
		protected String getSelectionTitle() {
			return «EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPageSelectionTitle(self)) FOR editorGen»;
		}

		«EXPAND xpt::Common::generatedMemberComment»
		protected boolean validatePage() {
			if (selectedModelElement == null) {
				setErrorMessage(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPageNoSelectionMessage(self)) FOR editorGen»);
				return false;
			}
			boolean result = org.eclipse.gmf.runtime.diagram.core.services.ViewService.getInstance().provides(
				new org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation(
					new org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter(selectedModelElement),
					«EXPAND xpt::editor::VisualIDRegistry::modelID», «EXPAND xpt::plugin::Activator::preferenceHintAccess FOR editorGen»));
			setErrorMessage(result ? null : «EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPageInvalidSelectionMessage(self)) FOR editorGen»);
			return result;
		}
	}
}
«ENDDEFINE»

«DEFINE creationPage FOR gmfgen::GenDiagram»
«IF null = editorGen.application-»
org.eclipse.ui.dialogs.WizardNewFileCreationPage«ELSE-»
«editorGen.application.packageName».WizardNewFileCreationPage«ENDIF-»
«ENDDEFINE»

«DEFINE i18nAccessors FOR gmfgen::GenDiagram-»
«EXPAND xpt::Externalizer::accessorField(nameKey(i18nKeyForNewDiagramFileWizardCreationPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(titleKey(i18nKeyForNewDiagramFileWizardCreationPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(descriptionKey(i18nKeyForNewDiagramFileWizardCreationPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(nameKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(titleKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(descriptionKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewDiagramFileWizardRootSelectionPageSelectionTitle(self))-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewDiagramFileWizardRootSelectionPageNoSelectionMessage(self))-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewDiagramFileWizardRootSelectionPageInvalidSelectionMessage(self))-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewDiagramFileWizardInitDiagramCommand(self))-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewDiagramFileWizardIncorrectRootError(self))-»
«ENDDEFINE»

«DEFINE i18nValues FOR gmfgen::GenDiagram-»
«EXPAND xpt::Externalizer::messageEntry(nameKey(i18nKeyForNewDiagramFileWizardCreationPage(self)), 'Initialize new diagram file')-»
«EXPAND xpt::Externalizer::messageEntry(titleKey(i18nKeyForNewDiagramFileWizardCreationPage(self)), 'Diagram file')-»
«EXPAND xpt::Externalizer::messageEntry(descriptionKey(i18nKeyForNewDiagramFileWizardCreationPage(self)), 'Create new diagram based on {0} model content')-»
«EXPAND xpt::Externalizer::messageEntry(nameKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)), 'Select diagram root element')-»
«EXPAND xpt::Externalizer::messageEntry(titleKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)), 'Diagram root element')-»
«EXPAND xpt::Externalizer::messageEntry(descriptionKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)), 'Select semantic model element to be depicted on diagram')-»"Select diagram root element:"
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewDiagramFileWizardRootSelectionPageSelectionTitle(self), 'Select diagram root element:')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewDiagramFileWizardRootSelectionPageNoSelectionMessage(self), 'Diagram root element is not selected')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewDiagramFileWizardRootSelectionPageInvalidSelectionMessage(self), 'Invalid diagram root element is selected')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewDiagramFileWizardInitDiagramCommand(self), 'Initializing diagram contents')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewDiagramFileWizardIncorrectRootError(self), 'Incorrect model object stored as a root resource object')-»
«ENDDEFINE»

Back to the top