Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6db74791a0c9fe8bfe29cc5e1dcd0b554618c3a3 (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*
 * Copyright (c) 2006, 2009 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
 */

«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
«EXTENSION xpt::editor::Utils»

«DEFINE Editor FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::copyright FOR editorGen-»
package «packageName»;

	«EXPAND xpt::Common::generatedClassComment»
public class «className»  extends org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor«EXPAND implementsList FOR getEditorImplementsList(self)» {

	«EXPAND attributes-»
	
	«EXPAND _constructor-»
	
	«EXPAND getContextID-»
	«EXPAND createPaletteRoot FOR editorGen.diagram.palette-»
	
	«EXPAND getPreferencesHint-»
	
	«EXPAND getContributorId-»
	«EXPAND getAdapter-»
	
	«EXPAND getDocumentProvider-»
	
	«EXPAND getEditingDomain-»
	
	«EXPAND setDocumentProvider-»
	«IF isIDEMode(self)-»
	
		«EXPAND gotoMarker-»
		
		«EXPAND isSaveAsAllowed-»
		
		«EXPAND doSaveAs-»
		
		«EXPAND performSaveAs-»
		
		«EXPAND getShowInContext-»
		«EXPAND getNavigatorSelection FOR editorGen.navigator-»
	«ENDIF-»

	«EXPAND configureGraphicalViewer-»

	«IF editorGen.diagram.generateCreateShortcutAction()-»
	
		«EXPAND initializeGraphicalViewer-»
		
		«EXPAND DropTargetListener-»
	«ENDIF-»

	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE attributes FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
public static final String ID = "«iD»"; «EXPAND xpt::Common::nonNLS»
	
	«EXPAND xpt::Common::generatedMemberComment»
public static final String CONTEXT_ID = "«contextID»"; «EXPAND xpt::Common::nonNLS»
«ENDDEFINE»

«DEFINE _constructor FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
public «className»() {
	super(«null <> editorGen.diagram.palette and editorGen.diagram.palette.flyout»);
}
«ENDDEFINE»

«DEFINE getContextID FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
protected String getContextID() {
	return CONTEXT_ID;
}
«ENDDEFINE»

«DEFINE createPaletteRoot FOR gmfgen::Palette-»

	«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gef.palette.PaletteRoot createPaletteRoot(org.eclipse.gef.palette.PaletteRoot existingPaletteRoot) {
	org.eclipse.gef.palette.PaletteRoot root = super.createPaletteRoot(existingPaletteRoot);
	new «getFactoryQualifiedClassName()»().fillPalette(root);
	return root;
}
«ENDDEFINE»

«DEFINE getPreferencesHint FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint getPreferencesHint() {
«REM» 
	XXX seems better we use preference store directly (in configureGraphicalViewer) instead all these indirect ids 
«ENDREM»«-»
	return «EXPAND xpt::plugin::Activator::preferenceHintAccess FOR editorGen»;
}
«ENDDEFINE»

«DEFINE getContributorId FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
public String getContributorId() {
	return «editorGen.plugin.getActivatorQualifiedClassName()».ID;
}
«ENDDEFINE»

«DEFINE getAdapter FOR gmfgen::GenEditorView-»
	«IF not hasPropertySheet(self) or hasNavigator(self)-»
	
	«EXPAND xpt::Common::generatedMemberComment»
public Object getAdapter(Class type) {
	«IF not hasPropertySheet(self)-»
	if (type == org.eclipse.ui.views.properties.IPropertySheetPage.class) {
		return null;
	}
	«ENDIF-»
	«IF hasNavigator(self)-»
	if (type == org.eclipse.ui.part.IShowInTargetList.class) {
		return new org.eclipse.ui.part.IShowInTargetList() {
			public String[] getShowInTargetIds() {
				return new String[] { org.eclipse.ui.navigator.resources.ProjectExplorer.VIEW_ID };
			}
		};
	}
	«ENDIF-»
	return super.getAdapter(type);
}
	«ENDIF-»
«ENDDEFINE»

«DEFINE getDocumentProvider FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocumentProvider getDocumentProvider(org.eclipse.ui.IEditorInput input) {
	if («EXPAND checkEditorInput») {
		return «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getDocumentProvider();
	}
	return super.getDocumentProvider(input);
}
«ENDDEFINE»

«DEFINE getEditingDomain FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
public org.eclipse.emf.transaction.TransactionalEditingDomain getEditingDomain() {
	org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocument document = getEditorInput() != null ? getDocumentProvider().getDocument(getEditorInput()) : null;
	if (document instanceof org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument) {
		return ((org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument) document).getEditingDomain();
	}
	return super.getEditingDomain();
}
«ENDDEFINE»

«DEFINE setDocumentProvider FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
protected void setDocumentProvider(org.eclipse.ui.IEditorInput input) {
	if («EXPAND checkEditorInput») {
		setDocumentProvider(«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getDocumentProvider());
	} else {
		super.setDocumentProvider(input);
	}
}
«ENDDEFINE»

«DEFINE checkEditorInput FOR gmfgen::GenEditorView»«IF isIDEMode(self)»input instanceof org.eclipse.ui.IFileEditorInput || «ENDIF»input instanceof org.eclipse.emf.common.ui.URIEditorInput«ENDDEFINE»

«DEFINE gotoMarker FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
public void gotoMarker(org.eclipse.core.resources.IMarker marker) {
	org.eclipse.gmf.runtime.common.ui.services.marker.MarkerNavigationService.getInstance().gotoMarker(this, marker);
}
«ENDDEFINE»

«DEFINE isSaveAsAllowed FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
public boolean isSaveAsAllowed() {
	return true;
}
«ENDDEFINE»

«DEFINE doSaveAs FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
public void doSaveAs() {
	performSaveAs(new org.eclipse.core.runtime.NullProgressMonitor());
}
«ENDDEFINE»

«DEFINE performSaveAs FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
protected void performSaveAs(org.eclipse.core.runtime.IProgressMonitor progressMonitor) {
	org.eclipse.swt.widgets.Shell shell = getSite().getShell();
	org.eclipse.ui.IEditorInput input = getEditorInput();
	org.eclipse.ui.dialogs.SaveAsDialog dialog = new org.eclipse.ui.dialogs.SaveAsDialog(shell);
	org.eclipse.core.resources.IFile original = input instanceof org.eclipse.ui.IFileEditorInput ? ((org.eclipse.ui.IFileEditorInput) input).getFile() : null;
	if (original != null) {
		dialog.setOriginalFile(original);
	}
	dialog.create();
	org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocumentProvider provider = getDocumentProvider();
	if (provider == null) {
		// editor has been programmatically closed while the dialog was open
		return;
	}
	if (provider.isDeleted(input) && original != null) {
		String message = org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForSavingDeletedFile(self)) FOR editorGen», original.getName());
		dialog.setErrorMessage(null);
		dialog.setMessage(message, org.eclipse.jface.dialogs.IMessageProvider.WARNING);
	}
	if (dialog.open() == org.eclipse.jface.window.Window.CANCEL) {
		if (progressMonitor != null) {
			progressMonitor.setCanceled(true);
		}
		return;
	}
	org.eclipse.core.runtime.IPath filePath = dialog.getResult();
	if (filePath == null) {
		if (progressMonitor != null) {
			progressMonitor.setCanceled(true);
		}
		return;
	}
	org.eclipse.core.resources.IWorkspaceRoot workspaceRoot = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot();
	org.eclipse.core.resources.IFile file = workspaceRoot.getFile(filePath);
	final org.eclipse.ui.IEditorInput newInput = new org.eclipse.ui.part.FileEditorInput(file);
	// Check if the editor is already open
	org.eclipse.ui.IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
	org.eclipse.ui.IEditorReference[] editorRefs = org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
	for (int i = 0; i < editorRefs.length; i++) {
		if (matchingStrategy.matches(editorRefs[i], newInput)) {
			org.eclipse.jface.dialogs.MessageDialog.openWarning(shell, «EXPAND xpt::Externalizer::accessorCall(titleKey(i18nKeyForSaveAsProblems(self))) FOR editorGen», «EXPAND xpt::Externalizer::accessorCall(messageKey(i18nKeyForSaveAsProblems(self))) FOR editorGen»);
			return;
		}
	}
	boolean success = false;
	try {
		provider.aboutToChange(newInput);
		getDocumentProvider(newInput).saveDocument(progressMonitor, newInput, getDocumentProvider().getDocument(getEditorInput()), true);
		success = true;
	} catch (org.eclipse.core.runtime.CoreException x) {
		org.eclipse.core.runtime.IStatus status = x.getStatus();
		if (status == null || status.getSeverity() != org.eclipse.core.runtime.IStatus.CANCEL) {
			org.eclipse.jface.dialogs.ErrorDialog.openError(shell, «EXPAND xpt::Externalizer::accessorCall(titleKey(i18nKeyForSaveProblems(self))) FOR editorGen», «EXPAND xpt::Externalizer::accessorCall(messageKey(i18nKeyForSaveProblems(self))) FOR editorGen», x.getStatus());
		}
	} finally {
		provider.changed(newInput);
		if (success) {
			setInput(newInput);
		}
	}
	if (progressMonitor != null) {
		progressMonitor.setCanceled(!success);
	}
}
«ENDDEFINE»

«DEFINE getShowInContext FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
public org.eclipse.ui.part.ShowInContext getShowInContext() {
	return new org.eclipse.ui.part.ShowInContext(getEditorInput(), «IF hasNavigator(self)»getNavigatorSelection()«ELSE»getGraphicalViewer().getSelection()«ENDIF»);
}
«ENDDEFINE»

«DEFINE getNavigatorSelection FOR gmfgen::GenNavigator-»
	
	«EXPAND xpt::Common::generatedMemberComment»
private org.eclipse.jface.viewers.ISelection getNavigatorSelection() {
	org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument document = getDiagramDocument();
	«EXPAND xpt::navigator::NavigatorLinkHelper::findSelectionBody-»
}
«ENDDEFINE»

«DEFINE configureGraphicalViewer FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void configureGraphicalViewer() {
		super.configureGraphicalViewer();
		«EXPAND xpt::editor::DiagramEditorContextMenuProvider::qualifiedClassName FOR editorGen.diagram» provider =
				new «EXPAND xpt::editor::DiagramEditorContextMenuProvider::qualifiedClassName FOR editorGen.diagram»(this, getDiagramGraphicalViewer());
		getDiagramGraphicalViewer().setContextMenu(provider);
		getSite().registerContextMenu(org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds.DIAGRAM_EDITOR_CONTEXT_MENU, provider, getDiagramGraphicalViewer());
	}
«ENDDEFINE»

«DEFINE initializeGraphicalViewer FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
protected void initializeGraphicalViewer() {
	super.initializeGraphicalViewer();
	«EXPAND addDropTargetListener('org.eclipse.jface.util.LocalSelectionTransfer.getTransfer()')-»
	«EXPAND addDropTargetListener('org.eclipse.emf.edit.ui.dnd.LocalTransfer.getInstance()')-»
}
«ENDDEFINE»

«DEFINE addDropTargetListener(transferAccessor : String) FOR gmfgen::GenEditorView-»
getDiagramGraphicalViewer().addDropTargetListener(new DropTargetListener(getDiagramGraphicalViewer(), «transferAccessor») {

	protected Object getJavaObject(org.eclipse.swt.dnd.TransferData data) {
		return «transferAccessor».nativeToJava(data);
	}

});
«ENDDEFINE»

«DEFINE DropTargetListener FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedClassComment»
private abstract class DropTargetListener extends org.eclipse.gmf.runtime.diagram.ui.parts.DiagramDropTargetListener {

	«EXPAND DTL_constructor-»

	«EXPAND DTL_getObjectsBeingDropped-»

	«EXPAND DTL_getJavaObject-»

	«EXPAND DTL_additions-»
}
«ENDDEFINE»


«DEFINE DTL_constructor FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
public DropTargetListener(org.eclipse.gef.EditPartViewer viewer, org.eclipse.swt.dnd.Transfer xfer) {
	super(viewer, xfer);
}
«ENDDEFINE»

«DEFINE DTL_getObjectsBeingDropped FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
protected java.util.List getObjectsBeingDropped() {
	org.eclipse.swt.dnd.TransferData data = getCurrentEvent().currentDataType;
	java.util.Collection uris = new java.util.HashSet();

	Object transferedObject = getJavaObject(data);
	if (transferedObject instanceof org.eclipse.jface.viewers.IStructuredSelection) {
		org.eclipse.jface.viewers.IStructuredSelection selection = (org.eclipse.jface.viewers.IStructuredSelection) transferedObject;
		for (java.util.Iterator it = selection.iterator(); it.hasNext();) {
			Object nextSelectedObject = it.next();
«REM»
	TODO: move NavigatorItem to some place available in runtime and remove 
	"genEditor.getEditorGen().getNavigator() != null" test
«ENDREM»«-»
			«IF hasNavigator(self)»if (nextSelectedObject instanceof «editorGen.navigator.getNavigatorItemQualifiedClassName()») {
				org.eclipse.gmf.runtime.notation.View view = ((«editorGen.navigator.getNavigatorItemQualifiedClassName()») nextSelectedObject).getView();
				nextSelectedObject = view.getElement();
			} else «ENDIF»if (nextSelectedObject instanceof org.eclipse.core.runtime.IAdaptable) {
				org.eclipse.core.runtime.IAdaptable adaptable = (org.eclipse.core.runtime.IAdaptable) nextSelectedObject;
				nextSelectedObject = adaptable.getAdapter(org.eclipse.emf.ecore.EObject.class);
			}

			if (nextSelectedObject instanceof org.eclipse.emf.ecore.EObject) {
				org.eclipse.emf.ecore.EObject modelElement = (org.eclipse.emf.ecore.EObject) nextSelectedObject;
				org.eclipse.emf.ecore.resource.Resource modelElementResource = modelElement.eResource();
				uris.add(modelElementResource.getURI().appendFragment(modelElementResource.getURIFragment(modelElement)));	
			}
		}
	}

	java.util.List result = new java.util.ArrayList();
	for (java.util.Iterator it = uris.iterator(); it.hasNext();) {
		org.eclipse.emf.common.util.URI nextURI = (org.eclipse.emf.common.util.URI) it.next();
		org.eclipse.emf.ecore.EObject modelObject = getEditingDomain().getResourceSet().getEObject(nextURI, true);
		result.add(modelObject);
	}
	return result;
}
«ENDDEFINE»

«DEFINE DTL_getJavaObject FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Common::generatedMemberComment»
protected abstract Object getJavaObject(org.eclipse.swt.dnd.TransferData data);
«ENDDEFINE»

«DEFINE implementsList FOR Sequence(String)-»
«IF not self->isEmpty()» implements «EXPAND implementsListEntry FOREACH self SEPARATOR ', '»«ENDIF-»
«ENDDEFINE»

«DEFINE implementsListEntry FOR String»«self»«ENDDEFINE»

«DEFINE DTL_additions FOR gmfgen::GenEditorView-»
«ENDDEFINE»

«DEFINE additions FOR gmfgen::GenEditorView-»
«ENDDEFINE»

«DEFINE i18nValues FOR gmfgen::GenEditorView-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForSavingDeletedFile(self), 'The original file \"{0}\" has been deleted.')-»
«EXPAND xpt::Externalizer::messageEntry(titleKey(i18nKeyForSaveAsProblems(self)), 'Problem During Save As...')-»
«EXPAND xpt::Externalizer::messageEntry(messageKey(i18nKeyForSaveAsProblems(self)), 'Save could not be completed. Target file is already open in another editor.')-»
«EXPAND xpt::Externalizer::messageEntry(titleKey(i18nKeyForSaveProblems(self)), 'Save Problems')-»
«EXPAND xpt::Externalizer::messageEntry(messageKey(i18nKeyForSaveProblems(self)), 'Could not save file.')-»
«ENDDEFINE»

«DEFINE i18nAccessors FOR gmfgen::GenEditorView-»
	«EXPAND xpt::Externalizer::accessorField(i18nKeyForSavingDeletedFile(self))-»
	«EXPAND xpt::Externalizer::accessorField(titleKey(i18nKeyForSaveAsProblems(self)))-»
	«EXPAND xpt::Externalizer::accessorField(messageKey(i18nKeyForSaveAsProblems(self)))-»
	«EXPAND xpt::Externalizer::accessorField(titleKey(i18nKeyForSaveProblems(self)))-»
	«EXPAND xpt::Externalizer::accessorField(messageKey(i18nKeyForSaveProblems(self)))-»
«ENDDEFINE»

Back to the top