Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 60e6b763c8860186f558227c9cef6f4d98b6dbbd (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
	/**
	 * @generated
	 */
	private class <%=childContainer.getEditPartClassName()%>CanonicalEditPolicy extends <%=importManager.getImportedName("org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy")%> {

		/**
		 * @generated
		 */
		protected <%=importManager.getImportedName("java.util.List")%> getSemanticChildrenList() {	
<%
String modelElementInterfaceName = importManager.getImportedName(containerNode.getModelFacet().getMetaClass().getQualifiedInterfaceName());
%>		
			<%=modelElementInterfaceName%> modelElement = (<%=modelElementInterfaceName%>) ((View) getHost().getModel()).getElement();
			List result = new <%=importManager.getImportedName("java.util.LinkedList")%>();

<%
/*
	Since there could e several child nodes with the same childMetaFeatures, but different domainMetaClasses
specified, we are creating a Map{GenFeature -> Collection{GenChildNodes}}. If GenChildNode without specified 
domainMetaClass found, all the rest of GenChildNodes with the same childMetaFeature will be ignored because
all the elements from this childMetaFeature will be treated as "this" type of GenChildNodes (without specified 
domainMetaClass).
*/

Map childFeature2NodesMap = new HashMap();
for (Iterator it = childContainer.getChildNodes().iterator(); it.hasNext();) {
	GenChildNode nextChildNode = (GenChildNode) it.next();
	GenFeature genFeature = nextChildNode.getModelFacet().getChildMetaFeature();
	List genChildNodes; 
	if (!childFeature2NodesMap.containsKey(genFeature)) {
		genChildNodes = new ArrayList();
		childFeature2NodesMap.put(genFeature, genChildNodes);
	} else {
		genChildNodes = (List) childFeature2NodesMap.get(genFeature);
	}

	if (nextChildNode.getDomainMetaClass() == null) {
		genChildNodes.clear();
		genChildNodes.add(nextChildNode);
		continue;
	}
	if (genChildNodes.size() == 1 && ((GenChildNode) genChildNodes.get(0)).getDomainMetaClass() == null) {
		continue;
	}
	genChildNodes.add(nextChildNode);
}
		
// For each childMetaFeature:
for (Iterator it = childFeature2NodesMap.entrySet().iterator(); it.hasNext();) {
	Map.Entry nextEntry = (Map.Entry) it.next();
	GenFeature nextFeature = (GenFeature) nextEntry.getKey();
	List childNodes = (List) nextEntry.getValue();
	if (childNodes.size() == 1 && ((GenChildNode) childNodes.get(0)).getDomainMetaClass() == null) {
// GenChildNode without specified domainMetaClass found:
		if (nextFeature.isListType()) {
%>
			result.addAll(modelElement.<%=nextFeature.getGetAccessor()%>());
<%
		} else {
%>
			Object featureValue = modelElement.<%=nextFeature.getGetAccessor()%>();
			if (featureValue != null) {
				result.add(featureValue);
			}
<%
		}
// Continue with the next entry in the Map
		continue;
	}

// GenChildNodes with specified domainMetaClass found:			
	if (nextFeature.isListType()) {
%>
			<%=importManager.getImportedName("java.util.Collection")%> featureValues = modelElement.<%=nextFeature.getGetAccessor()%>();
			for (<%=importManager.getImportedName("java.util.Iterator")%> it = featureValues.iterator(); it.hasNext();) {
				<%=importManager.getImportedName("org.eclipse.emf.ecore.EObject")%> nextValue = (<%=importManager.getImportedName("org.eclipse.emf.ecore.EObject")%>) it.next();
<%
	} else {
%>
			<%=importManager.getImportedName("org.eclipse.emf.ecore.EObject")%> nextValue = (<%=importManager.getImportedName("org.eclipse.emf.ecore.EObject")%>) modelElement.<%=nextFeature.getGetAccessor()%>();
<%
	}
%>
			if (nextValue != null) {
				<%=importManager.getImportedName("org.eclipse.emf.ecore.EClass")%> nextEClass = nextValue.eClass();
<%			
	for (Iterator childNodesIterator = childNodes.iterator(); childNodesIterator.hasNext();) {
		GenChildNode nextChildNode = (GenChildNode) childNodesIterator.next();
		GenClass domainMetaclass = nextChildNode.getDomainMetaClass();
%>
				if (<%=importManager.getImportedName(domainMetaclass.getGenPackage().getQualifiedPackageInterfaceName())%>.eINSTANCE.get<%=domainMetaclass.getClassifierAccessorName()%>().equals(nextEClass)) {
					result.add(nextValue);
				} <%=childNodesIterator.hasNext() ? "else" : ""%>
<%
	}
	if (nextFeature.isListType()) {
%>
			}
<%
	}
%>
			}
<%
}
%>
			return result;
		}
	}

Back to the top