Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e12a3b7641bcadbd3a41350abbc9ac12fbe27929 (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
/*
 * Copyright (c) 2007, 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
 *    Michael Golubev (Borland) - [243151] explicit source/target for links
 */
«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
«IMPORT 'http://www.eclipse.org/papyrus/2009/papyrusgmfgenextension'»
«EXTENSION xpt::EMFUtils»
«EXTENSION xpt::diagram::updater::Utils»
«EXTENSION xpt::diagram::editpolicies::LinkUtils»
«EXTENSION xpt::GenModelUtils»
«EXTENSION gmf::GenModelUtils»

«DEFINE checkChildElementVisualID(inLoop : Boolean) FOR gmfgen::GenNode-»
if (visualID == «EXPAND xpt::editor::VisualIDRegistry::visualID») {
	result.add(new «getDiagram().editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»(«IF null <> modelFacet.childMetaFeature»«EXPAND MetaModel::DowncastToEObject('childElement') FOR getTypeGenClassX(modelFacet.childMetaFeature)»«ENDIF», visualID));
«IF inLoop-»
	continue;
«ENDIF-»
}
«ENDDEFINE»

«REM»TEST «ENDREM»
«DEFINE getSemanticChildrenOfView FOR gmfgen::GenContainerBase-»

	«EXPAND xpt::Common::generatedMemberComment»
public static «EXPAND CodeStyle::G('java.util.List', getDiagram().editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName())» «EXPAND getSemanticChildrenMethodName»(org.eclipse.gmf.runtime.notation.View view) {
	«IF getSemanticChildrenChildFeatures(self)->size() > 0 or self.getPhantomNodes()->size() > 0-»
	«EXPAND defineModelElement-»
	«EXPAND CodeStyle::newGenericInstance('result', 'java.util.LinkedList', getDiagram().editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName())»();
«REM»childMetaFeature can be null here!«ENDREM»«-»
		«FOREACH getSemanticChildrenChildFeatures(self) AS childMetaFeature-»
			«IF null = childMetaFeature-»
	{ /*FIXME no containment/child feature found in the genmodel, toolsmith need to specify Class here manually*/ childElement = /*FIXME no containment/child feature found in the genmodel, toolsmith need to specify correct one here manually*/;
			«ELSEIF isListType(childMetaFeature)-»
	for («EXPAND CodeStyle::G('java.util.Iterator', '?')» it = «EXPAND MetaModel::getFeatureValue('modelElement', self.getModelElementType()) FOR childMetaFeature».iterator(); it.hasNext();) {
		«EXPAND MetaModel::DeclareAndAssign('childElement', 'it.next()', true) FOR getTypeGenClassX(childMetaFeature)»
			«ELSE-»
	{ «EXPAND MetaModel::DeclareAndAssign('childElement', 'modelElement', self.getModelElementType(), childMetaFeature) FOR getTypeGenClassX(childMetaFeature)»
			«ENDIF-»
		int visualID = «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall FOR getDiagram()»(view, «EXPAND MetaModel::DowncastToEObject('childElement') FOR getTypeGenClassX(childMetaFeature)»);
			«EXPAND checkChildElementVisualID(null <> childMetaFeature and isListType(childMetaFeature)) FOREACH getSemanticChildren(self, childMetaFeature)-»
	}
		«ENDFOREACH-»
«IF self.getPhantomNodes()->notEmpty()-»
	org.eclipse.emf.ecore.resource.Resource resource = modelElement.eResource();
	for (java.util.Iterator semanticIterator = getPhantomNodesIterator(resource); semanticIterator.hasNext();) {
			org.eclipse.emf.ecore.EObject childElement = (org.eclipse.emf.ecore.EObject) semanticIterator.next();
									
		if (childElement == modelElement) {
			continue;
		}
		«EXPAND addNextIfPhantom FOREACH self.getPhantomNodes()-»
	}
«ENDIF-»		
	return result;
	«ELSE-»
	return «EXPAND CodeStyle::emptyList»;
	«ENDIF-»
}
«ENDDEFINE»
«REM»FIN TEST «ENDREM»



«REM»The EcoreSwitch that will navigate the proper features according to the canvas' EObject«ENDREM»
«DEFINE createUpdaterSwitch FOR gmfgen::GenDiagram»
«EXPAND xpt::Common::generatedMemberComment»
	static class ThisDiagramUpdaterSwitch extends es.cv.gvcase.mdt.common.util.BasicEcoreSwitch<java.util.List<«editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»>, org.eclipse.gmf.runtime.notation.View> {
		@Override
		public java.util.List<«editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»> doSwitch(org.eclipse.emf.ecore.EObject modelElement) {
			«REM»getInfo provides the View«ENDREM»
			final org.eclipse.gmf.runtime.notation.View view = getInfo();
			if (view == null) {
				return java.util.Collections.EMPTY_LIST;
			}
			
			«getModelSwitchQualifiedName(domainDiagramElement)»<java.util.List<«editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»>> aSwitch = new «getModelSwitchQualifiedName(domainDiagramElement)»<java.util.List<«editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»>>() {
				«REM»Start of cases«ENDREM»
				@Override
				public java.util.List<«editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»> case«domainDiagramElement.ecoreClass.name»(«EXPAND MetaModel::MetaClass FOR domainDiagramElement» modelElement) {
					java.util.List<«editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»> result = new java.util.LinkedList<«editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»>();
					«FOREACH getSemanticChildrenChildFeatures(self) AS childMetaFeature-»
						«IF null = childMetaFeature-»
							{ /*FIXME no containment/child feature found in the genmodel, toolsmith need to specify Class here manually*/ childElement = /*FIXME no containment/child feature found in the genmodel, toolsmith need to specify correct one here manually*/;
						«ELSEIF isListType(childMetaFeature)-»
					for (java.util.Iterator it = «EXPAND xpt::Common::getFeatureValue('modelElement', getModelElementType()) FOR childMetaFeature».iterator(); it.hasNext();) {
						«EXPAND MetaModel::MetaClass FOR getTypeGenClassX(childMetaFeature)» childElement = («getQualifiedInterfaceName(getTypeGenClassX(childMetaFeature))») it.next();
						«ELSE-»
					{ «getQualifiedInterfaceName(getTypeGenClassX(childMetaFeature))» childElement = «EXPAND xpt::Common::getFeatureValue('modelElement', getModelElementType()) FOR childMetaFeature»;
						«ENDIF-»
						int visualID = «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall FOR getDiagram()»(view, «EXPAND xpt::Common::castToEObject FOR getTypeGenClassX(childMetaFeature)»childElement);
						«EXPAND checkChildElementVisualID(null <> childMetaFeature and isListType(childMetaFeature)) FOREACH getSemanticChildren(self, childMetaFeature)-»
					}
					«ENDFOREACH-»
					«IF not getPhantomNodes(self).isEmpty()-»
					org.eclipse.emf.ecore.resource.Resource resource = modelElement.eResource();
					for (java.util.Iterator semanticIterator = getPhantomNodesIterator(resource); semanticIterator.hasNext();) {
						org.eclipse.emf.ecore.EObject childElement = (org.eclipse.emf.ecore.EObject) semanticIterator.next();
						if (childElement == modelElement) {
							continue;
						}
					«EXPAND addNextIfPhantom FOREACH getPhantomNodes(self)-»
					}
					«ENDIF-»		
					return result;
				}
				
				«FOREACH getReferencingObjects().typeSelect(AlternateCanvas) AS referencer»
				@Override
				public java.util.List<«editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»> case«referencer.domainDiagramElement.ecoreClass.name»(«getQualifiedInterfaceName(referencer.domainDiagramElement)» modelElement) {
					java.util.List<«editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»> result = new java.util.LinkedList<«editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»>();
					«REM»«FOREACH getSemanticChildrenChildFeatures(this) AS childMetaFeature-»«ENDREM»
					«FOREACH getMutatingChildrenFeatures(referencer) AS childMetaFeature-»
						«IF null = childMetaFeature-»
							{ /*FIXME no containment/child feature found in the genmodel, toolsmith need to specify Class here manually*/ childElement = /*FIXME no containment/child feature found in the genmodel, toolsmith need to specify correct one here manually*/;
						«ELSEIF isListType(childMetaFeature)-»
					for (java.util.Iterator it = «EXPAND xpt::Common::getFeatureValue('modelElement', referencer.domainDiagramElement) FOR childMetaFeature».iterator(); it.hasNext();) {
						«getQualifiedInterfaceName(getTypeGenClassX(childMetaFeature))» childElement = («getQualifiedInterfaceName(getTypeGenClassX(childMetaFeature))») it.next();
						«ELSE-»
					{ «getQualifiedInterfaceName(getTypeGenClassX(childMetaFeature))» childElement = «EXPAND xpt::Common::getFeatureValue('modelElement', referencer.domainDiagramElement) FOR childMetaFeature»;
						«ENDIF-»
						int visualID = «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall FOR getDiagram()»(view, «EXPAND xpt::Common::castToEObject FOR getTypeGenClassX(childMetaFeature)»childElement);
						«REM»«EXPAND checkChildElementVisualID(null != childMetaFeature && isListType(childMetaFeature)) FOREACH getSemanticChildren(this, childMetaFeature)-»«ENDREM»
						«EXPAND checkMutatingChildElementVisualID(null <> childMetaFeature and isListType(childMetaFeature)) FOREACH getMutatingSemanticChildren(referencer, childMetaFeature)-»
					}
					«ENDFOREACH-»
					«REM»«IF !getPhantomNodes(this).isEmpty()-»
					org.eclipse.emf.ecore.resource.Resource resource = modelElement.eResource();
					for (java.util.Iterator semanticIterator = getPhantomNodesIterator(resource); semanticIterator.hasNext();) {
						org.eclipse.emf.ecore.EObject childElement = (org.eclipse.emf.ecore.EObject) semanticIterator.next();
						if (childElement == modelElement) {
							continue;
						}
					«EXPAND addNextIfPhantom FOREACH getPhantomNodes(this)-»
					}
					«ENDIF-»
					«ENDREM»		
					return result;
				}
				«ENDFOREACH»
				
				«REM»End of cases«ENDREM»			
			};
			return aSwitch.doSwitch(modelElement);
		}
	};
	«REM»The global variable for a Switch«ENDREM»
	«EXPAND xpt::Common::generatedMemberComment»
	private static ThisDiagramUpdaterSwitch aSwitch = new ThisDiagramUpdaterSwitch();
«ENDDEFINE»
«REM» Mutating check Visual ID «ENDREM»
«DEFINE checkMutatingChildElementVisualID(boolean inLoop) FOR papyrusgmfgenextension::AlternateGenTopLevelNode-»
	if (visualID == «EXPAND visualID») {
		result.add(new «genTopLevelNode.getDiagram().editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()»(«IF null <> typeModelFacet.childMetaFeature»«EXPAND xpt::Common::castToEObject FOR getTypeGenClassX(typeModelFacet.childMetaFeature)»«ENDIF»childElement, visualID));
	«IF inLoop-»
		continue;
	«ENDIF-»
	}
«ENDDEFINE»
«REM» Mutating VisualID espansion «ENDREM»
«DEFINE visualID FOR papyrusgmfgenextension::AlternateGenTopLevelNode»
	«EXPAND xpt::editor::VisualIDRegistry::visualID FOR genTopLevelNode»
«ENDDEFINE»
«DEFINE defineModelElement FOR gmfgen::GenContainerBase-»
if (!view.isSetElement()) {
	return java.util.Collections.EMPTY_LIST;
}
«EXPAND MetaModel::DeclareAndAssign('modelElement', 'view.getElement()') FOR getModelElementType()»
«ENDDEFINE»
«DEFINE getContainedLinksByTypeMethodBody(genLink : gmfgen::GenLink, sourceVarDefined : Boolean) FOR gmfgen::TypeLinkModelFacet-»
java.util.Collection result = new java.util.LinkedList();
	«LET isListType(childMetaFeature) AS inLoop-»
«IF inLoop-»
for (java.util.Iterator links = «EXPAND MetaModel::getFeatureValue('container', childMetaFeature.genClass) FOR childMetaFeature».iterator(); links.hasNext();) {
	org.eclipse.emf.ecore.EObject linkObject = (org.eclipse.emf.ecore.EObject ) links.next();
	if («EXPAND MetaModel::NotInstance('linkObject') FOR metaClass») {
		continue;
	}
	«EXPAND MetaModel::DeclareAndAssign('link', 'linkObject') FOR metaClass»
«ELSE-»
	«IF getTypeGenClassX(childMetaFeature) = metaClass-»
		«EXPAND MetaModel::DeclareAndAssign('link', 'container', getSourceType(), childMetaFeature) FOR metaClass»
	«ELSE-»
		«EXPAND MetaModel::DeclareAndAssign('linkObject', 'container', getSourceType(), childMetaFeature) FOR getTypeGenClassX(childMetaFeature)»
		if («EXPAND MetaModel::NotInstance('linkObject') FOR metaClass») {
			return result;
		}
		«EXPAND MetaModel::DeclareAndAssign('link', 'linkObject') FOR metaClass»
	«ENDIF-»
«ENDIF-»
		«EXPAND checkLinkVisualID(genLink, inLoop)-»

		«REM»BEGIN: PapyrusGenCode«ENDREM»
		«REM»Test if the source and target reference the same feature, in this case generation with collection«ENDREM»
		
		«IF self.sourceMetaFeature=self.targetMetaFeature»
			//Papyrus GenCode 
		    «EXPAND defineLinkDestinationForSet(inLoop) FOR self-»
			«IF null <> sourceMetaFeature-»
				«EXPAND defineLinkSource(inLoop)-»
				«IF sourceVarDefined-»
					«EXPAND checkLinkSource(inLoop)-»
				«ENDIF-»
				«EXPAND addLinkDescriptor(genLink, 'src', 'dst')-»
			«ELSE-»
				«EXPAND addLinkDescriptor(genLink, 'container', 'dst')-»
			«ENDIF-»
		«ELSE»
		«REM»END: PapyrusGenCode«ENDREM»
		«EXPAND defineLinkDestination(inLoop)-»
		«IF null <> sourceMetaFeature-»
			«EXPAND defineLinkSource(inLoop)-»
			«IF sourceVarDefined-»
				«EXPAND checkLinkSource(inLoop)-»
			«ENDIF-»
			«EXPAND addLinkDescriptor(genLink, 'src', 'dst')-»
		«ELSE-»
			«EXPAND addLinkDescriptor(genLink, 'container', 'dst')-»
		«ENDIF-»
«REM»BEGIN: PapyrusGenCode«ENDREM»
		«ENDIF-»
		«REM»END: PapyrusGenCode«ENDREM»
«IF inLoop-»
}
«ENDIF-»
	«ENDLET-»
return result;	
«ENDDEFINE»
«DEFINE defineLinkSource(inLoop : Boolean) FOR gmfgen::TypeLinkModelFacet-»
	«IF isListType(sourceMetaFeature)-»
java.util.List sources = «EXPAND MetaModel::getFeatureValue('link', metaClass) FOR sourceMetaFeature»;
«REM»BEGIN: PapyrusGenCode«ENDREM»
«REM»In the case of set greater that 1! not equal«ENDREM»
Object theSource = sources.size() >= 1 ? sources.get(0) : null;
«REM»END: PapyrusGenCode«ENDREM»
if («EXPAND MetaModel::NotInstance('theSource') FOR getSourceType()») {
	«EXPAND stopLinkProcessing(inLoop)-»
}
«EXPAND MetaModel::DeclareAndAssign('src', 'theSource', true) FOR getSourceType()»
	«ELSE-»
«EXPAND MetaModel::DeclareAndAssign('src', 'link', metaClass, sourceMetaFeature) FOR getSourceType()»
	«ENDIF-»
«ENDDEFINE»
«DEFINE checkLinkSource(inLoop : Boolean) FOR gmfgen::TypeLinkModelFacet-»
if (src != source) {
	«EXPAND stopLinkProcessing(inLoop)-»
}
«ENDDEFINE»


«REM»BEGIN: PapyrusGenCode«ENDREM»
«REM»Define target and source that can manage set«ENDREM»
«DEFINE defineLinkDestinationForSet(inLoop:Boolean) FOR gmfgen::TypeLinkModelFacet-»
	«IF isListType(targetMetaFeature)-»
java.util.List targets = «EXPAND MetaModel::getFeatureValue('link', metaClass) FOR targetMetaFeature»;
Object theTarget = targets.size() >=2 ? targets.get(1) : null;
if («EXPAND MetaModel::NotInstance('theTarget') FOR getTargetType()») {
	«EXPAND stopLinkProcessing(inLoop)-»
}
«EXPAND MetaModel::DeclareAndAssign('dst', 'theTarget', true) FOR getTargetType()»
	«ELSE-»
«EXPAND MetaModel::DeclareAndAssign('dst', 'link', metaClass, targetMetaFeature) FOR getTargetType()»
	«ENDIF-»
«ENDDEFINE»
«REM»END: PapyrusGenCode«ENDREM»

Back to the top