Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1e6817966ef1b35e7ea91689706ee95e45f22cfd (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
/*
 * 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 CreateLinkStartCommand 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 shouldExecute-»
	«EXPAND xpt::commands::Common::getRelationshipContainer FOR modelFacet-»
	«EXPAND additions-»
}
«ENDDEFINE»

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

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

«DEFINE supertypes FOR gmfgen::GenLink»extends org.eclipse.gmf.runtime.lite.commands.VetoCommand«ENDDEFINE»

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

«DEFINE ctors FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	public «EXPAND className»(org.eclipse.gmf.runtime.lite.requests.CreateConnectionRequestEx requestEx) {
		//Until the mouse button is pressed, the source of the connection is in request.getTargetEditPart(), not in request.getSourceEditPart().
		source = (org.eclipse.gmf.runtime.notation.View)requestEx.getTargetEditPart().getModel();
	}
«ENDDEFINE»

«DEFINE shouldExecute FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected boolean shouldExecute() {
		if (source == null) {
			return false;
		}
		«EXPAND xpt::commands::Common::checkLinkConstraints("source.getElement()", "null") FOR creationConstraints-»
		«EXPAND shouldExecute FOR modelFacet-»
	}
«ENDDEFINE»

«DEFINE shouldExecute FOR gmfgen::LinkModelFacet»return false;«ENDDEFINE»

«DEFINE shouldExecute FOR gmfgen::TypeLinkModelFacet-»
«IF null != containmentMetaFeature-»
«EXPAND shouldExecuteForNonNullContainmentMetaFeature-»
«ELSE-»
return false;
«ENDIF-»
«ENDDEFINE»

«DEFINE shouldExecuteForNonNullContainmentMetaFeature FOR gmfgen::TypeLinkModelFacet-»
	«containmentMetaFeature.genClass.getQualifiedInterfaceName()» container = («containmentMetaFeature.genClass.getQualifiedInterfaceName()») getRelationshipContainer(source.getElement(), «EXPAND xpt::Common::metaClassAccessor FOR containmentMetaFeature.genClass»);
	if (container == null) {
		return false;
	}
	«EXPAND checkFeature("container", containmentMetaFeature.genClass) FOR containmentMetaFeature-»
«IF childMetaFeature != null && childMetaFeature != containmentMetaFeature && !childMetaFeature.ecoreFeature.derived-»
	«EXPAND checkFeature("container", containmentMetaFeature.genClass) FOR childMetaFeature-»
«ENDIF-»
«IF sourceMetaFeature != null-»
«LET sourceMetaFeature.getReverse() AS sourceReverseFeature-»
«IF sourceReverseFeature != null && !sourceReverseFeature.ecoreFeature.derived && sourceReverseFeature != containmentMetaFeature && sourceReverseFeature != childMetaFeature-»
	«EXPAND checkFeature("source.getElement()", null) FOR sourceReverseFeature-»
«ENDIF-»
«ENDLET-»
«ENDIF-»
		return true;
«ENDDEFINE»

«DEFINE shouldExecute FOR gmfgen::FeatureLinkModelFacet-»
	«EXPAND checkFeature("source.getElement()", null) FOR metaFeature-»
	return true;
«ENDDEFINE»

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

Back to the top