Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4dc49a7a8471fbee687c5b84b394a090a6c977a3 (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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
/*
 * 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
 */

IMPORT "http://www.eclipse.org/gmf/2008/GenModel"
IMPORT "http://www.eclipse.org/emf/2002/GenModel"
IMPORT "http://www.eclipse.org/emf/2002/Ecore"

EXTENSION xpt::diagram::updater::Utils
EXTENSION xpt::diagram::editpolicies::LinkUtils
EXTENSION xpt::GenModelUtils

DEFINE DiagramUpdater FOR gmfgen::GenDiagramUpdater-
	EXPAND xpt::Common::copyright FOR editorGen-
package editorGen.editor.packageName;

	EXPAND xpt::Common::generatedClassComment
public class diagramUpdaterClassName {
	EXPAND isShortcutOrphaned-
LET editorGen.diagram.getAllContainers().select(container | hasSemanticChildren(container)) AS semanticContainers-

	EXPAND getGenericSemanticChildrenOfView(semanticContainers)-
	EXPAND getSemanticChildrenOfView FOREACH semanticContainers-
	EXPAND getPhantomNodesIterator-
ENDLET-

	EXPAND getGenericConnectedLinks(getAllSemanticElements(editorGen.diagram), getContainedLinksMethodNameSuffix())-
	
	EXPAND getGenericConnectedLinks(getAllSemanticDiagramElements(editorGen.diagram), getIncomingLinksMethodNameSuffix())-
	
	EXPAND getGenericConnectedLinks(getAllSemanticDiagramElements(editorGen.diagram), getOutgoingLinksMethodNameSuffix())-
	EXPAND getContainedLinks FOREACH getAllSemanticElements(editorGen.diagram)-
	EXPAND getIncomingLinks FOREACH getAllSemanticDiagramElements(editorGen.diagram)-
	EXPAND getOutgoingLinks FOREACH getAllSemanticDiagramElements(editorGen.diagram)-
	EXPAND getContainedLinksByTypeMethod FOREACH getAllContainedLinks(editorGen.diagram)-
	EXPAND getIncomingLinksByTypeMethod FOREACH getAllIncomingLinks(editorGen.diagram)-
	EXPAND getOutgoingLinksByTypeMethod FOREACH getAllOutgoingLinks(editorGen.diagram)-

	EXPAND additions-
}
ENDDEFINE

REM
	Currently shortcuts are supported only for domain-based diagram element.
	This means, view.isSetElement() == true.
ENDREM
DEFINE isShortcutOrphaned FOR gmfgen::GenDiagramUpdater-
	IF !editorGen.diagram.containsShortcutsTo.isEmpty()-

	EXPAND xpt::Common::generatedMemberComment
public static boolean isShortcutOrphaned(org.eclipse.gmf.runtime.notation.View view) {
	return !view.isSetElement() || view.getElement() == null || view.getElement().eIsProxy();
}
	ENDIF-
ENDDEFINE

DEFINE getGenericSemanticChildrenOfView(List[gmfgen::GenContainerBase] semanticContainers) FOR gmfgen::GenDiagramUpdater-
	EXPAND xpt::Common::generatedMemberComment
public static java.util.List getSemanticChildren(org.eclipse.gmf.runtime.notation.View view) {
	IF !semanticContainers.isEmpty()-
	switch (EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR editorGen.diagram(view)) {
		EXPAND getSemanticChildrenCase FOREACH semanticContainers-
	}
	ENDIF-
	return java.util.Collections.EMPTY_LIST;
}
ENDDEFINE

DEFINE getSemanticChildrenCase FOR gmfgen::GenContainerBase-
EXPAND xpt::Common::caseVisualID
	return EXPAND getSemanticChildrenMethodName(view);
ENDDEFINE

DEFINE getSemanticChildrenOfView FOR gmfgen::GenContainerBase-

	EXPAND xpt::Common::generatedMemberComment
public static java.util.List EXPAND getSemanticChildrenMethodName(org.eclipse.gmf.runtime.notation.View view) {
	IF getSemanticChildrenChildFeatures(this).size() > 0 || getPhantomNodes(this).size() > 0-
	EXPAND defineModelElement-
	java.util.List result = new java.util.LinkedList();
REMchildMetaFeature can be null here!ENDREM-
		FOREACH getSemanticChildrenChildFeatures(this) 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 MetaModel::getFeatureValue("modelElement", getModelElementType()) FOR childMetaFeature.iterator(); it.hasNext();) {
		EXPAND MetaModel::DeclareAndAssign("childElement", "it.next()", true) FOR getTypeGenClassX(childMetaFeature)
			ELSE-
	{ EXPAND MetaModel::DeclareAndAssign("childElement", "modelElement", 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 && isListType(childMetaFeature)) FOREACH getSemanticChildren(this, childMetaFeature)-
	}
		ENDFOREACH-
		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-		
	return result;
	ELSE-
	return java.util.Collections.EMPTY_LIST;
	ENDIF-
}
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 defineModelElement FOR gmfgen::GenCompartment-
if (false == view.eContainer() instanceof org.eclipse.gmf.runtime.notation.View) {
	return java.util.Collections.EMPTY_LIST;
}
org.eclipse.gmf.runtime.notation.View containerView = (org.eclipse.gmf.runtime.notation.View) view.eContainer();
if (!containerView.isSetElement()) {
	return java.util.Collections.EMPTY_LIST;
}
EXPAND MetaModel::DeclareAndAssign("modelElement", "containerView.getElement()") FOR getModelElementType()
ENDDEFINE

DEFINE getSemanticChildrenMethodName FOR gmfgen::GenContainerBasegetgetUniqueIdentifier()SemanticChildrenENDDEFINE

DEFINE getSemanticChildrenMethodCall FOR gmfgen::GenContainerBasegetDiagram().editorGen.diagramUpdater.getDiagramUpdaterQualifiedClassName().EXPAND getSemanticChildrenMethodNameENDDEFINE

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

DEFINE addNextIfPhantom FOR gmfgen::GenNode-
if (EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall FOR getDiagram()(view, childElement) == EXPAND xpt::editor::VisualIDRegistry::visualID) {
	result.add(new getDiagram().editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()(childElement, EXPAND xpt::editor::VisualIDRegistry::visualID));
	continue;
}
ENDDEFINE


DEFINE getPhantomNodesIterator FOR gmfgen::GenDiagramUpdater-
	IF !getPhantomNodes(editorGen.diagram).isEmpty()-
	
	EXPAND xpt::Common::generatedMemberComment
private static java.util.Iterator getPhantomNodesIterator(org.eclipse.emf.ecore.resource.Resource resource) {
	return resource.getAllContents();
}
	ENDIF-
ENDDEFINE

DEFINE getGenericConnectedLinks(List[gmfgen::GenCommonBase] linkContainers, String methodNameSuffix) FOR gmfgen::GenDiagramUpdater-
	EXPAND xpt::Common::generatedMemberComment
public static java.util.List getmethodNameSuffixLinks(org.eclipse.gmf.runtime.notation.View view) {
	IF !linkContainers.isEmpty()-
	switch (EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR editorGen.diagram(view)) {
		EXPAND getContainedLinksCase(methodNameSuffix) FOREACH linkContainers-
	}
	ENDIF-
	return java.util.Collections.EMPTY_LIST;
}
ENDDEFINE

DEFINE getContainedLinksCase(String methodNameSuffix) FOR gmfgen::GenCommonBase-
EXPAND xpt::Common::caseVisualID
	return EXPAND linkGetterName(methodNameSuffix)(view);
ENDDEFINE

REMThis DEFING can be used from other templates to inject call to the corresponding methodENDREM
DEFINE getContainedLinksMethodCall FOR gmfgen::GenCommonBasegetDiagram().editorGen.diagramUpdater.getDiagramUpdaterQualifiedClassName().EXPAND linkGetterName(getContainedLinksMethodNameSuffix())ENDDEFINE

REMThis DEFING can be used from other templates to inject call to the corresponding methodENDREM
DEFINE getIncomingLinksMethodCall FOR gmfgen::GenCommonBasegetDiagram().editorGen.diagramUpdater.getDiagramUpdaterQualifiedClassName().EXPAND linkGetterName(getIncomingLinksMethodNameSuffix())ENDDEFINE

REMThis DEFING can be used from other templates to inject call to the corresponding methodENDREM
DEFINE getOutgoingLinksMethodCall FOR gmfgen::GenCommonBasegetDiagram().editorGen.diagramUpdater.getDiagramUpdaterQualifiedClassName().EXPAND linkGetterName(getOutgoingLinksMethodNameSuffix())ENDDEFINE

DEFINE linkGetterName(String suffix) FOR gmfgen::GenCommonBasegetgetUniqueIdentifier()suffixLinksENDDEFINE

DEFINE getContainedLinks FOR gmfgen::GenCommonBase-
	EXPAND getConnectedLinks(getContainedLinks(getMetaClass(this), getDiagram()), getContainedLinksMethodNameSuffix(), false)-
ENDDEFINE

DEFINE getIncomingLinks FOR gmfgen::GenCommonBase-
	EXPAND getConnectedLinks(getIncomingLinks(getMetaClass(this), getDiagram()), getIncomingLinksMethodNameSuffix(), true)-
ENDDEFINE

DEFINE getOutgoingLinks FOR gmfgen::GenCommonBase-
	EXPAND getConnectedLinks(getOutgoingLinks(getMetaClass(this), getDiagram()), getOutgoingLinksMethodNameSuffix(), false)-
ENDDEFINE

DEFINE getConnectedLinks(List[gmfgen::GenLink] genLinks, String methodNameSuffix, boolean needCrossReferencer) FOR gmfgen::GenCommonBase-

	EXPAND xpt::Common::generatedMemberComment
public static java.util.List EXPAND linkGetterName(methodNameSuffix)(org.eclipse.gmf.runtime.notation.View view) {
	IF !genLinks.isEmpty()-
		LET getMetaClass(this) AS metaclass-
	EXPAND MetaModel::DeclareAndAssign("modelElement", "view.getElement()") FOR metaclass
			IF needCrossReferencer-
	java.util.Map crossReferences = org.eclipse.emf.ecore.util.EcoreUtil.CrossReferencer.find(view.eResource().getResourceSet().getResources());
			ENDIF-
	java.util.List result = new java.util.LinkedList();
			EXPAND colectConnectedLinks(methodNameSuffix, needCrossReferencer, metaclass.isExternalInterface()) FOREACH genLinks-
	return result;
		ENDLET-
	ELSE-
	return java.util.Collections.EMPTY_LIST;
	ENDIF-
}
ENDDEFINE

DEFINE colectConnectedLinks(String methodNameSuffix, boolean needCrossReferencer, boolean isExternalInterface) FOR gmfgen::GenLink-
IF isExternalInterface-
	if (EXPAND MetaModel::IsInstance("modelElement") FOR modelFacet.getLinkEndType(methodNameSuffix)) {
ENDIF-
	result.addAll(EXPAND chooseConnectedLinksByTypeMethodName(methodNameSuffix, this) FOR modelFacet(IF isExternalInterface-
EXPAND MetaModel::CastEObject("modelElement") FOR getLinkEndType(modelFacet, methodNameSuffix)ELSEmodelElementENDIFIF needCrossReferencer, crossReferencesENDIF));	
IF isExternalInterface-
	}
ENDIF-
ENDDEFINE

DEFINE chooseConnectedLinksByTypeMethodName(String methodNameSuffix, gmfgen::GenLink genLink) FOR gmfgen::LinkModelFacet-
	EXPAND incorrectLinkModelFacet-
ENDDEFINE

REM
	For FeatureModelFacet-based links we are calling 
	getOutgoing???Links instead of getContained???Links
ENDREM
DEFINE chooseConnectedLinksByTypeMethodName(String methodNameSuffix, gmfgen::GenLink genLink) FOR gmfgen::FeatureLinkModelFacet-
IF getContainedLinksMethodNameSuffix() == methodNameSuffixEXPAND getConnectedLinksByTypeMethodName(getOutgoingLinksMethodNameSuffix()) FOR genLink-
ELSEEXPAND getConnectedLinksByTypeMethodName(methodNameSuffix) FOR genLink-
ENDIF-
ENDDEFINE

REM
	For TypeModelFacet-based links we are calling 
	getContained???Links instead of getOutgoinf???Links 
	if sourceMetaFeature was not specified
ENDREM
DEFINE chooseConnectedLinksByTypeMethodName(String methodNameSuffix, gmfgen::GenLink genLink) FOR gmfgen::TypeLinkModelFacet-
IF getOutgoingLinksMethodNameSuffix() == methodNameSuffix && null == sourceMetaFeatureEXPAND getConnectedLinksByTypeMethodName(getContainedLinksMethodNameSuffix()) FOR genLink-
ELSEEXPAND getConnectedLinksByTypeMethodName(methodNameSuffix) FOR genLink-
ENDIF-
ENDDEFINE

DEFINE getContainedLinksByTypeMethod FOR gmfgen::GenLinkEXPAND getContainedLinksByTypeMethod(this) FOR modelFacetENDDEFINE

DEFINE getConnectedLinksByTypeMethodName(String suffix) FOR gmfgen::GenLinkgetsuffixEXPAND getConnectedLinksByTypeMethodFragment FOR modelFacet_visualIDENDDEFINE

DEFINE getConnectedLinksByTypeMethodFragment FOR gmfgen::TypeLinkModelFacetTypeModelFacetLinks_metaClass.ecoreClass.nameENDDEFINE

DEFINE getConnectedLinksByTypeMethodFragment FOR gmfgen::FeatureLinkModelFacetFeatureModelFacetLinks_metaFeature.genClass.ecoreClass.name_metaFeature.ecoreFeature.name.toFirstUpper()ENDDEFINE

DEFINE getConnectedLinksByTypeMethodFragment FOR gmfgen::LinkModelFacet-
	EXPAND incorrectLinkModelFacet-
ENDDEFINE

DEFINE getContainedLinksByTypeMethod(gmfgen::GenLink genLink) FOR gmfgen::LinkModelFacet-
	EXPAND incorrectLinkModelFacet-
ENDDEFINE

DEFINE getContainedLinksByTypeMethod(gmfgen::GenLink genLink) FOR gmfgen::FeatureLinkModelFacetENDDEFINE

DEFINE getContainedLinksByTypeMethod(gmfgen::GenLink genLink) FOR gmfgen::TypeLinkModelFacet-

	EXPAND xpt::Common::generatedMemberComment
private static java.util.Collection EXPAND getConnectedLinksByTypeMethodName(getContainedLinksMethodNameSuffix()) FOR genLink(EXPAND MetaModel::QualifiedClassName FOR getSourceType() container) {
	EXPAND getContainedLinksByTypeMethodBody(genLink, false)-
}
ENDDEFINE

DEFINE getContainedLinksByTypeMethodBody(gmfgen::GenLink genLink, boolean sourceVarDefined) FOR gmfgen::TypeLinkModelFacet-
java.util.Collection result = new java.util.LinkedList();
	LET childMetaFeature.isListType() 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)-
		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-
IF inLoop-
}
ENDIF-
	ENDLET-
return result;	
ENDDEFINE

DEFINE addLinkDescriptor(gmfgen::GenLink genLink, String srcVar, String dstVar) FOR gmfgen::TypeLinkModelFacet-
result.add(new genLink.getDiagram().editorGen.diagramUpdater.getLinkDescriptorQualifiedClassName()(EXPAND MetaModel::DowncastToEObject(srcVar) FOR getSourceType(), EXPAND MetaModel::DowncastToEObject(dstVar) FOR getTargetType(), EXPAND MetaModel::DowncastToEObject("link") FOR metaClass, genLink.getDiagram().getElementTypesQualifiedClassName().genLink.getUniqueIdentifier(), EXPAND xpt::editor::VisualIDRegistry::visualID FOR genLink));
ENDDEFINE

DEFINE checkLinkVisualID(gmfgen::GenLink genLink, boolean inLoop) FOR gmfgen::TypeLinkModelFacet-
if (EXPAND xpt::editor::VisualIDRegistry::visualID FOR genLink != EXPAND xpt::editor::VisualIDRegistry::getLinkWithClassVisualIDMethodCall FOR genLink.getDiagram()(EXPAND MetaModel::DowncastToEObject("link") FOR metaClass)) {
	EXPAND stopLinkProcessing(inLoop)-
}
ENDDEFINE

DEFINE defineLinkSource(boolean inLoop) FOR gmfgen::TypeLinkModelFacet-
	IF sourceMetaFeature.isListType()-
java.util.List sources = EXPAND MetaModel::getFeatureValue("link", metaClass) FOR sourceMetaFeature;
Object theSource = sources.size() == 1 ? sources.get(0) : null;
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(boolean inLoop) FOR gmfgen::TypeLinkModelFacet-
if (src != source) {
	EXPAND stopLinkProcessing(inLoop)-
}
ENDDEFINE

DEFINE defineLinkDestination(boolean inLoop) FOR gmfgen::TypeLinkModelFacet-
	IF targetMetaFeature.isListType()-
java.util.List targets = EXPAND MetaModel::getFeatureValue("link", metaClass) FOR targetMetaFeature;
Object theTarget = targets.size() == 1 ? targets.get(0) : 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

DEFINE stopLinkProcessing(boolean inLoop) FOR gmfgen::TypeLinkModelFacet-
IF inLoop-
continue;
ELSE-
return result;
ENDIF-
ENDDEFINE

DEFINE getIncomingLinksByTypeMethod FOR gmfgen::GenLink-

	EXPAND xpt::Common::generatedMemberComment
private static java.util.Collection EXPAND getConnectedLinksByTypeMethodName(getIncomingLinksMethodNameSuffix())(EXPAND MetaModel::QualifiedClassName FOR modelFacet.getTargetType() target, java.util.Map crossReferences) {
	java.util.Collection result = new java.util.LinkedList();
	java.util.Collection settings = (java.util.Collection) crossReferences.get(target);
	for (java.util.Iterator it = settings.iterator(); it.hasNext();) {
		org.eclipse.emf.ecore.EStructuralFeature.Setting setting = (org.eclipse.emf.ecore.EStructuralFeature.Setting) it.next();
		EXPAND getIncomingLinksByTypeMethodBody(this) FOR modelFacet-
	}
	return result;	
}
ENDDEFINE

DEFINE getIncomingLinksByTypeMethodBody(gmfgen::GenLink genLink) FOR gmfgen::TypeLinkModelFacet-
if (setting.getEStructuralFeature() != EXPAND MetaModel::MetaFeature FOR targetMetaFeature || EXPAND MetaModel::NotInstance("setting.getEObject()") FOR metaClass) {
	continue;
}
EXPAND MetaModel::DeclareAndAssign("link", "setting.getEObject()") FOR metaClass
	EXPAND checkLinkVisualID(genLink, true)-
	IF null != sourceMetaFeature-
		EXPAND defineLinkSource(true)-
		EXPAND addLinkDescriptor(genLink, "src", "target")-
	ELSE-
		EXPAND defineLinkContainer(true)-
		EXPAND addLinkDescriptor(genLink, "container", "target")-
REMTODO: continue here.ENDREM
	ENDIF-
ENDDEFINE

DEFINE defineLinkContainer(boolean inLoop) FOR gmfgen::TypeLinkModelFacet-
if (false == EXPAND MetaModel::IsContainerInstance("link", metaClass) FOR containmentMetaFeature.genClass) {
	EXPAND stopLinkProcessing(inLoop)-
}
EXPAND MetaModel::DeclareAndAssignContainer("container", "link", metaClass) FOR containmentMetaFeature.genClass
ENDDEFINE

DEFINE getIncomingLinksByTypeMethodBody(gmfgen::GenLink genLink) FOR gmfgen::FeatureLinkModelFacet-
if (setting.getEStructuralFeature() == EXPAND MetaModel::MetaFeature FOR metaFeature) {
	result.add(new genLink.getDiagram().editorGen.diagramUpdater.getLinkDescriptorQualifiedClassName()(setting.getEObject(), EXPAND MetaModel::DowncastToEObject("target") FOR getTargetType(), genLink.getDiagram().getElementTypesQualifiedClassName().genLink.getUniqueIdentifier(), EXPAND xpt::editor::VisualIDRegistry::visualID FOR genLink));
}
ENDDEFINE

DEFINE getIncomingLinksByTypeMethodBody(gmfgen::GenLink genLink) FOR gmfgen::LinkModelFacet-
	EXPAND incorrectLinkModelFacet-
ENDDEFINE

DEFINE getOutgoingLinksByTypeMethod FOR gmfgen::GenLink-
	EXPAND getOutgoingLinksByTypeMethod(this) FOR modelFacet-
ENDDEFINE

DEFINE getOutgoingLinksByTypeMethodSignature FOR gmfgen::GenLinkprivate static java.util.Collection EXPAND getConnectedLinksByTypeMethodName(getOutgoingLinksMethodNameSuffix())(EXPAND MetaModel::QualifiedClassName FOR modelFacet.getSourceType() source)ENDDEFINE

DEFINE getOutgoingLinksByTypeMethod(gmfgen::GenLink genLink) FOR gmfgen::FeatureLinkModelFacet-

	EXPAND xpt::Common::generatedMemberComment
EXPAND getOutgoingLinksByTypeMethodSignature FOR genLink {
	java.util.Collection result = new java.util.LinkedList();
	IF metaFeature.isListType()-
	for (java.util.Iterator destinations = EXPAND MetaModel::getFeatureValue("source", getSourceType()) FOR metaFeature.iterator(); destinations.hasNext();) {
		EXPAND MetaModel::DeclareAndAssign("destination", "destinations.next()", true) FOR getTargetType()
	ELSE-
	EXPAND MetaModel::DeclareAndAssign("destination", "source", getSourceType(), metaFeature) FOR getTargetType()
	if (destination == null) {
		return result;
	}
	ENDIF-
	result.add(new genLink.getDiagram().editorGen.diagramUpdater.getLinkDescriptorQualifiedClassName()(EXPAND MetaModel::DowncastToEObject("source") FOR getSourceType(), EXPAND MetaModel::DowncastToEObject("destination") FOR getTargetType(), genLink.getDiagram().getElementTypesQualifiedClassName().genLink.getUniqueIdentifier(), EXPAND xpt::editor::VisualIDRegistry::visualID FOR genLink));
	IF metaFeature.isListType()-
	}
	ENDIF-
	return result;
}
ENDDEFINE

REMMore careful way to find container should be used here then GMF will be modified in accordanceENDREM
DEFINE getOutgoingLinksByTypeMethod(gmfgen::GenLink genLink) FOR gmfgen::TypeLinkModelFacet-
	IF null != sourceMetaFeature-
	
		EXPAND xpt::Common::generatedMemberComment
EXPAND getOutgoingLinksByTypeMethodSignature FOR genLink {
	EXPAND MetaModel::QualifiedClassName FOR containmentMetaFeature.genClass container = null;
	// Find container element for the link.
	// Climb up by containment hierarchy starting from the source
	// and return the first element that is instance of the container class.
	for (org.eclipse.emf.ecore.EObject element = EXPAND MetaModel::DowncastToEObject("source") FOR getSourceType(); element != null && container == null; element = element.eContainer()) {
		if (EXPAND MetaModel::IsInstance("element") FOR containmentMetaFeature.genClass) {
			container = EXPAND MetaModel::CastEObject("element") FOR containmentMetaFeature.genClass;
		}
	}
	if (container == null) {
		return java.util.Collections.EMPTY_LIST;
	}
		EXPAND getContainedLinksByTypeMethodBody(genLink, true)-
}		
	ENDIF-
ENDDEFINE

DEFINE getOutgoingLinksByTypeMethod(gmfgen::GenLink genLink) FOR gmfgen::LinkModelFacet-
	EXPAND incorrectLinkModelFacet-
ENDDEFINE

DEFINE incorrectLinkModelFacet FOR gmfgen::LinkModelFacet-
	ERROR "Incorrect LinkModelFacet: " + this
ENDDEFINE

DEFINE additions FOR gmfgen::GenDiagramUpdaterENDDEFINE

Back to the top