Skip to main content
aboutsummaryrefslogblamecommitdiffstats
blob: 2365eab0dd1d7d697a9c3af8848dd59be9ca0065 (plain) (tree)















































































































































































































                                                                                                                                                                                                                                                                             
/*
 * 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 CreateLinkCompleteCommand 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 prepare-»
	«EXPAND initializeDomainModelCommand-»
	«EXPAND canUndo-»
	«EXPAND execute-»
	«EXPAND undo-»
	«EXPAND redo-»
	«EXPAND xpt::commands::Common::getRelationshipContainer FOR modelFacet-»
	«EXPAND additions-»
}
«ENDDEFINE»

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

«DEFINE supertypes FOR gmfgen::GenLink»extends org.eclipse.emf.common.command.AbstractCommand«ENDDEFINE»

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

	«EXPAND xpt::Common::generatedMemberComment»
	private final org.eclipse.gmf.runtime.notation.View target;

	«EXPAND xpt::Common::generatedMemberComment»
	private final org.eclipse.gmf.runtime.notation.Edge createdEdge;

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

«DEFINE ctors FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	public «EXPAND className»(org.eclipse.gmf.runtime.lite.requests.CreateConnectionRequestEx requestEx) {
		if (requestEx.getSourceEditPart().getModel() instanceof org.eclipse.gmf.runtime.notation.View) {
			source = (org.eclipse.gmf.runtime.notation.View) requestEx.getSourceEditPart().getModel();
		} else {
			source = null;
		}
		if (requestEx.getTargetEditPart().getModel() instanceof org.eclipse.gmf.runtime.notation.View) {
			target = (org.eclipse.gmf.runtime.notation.View) requestEx.getTargetEditPart().getModel();
		} else {
			target = null;
		}
		if (source == null || target == null) {
			createdEdge = null;
			return;
		}
		createdEdge = org.eclipse.gmf.runtime.notation.NotationFactory.eINSTANCE.createEdge();
		«EXPAND setEdgeElement(this) FOR modelFacet-»
		«getNotationViewFactoryQualifiedClassName()».INSTANCE.decorateView(createdEdge);
	}
«ENDDEFINE»

«DEFINE setEdgeElement(gmfgen::GenLink genLink) FOR gmfgen::LinkModelFacet-»
	createdEdge.setElement(null);
«ENDDEFINE»

«DEFINE setEdgeElement(gmfgen::GenLink genLink) FOR gmfgen::TypeLinkModelFacet-»
	«EXPAND xpt::Common::newInstance("createdDomainElement") FOR metaClass-»
	createdEdge.setElement(«unparenthesizedCast("createdDomainElement", metaClass, null)»);
	«EXPAND xpt::commands::Common::DomainElementInitializerQualifiedClassName FOR genLink».«genLink.getUniqueIdentifier()».initializeElement(«unparenthesizedCast("createdDomainElement", metaClass, null)»);
«ENDDEFINE»

«DEFINE prepare FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected boolean prepare() {
		if (source == null || target == null || createdEdge == null) {
			return false;
		}
		«EXPAND xpt::commands::Common::checkLinkConstraints("source.getElement()", "target.getElement()") FOR creationConstraints-»
		domainModelAddCommand = initializeDomainModelCommand();
		if (domainModelAddCommand == null || !domainModelAddCommand.canExecute()) {
			return false;
		}
		return true;
	}
«ENDDEFINE»

«DEFINE initializeDomainModelCommand FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.emf.common.command.Command initializeDomainModelCommand() {
		«EXPAND initializeDomainModelCommand FOR modelFacet-»
	}
«ENDDEFINE»

«DEFINE initializeDomainModelCommand FOR gmfgen::LinkModelFacet-»
return org.eclipse.emf.common.command.UnexecutableCommand.INSTANCE;
«ENDDEFINE»

«DEFINE initializeDomainModelCommand FOR gmfgen::TypeLinkModelFacet-»
	«containmentMetaFeature.genClass.getQualifiedInterfaceName()» container = («containmentMetaFeature.genClass.getQualifiedInterfaceName()») getRelationshipContainer(source.getElement(), «EXPAND xpt::Common::metaClassAccessor FOR containmentMetaFeature.genClass»);
	if (container == null) {
		return org.eclipse.emf.common.command.UnexecutableCommand.INSTANCE;
	}
«LET childMetaFeature != null && childMetaFeature != containmentMetaFeature && !childMetaFeature.ecoreFeature.derived AS addChild-»
«LET sourceMetaFeature != null && !sourceMetaFeature.ecoreFeature.derived && ecore::EReference.isSuperTypeOf(sourceMetaFeature.ecoreFeature.eClass()) 
	&& ((ecore::EReference) sourceMetaFeature.ecoreFeature).eOpposite !=containmentMetaFeature.ecoreFeature && 
		(addChild implies ((ecore::EReference) sourceMetaFeature.ecoreFeature).eOpposite != childMetaFeature.ecoreFeature) AS addSource-»
«LET targetMetaFeature != null && !targetMetaFeature.ecoreFeature.derived && ecore::EReference.isSuperTypeOf(targetMetaFeature.ecoreFeature.eClass()) 
	&& ((ecore::EReference) targetMetaFeature.ecoreFeature).eOpposite !=containmentMetaFeature.ecoreFeature && 
		(addChild implies ((ecore::EReference) targetMetaFeature.ecoreFeature).eOpposite != childMetaFeature.ecoreFeature) AS addTarget-»
	«IF addSource-»
		«EXPAND checkFeature("createdEdge.getElement()", null) FOR sourceMetaFeature-»
	«ENDIF-»
	«IF addTarget-»
		«EXPAND checkFeature("createdEdge.getElement()", null) FOR targetMetaFeature-»
		«LET targetMetaFeature.getReverse() AS targetReverseFeature-»
			«IF targetReverseFeature != null && !targetReverseFeature.ecoreFeature.derived-»
				«EXPAND checkFeature("target.getElement()", null) FOR targetReverseFeature-»
			«ENDIF-»
		«ENDLET-»
	«ENDIF-»
	org.eclipse.emf.transaction.TransactionalEditingDomain domainModelEditDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(source.getDiagram().getElement());
	org.eclipse.emf.common.command.CompoundCommand addLinkEndsCommand = new org.eclipse.emf.common.command.CompoundCommand();
	addLinkEndsCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "container", "createdEdge.getElement()") FOR containmentMetaFeature»);
	«IF addChild-»
	addLinkEndsCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "container", "createdEdge.getElement()") FOR childMetaFeature»);
	«ENDIF-»
	«IF addSource-»
	addLinkEndsCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "createdEdge.getElement()", "source.getElement()") FOR sourceMetaFeature»);
	«ENDIF-»
	«IF addTarget-»
	addLinkEndsCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "createdEdge.getElement()", "target.getElement()") FOR targetMetaFeature»);
	«ENDIF-»
	return addLinkEndsCommand;
«ENDLET-»
«ENDLET-»
«ENDLET-»
«ENDDEFINE»

«DEFINE initializeDomainModelCommand FOR gmfgen::FeatureLinkModelFacet-»
«LET metaFeature.getReverse() AS reverseMetaFeature-»
	«IF reverseMetaFeature != null && !reverseMetaFeature.ecoreFeature.derived-»
		«EXPAND checkFeature("target.getElement()", null) FOR reverseMetaFeature-»
	«ENDIF-»
	org.eclipse.emf.transaction.TransactionalEditingDomain domainModelEditDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(source.getDiagram().getElement());
	return «EXPAND xpt::commands::Common::plugFeatureCommand("domainModelEditDomain", "source.getElement()", "target.getElement()") FOR metaFeature»;
«ENDLET-»
«ENDDEFINE»

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

«DEFINE execute FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	public void execute() {
		domainModelAddCommand.execute();
		source.getDiagram().insertEdge(createdEdge);
		createdEdge.setSource(source);
		createdEdge.setTarget(target);
	}
«ENDDEFINE»

«DEFINE undo FOR gmfgen::GenLink-»
	«EXPAND xpt::Common::generatedMemberComment»
	public void undo() {
		domainModelAddCommand.undo();
		source.getDiagram().removeEdge(createdEdge);
		createdEdge.setSource(null);
		createdEdge.setTarget(null);
	}
«ENDDEFINE»

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

«DEFINE additions FOR gmfgen::GenLink-»
«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»

Back to the top