| /* |
| * 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: |
| * bblajer (Borland) - initial API and implementation |
| */ |
| |
| «IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'» |
| «IMPORT 'http://www.eclipse.org/emf/2002/GenModel'» |
| «EXTENSION xpt::GenModelUtils» |
| |
| «DEFINE CreateLinkStartCommand 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 shouldExecute-» |
| «EXPAND xpt::commands::Common::getRelationshipContainer FOR modelFacet-» |
| «EXPAND additions-» |
| } |
| «ENDDEFINE» |
| |
| «DEFINE additions FOR gmfgen::GenLink-» |
| «ENDDEFINE» |
| |
| «DEFINE className FOR gmfgen::GenLink»Create«EXPAND xpt::commands::Common::commandNameInfix»StartCommand«ENDDEFINE» |
| «DEFINE qualifiedClassName FOR gmfgen::GenLink»«getDiagram().editCommandsPackageName».«EXPAND className»«ENDDEFINE» |
| «DEFINE supertypes FOR gmfgen::GenLink»extends org.eclipse.gmf.runtime.lite.commands.VetoCommand«ENDDEFINE» |
| |
| «DEFINE attributes FOR gmfgen::GenLink-» |
| «EXPAND xpt::Common::generatedMemberComment» |
| private org.eclipse.gmf.runtime.notation.View source; |
| «ENDDEFINE» |
| |
| «DEFINE ctors FOR gmfgen::GenLink-» |
| «EXPAND xpt::Common::generatedMemberComment» |
| public «EXPAND className»(org.eclipse.gmf.runtime.lite.requests.CreateConnectionRequestEx requestEx) { |
| //Until the mouse button is pressed, the source of the connection is in request.getTargetEditPart(), not in request.getSourceEditPart(). |
| source = (org.eclipse.gmf.runtime.notation.View)requestEx.getTargetEditPart().getModel(); |
| } |
| «ENDDEFINE» |
| |
| «DEFINE shouldExecute FOR gmfgen::GenLink-» |
| «EXPAND xpt::Common::generatedMemberComment» |
| protected boolean shouldExecute() { |
| if (source == null) { |
| return false; |
| } |
| «EXPAND xpt::commands::Common::checkLinkConstraints('source.getElement()', 'null') FOR creationConstraints-» |
| «EXPAND shouldExecute FOR modelFacet-» |
| } |
| «ENDDEFINE» |
| |
| «DEFINE shouldExecute FOR gmfgen::LinkModelFacet»return false;«ENDDEFINE» |
| |
| «DEFINE shouldExecute FOR gmfgen::TypeLinkModelFacet-» |
| «IF null <> containmentMetaFeature-» |
| «EXPAND shouldExecuteForNonNullContainmentMetaFeature-» |
| «ELSE-» |
| return false; |
| «ENDIF-» |
| «ENDDEFINE» |
| |
| «DEFINE shouldExecuteForNonNullContainmentMetaFeature FOR gmfgen::TypeLinkModelFacet-» |
| org.eclipse.emf.ecore.EObject containerEObj = getRelationshipContainer(source.getElement(), «EXPAND MetaModel::MetaClass FOR containmentMetaFeature.genClass»); |
| «EXPAND MetaModel::DeclareAndAssign('container', 'containerEObj') FOR containmentMetaFeature.genClass» |
| if (container == null) { |
| return false; |
| } |
| «EXPAND checkFeature('container', containmentMetaFeature.genClass) FOR containmentMetaFeature-» |
| «IF childMetaFeature <> null and (childMetaFeature <> containmentMetaFeature and not childMetaFeature.ecoreFeature._derived)-» |
| «EXPAND checkFeature('container', containmentMetaFeature.genClass) FOR childMetaFeature-» |
| «ENDIF-» |
| «IF sourceMetaFeature <> null-» |
| «LET getReverse(sourceMetaFeature) AS sourceReverseFeature-» |
| «IF sourceReverseFeature <> null and (not sourceReverseFeature.ecoreFeature._derived and (sourceReverseFeature <> containmentMetaFeature and sourceReverseFeature <> childMetaFeature))-» |
| «EXPAND checkFeature('source.getElement()', null) FOR sourceReverseFeature-» |
| «ENDIF-» |
| «ENDLET-» |
| «ENDIF-» |
| return true; |
| «ENDDEFINE» |
| |
| «DEFINE shouldExecute FOR gmfgen::FeatureLinkModelFacet-» |
| «EXPAND checkFeature('source.getElement()', null) FOR metaFeature-» |
| return true; |
| «ENDDEFINE» |
| |
| «DEFINE checkFeature(containerVar : String, containerClass : genmodel::GenClass) FOR genmodel::GenFeature-» |
| «IF ecoreFeature.upperBound > 0-» |
| if («EXPAND xpt::commands::Common::featureMultiplicityComparator(containerVar, containerClass)») { |
| return false; |
| } |
| «ENDIF-» |
| «ENDDEFINE» |