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

«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»

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

«REM»
	Expands to all accessor methods for link and it's ends.
«ENDREM»
«DEFINE accessors FOR gmfgen::GenLink-»
	«EXPAND linkAccessor FOR modelFacet-»
	«EXPAND oldSourceAccessor FOR modelFacet-»
	«EXPAND newSourceAccessor FOR modelFacet-»
	«EXPAND oldTargetAccessor FOR modelFacet-»
	«EXPAND newTargetAccessor FOR modelFacet-»
«ENDDEFINE»

«DEFINE linkAccessor FOR gmfgen::LinkModelFacet-»
«ENDDEFINE»

«DEFINE linkAccessor FOR gmfgen::TypeLinkModelFacet-»

	«EXPAND xpt::Common::generatedMemberComment»
	protected «EXPAND MetaModel::QualifiedClassName FOR metaClass» getLink() {
		return «EXPAND MetaModel::CastEObject('getElementToEdit()') FOR metaClass»;
	}
«ENDDEFINE»

«DEFINE oldSourceAccessor FOR gmfgen::LinkModelFacet-»
«ENDDEFINE»

«DEFINE oldSourceAccessor FOR gmfgen::TypeLinkModelFacet-»

	«EXPAND xpt::Common::generatedMemberComment»
	protected «EXPAND MetaModel::QualifiedClassName FOR getSourceType()» getOldSource() {
		return «EXPAND MetaModel::CastEObject('oldEnd') FOR getSourceType()»;
	}
«ENDDEFINE»

«DEFINE oldSourceAccessor FOR gmfgen::FeatureLinkModelFacet-»

	«EXPAND xpt::Common::generatedMemberComment»
	protected «EXPAND MetaModel::QualifiedClassName FOR getSourceType()» getOldSource() {
		return «EXPAND MetaModel::CastEObject('referenceOwner') FOR getSourceType()»;
	}
«ENDDEFINE»

«DEFINE newSourceAccessor FOR gmfgen::LinkModelFacet-»

	«EXPAND xpt::Common::generatedMemberComment»
	protected «EXPAND MetaModel::QualifiedClassName FOR getSourceType()» getNewSource() {
		return «EXPAND MetaModel::CastEObject('newEnd') FOR getSourceType()»;
	}
«ENDDEFINE»

«DEFINE oldTargetAccessor FOR gmfgen::LinkModelFacet-»

	«EXPAND xpt::Common::generatedMemberComment»
	protected «EXPAND MetaModel::QualifiedClassName FOR getTargetType()» getOldTarget() {
		return «EXPAND MetaModel::CastEObject('oldEnd') FOR getTargetType()»;
	}
«ENDDEFINE»

«DEFINE newTargetAccessor FOR gmfgen::LinkModelFacet-»

	«EXPAND xpt::Common::generatedMemberComment»
	protected «EXPAND MetaModel::QualifiedClassName FOR getTargetType()» getNewTarget() {
		return «EXPAND MetaModel::CastEObject('newEnd') FOR getTargetType()»;
	}
«ENDDEFINE»

«REM»
	Generates canExecute() method for the command that reorients link.
	Implementation should perform all static checks that command can be executed.
«ENDREM»
«DEFINE canReorient(link : gmfgen::GenLink) FOR gmfgen::LinkModelFacet-»

	«EXPAND xpt::Common::generatedMemberComment»
	public boolean canExecute() {
		«EXPAND checkLinkValidity-»
		if (reorientDirection == org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest.REORIENT_SOURCE) {
			return canReorientSource();
		}
		if (reorientDirection == org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest.REORIENT_TARGET) {
			return canReorientTarget();
		}
		return false;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected boolean canReorientSource() {
		«EXPAND checkSourceRequestValidity(link)-»
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected boolean canReorientTarget() {
		«EXPAND checkTargetRequestValidity(link)-»
	}
«ENDDEFINE»

«DEFINE checkLinkValidity FOR gmfgen::LinkModelFacet-»
«ENDDEFINE»

«DEFINE checkLinkValidity FOR gmfgen::TypeLinkModelFacet-»
	if («EXPAND MetaModel::NotInstance('getElementToEdit()') FOR metaClass») {
		return false;
	}
«ENDDEFINE»

«DEFINE checkLinkValidity FOR gmfgen::FeatureLinkModelFacet-»
	if («EXPAND MetaModel::NotInstance('referenceOwner') FOR getSourceType()») {
		return false;
	}
«ENDDEFINE»

«DEFINE checkSourceRequestValidity(link : gmfgen::GenLink) FOR gmfgen::LinkModelFacet-»
«ENDDEFINE»

«DEFINE checkSourceRequestValidity(link : gmfgen::GenLink) FOR gmfgen::TypeLinkModelFacet-»
	if (!(«EXPAND MetaModel::IsInstance('oldEnd') FOR getSourceType()» && «EXPAND MetaModel::IsInstance('newEnd') FOR getSourceType()»)) {
		return false;
	}
	«EXPAND extractFeatureWithCheck('getLink()', metaClass, 'target', getTargetType()) FOR targetMetaFeature-»
	«EXPAND checkLinkConstraint(link, 'getNewSource()', 'target')-»
«ENDDEFINE»

«REM»
	When feature source is being reoriented oldEnd is the link target.
«ENDREM»
«DEFINE checkSourceRequestValidity(link : gmfgen::GenLink) FOR gmfgen::FeatureLinkModelFacet-»
	if (!(«EXPAND MetaModel::IsInstance('oldEnd') FOR getTargetType()» && «EXPAND MetaModel::IsInstance('newEnd') FOR getSourceType()»)) {
		return false;
	}
	return «EXPAND checkLinkConstraintInvocation FOR link»(getNewSource(), getOldTarget());
«ENDDEFINE»

«DEFINE checkTargetRequestValidity(link : gmfgen::GenLink) FOR gmfgen::LinkModelFacet-»
«ENDDEFINE»

«DEFINE checkTargetRequestValidity(link : gmfgen::GenLink) FOR gmfgen::TypeLinkModelFacet-»
	if (!(«EXPAND MetaModel::IsInstance('oldEnd') FOR getTargetType()» && «EXPAND MetaModel::IsInstance('newEnd') FOR getTargetType()»)) {
		return false;
	}
	«IF sourceMetaFeature <> null-»
		«EXPAND extractFeatureWithCheck('getLink()', metaClass, 'source', getSourceType()) FOR sourceMetaFeature-»
	«ELSE-»
		if (!(«EXPAND MetaModel::IsContainerInstance('getLink()', metaClass) FOR getSourceType()»)) {
			return false;
		}
		«EXPAND MetaModel::DeclareAndAssignContainer('source', 'getLink()', metaClass) FOR getSourceType()»
	«ENDIF-»
	«EXPAND checkLinkConstraint(link, 'source', 'getNewTarget()')-»
«ENDDEFINE»

«DEFINE checkTargetRequestValidity(link : gmfgen::GenLink) FOR gmfgen::FeatureLinkModelFacet-»
	if (!(«EXPAND MetaModel::IsInstance('oldEnd') FOR getTargetType()» && «EXPAND MetaModel::IsInstance('newEnd') FOR getTargetType()»)) {
		return false;
	}
	return «EXPAND checkLinkConstraintInvocation FOR link»(getOldSource(), getNewTarget());
«ENDDEFINE»

«DEFINE extractFeatureWithCheck(containerVar : String, containerMetaClass : genmodel::GenClass, _var : String, varMetaClass : genmodel::GenClass) FOR genmodel::GenFeature-»
	«IF ecoreFeature.many-»
		if («EXPAND MetaModel::getFeatureValue(containerVar, containerMetaClass)».size() != 1) {
			return false;
		}
		«EXPAND MetaModel::DeclareAndAssign2(_var, containerVar, containerMetaClass, self, 'get(0)', true) FOR varMetaClass»
	«ELSE-»
		«EXPAND MetaModel::DeclareAndAssign(_var, containerVar, containerMetaClass, self) FOR varMetaClass»
	«ENDIF-»
«ENDDEFINE»

«DEFINE checkLinkConstraint(link : gmfgen::GenLink, sourceVar : String, targetVar : String) FOR gmfgen::TypeLinkModelFacet-»
	«IF hasContainerOtherThanSource(self)-»
		if (!(«EXPAND MetaModel::IsContainerInstance('getLink()', metaClass) FOR containmentMetaFeature.genClass»)) {
			return false;
		}
		«EXPAND MetaModel::DeclareAndAssignContainer('container', 'getLink()', metaClass) FOR containmentMetaFeature.genClass»
		return «EXPAND checkLinkConstraintInvocation FOR link»(container, «sourceVar», «targetVar»);
	«ELSE-»
		return «EXPAND checkLinkConstraintInvocation FOR link»(«sourceVar», «targetVar»);
	«ENDIF-»
«ENDDEFINE»

«DEFINE checkLinkConstraintInvocation FOR gmfgen::GenLink-»
	«diagram.getBaseItemSemanticEditPolicyQualifiedClassName()».«diagram.getLinkCreationConstraintsClassName()».canExist«getUniqueIdentifier()»
«ENDDEFINE»

«REM»
	Generates doExecuteWithResult() method for the command that reorients link.
	Implementation should throw ExecutionException if it can't execute the command.
«ENDREM»
«DEFINE reorient FOR gmfgen::LinkModelFacet-»

	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.gmf.runtime.common.core.command.CommandResult doExecuteWithResult(
			org.eclipse.core.runtime.IProgressMonitor monitor, org.eclipse.core.runtime.IAdaptable info)
			throws org.eclipse.core.commands.ExecutionException {
		if (!canExecute()) {
			throw new org.eclipse.core.commands.ExecutionException("Invalid arguments in reorient link command"); «EXPAND xpt::Common::nonNLS»
		}
		if (reorientDirection == org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest.REORIENT_SOURCE) {
			return reorientSource();
		}
		if (reorientDirection == org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest.REORIENT_TARGET) {
			return reorientTarget();
		}
		throw new IllegalStateException();
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.gmf.runtime.common.core.command.CommandResult reorientSource() throws org.eclipse.core.commands.ExecutionException {
		«EXPAND reorientSource-»
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.gmf.runtime.common.core.command.CommandResult reorientTarget() throws org.eclipse.core.commands.ExecutionException {
		«EXPAND reorientTarget-»
	}
«ENDDEFINE»

«DEFINE reorientSource FOR gmfgen::LinkModelFacet-»
«ENDDEFINE»

«REM»
	Shouldn't we change link container here?
	[artem] especially when there's explicit childMetaFeature and 
	we changed source to another, but didn't change the container. Perhaps,
	makes sense to deduceContainer() using new source?
«ENDREM»
«DEFINE reorientSource FOR gmfgen::TypeLinkModelFacet-»
«IF (if sourceMetaFeature = null then containmentMetaFeature.ecoreFeature.changeable else sourceMetaFeature.ecoreFeature.changeable endif)-»
«IF sourceMetaFeature <> null-»
	«EXPAND changeTarget('getLink()', metaClass, 'getOldSource()', 'getNewSource()') FOR sourceMetaFeature-»
«ELSE-»
	«EXPAND changeSource('getLink()', 'getOldSource()', 'getNewSource()', getSourceType()) FOR (if hasExplicitChildFeature(self) then childMetaFeature else containmentMetaFeature endif)-»
«ENDIF-»
	return org.eclipse.gmf.runtime.common.core.command.CommandResult.newOKCommandResult(getLink());
«ELSE-»
	throw new UnsupportedOperationException();
«ENDIF-»
«ENDDEFINE»

«REM»
	When feature source is being reoriented oldEnd is the link target.
«ENDREM»
«DEFINE reorientSource FOR gmfgen::FeatureLinkModelFacet-»
«IF metaFeature.ecoreFeature.changeable-»
	«EXPAND changeSource('getOldTarget()', 'getOldSource()', 'getNewSource()', getSourceType()) FOR metaFeature-»
	return org.eclipse.gmf.runtime.common.core.command.CommandResult.newOKCommandResult(referenceOwner);
«ELSE-»
	throw new UnsupportedOperationException();
«ENDIF-»
«ENDDEFINE»

«DEFINE reorientTarget FOR gmfgen::LinkModelFacet-»
«ENDDEFINE»

«DEFINE reorientTarget FOR gmfgen::TypeLinkModelFacet-»
«IF targetMetaFeature.ecoreFeature.changeable-»
	«EXPAND changeTarget('getLink()', metaClass, 'getOldTarget()', 'getNewTarget()') FOR targetMetaFeature-»
	return org.eclipse.gmf.runtime.common.core.command.CommandResult.newOKCommandResult(getLink());
«ELSE-»
	throw new UnsupportedOperationException();
«ENDIF-»
«ENDDEFINE»

«DEFINE reorientTarget FOR gmfgen::FeatureLinkModelFacet-»
«IF metaFeature.ecoreFeature.changeable-»
	«EXPAND changeTarget('getOldSource()', getSourceType(), 'getOldTarget()', 'getNewTarget()') FOR metaFeature-»
	return org.eclipse.gmf.runtime.common.core.command.CommandResult.newOKCommandResult(referenceOwner);
«ELSE-»
	throw new UnsupportedOperationException();
«ENDIF-»
«ENDDEFINE»

«REM»
	Replace old target with the new one in the source.
«ENDREM»
«DEFINE changeTarget(sourceVar : String, sourceVarGenClass : genmodel::GenClass, oldTargetVar : String, newTargetVar : String) FOR genmodel::GenFeature-»
«EXPAND MetaModel::replaceFeatureValue(sourceVar, sourceVarGenClass, oldTargetVar, newTargetVar)»
«ENDDEFINE»

«REM»
	Move target from old source to the new one.
«ENDREM»
«DEFINE changeSource(targetVar : String, oldSourceVar : String, newSourceVar : String, sourceVarGenClass : genmodel::GenClass) FOR genmodel::GenFeature-»
«EXPAND MetaModel::moveFeatureValue(oldSourceVar, newSourceVar, sourceVarGenClass, targetVar)»
«ENDDEFINE»

Back to the top