diff options
author | rschnekenbu | 2014-03-28 08:57:17 +0000 |
---|---|---|
committer | rschnekenbu | 2014-03-28 08:57:17 +0000 |
commit | abd51c56328931a1b0a3b212c04ac89f64d90c6e (patch) | |
tree | 5e8f3428e1c51a88d9734f5ba8520b2ba33d58d2 /plugins/developer | |
parent | 1eb28d11e147be4960464706bf4977277889c6aa (diff) | |
download | org.eclipse.papyrus-abd51c56328931a1b0a3b212c04ac89f64d90c6e.tar.gz org.eclipse.papyrus-abd51c56328931a1b0a3b212c04ac89f64d90c6e.tar.xz org.eclipse.papyrus-abd51c56328931a1b0a3b212c04ac89f64d90c6e.zip |
[Element Types] It should be possible to create elements in diagrams
related to generic Element Types.
Simplifying code generation for standard gmfgen diagrams, for the item
semantic edit policies.
The generic creation is now handled by the BaseSemanticItemEditPolicy,
instead of returning simply null.
Diffstat (limited to 'plugins/developer')
4 files changed, 32 insertions, 33 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xtend b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xtend index e907969828a..1556194cfb0 100644 --- a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xtend +++ b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xtend @@ -192,10 +192,20 @@ protected org.eclipse.gef.commands.Command getCreateRelationshipCommand(org.ecli override getCreateCommand(GenDiagram it) ''' «generatedMemberComment()» - protected org.eclipse.gef.commands.Command getCreateCommand(org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest req) { - // no more usage of the extended types here. - return null; - } + protected org.eclipse.gef.commands.Command getCreateCommand(org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest req) { + org.eclipse.gmf.runtime.emf.type.core.IElementType requestElementType = req.getElementType(); + if (requestElementType instanceof org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType) { + // try to get a semantic create command from the extended type + org.eclipse.papyrus.infra.services.edit.service.IElementEditService commandProvider = org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils.getCommandProvider(req.getContainer()); + if (commandProvider != null) { + org.eclipse.gmf.runtime.common.core.command.ICommand command = commandProvider.getEditCommand(req); + if (command != null && command.canExecute()) { + return new org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy(command); + } + } + } + return null; + } '''
def getCreateExtendedTypeCommand(GenDiagram it) ''' diff --git a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/CompartmentItemSemanticEditPolicy.xtend b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/CompartmentItemSemanticEditPolicy.xtend index ea98c1d02fa..237da6a0154 100644 --- a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/CompartmentItemSemanticEditPolicy.xtend +++ b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/CompartmentItemSemanticEditPolicy.xtend @@ -22,6 +22,7 @@ import org.eclipse.gmf.codegen.gmfgen.GenNode import org.eclipse.gmf.codegen.gmfgen.TypeModelFacet
import org.eclipse.papyrus.papyrusgmfgenextension.ConstrainedByReferenceCompartmentItemSemanticEditPolicy
import xpt.Common
+import xpt.diagram.editpolicies.childContainerCreateCommand
@Singleton class CompartmentItemSemanticEditPolicy extends xpt.diagram.editpolicies.CompartmentItemSemanticEditPolicy { @Inject extension Common; diff --git a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/NodeItemSemanticEditPolicy.xtend b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/NodeItemSemanticEditPolicy.xtend index 481f829bee6..9c54424d319 100644 --- a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/NodeItemSemanticEditPolicy.xtend +++ b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/NodeItemSemanticEditPolicy.xtend @@ -23,6 +23,7 @@ import org.eclipse.gmf.codegen.gmfgen.TypeLinkModelFacet import org.eclipse.papyrus.papyrusgmfgenextension.EditPartUsingDeleteService
import utils.UtilsItemSemanticEditPolicy
import xpt.Common
+import xpt.diagram.editpolicies.childContainerCreateCommand
import xpt.editor.VisualIDRegistry
/**
diff --git a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/childContainerCreateCommand.xtend b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/childContainerCreateCommand.xtend index da889d954a4..615b782bf85 100644 --- a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/childContainerCreateCommand.xtend +++ b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/xpt/diagram/editpolicies/childContainerCreateCommand.xtend @@ -40,18 +40,7 @@ import metamodel.MetaModel if(requestElementType == null) { return super.getCreateCommand(req); } - org.eclipse.gmf.runtime.emf.type.core.IElementType baseElementType = requestElementType; - boolean isExtendedType = false; - if(requestElementType instanceof org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType) { - baseElementType = org.eclipse.papyrus.infra.extendedtypes.util.ElementTypeUtils.getClosestDiagramType(requestElementType); - if(baseElementType != null) { - isExtendedType = true; - } else { - // no reference element type ID. using the closest super element type to give more opportunities, but can lead to bugs. - baseElementType = org.eclipse.papyrus.infra.extendedtypes.util.ElementTypeUtils.findClosestNonExtendedElementType((org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType)requestElementType); - isExtendedType = true; - } - } + «FOR n : nodes» «IF !n.sansDomain» @@ -63,23 +52,21 @@ import metamodel.MetaModel «ENDIF» ''' -def childNodeCreateCommand(TypeModelFacet it,GenNode node)''' -if («accessElementType(node)» == baseElementType) { - «IF it.eResource.allContents.filter(typeof (GenerateUsingElementTypeCreationCommand)).size>0» - // adjust the containment feature - org.eclipse.emf.ecore.EReference containmentFeature = «MetaFeature(it.childMetaFeature)»; - req.setContainmentFeature(containmentFeature); - «ENDIF» - if(isExtendedType) { - return getExtendedTypeCreationCommand(req, (org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType)requestElementType); + def childNodeCreateCommand(TypeModelFacet it,GenNode node)''' + if («accessElementType(node)» == requestElementType) { + «IF it.eResource.allContents.filter(typeof (GenerateUsingElementTypeCreationCommand)).size>0» + // adjust the containment feature + org.eclipse.emf.ecore.EReference containmentFeature = «MetaFeature(it.childMetaFeature)»; + req.setContainmentFeature(containmentFeature); + «ENDIF» + + «IF it.eResource.allContents.filter(typeof (GenerateUsingElementTypeCreationCommand)).size>0» + return getGEFWrapper(getSemanticCreationCommand(req)); + «ELSE» + return getGEFWrapper(new «node.getCreateCommandQualifiedClassName()»(req, org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils.getDiagramFrom(getHost()))); + «ENDIF» + } - «IF it.eResource.allContents.filter(typeof (GenerateUsingElementTypeCreationCommand)).size>0» - return getGEFWrapper(getSemanticCreationCommand(req)); - «ELSE» - return getGEFWrapper(new «node.getCreateCommandQualifiedClassName()»(req, org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils.getDiagramFrom(getHost()))); - «ENDIF» - -} -''' + ''' }
\ No newline at end of file |