Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b1abb033a650c4bc66dac511d6e8398da14eeb4a (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
/*
 * Copyright (c) 2007 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/2008/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»

«EXTENSION xpt::diagram::Utils»

«DEFINE ViewProvider FOR gmfgen::GenDiagram-»
«EXPAND xpt::Common::copyright FOR getDiagram().editorGen-»
package «providersPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «notationViewProviderClassName» extends org.eclipse.gmf.runtime.diagram.core.providers.AbstractViewProvider {
	«EXPAND getDiagramViewClass-»
	«EXPAND getNodeViewClass-»
	«EXPAND getEdgeViewClass-»
	«EXPAND getSemanticElementType-»
	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE getDiagramViewClass FOR gmfgen::GenDiagram-»

«EXPAND xpt::Common::generatedMemberComment»
protected Class getDiagramViewClass(org.eclipse.core.runtime.IAdaptable semanticAdapter, String diagramKind) {
	«REM»When diagram domain element is null only diagram kind is checked«ENDREM-»
	«EXPAND defineSemanticElement FOR domainDiagramElement-»
	if («EXPAND xpt::editor::VisualIDRegistry::modelID».equals(diagramKind)«EXPAND checkSemanticElement(self) FOR domainDiagramElement») {
			return «getNotationViewFactoryQualifiedClassName()».class;
	}
	return null;
}
«ENDDEFINE»

«DEFINE defineSemanticElement FOR genmodel::GenClass-»
org.eclipse.emf.ecore.EObject semanticElement = getSemanticElement(semanticAdapter);
«ENDDEFINE»

«DEFINE checkSemanticElement(diagram : gmfgen::GenDiagram) FOR genmodel::GenClass» && «EXPAND xpt::editor::VisualIDRegistry::getDiagramVisualIDMethodCall FOR diagram»(semanticElement) != -1«ENDDEFINE»

«DEFINE getNodeViewClass FOR gmfgen::GenDiagram-»

«EXPAND xpt::Common::generatedMemberComment»
protected Class getNodeViewClass(org.eclipse.core.runtime.IAdaptable semanticAdapter,
		org.eclipse.gmf.runtime.notation.View containerView, String semanticHint) {
	if (containerView == null) {
		return null;
	}
	org.eclipse.gmf.runtime.emf.type.core.IElementType elementType = getSemanticElementType(semanticAdapter);
	org.eclipse.emf.ecore.EObject domainElement = getSemanticElement(semanticAdapter);
	int visualID;
	if (semanticHint == null) {
		// Semantic hint is not specified. Can be a result of call from CanonicalEditPolicy.
		// In this situation there should be NO elementType, visualID will be determined
		// by VisualIDRegistry.getNodeVisualID() for domainElement.
		if (elementType != null || domainElement == null) {
			return null;
		}
		visualID = «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall»(containerView, domainElement);
	} else {
		visualID = «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall»(semanticHint);
		if (elementType != null) {
			// Semantic hint is specified together with element type.
			// Both parameters should describe exactly the same diagram element.
			// In addition we check that visualID returned by VisualIDRegistry.getNodeVisualID() for
			// domainElement (if specified) is the same as in element type.
			if (!«getElementTypesQualifiedClassName()».isKnownElementType(elementType)
					|| (!(elementType instanceof org.eclipse.gmf.runtime.emf.type.core.IHintedType))) {
				return null; // foreign element type
			}
			String elementTypeHint = ((org.eclipse.gmf.runtime.emf.type.core.IHintedType) elementType).getSemanticHint();
			if (!semanticHint.equals(elementTypeHint)) {
				return null; // if semantic hint is specified it should be the same as in element type
			}
			if (domainElement != null && visualID != «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall»(containerView, domainElement)) {
				return null; // visual id for node EClass should match visual id from element type
			}
		} else {
			// Element type is not specified. Domain element should be present (except pure design elements).
			// This method is called with EObjectAdapter as parameter from:
			//   - ViewService.createNode(View container, EObject eObject, String type, PreferencesHint preferencesHint) 
			//   - generated ViewFactory.decorateView() for parent element
	«IF getElements(self)->select(e | e.elementType <> null)->size() > 0-»
			if (!«getEditPartQualifiedClassName()».MODEL_ID.equals(«getVisualIDRegistryQualifiedClassName()».getModelID(containerView))) {
				return null; // foreign diagram
			}
			switch (visualID) {
		«IF ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::NotationType]->size() > 0-»
			«EXPAND caseVisualID FOREACH ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::NotationType]-»
				break; // pure design element
		«ENDIF-»
		«IF ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::MetamodelType]->size() > 0 or ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::SpecializationType]->size() > 0-»
			«EXPAND caseVisualID FOREACH ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::MetamodelType]-»
			«EXPAND caseVisualID FOREACH ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::SpecializationType]-»
				if (domainElement == null || visualID != «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall»(containerView, domainElement)) {
					return null; // visual id in semantic hint should match visual id for domain element
				}
				break;
		«ENDIF-»
			«EXPAND checkChildrenVisualIDs FOREACH getElements(self)->select(e | e.elementType <> null)-»
			default:
				return null;
			}
	«ELSE-»
			return null;
	«ENDIF-»
		}
	}
	return getNodeViewClass(containerView, visualID);
}

«EXPAND xpt::Common::generatedMemberComment»
protected Class getNodeViewClass(org.eclipse.gmf.runtime.notation.View containerView, int visualID) {
	if (containerView == null || !«EXPAND xpt::editor::VisualIDRegistry::canCreateNodeMethodCall»(containerView, visualID)) {
		return null;
	}
	switch (visualID) {
	«EXPAND caseContainerVisualID FOREACH getAllChildContainers()-»
	«EXPAND caseEntry FOREACH links.labels-»
	}
	return null;
}
«ENDDEFINE»

«DEFINE caseVisualID FOR gmfgen::ElementType-»
	«EXPAND xpt::Common::caseVisualID FOR diagramElement»
«ENDDEFINE»

«DEFINE checkChildrenVisualIDs FOR gmfgen::GenCommonBase-»
«ENDDEFINE»

«DEFINE checkChildrenVisualIDs FOR gmfgen::GenNode-»
	«EXPAND xpt::Common::caseVisualID FOREACH labels-»
	«EXPAND xpt::Common::caseVisualID FOREACH compartments-»
	«IF not labels->isEmpty() or not compartments->isEmpty()-»
if («EXPAND xpt::editor::VisualIDRegistry::visualID» != «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR getDiagram()»(containerView)
		|| containerView.getElement() != domainElement) {
	return null; // wrong container
}
break;
	«ENDIF-»
«ENDDEFINE»

«DEFINE checkChildrenVisualIDs FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::caseVisualID FOREACH labels-»
	«IF not labels->isEmpty()-»
if («EXPAND xpt::editor::VisualIDRegistry::visualID» != «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR getDiagram()»(containerView)
		|| containerView.getElement() != domainElement) {
	return null; // wrong container
}
break;
	«ENDIF-»
«ENDDEFINE»

«DEFINE caseContainerVisualID FOR gmfgen::GenChildContainer-»
	«EXPAND caseEntry-»
«ENDDEFINE»

«DEFINE caseContainerVisualID FOR gmfgen::GenNode-»
	«EXPAND caseEntry-»
	«EXPAND caseEntry FOREACH labels-»
«ENDDEFINE»

«DEFINE caseEntry FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::caseVisualID» return «getNotationViewFactoryQualifiedClassName()».class;
«ENDDEFINE»

«DEFINE getEdgeViewClass FOR gmfgen::GenDiagram-»

«EXPAND xpt::Common::generatedMemberComment»
protected Class getEdgeViewClass(org.eclipse.core.runtime.IAdaptable semanticAdapter,
		org.eclipse.gmf.runtime.notation.View containerView, String semanticHint) {
	org.eclipse.gmf.runtime.emf.type.core.IElementType elementType = getSemanticElementType(semanticAdapter);
	if (!«getElementTypesQualifiedClassName()».isKnownElementType(elementType)
			|| (!(elementType instanceof org.eclipse.gmf.runtime.emf.type.core.IHintedType))) {
		return null; // foreign element type
	}
	String elementTypeHint = ((org.eclipse.gmf.runtime.emf.type.core.IHintedType) elementType).getSemanticHint();
	if (elementTypeHint == null) {
		return null; // our hint is visual id and must be specified
	}
	if (semanticHint != null && !semanticHint.equals(elementTypeHint)) {
		return null; // if semantic hint is specified it should be the same as in element type
	}
	int visualID = «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall»(elementTypeHint);
	org.eclipse.emf.ecore.EObject domainElement = getSemanticElement(semanticAdapter);
	if (domainElement != null && visualID != «EXPAND xpt::editor::VisualIDRegistry::getLinkWithClassVisualIDMethodCall»(domainElement)) {
		return null; // visual id for link EClass should match visual id from element type
	}
	return getEdgeViewClass(visualID);
}

«EXPAND xpt::Common::generatedMemberComment»
protected Class getEdgeViewClass(int visualID) {
	switch (visualID) {
	«EXPAND caseEntry FOREACH links-»
	}
	return null;
}
«ENDDEFINE»

«DEFINE getSemanticElementType FOR gmfgen::GenDiagram-»

«EXPAND xpt::Common::generatedMemberComment»
private org.eclipse.gmf.runtime.emf.type.core.IElementType getSemanticElementType(
		org.eclipse.core.runtime.IAdaptable semanticAdapter) {
	if (semanticAdapter == null) {
		return null;
	}
	return (org.eclipse.gmf.runtime.emf.type.core.IElementType) semanticAdapter.getAdapter(
			org.eclipse.gmf.runtime.emf.type.core.IElementType.class);
}
«ENDDEFINE»

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

Back to the top