Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 443b79f4fb0555617dc2f480f723fe67c5c62e75 (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
/*
 * Copyright (c) 2007, 2010 Borland Software Corporation and others
 * 
 * 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:
 *    Dmitry Stadnik (Borland) - initial API and implementation
 *    Michael Golubev (Borland) - #244970 (GenChildLabelNode can't be link's source/target)
 */

«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»

«EXTENSION xpt::providers::i18n»

«DEFINE ModelingAssistantProvider FOR gmfgen::GenDiagram-»
«EXPAND xpt::Common::copyright FOR editorGen-»
package «providersPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «modelingAssistantProviderClassName»
		extends org.eclipse.gmf.runtime.emf.ui.services.modelingassistant.ModelingAssistantProvider {

	«EXPAND selectExistingElementForSource-»

	«EXPAND selectExistingElementForTarget-»

	«EXPAND selectExistingElement-»

	«EXPAND isApplicableElement-»

	«EXPAND selectElement-»
	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE selectExistingElementForSource FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.emf.ecore.EObject selectExistingElementForSource(
			org.eclipse.core.runtime.IAdaptable target,
			org.eclipse.gmf.runtime.emf.type.core.IElementType relationshipType) {
		return selectExistingElement(target, getTypesForSource(target, relationshipType));
	}
«ENDDEFINE»

«DEFINE selectExistingElementForTarget FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.emf.ecore.EObject selectExistingElementForTarget(
			org.eclipse.core.runtime.IAdaptable source,
			org.eclipse.gmf.runtime.emf.type.core.IElementType relationshipType) {
		return selectExistingElement(source, getTypesForTarget(source, relationshipType));
	}
«ENDDEFINE»

«DEFINE selectExistingElement FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.emf.ecore.EObject selectExistingElement(
			org.eclipse.core.runtime.IAdaptable host, java.util.Collection types) {
		if (types.isEmpty()) {
			return null;
		}
		org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart editPart =
				(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) host.getAdapter(
						org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.class);
		if (editPart == null) {
			return null;
		}
		org.eclipse.gmf.runtime.notation.Diagram diagram =
				(org.eclipse.gmf.runtime.notation.Diagram) editPart.getRoot().getContents().getModel();
		«EXPAND CodeStyle::newGenericInstance('elements', 'java.util.HashSet', 'org.eclipse.emf.ecore.EObject')»();
		«EXPAND CodeStyle::iterate('element', 'org.eclipse.emf.ecore.EObject', 'it', 'diagram.getElement().eAllContents()')-»
			if (isApplicableElement(element, types)) {
				elements.add(element);
			}
		}
		if (elements.isEmpty()) {
			return null;
		}
		return selectElement((org.eclipse.emf.ecore.EObject[]) elements.toArray(
				new org.eclipse.emf.ecore.EObject[elements.size()]));
	}
«ENDDEFINE»

«DEFINE isApplicableElement FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected boolean isApplicableElement(org.eclipse.emf.ecore.EObject element, java.util.Collection types) {
		org.eclipse.gmf.runtime.emf.type.core.IElementType type =
				org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry.getInstance().getElementType(element);
		return types.contains(type);
	}
«ENDDEFINE»

«DEFINE selectElement FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.emf.ecore.EObject selectElement(org.eclipse.emf.ecore.EObject[] elements) {
		org.eclipse.swt.widgets.Shell shell = org.eclipse.swt.widgets.Display.getCurrent().getActiveShell();
		org.eclipse.jface.viewers.ILabelProvider labelProvider =
			new org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider(
				«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getItemProvidersAdapterFactory());
		org.eclipse.ui.dialogs.ElementListSelectionDialog dialog =
				new org.eclipse.ui.dialogs.ElementListSelectionDialog(shell, labelProvider);
		dialog.setMessage(«EXPAND xpt::Externalizer::accessorCall(messageKey(i18nKeyForModelingAssistantProvider(self))) FOR editorGen»);
		dialog.setTitle(«EXPAND xpt::Externalizer::accessorCall(titleKey(i18nKeyForModelingAssistantProvider(self))) FOR editorGen»);
		dialog.setMultipleSelection(false);
		dialog.setElements(elements);
		org.eclipse.emf.ecore.EObject selected = null;
		if (dialog.open() == org.eclipse.jface.window.Window.OK) {
			selected = (org.eclipse.emf.ecore.EObject) dialog.getFirstResult();
		}
		return selected;
	}
«ENDDEFINE»

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

«DEFINE i18nValues FOR gmfgen::GenDiagram-»
«EXPAND xpt::Externalizer::messageEntry(titleKey(i18nKeyForModelingAssistantProvider(self)), 'Select domain model element')-»
«EXPAND xpt::Externalizer::messageEntry(messageKey(i18nKeyForModelingAssistantProvider(self)), 'Available domain model elements:')-»
«ENDDEFINE»

«DEFINE i18nAccessors FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Externalizer::accessorField(titleKey(i18nKeyForModelingAssistantProvider(self)))-»
	«EXPAND xpt::Externalizer::accessorField(messageKey(i18nKeyForModelingAssistantProvider(self)))-»
«ENDDEFINE»

Back to the top