Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a8e1a388faf514c2102ed4faf52111329a689010 (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
/*
 * 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/2006/GenModel"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«IMPORT "http://www.eclipse.org/emf/2002/GenModel"»
«EXTENSION xpt::GenModelUtils»
«EXTENSION xpt::commands::CommandUtils»

«DEFINE AddNodeCommand FOR gmfgen::GenNode-»
«EXPAND xpt::Common::copyright FOR getDiagram().editorGen»
package «getDiagram().editCommandsPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «EXPAND className» «EXPAND supertypes» {
«REM»caching related nodes: calculating it may be quite expensive«ENDREM-»
«LET getRelatedGenNodes() AS relatedNodes-»
«LET relatedNodes.size() > 1 AS multipleRelatedNodes-»
	«EXPAND attributes(multipleRelatedNodes)-»
	«EXPAND ctors(multipleRelatedNodes)-»
	«EXPAND createCommand(relatedNodes)-»
	«EXPAND additions-»
«ENDLET-»
«ENDLET-»
}
«ENDDEFINE»

«DEFINE className FOR gmfgen::GenNode»Add«EXPAND xpt::commands::Common::commandNameInfix»Command«ENDDEFINE»
«DEFINE supertypes FOR gmfgen::GenNode»extends org.eclipse.emf.common.command.CommandWrapper«ENDDEFINE»

«DEFINE attributes(boolean multipleRelatedNodes) FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
private final org.eclipse.gmf.runtime.notation.View parentView;
«EXPAND xpt::Common::generatedMemberComment»
private final org.eclipse.gmf.runtime.notation.Node childNode;
«IF multipleRelatedNodes-»
«EXPAND xpt::Common::generatedMemberComment»
private final int oldVisualID;
«ENDIF-»
«EXPAND xpt::Common::generatedMemberComment»
private final int newVisualID;
«EXPAND xpt::Common::generatedMemberComment»
private final org.eclipse.draw2d.geometry.Rectangle constraint;
«ENDDEFINE»

«DEFINE ctors(boolean multipleRelatedNodes) FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public «EXPAND className»(org.eclipse.gmf.runtime.notation.View parentView, org.eclipse.gmf.runtime.notation.Node childNode, int newVisualID, org.eclipse.draw2d.geometry.Rectangle constraint) {
	this.parentView = parentView;
	this.childNode = childNode;
«IF multipleRelatedNodes-»
	this.oldVisualID = «getDiagram().getVisualIDRegistryQualifiedClassName()».getVisualID(childNode);
«ENDIF-»
	this.newVisualID = newVisualID;
	this.constraint = constraint;
}
«ENDDEFINE»

«DEFINE createCommand(Collection[gmfgen::GenNode] relatedNodes) FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.emf.common.command.Command createCommand() {
	«EXPAND checkFeatures FOR modelFacet-»
	org.eclipse.emf.common.command.CompoundCommand result = new org.eclipse.emf.common.command.CompoundCommand();
	org.eclipse.emf.ecore.EObject element = childNode.getElement();
	org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(parentView.getDiagram().getElement());
«IF relatedNodes.size() > 1-»
	switch (oldVisualID) {
«ENDIF-»
«FOREACH relatedNodes AS next-»
«IF relatedNodes.size() > 1-»
	case «next.getEditPartQualifiedClassName()».VISUAL_ID:
«ENDIF-»
		«EXPAND unplugFeatures FOR next.modelFacet-»
«IF relatedNodes.size() > 1-»
		break;
«ENDIF-»
«ENDFOREACH-»
«IF relatedNodes.size() > 1-»
	}
«ENDIF-»
	«EXPAND plugFeatures FOR modelFacet-»
	result.append(org.eclipse.emf.edit.command.RemoveCommand.create(editingDomain, childNode.eContainer(), childNode.eContainmentFeature(), childNode));
«IF relatedNodes.size() > 1-»
	if (newVisualID == oldVisualID) {
«ENDIF-»
		result.append(new org.eclipse.gmf.runtime.lite.commands.ExpandDrawerCommand(parentView));
		result.append(org.eclipse.emf.edit.command.AddCommand.create(editingDomain, parentView, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getView_PersistedChildren(), childNode));
		result.append(new org.eclipse.gmf.runtime.lite.commands.SetBoundsCommand(childNode, constraint));
«IF relatedNodes.size() > 1-»
	} else {
		«EXPAND xpt::commands::Common::adjustConstraint-»
		result.append(new org.eclipse.gmf.runtime.lite.commands.CreateNotationalNodeCommand(parentView, element, constraint, «getNotationViewFactoryQualifiedClassName()».INSTANCE));
	}
«ENDIF-»
	return result;
}
«ENDDEFINE»

«DEFINE checkFeatures FOR gmfgen::TypeModelFacet-»
«EXPAND checkFeature("parentView.getElement()", null) FOR containmentMetaFeature-»
«LET childMetaFeature != null && childMetaFeature != containmentMetaFeature && !childMetaFeature.ecoreFeature.derived AS addChild-»
«IF addChild-»
	«EXPAND checkFeature("parentView.getElement()", null) FOR childMetaFeature-»
«ENDIF-»
«ENDLET-»
«ENDDEFINE»

«DEFINE plugFeatures FOR gmfgen::TypeModelFacet-»
«LET childMetaFeature != null && childMetaFeature != containmentMetaFeature && !childMetaFeature.ecoreFeature.derived AS addChild-»
«IF addChild-»
result.append(«EXPAND xpt::commands::Common::plugFeatureCommand("editingDomain", "parentView.getElement()", "element") FOR childMetaFeature»);
«ENDIF-»
«ENDLET-»
result.append(«EXPAND xpt::commands::Common::plugFeatureCommand("editingDomain", "parentView.getElement()", "element") FOR containmentMetaFeature»);
«ENDDEFINE»

«DEFINE unplugFeatures FOR gmfgen::TypeModelFacet-»
«LET childMetaFeature != null && childMetaFeature != containmentMetaFeature && !childMetaFeature.ecoreFeature.derived AS removeChild-»
«IF removeChild-»
result.append(«EXPAND xpt::commands::Common::unplugFeatureCommand("editingDomain", "element.eContainer()", "element") FOR childMetaFeature»);
«ENDIF-»
«ENDLET-»
result.append(«EXPAND xpt::commands::Common::unplugFeatureCommand("editingDomain", "element.eContainer()", "element") FOR containmentMetaFeature»);
«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»

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

Back to the top