Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4882adcd20d9cea8d2a1feb9b2556c6d3062d86e (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
/*
 * 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»
«EXTENSION xpt::commands::CommandUtils»

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

«EXPAND xpt::Common::generatedClassComment»
public class «EXPAND className» «EXPAND supertypes» {
	«EXPAND attributes-»
	«EXPAND ctors-»
	«EXPAND createCommand-»
	«EXPAND createAfterCopyCommand-»
	«EXPAND execute-»
	«EXPAND canUndo-»
	«EXPAND undo-»
	«EXPAND redo-»
	«EXPAND dispose-»
	«EXPAND additions-»
}
«ENDDEFINE»

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

«DEFINE attributes 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;
«EXPAND xpt::Common::generatedMemberComment»
private final org.eclipse.draw2d.geometry.Rectangle constraint;
«EXPAND xpt::Common::generatedMemberComment»
private final org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain;
«EXPAND xpt::Common::generatedMemberComment»
private org.eclipse.emf.common.command.Command afterCopyCommand;
«ENDDEFINE»

«DEFINE ctors FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public «EXPAND className»(org.eclipse.gmf.runtime.notation.View parentView, org.eclipse.gmf.runtime.notation.Node childNode, org.eclipse.draw2d.geometry.Rectangle constraint) {
	this.parentView = parentView;
	this.childNode = childNode;
	this.constraint = constraint;
	this.editingDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(childNode.getDiagram().getElement());
}
«ENDDEFINE»

«DEFINE createCommand FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.emf.common.command.Command createCommand() {
	«EXPAND checkFeatures FOR modelFacet-»
	org.eclipse.emf.ecore.EObject element = childNode.getElement();
	//We are being optimistic here about whether further commands can be executed.
	//Otherwise, we would have to execute the CopyCommand on every mouse move, which could be much too expensive.
	return org.eclipse.emf.edit.command.CopyCommand.create(editingDomain, element);
}
«ENDDEFINE»

«DEFINE execute FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public void execute() {
	super.execute();
	afterCopyCommand = createAfterCopyCommand();
	if (afterCopyCommand.canExecute()) {
		afterCopyCommand.execute();
	} else {
		assert false;
	}
}
«ENDDEFINE»

«DEFINE createAfterCopyCommand FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
private org.eclipse.emf.common.command.Command createAfterCopyCommand() {
	final java.util.Collection copyResults = super.getResult();
	assert copyResults.size() == 1;
	org.eclipse.emf.ecore.EObject copyResult = (org.eclipse.emf.ecore.EObject) copyResults.iterator().next();
	org.eclipse.emf.common.command.CompoundCommand result = new org.eclipse.emf.common.command.CompoundCommand();
	«EXPAND plugFeatures FOR modelFacet-»
	«EXPAND xpt::commands::Common::adjustConstraint-»
	result.append(new org.eclipse.gmf.runtime.lite.commands.CreateNotationalNodeCommand(parentView, copyResult, constraint, «getNotationViewFactoryQualifiedClassName()».INSTANCE));
	return result;
}
«ENDDEFINE»

«DEFINE canUndo FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public boolean canUndo() {
	return super.canUndo() && afterCopyCommand != null && afterCopyCommand.canUndo();
}
«ENDDEFINE»

«DEFINE undo FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public void undo() {
	afterCopyCommand.undo();
	super.undo();
}
«ENDDEFINE»

«DEFINE redo FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public void redo() {
	super.redo();
	afterCopyCommand.redo();
}
«ENDDEFINE»

«DEFINE dispose FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public void dispose() {
	super.dispose();
	if (afterCopyCommand != null) {
		afterCopyCommand.dispose();
	}
}
«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()", "copyResult") FOR childMetaFeature»);
«ENDIF-»
«ENDLET-»
result.append(«EXPAND xpt::commands::Common::plugFeatureCommand("editingDomain", "parentView.getElement()", "copyResult") 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