Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2365eab0dd1d7d697a9c3af8848dd59be9ca0065 (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
/*
 * 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:
 *    bblajer (Borland) - initial API and implementation
 */

«IMPORT "http://www.eclipse.org/gmf/2005/GenModel/2.0"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«IMPORT "http://www.eclipse.org/emf/2002/GenModel"»
«EXTENSION xpt::GenModelUtils»

«DEFINE CreateLinkCompleteCommand FOR gmfgen::GenLink-»
«EXPAND xpt::Common::copyright FOR diagram.editorGen»
package «diagram.editCommandsPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «EXPAND className» «EXPAND supertypes» {
	«EXPAND attributes-»
	«EXPAND ctors-»
	«EXPAND prepare-»
	«EXPAND initializeDomainModelCommand-»
	«EXPAND canUndo-»
	«EXPAND execute-»
	«EXPAND undo-»
	«EXPAND redo-»
	«EXPAND xpt::commands::Common::getRelationshipContainer FOR modelFacet-»
	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE className FOR gmfgen::GenLink»Create«EXPAND xpt::commands::Common::commandNameInfix»Command«ENDDEFINE»

«DEFINE supertypes FOR gmfgen::GenLink»extends org.eclipse.emf.common.command.AbstractCommand«ENDDEFINE»

«DEFINE attributes FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	private final org.eclipse.gmf.runtime.notation.View source;

	«EXPAND xpt::Common::generatedMemberComment»
	private final org.eclipse.gmf.runtime.notation.View target;

	«EXPAND xpt::Common::generatedMemberComment»
	private final org.eclipse.gmf.runtime.notation.Edge createdEdge;

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.emf.common.command.Command domainModelAddCommand;
«ENDDEFINE»

«DEFINE ctors FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	public «EXPAND className»(org.eclipse.gmf.runtime.lite.requests.CreateConnectionRequestEx requestEx) {
		if (requestEx.getSourceEditPart().getModel() instanceof org.eclipse.gmf.runtime.notation.View) {
			source = (org.eclipse.gmf.runtime.notation.View) requestEx.getSourceEditPart().getModel();
		} else {
			source = null;
		}
		if (requestEx.getTargetEditPart().getModel() instanceof org.eclipse.gmf.runtime.notation.View) {
			target = (org.eclipse.gmf.runtime.notation.View) requestEx.getTargetEditPart().getModel();
		} else {
			target = null;
		}
		if (source == null || target == null) {
			createdEdge = null;
			return;
		}
		createdEdge = org.eclipse.gmf.runtime.notation.NotationFactory.eINSTANCE.createEdge();
		«EXPAND setEdgeElement(this) FOR modelFacet-»
		«getNotationViewFactoryQualifiedClassName()».INSTANCE.decorateView(createdEdge);
	}
«ENDDEFINE»

«DEFINE setEdgeElement(gmfgen::GenLink genLink) FOR gmfgen::LinkModelFacet-»
	createdEdge.setElement(null);
«ENDDEFINE»

«DEFINE setEdgeElement(gmfgen::GenLink genLink) FOR gmfgen::TypeLinkModelFacet-»
	«EXPAND xpt::Common::newInstance("createdDomainElement") FOR metaClass-»
	createdEdge.setElement(«unparenthesizedCast("createdDomainElement", metaClass, null)»);
	«EXPAND xpt::commands::Common::DomainElementInitializerQualifiedClassName FOR genLink».«genLink.getUniqueIdentifier()».initializeElement(«unparenthesizedCast("createdDomainElement", metaClass, null)»);
«ENDDEFINE»

«DEFINE prepare FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected boolean prepare() {
		if (source == null || target == null || createdEdge == null) {
			return false;
		}
		«EXPAND xpt::commands::Common::checkLinkConstraints("source.getElement()", "target.getElement()") FOR creationConstraints-»
		domainModelAddCommand = initializeDomainModelCommand();
		if (domainModelAddCommand == null || !domainModelAddCommand.canExecute()) {
			return false;
		}
		return true;
	}
«ENDDEFINE»

«DEFINE initializeDomainModelCommand FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.emf.common.command.Command initializeDomainModelCommand() {
		«EXPAND initializeDomainModelCommand FOR modelFacet-»
	}
«ENDDEFINE»

«DEFINE initializeDomainModelCommand FOR gmfgen::LinkModelFacet-»
return org.eclipse.emf.common.command.UnexecutableCommand.INSTANCE;
«ENDDEFINE»

«DEFINE initializeDomainModelCommand FOR gmfgen::TypeLinkModelFacet-»
	«containmentMetaFeature.genClass.getQualifiedInterfaceName()» container = («containmentMetaFeature.genClass.getQualifiedInterfaceName()») getRelationshipContainer(source.getElement(), «EXPAND xpt::Common::metaClassAccessor FOR containmentMetaFeature.genClass»);
	if (container == null) {
		return org.eclipse.emf.common.command.UnexecutableCommand.INSTANCE;
	}
«LET childMetaFeature != null && childMetaFeature != containmentMetaFeature && !childMetaFeature.ecoreFeature.derived AS addChild-»
«LET sourceMetaFeature != null && !sourceMetaFeature.ecoreFeature.derived && ecore::EReference.isSuperTypeOf(sourceMetaFeature.ecoreFeature.eClass()) 
	&& ((ecore::EReference) sourceMetaFeature.ecoreFeature).eOpposite !=containmentMetaFeature.ecoreFeature && 
		(addChild implies ((ecore::EReference) sourceMetaFeature.ecoreFeature).eOpposite != childMetaFeature.ecoreFeature) AS addSource-»
«LET targetMetaFeature != null && !targetMetaFeature.ecoreFeature.derived && ecore::EReference.isSuperTypeOf(targetMetaFeature.ecoreFeature.eClass()) 
	&& ((ecore::EReference) targetMetaFeature.ecoreFeature).eOpposite !=containmentMetaFeature.ecoreFeature && 
		(addChild implies ((ecore::EReference) targetMetaFeature.ecoreFeature).eOpposite != childMetaFeature.ecoreFeature) AS addTarget-»
	«IF addSource-»
		«EXPAND checkFeature("createdEdge.getElement()", null) FOR sourceMetaFeature-»
	«ENDIF-»
	«IF addTarget-»
		«EXPAND checkFeature("createdEdge.getElement()", null) FOR targetMetaFeature-»
		«LET targetMetaFeature.getReverse() AS targetReverseFeature-»
			«IF targetReverseFeature != null && !targetReverseFeature.ecoreFeature.derived-»
				«EXPAND checkFeature("target.getElement()", null) FOR targetReverseFeature-»
			«ENDIF-»
		«ENDLET-»
	«ENDIF-»
	org.eclipse.emf.transaction.TransactionalEditingDomain domainModelEditDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(source.getDiagram().getElement());
	org.eclipse.emf.common.command.CompoundCommand addLinkEndsCommand = new org.eclipse.emf.common.command.CompoundCommand();
	addLinkEndsCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "container", "createdEdge.getElement()") FOR containmentMetaFeature»);
	«IF addChild-»
	addLinkEndsCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "container", "createdEdge.getElement()") FOR childMetaFeature»);
	«ENDIF-»
	«IF addSource-»
	addLinkEndsCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "createdEdge.getElement()", "source.getElement()") FOR sourceMetaFeature»);
	«ENDIF-»
	«IF addTarget-»
	addLinkEndsCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "createdEdge.getElement()", "target.getElement()") FOR targetMetaFeature»);
	«ENDIF-»
	return addLinkEndsCommand;
«ENDLET-»
«ENDLET-»
«ENDLET-»
«ENDDEFINE»

«DEFINE initializeDomainModelCommand FOR gmfgen::FeatureLinkModelFacet-»
«LET metaFeature.getReverse() AS reverseMetaFeature-»
	«IF reverseMetaFeature != null && !reverseMetaFeature.ecoreFeature.derived-»
		«EXPAND checkFeature("target.getElement()", null) FOR reverseMetaFeature-»
	«ENDIF-»
	org.eclipse.emf.transaction.TransactionalEditingDomain domainModelEditDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(source.getDiagram().getElement());
	return «EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "source.getElement()", "target.getElement()") FOR metaFeature»;
«ENDLET-»
«ENDDEFINE»

«DEFINE canUndo FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	public boolean canUndo() {
		return source != null && target != null && createdEdge != null && domainModelAddCommand != null && domainModelAddCommand.canUndo();
	}
«ENDDEFINE»

«DEFINE execute FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	public void execute() {
		domainModelAddCommand.execute();
		source.getDiagram().insertEdge(createdEdge);
		createdEdge.setSource(source);
		createdEdge.setTarget(target);
	}
«ENDDEFINE»

«DEFINE undo FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	public void undo() {
		domainModelAddCommand.undo();
		source.getDiagram().removeEdge(createdEdge);
		createdEdge.setSource(null);
		createdEdge.setTarget(null);
	}
«ENDDEFINE»

«DEFINE redo FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	public void redo() {
		execute();
	}
«ENDDEFINE»

«DEFINE additions FOR gmfgen::GenLink-»
«ENDDEFINE»

«DEFINE checkFeature(String containerVar, genmodel::GenClass containerClass) FOR genmodel::GenFeature-»
«IF ecoreFeature.upperBound > 0-»
if («EXPAND xpt::commands::Common::featureMultiplicityComparator(containerVar, containerClass)») {
	return org.eclipse.emf.common.command.UnexecutableCommand.INSTANCE;
}
«ENDIF-»
«ENDDEFINE»

Back to the top