Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 834a0d26960521159316a9a00062620eae31db15 (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
/*
 * Copyright (c) 2007, 2009 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/2009/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»

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

«DEFINE CreateLinkCommand FOR gmfgen::GenLink»«EXPAND Main»«ENDDEFINE»

«DEFINE Main FOR gmfgen::GenLink-»
«EXPAND xpt::Common::copyright FOR diagram.editorGen-»
package «diagram.editCommandsPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «createCommandClassName» extends org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand {
	«EXPAND xpt::diagram::commands::CreateLinkUtils::fields FOR modelFacet-»

	«EXPAND xpt::Common::generatedMemberComment»
	public «createCommandClassName»(org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest request, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EObject target) {
		super(request.getLabel(), null, request);
		«EXPAND xpt::diagram::commands::CreateLinkUtils::_init FOR modelFacet-»
	}
	«EXPAND xpt::diagram::commands::CreateLinkUtils::canCreate(self) FOR modelFacet-»

	«EXPAND doExecuteWithResultMethod»

	«EXPAND doConfigure(self) FOR modelFacet-»

	«EXPAND xpt::Common::generatedMemberComment»
	protected void setElementToEdit(org.eclipse.emf.ecore.EObject element) {
		throw new UnsupportedOperationException();
	}
	«EXPAND xpt::diagram::commands::CreateLinkUtils::accessors FOR modelFacet-»
«EXPAND additions-»
}
«ENDDEFINE»

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

«DEFINE doExecuteWithResultMethod FOR gmfgen::GenLink»
	«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 create link command");«EXPAND xpt::Common::nonNLS»
		}
		«EXPAND execute(self) FOR modelFacet»
	}
«ENDDEFINE»

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

«DEFINE execute(link : gmfgen::GenLink) FOR gmfgen::TypeLinkModelFacet»
«IF (if sourceMetaFeature = null then containmentMetaFeature.ecoreFeature.changeable else sourceMetaFeature.ecoreFeature.changeable endif) and targetMetaFeature.ecoreFeature.changeable-»
		«EXPAND MetaModel::NewInstance('newElement') FOR metaClass-»
		«EXPAND MetaModel::modifyFeature((if hasContainerOtherThanSource(self) then 'getContainer()' else 'getSource()' endif), containmentMetaFeature.genClass, 'newElement') FOR containmentMetaFeature-»
		«IF sourceMetaFeature <> null-»
			«EXPAND MetaModel::modifyFeature('newElement', metaClass, 'getSource()') FOR sourceMetaFeature-»
		«ENDIF-»
		«EXPAND MetaModel::modifyFeature('newElement', metaClass, 'getTarget()') FOR targetMetaFeature-»
		«IF hasExplicitChildFeature(self)-»
			«IF sourceMetaFeature <> null-»
				«EXPAND MetaModel::modifyFeature('getContainer()', containmentMetaFeature.genClass, 'newElement') FOR childMetaFeature-»
			«ELSE-»
				«EXPAND MetaModel::modifyFeature('getSource()', getSourceType(), 'newElement') FOR childMetaFeature-»
			«ENDIF-»
		«ENDIF-»
		«EXPAND initialize(link, 'newElement')-»
		doConfigure(newElement, monitor, info);
		((org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest) getRequest()).setNewElement(«EXPAND MetaModel::DowncastToEObject('newElement') FOR metaClass»);
		return org.eclipse.gmf.runtime.common.core.command.CommandResult.newOKCommandResult(newElement);
«ELSE-»
		throw new UnsupportedOperationException();
«ENDIF-»
«ENDDEFINE»


«DEFINE initialize(link : gmfgen::GenLink, newElementvVar : String) FOR gmfgen::TypeModelFacet»«IF modelElementInitializer <> null-»
«link.diagram.getElementTypesQualifiedClassName()».init_«link.getUniqueIdentifier()»(«newElementvVar»);
«ENDIF»«ENDDEFINE»


«DEFINE execute(link : gmfgen::GenLink) FOR gmfgen::FeatureLinkModelFacet»
«IF metaFeature.ecoreFeature.changeable-»
	if (getSource() != null && getTarget() != null) {
		«EXPAND MetaModel::modifyFeature('getSource()', getSourceType(), 'getTarget()') FOR metaFeature-»
	}
	return org.eclipse.gmf.runtime.common.core.command.CommandResult.newOKCommandResult();
«ELSE-»
	throw new UnsupportedOperationException();
«ENDIF-»
«ENDDEFINE»


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

/*
 * TODO invocation of configure command should be optional, and better yet, 
 * configuration should rather happen from EditPolicy then from within creation command 
 */
«DEFINE doConfigure(link : gmfgen::GenLink) FOR gmfgen::TypeLinkModelFacet-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void doConfigure(«EXPAND MetaModel::QualifiedClassName FOR metaClass» newElement, org.eclipse.core.runtime.IProgressMonitor monitor, org.eclipse.core.runtime.IAdaptable info) throws org.eclipse.core.commands.ExecutionException {
		org.eclipse.gmf.runtime.emf.type.core.IElementType elementType = ((org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest) getRequest()).getElementType();
		org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest configureRequest = new org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest(getEditingDomain(), «EXPAND MetaModel::DowncastToEObject('newElement') FOR metaClass», elementType);
		configureRequest.setClientContext(((org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest) getRequest()).getClientContext());
		configureRequest.addParameters(getRequest().getParameters());
		configureRequest.setParameter(org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest.SOURCE, getSource());
		configureRequest.setParameter(org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest.TARGET, getTarget());
		org.eclipse.gmf.runtime.common.core.command.ICommand configureCommand = elementType.getEditCommand(configureRequest);
		if (configureCommand != null && configureCommand.canExecute()) {
			configureCommand.execute(monitor, info);
		}
	}
«ENDDEFINE»

Back to the top