Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 691f1d93df716f3c6d4aa5d563d8f3af3797da4c (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
/*
 * 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
 */

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

«EXTENSION xpt::diagram::updater::Utils»
«EXTENSION xpt::GenModelUtils»

«DEFINE DiagramContentInitializer FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::copyright FOR getDiagram().editorGen-»
package «editorGen.editor.packageName»;

	«EXPAND xpt::Common::generatedClassComment»
public class «diagramContentInitializerClassName» {

	«EXPAND attributes-»

	«EXPAND initDiagramContent-»
	
	«EXPAND createChildren FOREACH getAllContainers()->select(container | not container.sansDomain)-»
	
	«EXPAND createNode-»
	
	«EXPAND createLinks-»
	«IF not (getAllContainers())[gmfgen::GenCompartment]->isEmpty()-»
	
		«EXPAND getCompartment-»
	«ENDIF-»

	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE attributes FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
private java.util.Map myDomain2NotationMap = new java.util.HashMap();

	«EXPAND xpt::Common::generatedMemberComment»
private java.util.Collection myLinkDescriptors = new java.util.LinkedList();
«ENDDEFINE»

«DEFINE initDiagramContent FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
public void initDiagramContent(org.eclipse.gmf.runtime.notation.Diagram diagram) {
	if (!«EXPAND xpt::editor::VisualIDRegistry::modelID».equals(diagram.getType())) {
		«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Incorrect diagram passed as a parameter: " + diagram.getType());
		return;
	}
	if («EXPAND MetaModel::NotInstance('diagram.getElement()') FOR domainDiagramElement») {
		«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Incorrect diagram element specified: " + diagram.getElement() + " instead of «domainDiagramElement.ecoreClass.name»");
		return;
	}
	«EXPAND createChildrenMethodName»(diagram);
	createLinks(diagram);
}
«ENDDEFINE»

«DEFINE createChildrenMethodName FOR gmfgen::GenContainerBase»create«getUniqueIdentifier()»Children«ENDDEFINE»

«DEFINE createChildren FOR gmfgen::GenContainerBase-»
	«EXPAND xpt::Common::generatedMemberComment»
private void «EXPAND createChildrenMethodName»(org.eclipse.gmf.runtime.notation.View view) {
	«EXPAND collectContainedLinks-»
	«IF hasSemanticChildren(self)-»
	java.util.Collection childNodeDescriptors = «EXPAND xpt::diagram::updater::DiagramUpdater::getSemanticChildrenMethodCall»(view);
	for (java.util.Iterator it = childNodeDescriptors.iterator(); it.hasNext();) {
		createNode(view, («getDiagram().editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()») it.next());
	}
	«ENDIF-»
	«EXPAND createCompartmentsChildren-»
}
«ENDDEFINE»

«DEFINE collectContainedLinks FOR gmfgen::GenContainerBase»«ENDDEFINE»

«DEFINE collectContainedLinks FOR gmfgen::GenNode-»
	myDomain2NotationMap.put(view.getElement(), view);
	myLinkDescriptors.addAll(«EXPAND xpt::diagram::updater::DiagramUpdater::getOutgoingLinksMethodCall»(view));
«ENDDEFINE»

«DEFINE createCompartmentsChildren FOR gmfgen::GenContainerBase»«ENDDEFINE»

«DEFINE createCompartmentsChildren FOR gmfgen::GenNode-»
	«EXPAND callCreateCompartmentChildren FOREACH compartments»
«ENDDEFINE»

«REM»
	Will be called for each compartment of GenNode for GenNode.isSansDomain() == false. 
	if !GenNode.isSansDomain() => !GenCompartment.isSansDomain() so should not check 
	!this.isSansDomain() here.
«ENDREM»
«DEFINE callCreateCompartmentChildren FOR gmfgen::GenCompartment-»
	«EXPAND createChildrenMethodName»(getCompartment(view, «EXPAND xpt::editor::VisualIDRegistry::visualID»));
«ENDDEFINE»

«DEFINE createNode FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
private void createNode(org.eclipse.gmf.runtime.notation.View parentView, «editorGen.diagramUpdater.getNodeDescriptorQualifiedClassName()» nodeDescriptor) {
	final String nodeType = «EXPAND xpt::editor::VisualIDRegistry::typeMethodCall('nodeDescriptor.getVisualID()')»;
	org.eclipse.gmf.runtime.notation.Node node = org.eclipse.gmf.runtime.diagram.core.services.ViewService.createNode(parentView, nodeDescriptor.getModelElement(), nodeType, «EXPAND xpt::plugin::Activator::preferenceHintAccess FOR editorGen»);
	switch (nodeDescriptor.getVisualID()) {
	«EXPAND createNodeCase FOREACH getAllNodes()->select(node | not node.sansDomain)-»
	}
}
«ENDDEFINE»

«DEFINE createNodeCase FOR gmfgen::GenContainerBase-»
«EXPAND xpt::Common::caseVisualID»
	«EXPAND createChildrenMethodName»(node);
	return;
«ENDDEFINE»

«REM»Adopt this code to work with links to links«ENDREM»
«DEFINE createLinks FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
private void createLinks(org.eclipse.gmf.runtime.notation.Diagram diagram) {
	for (boolean continueLinkCreation = true; continueLinkCreation;) {
		continueLinkCreation = false;
		java.util.Collection additionalDescriptors = new java.util.LinkedList();
		for (java.util.Iterator it = myLinkDescriptors.iterator(); it.hasNext();) {
			«editorGen.diagramUpdater.getLinkDescriptorQualifiedClassName()» nextLinkDescriptor = («editorGen.diagramUpdater.getLinkDescriptorQualifiedClassName()») it.next();
			if (!myDomain2NotationMap.containsKey(nextLinkDescriptor.getSource()) || !myDomain2NotationMap.containsKey(nextLinkDescriptor.getDestination())) {
				continue;
			}
			final String linkType = «EXPAND xpt::editor::VisualIDRegistry::typeMethodCall('nextLinkDescriptor.getVisualID()')»;
			org.eclipse.gmf.runtime.notation.Edge edge = org.eclipse.gmf.runtime.diagram.core.services.ViewService.getInstance().createEdge(nextLinkDescriptor.getSemanticAdapter(), diagram, linkType, org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.APPEND, true, «EXPAND xpt::plugin::Activator::preferenceHintAccess FOR editorGen»);
			if (edge != null) {
				edge.setSource((org.eclipse.gmf.runtime.notation.View) myDomain2NotationMap.get(nextLinkDescriptor.getSource()));
				edge.setTarget((org.eclipse.gmf.runtime.notation.View) myDomain2NotationMap.get(nextLinkDescriptor.getDestination()));
				it.remove();
				if (nextLinkDescriptor.getModelElement() != null) {
					myDomain2NotationMap.put(nextLinkDescriptor.getModelElement(), edge);
				}
				continueLinkCreation = true;
				switch (nextLinkDescriptor.getVisualID()) {
	«EXPAND createLinksCase FOREACH links->select(link | null <> link.getMetaClass())-»
				}
			}
		}
		myLinkDescriptors.addAll(additionalDescriptors);
	}
}
«ENDDEFINE»

«DEFINE createLinksCase FOR gmfgen::GenLink-»
«EXPAND xpt::Common::caseVisualID»
	additionalDescriptors.addAll(«EXPAND xpt::diagram::updater::DiagramUpdater::getOutgoingLinksMethodCall»(edge));
	break;
«ENDDEFINE»

«DEFINE getCompartment FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
private org.eclipse.gmf.runtime.notation.Node getCompartment(org.eclipse.gmf.runtime.notation.View node, int visualID) {
	String type = «EXPAND xpt::editor::VisualIDRegistry::typeMethodCall('visualID')»;
	for (java.util.Iterator it = node.getChildren().iterator(); it.hasNext();) {
		org.eclipse.gmf.runtime.notation.View nextView = (org.eclipse.gmf.runtime.notation.View) it.next();
		if (nextView instanceof org.eclipse.gmf.runtime.notation.Node && type.equals(nextView.getType())) {
			return (org.eclipse.gmf.runtime.notation.Node) nextView;
		}
	}
	return null;
}
«ENDDEFINE»

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

Back to the top