Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 14cf80e186f804b25dade8558b48f235cd2def5c (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
/*
 * 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 CreateNodeCommand 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 prepare-»
	«EXPAND canUndo-»
	«EXPAND execute-»
	«EXPAND undo-»
	«EXPAND redo-»
	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE attributes FOR gmfgen::GenNode-»
	«EXPAND xpt::Common::generatedMemberComment»
	private final org.eclipse.gmf.runtime.lite.commands.CreateNotationalNodeCommand notationAddCommand;

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

«DEFINE ctors FOR gmfgen::GenNode-»
	«EXPAND xpt::Common::generatedMemberComment»
	public «EXPAND className»(org.eclipse.gmf.runtime.notation.View parent, org.eclipse.gmf.runtime.lite.requests.CreateRequestEx request) {
		this(parent, request, null);
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public «EXPAND className»(org.eclipse.gmf.runtime.notation.View parent, org.eclipse.gmf.runtime.lite.requests.CreateRequestEx request, org.eclipse.draw2d.geometry.Rectangle constraint) {
		«EXPAND xpt::Common::newInstanceAsEObject("createdDomainElement") FOR modelFacet.metaClass-»
		«EXPAND xpt::commands::Common::DomainElementInitializerQualifiedClassName».«getUniqueIdentifier()».initializeElement(createdDomainElement);
		«EXPAND initializeDomainModelCommand FOR modelFacet-»
		«EXPAND xpt::commands::Common::adjustConstraint-»
		this.notationAddCommand = new org.eclipse.gmf.runtime.lite.commands.CreateNotationalNodeCommand(parent, createdDomainElement, 
			constraint, «getNotationViewFactoryQualifiedClassName()».INSTANCE);
		request.setCreatedObject(notationAddCommand.getCreatedView());
	}
«ENDDEFINE»

«DEFINE initializeDomainModelCommand FOR gmfgen::TypeModelFacet-»
		«EXPAND checkFeature("parent.getElement()", null) FOR containmentMetaFeature-»
«LET childMetaFeature != null && childMetaFeature != containmentMetaFeature && !childMetaFeature.ecoreFeature.derived AS addChild-»
	«IF addChild-»
		«EXPAND checkFeature("parent.getElement()", null) FOR childMetaFeature-»
	«ENDIF-»
		org.eclipse.emf.transaction.TransactionalEditingDomain domainModelEditDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(parent.getDiagram().getElement());
	«IF addChild-»
		org.eclipse.emf.common.command.CompoundCommand compoundCommand = new org.eclipse.emf.common.command.CompoundCommand();
		compoundCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "parent.getElement()", "createdDomainElement") FOR containmentMetaFeature»);
		compoundCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "parent.getElement()", "createdDomainElement") FOR childMetaFeature»);
		domainModelAddCommand = compoundCommand;
	«ELSE-»
		domainModelAddCommand = «EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "parent.getElement()", "createdDomainElement") FOR containmentMetaFeature»;
	«ENDIF-»
«ENDLET-»
«ENDDEFINE»

«DEFINE prepare FOR gmfgen::GenNode-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected boolean prepare() {
		return domainModelAddCommand != null && domainModelAddCommand.canExecute() && notationAddCommand != null && notationAddCommand.canExecute();
	}
«ENDDEFINE»

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

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

«DEFINE execute FOR gmfgen::GenNode-»
	«EXPAND xpt::Common::generatedMemberComment»
	public void execute() {
		domainModelAddCommand.execute();
		notationAddCommand.execute();
	}
«ENDDEFINE»

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

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

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

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

Back to the top