diff options
author | Patrick Tessier | 2013-10-04 08:41:11 +0000 |
---|---|---|
committer | Patrick Tessier | 2013-10-04 08:41:11 +0000 |
commit | edf36ffe95e2e84a96202b75df85a8f53f00002d (patch) | |
tree | 14686131bd7bb319f9ab72127293b386efbe7eca /plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric | |
parent | f9b32bdb44861826562138aa315cc5062b0228a3 (diff) | |
download | org.eclipse.papyrus-edf36ffe95e2e84a96202b75df85a8f53f00002d.tar.gz org.eclipse.papyrus-edf36ffe95e2e84a96202b75df85a8f53f00002d.tar.xz org.eclipse.papyrus-edf36ffe95e2e84a96202b75df85a8f53f00002d.zip |
Applied Patch for R. Chevrel for
Bug 413991 - [SysML Parametric Diagram] Pb with Show hide contents menu
- Bug 413992 - [SysML Parametric Diagram] Drag&Drop problem
- Bug 413996 - [SysML Parametric Diagram] Pb with Graphical
representation of constraint property
- Bug 413999 - [SysML Parametric Diagram] Problem with reference
properties displayed as parameters
- Bug 414005 - [SysML Parametric diagram]Pb with creating a constraint
property from Palette
- Bug 414013 - [SysML Parametric Diagram] Automatically stereotyping
constraint properties
- Problem 2 of Bug 415663 - [Parametric Diagrams] Problem with
constraints
Conflicts:
plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/command/CustomContextLinkCreateCommand.java
Diffstat (limited to 'plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric')
28 files changed, 1430 insertions, 122 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/META-INF/MANIFEST.MF b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/META-INF/MANIFEST.MF index a7a0d4d5a1c..95fa0399562 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/META-INF/MANIFEST.MF +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/META-INF/MANIFEST.MF @@ -30,7 +30,11 @@ Require-Bundle: org.eclipse.ui, org.eclipse.gmf.tooling.runtime;bundle-version="3.1.0", org.eclipse.papyrus.sysml.diagram.internalblock;bundle-version="0.10.1", org.eclipse.papyrus.uml.diagram.common;bundle-version="0.10.1", - org.eclipse.papyrus.sysml.diagram.common;bundle-version="0.10.1" + org.eclipse.papyrus.sysml.diagram.common;bundle-version="0.10.1", + org.eclipse.papyrus.uml.diagram.clazz;bundle-version="0.10.1", + org.eclipse.papyrus.views.properties;bundle-version="0.10.1", + org.eclipse.core.databinding.observable;bundle-version="1.4.1", + org.eclipse.papyrus.views.properties.model;bundle-version="0.10.1" Bundle-ManifestVersion: 2 Bundle-ActivationPolicy: lazy Bundle-Name: %pluginName @@ -52,3 +56,4 @@ Export-Package: org.eclipse.papyrus.sysml.diagram.parametric, org.eclipse.papyrus.sysml.diagram.parametric.preferences, org.eclipse.papyrus.sysml.diagram.parametric.provider, org.eclipse.papyrus.sysml.diagram.parametric.utils +Import-Package: org.eclipse.gmf.runtime.notation diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/palettes/parametric.palette.xml b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/palettes/parametric.palette.xml index 75247fe2000..f385c0ec607 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/palettes/parametric.palette.xml +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/palettes/parametric.palette.xml @@ -36,6 +36,9 @@ <aspectTool description="Create a new CommentAnnotatedElement" id="parametric.tool.commentannotatedelement" name="CommentAnnotatedElement" refToolId="parametric.tool.comment_constraint_link"> </aspectTool> + <aspectTool description="Create a new ContextLink" id="parametric.tool.context_link" + name="ContextLink" refToolId="parametric.tool.context_link"> + </aspectTool> </drawer> </content> </paletteDefinition> diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/plugin.properties b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/plugin.properties index 1095de7c781..6f678bf8b44 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/plugin.properties +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/plugin.properties @@ -10,3 +10,5 @@ ################################################################################## pluginName=SysML Parametric Diagram providerName=Eclipse Modeling Project +context.description=Papyrus SysML Parametric Diagram Editing +context.name=In Papyrus SysML Parametric Diagram Editor diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/plugin.xml b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/plugin.xml index 739ef57ab0a..2a9c65f867b 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/plugin.xml +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/plugin.xml @@ -2,6 +2,16 @@ <?eclipse version="3.4"?> <plugin> +<extension point="org.eclipse.ui.contexts" id="ui-context"> + <?gmfgen generated="true"?> + <context + description="%context.description" + id="org.eclipse.papyrus.sysml.diagram.parametric.ui.diagramContext" + name="%context.name" + parentId="org.eclipse.gmf.runtime.diagram.ui.diagramContext"> + </context> +</extension> + <!-- Diagram declaration --> <extension point="org.eclipse.papyrus.infra.core.papyrusDiagram"> <creationCommand @@ -22,6 +32,18 @@ name="Create a new Parametric Diagram" description="Create a new Parametric Diagram" categoryId="org.eclipse.papyrus.editor.category"/> + <command + categoryId="org.eclipse.papyrus.editor.category" + description="Switch ConstraintProperty Representation" + defaultHandler="org.eclipse.papyrus.sysml.diagram.parametric.commands.switchrepresentation.SwitchConstraintPropertyRepresentationCommandHandler" + id="org.eclipse.papyrus.sysml.diagram.parametric.custom.switchConstraintProperty" + name="Switch ConstraintProperty Representation"/> + <command + categoryId="org.eclipse.papyrus.editor.category" + description="Show/Hide ConstraintExpression" + defaultHandler="org.eclipse.papyrus.sysml.diagram.parametric.commands.switchrepresentation.ShowHideConstraintExpressionCommandHandler" + id="org.eclipse.papyrus.sysml.diagram.parametric.custom.showHideConstraintExpression" + name="Show/Hide Constraint expression"/> </extension> <extension point="org.eclipse.ui.handlers"> @@ -77,7 +99,79 @@ </command> </menuContribution> - + + <menuContribution locationURI="popup:org.eclipse.papyrus.uml.diagram.ui.popupmenu.format"> + <menu + label="Representation" + tooltip="Representation"> + <command + commandId="org.eclipse.papyrus.sysml.diagram.parametric.custom.switchConstraintProperty" + label="Switch ConstraintProperty representation" + style="push" + tooltip="Switch ConstraintProperty representation"> + <visibleWhen> + <and> + <iterate> + <instanceof + value="org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomConstraintBlockPropertyCompositeEditPart"> + </instanceof> + </iterate> + <with + variable="selection"> + <not> + <count + value="0"> + </count> + </not> + </with> + </and> + </visibleWhen> + </command> + </menu> + <separator + name="org.eclipse.papyrus.uml.diagram.menu.popup.separatorRepresentation" + visible="true"> + </separator> + </menuContribution> + + <menuContribution locationURI="popup:org.eclipse.papyrus.uml.diagram.ui.popupmenu.filters"> + <command + commandId="org.eclipse.papyrus.sysml.diagram.parametric.custom.showHideConstraintExpression" + icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Constraint.gif" + label="Show/Hide Constraint expression" + style="push" + tooltip="Show/Hide Constraint expression"> + <visibleWhen> + <and> + <iterate> + <instanceof + value="org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomConstraintBlockPropertyCompositeEditPart"> + </instanceof> + </iterate> + <with + variable="selection"> + <not> + <count + value="0"> + </count> + </not> + </with> + </and> + </visibleWhen> + </command> + </menuContribution> +</extension> + + +<extension + id="update-cmd-binding" + point="org.eclipse.ui.bindings"> + <key + commandId="org.eclipse.papyrus.sysml.diagram.parametric.custom.switchConstraintProperty" + contextId="org.eclipse.gmf.runtime.diagram.ui.diagramContext" + schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" + sequence="CTRL+R"> + </key> </extension> <!-- Handler for Show/Hide content on Part or Ref. --> @@ -244,7 +338,7 @@ small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Comment.gif"> </entry> - <!-- internalblock.tool.constraint --> + <!-- parametric.tool.constraint --> <entry defineOnly="true" description="Create a Constraint" id="parametric.tool.constraint" @@ -256,10 +350,20 @@ <entry defineOnly="true" - description="Create a Comment / Constraint link" + description="CommentAnnotatedElement" id="parametric.tool.comment_constraint_link" kind="tool" - label="Comment / Constraint link" + label="CommentAnnotatedElement" + large_icon="icons/obj16/Link.gif" + small_icon="icons/obj16/Link.gif"> + </entry> + + <entry + defineOnly="true" + description="Create a ContextLink" + id="parametric.tool.context_link" + kind="tool" + label="Constraint link" large_icon="icons/obj16/Link.gif" small_icon="icons/obj16/Link.gif"> </entry> @@ -606,12 +710,31 @@ <!-- UML ElementType bindings to Papyrus shared IClientContext --> <extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypeBindings"> - <!-- Bindings declaration to shared IClientContext --> <binding context="org.eclipse.papyrus.infra.services.edit.TypeContext"> <elementType ref="org.eclipse.papyrus.sysml.service.types.helper.ConstraintParameterEditHelperAdvice"/> </binding> - +</extension> + +<extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypes"> + <metamodel nsURI="http://www.eclipse.org/uml2/4.0.0/UML"> + <specializationType + id="org.eclipse.papyrus.uml.diagram.parametric.ContextLink" + name="ContextLink" + kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"> + <specializes id="org.eclipse.gmf.runtime.emf.type.core.null"/> + <param name="semanticHint" value="8500"/> + </specializationType> + </metamodel> + <metamodel nsURI="http://www.eclipse.org/uml2/4.0.0/UML"> + <specializationType + id="org.eclipse.papyrus.uml.diagram.parametric.ContextLinkAppliedStereotype" + name="ContextLinkAppliedStereotype" + kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"> + <specializes id="org.eclipse.gmf.runtime.emf.type.core.null"/> + <param name="semanticHint" value="8501"/> + </specializationType> + </metamodel> </extension> <!-- // End of user code --> diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/factory/DiagramPaletteFactory.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/factory/DiagramPaletteFactory.java index 2a7b5905238..a830a4f62d5 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/factory/DiagramPaletteFactory.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/factory/DiagramPaletteFactory.java @@ -6,7 +6,7 @@ import java.util.HashMap; import org.eclipse.gef.Tool; import org.eclipse.gmf.runtime.diagram.ui.services.palette.PaletteFactory; import org.eclipse.gmf.runtime.emf.type.core.IElementType; -import org.eclipse.papyrus.sysml.diagram.internalblock.provider.ElementTypes; +import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes; import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes; import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeConnectionTool; import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeCreationTool; @@ -39,7 +39,8 @@ public class DiagramPaletteFactory extends PaletteFactory.Adapter { put("parametric.tool.connector", new IElementType[]{ UMLElementTypes.CONNECTOR }); put("parametric.tool.dependency", new IElementType[]{ UMLElementTypes.DEPENDENCY }); //Start of user code Custom edges - put("parametric.tool.comment_constraint_link", new IElementType[]{ ElementTypes.COMMENT_ANNOTATED_ELEMENT, ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT }); + put("parametric.tool.comment_constraint_link", new IElementType[]{ ElementTypes.COMMENT_ANNOTATED_ELEMENT }); + put("parametric.tool.context_link", new IElementType[]{ ElementTypes.CONTEXT_LINK }); //End of user code } }; diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomGraphicalTypeRegistry.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomGraphicalTypeRegistry.java index 0a1a37dd3c0..e03c0d72fd9 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomGraphicalTypeRegistry.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomGraphicalTypeRegistry.java @@ -2,11 +2,14 @@ package org.eclipse.papyrus.sysml.diagram.parametric.provider; import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType; +import org.eclipse.papyrus.sysml.constraints.ConstraintBlock; import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes; import org.eclipse.papyrus.sysml.diagram.internalblock.provider.ElementTypes; import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes; import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes; import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.util.UMLUtil; public class CustomGraphicalTypeRegistry extends GraphicalTypeRegistry { @@ -69,41 +72,44 @@ public class CustomGraphicalTypeRegistry extends GraphicalTypeRegistry { return UNDEFINED_TYPE; } - if(((ISpecializationType)SysMLElementTypes.PART_PROPERTY).getMatcher().matches(domainElement)) { - if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) { - return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; - } - if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) { - return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; - } - if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) { - return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; - } - return UNDEFINED_TYPE; - } - if(((ISpecializationType)SysMLElementTypes.REFERENCE_PROPERTY).getMatcher().matches(domainElement)) { - if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) { - return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; - } - if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) { - return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; - } - if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) { - return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; - } - return UNDEFINED_TYPE; - } - if(((ISpecializationType)SysMLElementTypes.VALUE_PROPERTY).getMatcher().matches(domainElement)) { - if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) { - return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; - } - if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) { - return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; - } - if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) { - return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; - } - return UNDEFINED_TYPE; + // These element are only authorized on Block, not in Constraint Block. In ConstraintBlock it must become a ConstraintParameter + if (UMLUtil.getStereotypeApplication((Element)domainElement.eContainer(), ConstraintBlock.class) == null) { + if(((ISpecializationType)SysMLElementTypes.PART_PROPERTY).getMatcher().matches(domainElement)) { + if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) { + return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; + } + if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) { + return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; + } + if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) { + return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; + } + return UNDEFINED_TYPE; + } + if(((ISpecializationType)SysMLElementTypes.REFERENCE_PROPERTY).getMatcher().matches(domainElement)) { + if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) { + return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; + } + if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) { + return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; + } + if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) { + return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; + } + return UNDEFINED_TYPE; + } + if(((ISpecializationType)SysMLElementTypes.VALUE_PROPERTY).getMatcher().matches(domainElement)) { + if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) { + return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; + } + if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) { + return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; + } + if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) { + return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; + } + return UNDEFINED_TYPE; + } } // Order is important for Part/Reference/ConstraintProperty which are also Property if(UMLElementTypes.PROPERTY.getEClass().isInstance(domainElement)) { @@ -151,6 +157,7 @@ public class CustomGraphicalTypeRegistry extends GraphicalTypeRegistry { if(SysMLElementTypes.CONSTRAINT_PROPERTY.getSemanticHint().equals(proposedType)) { if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) { + return SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID; } if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) { diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/ElementTypes.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/ElementTypes.java index 21830b124f4..46afc2a7820 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/ElementTypes.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/ElementTypes.java @@ -46,7 +46,10 @@ public class ElementTypes extends AbstractElementTypeEnumerator { /** CompositeDiagram :: COMMENT_ANNOTATED_ELEMENT */ public static final IHintedType COMMENT_ANNOTATED_ELEMENT = (IHintedType)getElementType("org.eclipse.papyrus.uml.diagram.composite.CommentAnnotatedElement_4002"); //$NON-NLS-1$ - /** CompositeDiagram :: CONSTRAINT_CONSTRAINED_ELEMENT */ - public static final IHintedType CONSTRAINT_CONSTRAINED_ELEMENT = (IHintedType)getElementType("org.eclipse.papyrus.uml.diagram.composite.ConstraintConstrainedElement_4003"); //$NON-NLS-1$ - + /** CompositeDiagram :: CONTEXT_LINK */ + public static final IHintedType CONTEXT_LINK = (IHintedType)getElementType("org.eclipse.papyrus.uml.diagram.parametric.ContextLink"); //$NON-NLS-1$ + + /** CompositeDiagram :: CONContextLinkAppliedStereotype */ + public static final IHintedType CONTEXT_LINK_APPLIED_STEREOTYPE = (IHintedType)getElementType("org.eclipse.papyrus.uml.diagram.parametric.ContextLinkAppliedStereotype"); //$NON-NLS-1$ + } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/GraphicalTypeRegistry.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/GraphicalTypeRegistry.java index 95e3081cd89..b7ee9dd7613 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/GraphicalTypeRegistry.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/GraphicalTypeRegistry.java @@ -43,7 +43,8 @@ public class GraphicalTypeRegistry implements IGraphicalTypeRegistry { // Fill known edges set knownEdges.add(ElementTypes.COMMENT_ANNOTATED_ELEMENT.getSemanticHint()); - knownEdges.add(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT.getSemanticHint()); + knownEdges.add(ElementTypes.CONTEXT_LINK.getSemanticHint()); + knownEdges.add(ElementTypes.CONTEXT_LINK_APPLIED_STEREOTYPE.getSemanticHint()); // Fill known nodes set (primary nodes) knownNodes.add(UMLElementTypes.CONSTRAINT.getSemanticHint()); @@ -169,6 +170,11 @@ public class GraphicalTypeRegistry implements IGraphicalTypeRegistry { if(SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) { return ElementTypes.CONSTRAINT_CN.getSemanticHint(); } + + if(SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) { + return ElementTypes.CONSTRAINT_CN.getSemanticHint(); + } + return UNDEFINED_TYPE; } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/InheritedCompositeDiagramEditPartProvider.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/InheritedCompositeDiagramEditPartProvider.java index 6ec36d6fd70..03e8fafca04 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/InheritedCompositeDiagramEditPartProvider.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/InheritedCompositeDiagramEditPartProvider.java @@ -2,15 +2,29 @@ package org.eclipse.papyrus.sysml.diagram.parametric.provider; import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.common.core.service.IOperation; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation; import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ContextLinkAppliedStereotypeEditPart; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ContextLinkEditPart; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.papyrus.uml.diagram.composite.providers.UMLEditPartProvider; public class InheritedCompositeDiagramEditPartProvider extends UMLEditPartProvider { - + @Override + protected IGraphicalEditPart createEditPart(View view) { + int visualID = UMLVisualIDRegistry.getVisualID(view); + if (visualID == ContextLinkEditPart.VISUAL_ID) { + return new ContextLinkEditPart(view); + } + if (visualID == ContextLinkAppliedStereotypeEditPart.VISUAL_ID) { + return new ContextLinkAppliedStereotypeEditPart(view); + } + return super.createEditPart(view); + } + @Override public synchronized boolean provides(IOperation operation) { if(operation instanceof CreateGraphicEditPartOperation) { @@ -43,7 +57,10 @@ public class InheritedCompositeDiagramEditPartProvider extends UMLEditPartProvid return true; } /** Edges (Feature) : CONSTRAINT_CONSTRAINED_ELEMENT *********** */ - if(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT.getSemanticHint().equals(hint)) { + if(ElementTypes.CONTEXT_LINK.getSemanticHint().equals(hint)) { + return true; + } + if(ElementTypes.CONTEXT_LINK_APPLIED_STEREOTYPE.getSemanticHint().equals(hint)) { return true; } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/InheritedCompositeDiagramViewProvider.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/InheritedCompositeDiagramViewProvider.java index 37ef4b7f617..e29a09609ca 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/InheritedCompositeDiagramViewProvider.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/InheritedCompositeDiagramViewProvider.java @@ -15,8 +15,6 @@ import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.gmf.diagram.common.provider.IGraphicalTypeRegistry; import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes; -import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes; -import org.eclipse.papyrus.sysml.diagram.parametric.provider.GraphicalTypeRegistry; import org.eclipse.papyrus.sysml.diagram.parametric.Activator; import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter; import org.eclipse.papyrus.uml.diagram.composite.providers.UMLViewProvider; @@ -33,26 +31,12 @@ public class InheritedCompositeDiagramViewProvider extends UMLViewProvider { IElementType elementType = (IElementType)semanticAdapter.getAdapter(IElementType.class); if(elementType != null) { - createdEdge = super.createEdge(semanticAdapter, containerView, semanticHint, index, persisted, preferencesHint); - } else { - - EObject domainElement = (EObject)semanticAdapter.getAdapter(EObject.class); - - String domainElementGraphicalType = semanticHint; - if(domainElementGraphicalType == null) { - domainElementGraphicalType = registry.getEdgeGraphicalType(domainElement); + if (elementType == ElementTypes.CONTEXT_LINK) { + org.eclipse.papyrus.uml.diagram.clazz.providers.UMLViewProvider classDiagramUMLProvider = new org.eclipse.papyrus.uml.diagram.clazz.providers.UMLViewProvider(); + createdEdge = classDiagramUMLProvider.createConstraintContext_8500(containerView, index, persisted, preferencesHint); } - - if((!IGraphicalTypeRegistry.UNDEFINED_TYPE.equals(domainElementGraphicalType)) && (registry.isKnownEdgeType(domainElementGraphicalType))) { - // Cannot use createEdge from super class as it never take the graphical type (semanticHint) into account. - // createdEdge = super.createEdge(semanticAdapter, containerView, domainElementGraphicalType, index, persisted, preferencesHint); - - if(ElementTypes.COMMENT_ANNOTATED_ELEMENT.getSemanticHint().equals(domainElementGraphicalType)) { - createdEdge = createCommentAnnotatedElement_4002(containerView, index, persisted, preferencesHint); - } - if(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT.getSemanticHint().equals(domainElementGraphicalType)) { - createdEdge = createConstraintConstrainedElement_4003(containerView, index, persisted, preferencesHint); - } + else { + createdEdge = super.createEdge(semanticAdapter, containerView, semanticHint, index, persisted, preferencesHint); } } @@ -92,7 +76,7 @@ public class InheritedCompositeDiagramViewProvider extends UMLViewProvider { if(elementType == ElementTypes.COMMENT_ANNOTATED_ELEMENT) { return true; } - if(elementType == ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT) { + if(elementType == ElementTypes.CONTEXT_LINK) { return true; } @@ -206,6 +190,7 @@ public class InheritedCompositeDiagramViewProvider extends UMLViewProvider { return null; } + @Override protected void stampShortcut(View containerView, Node target) { if(!ElementTypes.DIAGRAM_ID.equals(containerView.getDiagram().getType())) { @@ -215,4 +200,38 @@ public class InheritedCompositeDiagramViewProvider extends UMLViewProvider { target.getEAnnotations().add(shortcutAnnotation); } } + +// /** +// * @generated +// */ +// @SuppressWarnings("unchecked") +// public Edge createContextLink_8500(View containerView, int index, boolean persisted, PreferencesHint preferencesHint) { +// Connector edge = NotationFactory.eINSTANCE.createConnector(); +// edge.getStyles().add(NotationFactory.eINSTANCE.createFontStyle()); +// RelativeBendpoints bendpoints = NotationFactory.eINSTANCE.createRelativeBendpoints(); +// ArrayList<RelativeBendpoint> points = new ArrayList<RelativeBendpoint>(2); +// points.add(new RelativeBendpoint()); +// points.add(new RelativeBendpoint()); +// bendpoints.setPoints(points); +// edge.setBendpoints(bendpoints); +// ViewUtil.insertChildView(containerView, edge, index, persisted); +// edge.setType(UMLVisualIDRegistry.getType(ContextLinkEditPart.VISUAL_ID)); +// edge.setElement(null); +// // initializePreferences +// final IPreferenceStore prefStore = (IPreferenceStore)preferencesHint.getPreferenceStore(); +// PreferenceInitializerForElementHelper.initForegroundFromPrefs(edge, prefStore, "Undefined"); +// PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "Undefined"); +// //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); +// //if (routing != null) { +// // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); +// //} +// PreferenceInitializerForElementHelper.initRountingFromPrefs(edge, prefStore, "Undefined"); +// Node label8501 = createLabel(edge, UMLVisualIDRegistry.getType(ContextLinkAppliedStereotypeEditPart.VISUAL_ID)); +// label8501.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); +// Location location8501 = (Location)label8501.getLayoutConstraint(); +// location8501.setX(0); +// location8501.setY(15); +// return edge; +// } + } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomBindingConnectorCreateCommand.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomBindingConnectorCreateCommand.java index 5b89a89a461..b6c15e2cc27 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomBindingConnectorCreateCommand.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomBindingConnectorCreateCommand.java @@ -8,6 +8,8 @@ *******************************************************************************/ package org.eclipse.papyrus.sysml.diagram.parametric.commands; +import java.util.List; + import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; @@ -18,13 +20,17 @@ import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand; import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.papyrus.sysml.blocks.Block; import org.eclipse.papyrus.sysml.blocks.BlocksPackage; import org.eclipse.papyrus.sysml.diagram.common.utils.ConstraintBlockHelper; import org.eclipse.papyrus.uml.service.types.utils.ConnectorUtils; import org.eclipse.papyrus.uml.service.types.utils.RequestParameterUtils; import org.eclipse.uml2.uml.Connector; import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Property; import org.eclipse.uml2.uml.StructuredClassifier; +import org.eclipse.uml2.uml.Type; +import org.eclipse.uml2.uml.util.UMLUtil; import org.eclipse.uml2.uml.util.UMLUtil.StereotypeApplicationHelper; /** @@ -55,12 +61,43 @@ public class CustomBindingConnectorCreateCommand extends EditElementCommand { return false; } if (this.source != null && this.target != null) { - return ConstraintBlockHelper.isConstraintParameter((Element)source, RequestParameterUtils.getSourceView(getRequest())) + + boolean hasEncapsulationViolation = !checkEncapsulationCrossing(); + + return hasEncapsulationViolation ? false : + // one of the end must be a ConstraintParameter + ConstraintBlockHelper.isConstraintParameter((Element)source, RequestParameterUtils.getSourceView(getRequest())) || ConstraintBlockHelper.isConstraintParameter((Element)target, RequestParameterUtils.getTargetView(getRequest())); } return false; } + private boolean checkEncapsulationCrossing() { + org.eclipse.papyrus.sysml.service.types.utils.ConnectorUtils util = new org.eclipse.papyrus.sysml.service.types.utils.ConnectorUtils(); + List<Property> nestedPropertyPath = util.getNestedPropertyPath(RequestParameterUtils.getSourceView(getRequest()), RequestParameterUtils.getTargetView(getRequest())); + for (Property property : nestedPropertyPath) { + Type type = property.getType(); + Block stereotypeApplication = UMLUtil.getStereotypeApplication(type, Block.class); + if (stereotypeApplication != null) { + if (stereotypeApplication.isEncapsulated()) { + return false; + } + } + } + + nestedPropertyPath = util.getNestedPropertyPath(RequestParameterUtils.getTargetView(getRequest()), RequestParameterUtils.getSourceView(getRequest())); + for (Property property : nestedPropertyPath) { + Type type = property.getType(); + Block stereotypeApplication = UMLUtil.getStereotypeApplication(type, Block.class); + if (stereotypeApplication != null) { + if (stereotypeApplication.isEncapsulated()) { + return false; + } + } + } + return true; + } + @Override protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomBindingConnectorReorientCommand.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomBindingConnectorReorientCommand.java index da6c53a1e25..3b0944c72b0 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomBindingConnectorReorientCommand.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomBindingConnectorReorientCommand.java @@ -1,26 +1,37 @@ package org.eclipse.papyrus.sysml.diagram.parametric.commands; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; +import java.util.Set; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultSemanticEditPolicy; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.papyrus.sysml.blocks.Block; import org.eclipse.papyrus.sysml.blocks.BlocksPackage; import org.eclipse.papyrus.sysml.blocks.NestedConnectorEnd; import org.eclipse.papyrus.sysml.diagram.common.utils.ConstraintBlockHelper; import org.eclipse.papyrus.sysml.service.types.utils.ConnectorUtils; +import org.eclipse.papyrus.uml.diagram.common.util.CrossReferencerUtil; import org.eclipse.papyrus.uml.service.types.command.ConnectorReorientCommand; import org.eclipse.uml2.uml.Connector; import org.eclipse.uml2.uml.ConnectorEnd; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Property; import org.eclipse.uml2.uml.StructuredClassifier; +import org.eclipse.uml2.uml.Type; import org.eclipse.uml2.uml.util.UMLUtil; import org.eclipse.uml2.uml.util.UMLUtil.StereotypeApplicationHelper; @@ -65,13 +76,43 @@ public class CustomBindingConnectorReorientCommand extends ConnectorReorientComm View targetView = getTargetView(); if (this.source != null && this.target != null) { - return ConstraintBlockHelper.isConstraintParameter((Element)source, sourceView) + boolean hasEncapsulationViolation = !checkEncapsulationCrossing(); + + return hasEncapsulationViolation ? false : + // one of the end must be a ConstraintParameter + ConstraintBlockHelper.isConstraintParameter((Element)source, sourceView) || ConstraintBlockHelper.isConstraintParameter((Element)target, targetView); } } return false; } + private boolean checkEncapsulationCrossing() { + org.eclipse.papyrus.sysml.service.types.utils.ConnectorUtils util = new org.eclipse.papyrus.sysml.service.types.utils.ConnectorUtils(); + List<Property> nestedPropertyPath = util.getNestedPropertyPath(getSourceView(), getTargetView()); + for (Property property : nestedPropertyPath) { + Type type = property.getType(); + Block stereotypeApplication = UMLUtil.getStereotypeApplication(type, Block.class); + if (stereotypeApplication != null) { + if (stereotypeApplication.isEncapsulated()) { + return false; + } + } + } + + nestedPropertyPath = util.getNestedPropertyPath(getTargetView(), getSourceView()); + for (Property property : nestedPropertyPath) { + Type type = property.getType(); + Block stereotypeApplication = UMLUtil.getStereotypeApplication(type, Block.class); + if (stereotypeApplication != null) { + if (stereotypeApplication.isEncapsulated()) { + return false; + } + } + } + return true; + } + @Override /** * Get the link to re-orient. @@ -131,10 +172,55 @@ public class CustomBindingConnectorReorientCommand extends ConnectorReorientComm updateNestedPropertyPath(connector.getEnds().get(0), getSourceView(), getTargetView()); updateNestedPropertyPath(connector.getEnds().get(1), getTargetView(), getSourceView()); } + + Set<View> memberViewsToDestroy = getMemberViewsToDestroy(connector); + // Suppress Connector representation which are not coherant with the new ConnectorEnd + for (View view : memberViewsToDestroy) { + // exclude reoriented connector representation + if (view != getConnectorView()) { + // Check Connector View ends matches with semantic ConnectorEnds + View sourceNode = ((org.eclipse.gmf.runtime.notation.Connector)view).getSource(); + View targetNode = ((org.eclipse.gmf.runtime.notation.Connector)view).getTarget(); + + EObject sourceElement = sourceNode.getElement(); + EObject targetElement = targetNode.getElement(); + + EList<ConnectorEnd> ends = connector.getEnds(); + boolean isSameEnds = true; + for (ConnectorEnd connectorEnd : ends) { + if (connectorEnd.getRole() != sourceElement && connectorEnd.getRole() != targetElement) { + isSameEnds = false; + break; + } + } + + // if no matching between graphical and semantic, we destroy the representation + if (!isSameEnds) { + final DestroyElementRequest destroyRequest = new DestroyElementRequest(getRequest().getEditingDomain(), view, false); + final IElementEditService commandProvider = ElementEditServiceUtils.getCommandProvider(view); + ICommand editCommand = commandProvider.getEditCommand(destroyRequest); + editCommand.execute(monitor, info); + } + } + } return result; } + + protected Set<View> getMemberViewsToDestroy(final Connector connector) { + Set<View> viewsToDestroy = new HashSet<View>(); + + // Find Views in Composite Structure Diagram that are referencing current member + Iterator<View> viewIt = CrossReferencerUtil.getCrossReferencingViews(connector, null).iterator(); + while(viewIt.hasNext()) { + View view = viewIt.next(); + viewsToDestroy.add(view); + } + + return viewsToDestroy; + } + private void updateNestedPropertyPath(ConnectorEnd connectorEnd, View sourceView, View targetView) { ConnectorUtils utils = new ConnectorUtils(); List<Property> nestedPropertyPath = utils.getNestedPropertyPath(sourceView, targetView); diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomParametricContextLinkCreateCommand.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomParametricContextLinkCreateCommand.java new file mode 100644 index 00000000000..02ece88563d --- /dev/null +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomParametricContextLinkCreateCommand.java @@ -0,0 +1,130 @@ +package org.eclipse.papyrus.sysml.diagram.parametric.commands;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.gmf.runtime.notation.Connector;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.clazz.custom.command.CustomContextLinkCreateCommand;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ContextLinkEditPart;
+import org.eclipse.papyrus.uml.service.types.utils.NamedElementHelper;
+import org.eclipse.uml2.common.util.CacheAdapter;
+import org.eclipse.uml2.uml.Constraint;
+import org.eclipse.uml2.uml.Namespace;
+import org.eclipse.uml2.uml.Property;
+
+public class CustomParametricContextLinkCreateCommand extends
+ CustomContextLinkCreateCommand {
+
+ public CustomParametricContextLinkCreateCommand(
+ CreateRelationshipRequest request, EObject source, EObject target) {
+ super(request, source, target);
+ }
+
+ @Override
+ public boolean canExecute() {
+ if(source == null && target == null) {
+ return false;
+ }
+ if(source != null && (false == source instanceof Constraint)) {
+ return false;
+ }
+ if(target != null && !(target instanceof Namespace)) {
+ if (target instanceof Property && !(((Property) target).getType() instanceof Namespace)) {
+ // Part / Reference / ConstraintProperty
+ return false;
+ }
+ }
+ if(getSource() == null) {
+ return true; // link creation is in progress; source is not defined yet
+ }
+ View viewSource = findView(source);
+
+ if(viewSource != null && source instanceof Constraint) {
+ View viewTarget = findView(target);
+ List<?> sourceConnections = ViewUtil.getSourceConnections(viewSource);
+
+ for(Object connector : sourceConnections) {
+ if(!(connector instanceof Connector)) {
+ continue;
+ }
+ Edge edge = (Edge)connector;
+
+ if(("" + ContextLinkEditPart.VISUAL_ID).equals(edge.getType())) {
+ if(viewTarget == edge.getTarget()) {
+ // the context link is already
+ // drawn between the Constraint and the NamedElement
+ return false;
+ }
+ }
+ }
+ }
+
+ if(resolveTargetNamespace() != null && (resolveTargetNamespace().getOwnedRules().contains(resolveTargetNamespace()))) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ if(!canExecute()) {
+ throw new ExecutionException("Invalid arguments in create link command"); //$NON-NLS-1$
+ }
+ Namespace context = resolveTargetNamespace();
+ if(getSource() != null && context != null) {
+ getSource().setContext(context);
+ String defaultNameWithIncrementFromBase = NamedElementHelper.getDefaultNameWithIncrementFromBase(Constraint.class.getSimpleName(), context.getOwnedRules());
+ getSource().setName(defaultNameWithIncrementFromBase);
+ return CommandResult.newOKCommandResult();
+ }
+ else {
+ return CommandResult.newErrorCommandResult("Try to define Constraint context to a non Namespace element");
+ }
+ }
+
+ private View findView(EObject element) {
+ if(element == null) {
+ return null;
+ }
+ Collection<Setting> settings = CacheAdapter.getInstance().getNonNavigableInverseReferences(element);
+ for(Setting ref : settings) {
+ if(NotationPackage.eINSTANCE.getView_Element().equals(ref.getEStructuralFeature())) {
+ View view = (View)ref.getEObject();
+ if(view != null) {
+ return view;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @generated
+ */
+ protected Namespace resolveTargetNamespace() {
+ EObject targetNamespace;
+ if (target instanceof Property) {
+ targetNamespace = ((Property) target).getType();
+ }
+ else {
+ targetNamespace = target;
+ }
+ if (targetNamespace instanceof Namespace) {
+ return (Namespace)targetNamespace;
+ }
+ else {
+ return null;
+ }
+ }
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomParametricContextLinkReorientCommand.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomParametricContextLinkReorientCommand.java new file mode 100644 index 00000000000..72964b7f50f --- /dev/null +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomParametricContextLinkReorientCommand.java @@ -0,0 +1,139 @@ +package org.eclipse.papyrus.sysml.diagram.parametric.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRequest;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.service.types.utils.NamedElementHelper;
+import org.eclipse.uml2.uml.Constraint;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Namespace;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
+
+/**
+ * A context link must have a Constraint as source and a Namespace as target
+ * @See ContextLinkReorientCommand
+ * @author Regis
+ *
+ */
+public class CustomParametricContextLinkReorientCommand extends EditElementCommand {
+
+ private final int reorientDirection;
+
+ protected ReorientReferenceRelationshipRequestWithGraphical request;
+ protected EObject referenceOwner;
+ protected EObject oldSource;
+ protected EObject newSource;
+ protected EObject oldTarget;
+ protected EObject newTarget;
+
+ public CustomParametricContextLinkReorientCommand(
+ ReorientReferenceRelationshipRequestWithGraphical request) {
+ super(request.getLabel(), null, request);
+ this.request = request;
+ reorientDirection = request.getDirection();
+ referenceOwner = request.getReferenceOwner();
+ oldSource = reorientDirection == ReorientRequest.REORIENT_SOURCE ? request.getOldRelationshipEnd() : request.getReferenceOwner();
+ newSource = reorientDirection == ReorientRequest.REORIENT_SOURCE ? request.getNewRelationshipEnd() : request.getReferenceOwner();
+ oldTarget = reorientDirection == ReorientRequest.REORIENT_SOURCE ? request.getReferenceOwner() : request.getOldRelationshipEnd();
+ newTarget = reorientDirection == ReorientRequest.REORIENT_SOURCE ? request.getReferenceOwner() : request.getNewRelationshipEnd();
+ }
+
+ public boolean canExecute() {
+ return getNewSource() instanceof Constraint && resolveNamespace(getNewTarget()) instanceof Namespace;
+ }
+
+ protected Namespace resolveNamespace(Element element) {
+ if (element instanceof Namespace) {
+ return (Namespace)element;
+ }
+ if (element instanceof Property) {
+ Type type = ((Property) element).getType();
+ if (type instanceof Namespace) {
+ return (Namespace)type;
+ }
+ }
+ return null;
+ }
+
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ if(!canExecute()) {
+ throw new ExecutionException("Invalid arguments in reorient link command"); //$NON-NLS-1$
+ }
+ if(reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
+ return reorientSource();
+ }
+ if(reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
+ return reorientTarget();
+ }
+ throw new IllegalStateException();
+ }
+
+ /**
+ * @generated
+ */
+ protected CommandResult reorientSource() throws ExecutionException {
+ EditPart sourceEditPart = request.getSourceEditPart();
+ Namespace nearestNamespace = getNearestNamespace(sourceEditPart);
+ getOldSource().setContext(nearestNamespace); // set a default container
+ Namespace context = resolveNamespace(getNewTarget());
+ // Check name
+ String defaultNameWithIncrementFromBase = NamedElementHelper.getDefaultNameWithIncrementFromBase(Constraint.class.getSimpleName(), context.getOwnedRules(), getNewSource());
+ ((Constraint)getNewSource()).setName(defaultNameWithIncrementFromBase);
+ // set the context
+ ((Constraint)getNewSource()).setContext(resolveNamespace(getNewTarget()));
+
+ return CommandResult.newOKCommandResult(referenceOwner);
+ }
+
+ private Namespace getNearestNamespace(EditPart editPart) {
+ if (editPart != null) {
+ EObject semanticElement = ViewUtil.resolveSemanticElement((View) editPart.getModel());
+ if (semanticElement != null) {
+ Namespace resolvedNamespace = resolveNamespace((Element)semanticElement);
+ if (resolvedNamespace instanceof Namespace) {
+ return resolvedNamespace;
+ }
+ return getNearestNamespace(editPart.getParent());
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @generated
+ */
+ protected CommandResult reorientTarget() throws ExecutionException {
+ Namespace context = resolveNamespace(getNewTarget());
+ // Check name
+ String defaultNameWithIncrementFromBase = NamedElementHelper.getDefaultNameWithIncrementFromBase(Constraint.class.getSimpleName(), context.getOwnedRules(), getNewSource());
+ ((Constraint)getNewSource()).setName(defaultNameWithIncrementFromBase);
+ // Set the context
+ ((Constraint)getNewSource()).setContext(context);
+ return CommandResult.newOKCommandResult(referenceOwner);
+ }
+
+ protected Constraint getOldSource() {
+ return (Constraint)oldSource;
+ }
+
+ protected Element getNewSource() {
+ return (Element)newSource;
+ }
+
+ protected Element getOldTarget() {
+ return (Element)oldTarget;
+ }
+
+ protected Element getNewTarget() {
+ return (Element)newTarget;
+ }
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/ShowHideConstraintExpressionCommand.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/ShowHideConstraintExpressionCommand.java new file mode 100644 index 00000000000..8b1468d5f97 --- /dev/null +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/ShowHideConstraintExpressionCommand.java @@ -0,0 +1,54 @@ +package org.eclipse.papyrus.sysml.diagram.parametric.commands.switchrepresentation;
+
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.sysml.diagram.common.figure.ConstraintBlockPropertyCompositeFigure;
+import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomConstraintBlockPropertyCompositeEditPart;
+import org.eclipse.papyrus.uml.diagram.common.edit.part.ConstraintNodeLabelEditPart;
+
+public class ShowHideConstraintExpressionCommand extends Command {
+
+ private final GraphicalEditPart editPartToSwitch;
+
+ public GraphicalEditPart getEditPartToSwitch() {
+ return editPartToSwitch;
+ }
+
+ public ShowHideConstraintExpressionCommand(final GraphicalEditPart editPartToRefresh) {
+ this.editPartToSwitch = editPartToRefresh;
+ }
+
+ @Override
+ public void execute() {
+ if (this.getEditPartToSwitch() instanceof CustomConstraintBlockPropertyCompositeEditPart) {
+ CustomConstraintBlockPropertyCompositeEditPart constraintBlockPropertyCompositeEditPart = (CustomConstraintBlockPropertyCompositeEditPart)this.getEditPartToSwitch();
+ WrappingLabel constraintLabel = ((ConstraintBlockPropertyCompositeFigure)constraintBlockPropertyCompositeEditPart.getPrimaryShape()).getConstraintLabel();
+ ConstraintNodeLabelEditPart constraintNodeLabelEditPart = null;
+ for (Object currentEditPart : constraintBlockPropertyCompositeEditPart.getChildren()) {
+ if (currentEditPart instanceof ConstraintNodeLabelEditPart) {
+ if (((ConstraintNodeLabelEditPart) currentEditPart).getFigure() == constraintLabel) {
+ constraintNodeLabelEditPart = (ConstraintNodeLabelEditPart)currentEditPart;
+ }
+ }
+ }
+
+ if (constraintNodeLabelEditPart != null) {
+ View constraintLabelView = (View)constraintNodeLabelEditPart.getModel();
+ constraintLabelView.setVisible(!constraintLabelView.isVisible());
+ }
+ }
+ }
+
+ @Override
+ public void undo() {
+ execute();
+ }
+
+ @Override
+ public void redo() {
+ execute();
+ }
+
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/ShowHideConstraintExpressionCommandHandler.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/ShowHideConstraintExpressionCommandHandler.java new file mode 100644 index 00000000000..be7987f5762 --- /dev/null +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/ShowHideConstraintExpressionCommandHandler.java @@ -0,0 +1,25 @@ +package org.eclipse.papyrus.sysml.diagram.parametric.commands.switchrepresentation;
+
+import java.util.List;
+
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomConstraintBlockPropertyCompositeEditPart;
+import org.eclipse.papyrus.uml.diagram.common.handlers.GraphicalCommandHandler;
+
+public class ShowHideConstraintExpressionCommandHandler extends GraphicalCommandHandler {
+
+ @Override
+ protected Command getCommand() {
+ final List<IGraphicalEditPart> selectedElements = getSelectedElements();
+ for(final IGraphicalEditPart selectedElement : selectedElements) {
+ if(selectedElement instanceof CustomConstraintBlockPropertyCompositeEditPart) {
+ return new ShowHideConstraintExpressionCommand((GraphicalEditPart)selectedElement);
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+}
+
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommand.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommand.java new file mode 100644 index 00000000000..b47e95352e2 --- /dev/null +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommand.java @@ -0,0 +1,134 @@ +/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml.diagram.parametric.commands.switchrepresentation;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.StringValueStyle;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.sysml.diagram.common.edit.part.ConstraintBlockPropertyCompositeEditPart;
+import org.eclipse.papyrus.sysml.diagram.common.figure.ConstraintBlockPropertyCompositeFigure;
+import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
+import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomConstraintBlockPropertyCompositeEditPart;
+
+/**
+ * TODO
+ */
+public class SwitchConstraintPropertyRepresentationCommand extends Command {
+
+ private final GraphicalEditPart editPartToSwitch;
+
+ public SwitchConstraintPropertyRepresentationCommand(final GraphicalEditPart editPartToRefresh) {
+ this.editPartToSwitch = editPartToRefresh;
+ }
+
+ public GraphicalEditPart getEditPartToSwitch() {
+ return this.editPartToSwitch;
+ }
+
+
+ @Override
+ public void execute() {
+ if (this.getEditPartToSwitch() instanceof CustomConstraintBlockPropertyCompositeEditPart) {
+ CustomConstraintBlockPropertyCompositeEditPart constraintBlockPropertyCompositeEditPart = (CustomConstraintBlockPropertyCompositeEditPart)this.getEditPartToSwitch();
+ ConstraintBlockPropertyCompositeFigure figure = constraintBlockPropertyCompositeEditPart.getPrimaryShape();
+ if (figure instanceof ConstraintBlockPropertyCompositeFigure) {
+ if (figure.getCorner() != 0) {
+ switchToSquareRepresentationWithStructure(constraintBlockPropertyCompositeEditPart, figure);
+ }
+ else {
+ switchToRoundedRepresentationWithoutStructure(constraintBlockPropertyCompositeEditPart, figure);
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void switchToSquareRepresentationWithStructure(CustomConstraintBlockPropertyCompositeEditPart editPart, IFigure figure) {
+
+ // Set corner as square
+ int newCorner = 0;
+ ((ConstraintBlockPropertyCompositeFigure) figure).setCorner(newCorner);
+
+ // add structure compartment (create if does not exist, set visible if exist)
+ View structureCompartment = editPart.getChildViewBySemanticHint(SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID);
+ if (structureCompartment != null) {
+ structureCompartment.setVisible(true);
+ }
+ else {
+ structureCompartment = ViewService.getInstance().createNode(null, (View)editPart.getModel(), SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID, ViewUtil.APPEND, true, new PreferencesHint("org.eclipse.papyrus.sysml.diagram.parametric"));
+ structureCompartment.setElement(editPart.resolveSemanticElement());
+ }
+
+ // add the << constraint >> tag
+ editPart.getPrimaryShape().setTagLabel(String.valueOf("\u00AB") + "constraint" + String.valueOf("\u00BB"));
+
+ // set the style to persist representation
+ StringValueStyle style = (StringValueStyle)((View)editPart.getModel()).getStyle(NotationPackage.eINSTANCE.getStringValueStyle());
+ if (style == null) {
+ ((View)editPart.getModel()).getStyles().add(NotationFactory.eINSTANCE.createStringValueStyle());
+ }
+ style = (StringValueStyle)((View)editPart.getModel()).getStyle(NotationPackage.eINSTANCE.getStringValueStyle());
+ style.setName(CustomConstraintBlockPropertyCompositeEditPart.REPRESENTATION_MODE_STYLE);
+ style.setStringValue(CustomConstraintBlockPropertyCompositeEditPart.SQUARE_REPRESENTATION_WITH_STRUCTURE);
+
+ // set the default style for new elements
+ ConstraintBlockPropertyCompositeEditPart.setLastRepresentation(CustomConstraintBlockPropertyCompositeEditPart.SQUARE_REPRESENTATION_WITH_STRUCTURE);
+ editPart.setCornerLocators(newCorner);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void switchToRoundedRepresentationWithoutStructure(CustomConstraintBlockPropertyCompositeEditPart editPart, IFigure figure) {
+ // rounded corner
+ int newCorner = 50;
+ ((ConstraintBlockPropertyCompositeFigure) figure).setCorner(newCorner);
+
+
+ // hide structure compartment if exist
+ View structureCompartmentFigure = editPart.getChildViewBySemanticHint(SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID);
+ if (structureCompartmentFigure != null) {
+ structureCompartmentFigure.setVisible(false);
+ }
+
+ // remove the << constraint >> tag
+ editPart.getPrimaryShape().setTagLabel("");
+
+ // set the style to persist representation
+ StringValueStyle style = (StringValueStyle)((View)editPart.getModel()).getStyle(NotationPackage.eINSTANCE.getStringValueStyle());
+ if (style == null) {
+ ((View)editPart.getModel()).getStyles().add(NotationFactory.eINSTANCE.createStringValueStyle());
+ }
+ style = (StringValueStyle)((View)editPart.getModel()).getStyle(NotationPackage.eINSTANCE.getStringValueStyle());
+ style.setName(CustomConstraintBlockPropertyCompositeEditPart.REPRESENTATION_MODE_STYLE);
+ style.setStringValue(CustomConstraintBlockPropertyCompositeEditPart.ROUNDED_REPRESENTATION);
+
+ // set the default style for new elements
+ ConstraintBlockPropertyCompositeEditPart.setLastRepresentation(CustomConstraintBlockPropertyCompositeEditPart.ROUNDED_REPRESENTATION);
+ editPart.setCornerLocators(newCorner);
+ }
+
+ @Override
+ public void undo() {
+ execute();
+ }
+
+ @Override
+ public void redo() {
+ execute();
+ }
+
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommandHandler.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommandHandler.java new file mode 100644 index 00000000000..2af307bab67 --- /dev/null +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommandHandler.java @@ -0,0 +1,28 @@ +package org.eclipse.papyrus.sysml.diagram.parametric.commands.switchrepresentation;
+
+import java.util.List;
+
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomConstraintBlockPropertyCompositeEditPart;
+import org.eclipse.papyrus.uml.diagram.common.handlers.GraphicalCommandHandler;
+
+public class SwitchConstraintPropertyRepresentationCommandHandler extends GraphicalCommandHandler {
+
+ @Override
+ protected Command getCommand() {
+ final List<IGraphicalEditPart> selectedElements = getSelectedElements();
+ for(final IGraphicalEditPart selectedElement : selectedElements) {
+ if(selectedElement instanceof CustomConstraintBlockPropertyCompositeEditPart) {
+ if (selectedElement.getParent() instanceof GraphicalEditPart) {
+ return new SwitchConstraintPropertyRepresentationCommand((GraphicalEditPart)selectedElement);
+ }
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/part/CustomBlockCompositeEditPartTN.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/part/CustomBlockCompositeEditPartTN.java index 6e868850244..71f9c990871 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/part/CustomBlockCompositeEditPartTN.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/part/CustomBlockCompositeEditPartTN.java @@ -1,22 +1,29 @@ package org.eclipse.papyrus.sysml.diagram.parametric.edit.part; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; import org.eclipse.gef.EditPart; import org.eclipse.gef.editpolicies.LayoutEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.sysml.blocks.Block; +import org.eclipse.papyrus.sysml.constraints.ConstraintBlock; import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockLabelNameEditPart; import org.eclipse.papyrus.sysml.diagram.common.edit.part.StructureCompartmentEditPart; -import org.eclipse.papyrus.sysml.diagram.common.figure.SysMLDiagramFrameFigure; import org.eclipse.papyrus.sysml.diagram.parametric.figures.ParametricDiagramFrameFigure; import org.eclipse.papyrus.uml.diagram.common.edit.part.AbstractElementEditPart; import org.eclipse.papyrus.uml.diagram.common.edit.part.ConstraintParameterAffixedNodeEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideRelatedContentsEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; import org.eclipse.papyrus.uml.diagram.common.locator.FullInsidePortPositionLocator; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.util.UMLUtil; public class CustomBlockCompositeEditPartTN extends AbstractElementEditPart { @@ -37,8 +44,8 @@ public class CustomBlockCompositeEditPartTN extends AbstractElementEditPart { } @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure)primaryShape; + public ParametricDiagramFrameFigure getPrimaryShape() { + return (ParametricDiagramFrameFigure)primaryShape; } @Override @@ -48,7 +55,7 @@ public class CustomBlockCompositeEditPartTN extends AbstractElementEditPart { return true; } if(childEditPart instanceof StructureCompartmentEditPart) { - IFigure pane = ((SysMLDiagramFrameFigure)getPrimaryShape()).getStructureCompartmentFigure(); + IFigure pane = getPrimaryShape(); setupContentPane(pane); pane.add(((StructureCompartmentEditPart)childEditPart).getFigure()); return true; @@ -67,7 +74,7 @@ public class CustomBlockCompositeEditPartTN extends AbstractElementEditPart { return true; } if(childEditPart instanceof StructureCompartmentEditPart) { - IFigure pane = ((SysMLDiagramFrameFigure)getPrimaryShape()).getStructureCompartmentFigure(); + IFigure pane = getPrimaryShape(); setupContentPane(pane); pane.remove(((StructureCompartmentEditPart)childEditPart).getFigure()); return true; @@ -81,9 +88,6 @@ public class CustomBlockCompositeEditPartTN extends AbstractElementEditPart { @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { - if(editPart instanceof StructureCompartmentEditPart) { - return ((SysMLDiagramFrameFigure)getPrimaryShape()).getStructureCompartmentFigure(); - } return getContentPane(); } @@ -96,4 +100,40 @@ public class CustomBlockCompositeEditPartTN extends AbstractElementEditPart { protected LayoutEditPolicy createLayoutEditPolicy() { return null; } + + + @Override + protected void refreshVisuals() { + refreshStereotypes(); + super.refreshVisuals(); + } + + protected void refreshStereotypes() { + Element resolveSemanticElement = (Element)this.resolveSemanticElement(); + EList<EObject> stereotypeApplications = resolveSemanticElement.getStereotypeApplications(); + List<EObject> additionnalStereotypeApplications = new ArrayList<EObject>(); + for (EObject currentStereotypeApplication : stereotypeApplications) { + if (!(currentStereotypeApplication instanceof Block) && !(currentStereotypeApplication instanceof ConstraintBlock)) { + additionnalStereotypeApplications.add(currentStereotypeApplication); + } + } + StringBuilder stereotypeLabel = new StringBuilder(); + String separator = ", "; + for (EObject eObject : additionnalStereotypeApplications) { + if (eObject != additionnalStereotypeApplications.get(0)) { + stereotypeLabel.append(separator); + } + stereotypeLabel.append(firstLetterToLowerCase(UMLUtil.getStereotype(eObject).getName())); + } + getPrimaryShape().setStereotypeLabel(stereotypeLabel.toString()); + } + + private String firstLetterToLowerCase(String string) { + String result = ""; + if (string != null && string.length() != 0) { + String lowerCaseFirstLetter = string.substring(0, 1).toLowerCase(); + result = lowerCaseFirstLetter + string.substring(1); + } + return result; + } } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/handler/ShowHideRelatedContentsAction.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/handler/ShowHideRelatedContentsAction.java index 18cbbf51cb0..2dea434c9a8 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/handler/ShowHideRelatedContentsAction.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/handler/ShowHideRelatedContentsAction.java @@ -14,7 +14,9 @@ package org.eclipse.papyrus.sysml.diagram.parametric.handler; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.sysml.diagram.common.utils.ConstraintBlockHelper; @@ -25,7 +27,7 @@ public class ShowHideRelatedContentsAction extends org.eclipse.papyrus.sysml.dia public ShowHideRelatedContentsAction() { super(); } - + /** * @see org.eclipse.papyrus.diagram.common.actions.AbstractShowHideAction#initAction() */ @@ -35,15 +37,34 @@ public class ShowHideRelatedContentsAction extends org.eclipse.papyrus.sysml.dia // Only ConstraintParameter are allowed => remove Ports (and subclasses) from AffixedNode selection List<EditPartRepresentation> editPartRepresentationsToRemove = new ArrayList<EditPartRepresentation>(); - AffixedChildrenEditPartRepresentation affixedNodeRepresentation = getAffixedNodeRepresenation(this.representations); - for (EditPartRepresentation currentRepresentation : affixedNodeRepresentation.getPossibleElement()) { + Set<EObject> representedAffixedElements = new HashSet<EObject>(); + AffixedChildrenEditPartRepresentation affixedNodeRepresentations = getAffixedNodeRepresentation(this.representations); + + for (EditPartRepresentation currentRepresentation : affixedNodeRepresentations.getPossibleElement()) { EObject semanticElement = currentRepresentation.getSemanticElement(); if (!(semanticElement == null || ConstraintBlockHelper.couldBeConstraintParameter(semanticElement, getOwnerSemanticElement()))) { editPartRepresentationsToRemove.add(currentRepresentation); } + else { + representedAffixedElements.add(semanticElement); + } } for (EditPartRepresentation editPartRepresentationToRemove : editPartRepresentationsToRemove) { - affixedNodeRepresentation.getPossibleElement().remove(editPartRepresentationToRemove); + affixedNodeRepresentations.getPossibleElement().remove(editPartRepresentationToRemove); + } + + editPartRepresentationsToRemove = new ArrayList<EditPartRepresentation>(); + CompartmentEditPartRepresentation compartmentEditPartRepresentation = getCompartmentEditPartRepresentation(this.representations); + if (compartmentEditPartRepresentation != null) { + for (EditPartRepresentation currentRepresentation : compartmentEditPartRepresentation.getPossibleElement()) { + EObject semanticElement = currentRepresentation.getSemanticElement(); + if (representedAffixedElements.contains(semanticElement)) { + editPartRepresentationsToRemove.add(currentRepresentation); + } + } + for (EditPartRepresentation editPartRepresentationToRemove : editPartRepresentationsToRemove) { + compartmentEditPartRepresentation.getPossibleElement().remove(editPartRepresentationToRemove); + } } } @@ -51,18 +72,43 @@ public class ShowHideRelatedContentsAction extends org.eclipse.papyrus.sysml.dia return this.representations.size() >= 1 ? this.representations.get(0).getSemanticElement() : null; } - private AffixedChildrenEditPartRepresentation getAffixedNodeRepresenation(List<EditPartRepresentation> editPartRepresentations) { + /** + * + * @param editPartRepresentations + * @return + */ + private AffixedChildrenEditPartRepresentation getAffixedNodeRepresentation(List<EditPartRepresentation> editPartRepresentations) { for (EditPartRepresentation representation : editPartRepresentations) { if (representation instanceof AffixedChildrenEditPartRepresentation) { return (AffixedChildrenEditPartRepresentation) representation; } // recursive search - AffixedChildrenEditPartRepresentation affixedNodeRepresentation = getAffixedNodeRepresenation(representation.getPossibleElement()); + AffixedChildrenEditPartRepresentation affixedNodeRepresentation = getAffixedNodeRepresentation(representation.getPossibleElement()); if (affixedNodeRepresentation != null) { return affixedNodeRepresentation; } } return null; } + + /** + * + * @param editPartRepresentations + * @return + */ + private CompartmentEditPartRepresentation getCompartmentEditPartRepresentation(List<EditPartRepresentation> editPartRepresentations) { + + for (EditPartRepresentation representation : editPartRepresentations) { + if (representation instanceof CompartmentEditPartRepresentation && !(representation instanceof AffixedChildrenEditPartRepresentation)) { + return (CompartmentEditPartRepresentation) representation; + } + // recursive search + CompartmentEditPartRepresentation compartmentEditPartRepresentation = getCompartmentEditPartRepresentation(representation.getPossibleElement()); + if (compartmentEditPartRepresentation != null) { + return compartmentEditPartRepresentation; + } + } + return null; + } } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java index 716fd76af50..ea17705d803 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java @@ -19,15 +19,15 @@ import java.util.List; import org.eclipse.emf.transaction.RunnableWithResult; import org.eclipse.gef.commands.Command; import org.eclipse.gef.commands.UnexecutableCommand; -import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand; -import org.eclipse.papyrus.sysml.diagram.parametric.utils.BlockDropHelper; import org.eclipse.papyrus.sysml.diagram.internalblock.utils.PartDropHelper; +import org.eclipse.papyrus.sysml.diagram.parametric.utils.BlockDropHelper; import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes; import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes; import org.eclipse.swt.widgets.Display; diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyStructureCompartmentSemanticEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyStructureCompartmentSemanticEditPolicy.java new file mode 100644 index 00000000000..1fa93115e98 --- /dev/null +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyStructureCompartmentSemanticEditPolicy.java @@ -0,0 +1,52 @@ +package org.eclipse.papyrus.sysml.diagram.parametric.policies;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.sysml.constraints.ConstraintBlock;
+import org.eclipse.papyrus.sysml.diagram.common.edit.policy.BlockPropertyStructureCompartmentSemanticEditPolicy;
+import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+public class CustomBlockPropertyStructureCompartmentSemanticEditPolicy extends
+ BlockPropertyStructureCompartmentSemanticEditPolicy {
+
+ @Override
+ protected Command getCreateCommand(CreateElementRequest req) {
+
+ View dropTargetView = ((IGraphicalEditPart) getHost()).getNotationView();
+ EObject eContainer = dropTargetView.eContainer();
+ Element parent = null;
+ if (eContainer != null && eContainer instanceof View) {
+ parent = (Element) ((View) eContainer).getElement();
+ }
+ if (parent instanceof Property) {
+ parent = ((Property) parent).getType();
+ }
+
+ if (parent != null) {
+ if (UMLUtil.getStereotypeApplication(parent, ConstraintBlock.class) != null) {
+ IElementType elementType = req.getElementType();
+ if (elementType != UMLElementTypes.CONSTRAINT
+ && elementType != UMLElementTypes.COMMENT) {
+ // ConstraintBlock
+ if (elementType != SysMLElementTypes.CONSTRAINT_PROPERTY) {
+ // only ConstraintProperty can be dropped in structure
+ // compartment of a diagram owned by a ConstraintBlock
+ // (except common Comment and Constraint)
+ return UnexecutableCommand.INSTANCE;
+ }
+ }
+ }
+ }
+
+ return super.getCreateCommand(req);
+ }
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomDefaultSemanticEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomDefaultSemanticEditPolicy.java index 3c6c623fc17..fe125c1ec12 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomDefaultSemanticEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomDefaultSemanticEditPolicy.java @@ -22,6 +22,7 @@ import org.eclipse.papyrus.gmf.diagram.common.provider.IGraphicalTypeRegistry; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultSemanticEditPolicy; import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants; import org.eclipse.papyrus.sysml.diagram.parametric.commands.CustomBindingConnectorReorientCommand; +import org.eclipse.papyrus.sysml.diagram.parametric.commands.CustomParametricContextLinkCreateCommand; import org.eclipse.papyrus.sysml.diagram.parametric.commands.ReorientReferenceRelationshipRequestWithGraphical; import org.eclipse.papyrus.sysml.diagram.parametric.provider.CustomGraphicalTypeRegistry; import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes; @@ -29,8 +30,6 @@ import org.eclipse.papyrus.sysml.diagram.parametric.provider.GraphicalTypeRegist import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes; import org.eclipse.papyrus.uml.diagram.composite.edit.commands.CommentAnnotatedElementCreateCommand; import org.eclipse.papyrus.uml.diagram.composite.edit.commands.CommentAnnotatedElementReorientCommand; -import org.eclipse.papyrus.uml.diagram.composite.edit.commands.ConstraintConstrainedElementCreateCommand; -import org.eclipse.papyrus.uml.diagram.composite.edit.commands.ConstraintConstrainedElementReorientCommand; import org.eclipse.papyrus.uml.service.types.command.ConnectorReorientCommand; /** @@ -58,8 +57,8 @@ public class CustomDefaultSemanticEditPolicy extends DefaultSemanticEditPolicy { return getGEFWrapper(new CommentAnnotatedElementCreateCommand(req, req.getSource(), req.getTarget())); } - if(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT == req.getElementType()) { - return getGEFWrapper(new ConstraintConstrainedElementCreateCommand(req, req.getSource(), req.getTarget())); + if(ElementTypes.CONTEXT_LINK == req.getElementType()) { + return getGEFWrapper(new CustomParametricContextLinkCreateCommand(req, req.getSource(), req.getTarget())); } String newEdgeGraphicalType = registry.getEdgeGraphicalType(req.getElementType()); @@ -87,10 +86,7 @@ public class CustomDefaultSemanticEditPolicy extends DefaultSemanticEditPolicy { if(ElementTypes.COMMENT_ANNOTATED_ELEMENT.getSemanticHint().equals(reconnectedViewType)) { return getGEFWrapper(new CommentAnnotatedElementReorientCommand(req)); } - - if(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT.getSemanticHint().equals(reconnectedViewType)) { - return getGEFWrapper(new ConstraintConstrainedElementReorientCommand(req)); - } + if(UMLGraphicalTypes.LINK_UML_CONNECTOR_ID.equals(reconnectedViewType)) { if (req instanceof ReorientReferenceRelationshipRequestWithGraphical) { return getGEFWrapper(new CustomBindingConnectorReorientCommand((ReorientReferenceRelationshipRequestWithGraphical)req)); diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomParametricSemanticPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomParametricSemanticPolicy.java index 6e5fc2d1538..a15eccbecc5 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomParametricSemanticPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomParametricSemanticPolicy.java @@ -16,11 +16,13 @@ import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelations import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.sysml.constraints.ConstraintBlock; import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockPropertyCompositeEditPart; -import org.eclipse.papyrus.sysml.diagram.common.edit.part.ConstraintBlockPropertyCompositeEditPart; import org.eclipse.papyrus.sysml.diagram.parametric.commands.CustomBindingConnectorCreateCommand; +import org.eclipse.papyrus.sysml.diagram.parametric.commands.CustomParametricContextLinkReorientCommand; import org.eclipse.papyrus.sysml.diagram.parametric.commands.ReorientReferenceRelationshipRequestWithGraphical; import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomBlockCompositeEditPartTN; +import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomConstraintBlockPropertyCompositeEditPart; import org.eclipse.papyrus.sysml.diagram.parametric.edit.policy.DiagramSemanticEditPolicy; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ContextLinkEditPart; import org.eclipse.papyrus.uml.diagram.common.edit.part.ConstraintParameterAffixedNodeEditPart; import org.eclipse.papyrus.uml.diagram.common.edit.part.PortAffixedNodeEditPart; import org.eclipse.papyrus.uml.tools.utils.UMLUtil; @@ -50,7 +52,7 @@ public class CustomParametricSemanticPolicy extends DiagramSemanticEditPolicy { if (getHost() instanceof CustomBlockCompositeEditPartTN) { return UnexecutableCommand.INSTANCE; } - if (getHost() instanceof ConstraintBlockPropertyCompositeEditPart) { + if (getHost() instanceof CustomConstraintBlockPropertyCompositeEditPart) { return UnexecutableCommand.INSTANCE; } if (getHost() instanceof ConstraintParameterAffixedNodeEditPart) { @@ -82,7 +84,7 @@ public class CustomParametricSemanticPolicy extends DiagramSemanticEditPolicy { if (target instanceof CustomBlockCompositeEditPartTN) { return UnexecutableCommand.INSTANCE; } - if (target instanceof ConstraintBlockPropertyCompositeEditPart) { + if (target instanceof CustomConstraintBlockPropertyCompositeEditPart) { return UnexecutableCommand.INSTANCE; } @@ -132,7 +134,7 @@ public class CustomParametricSemanticPolicy extends DiagramSemanticEditPolicy { if (target instanceof CustomBlockCompositeEditPartTN) { return UnexecutableCommand.INSTANCE; } - if (target instanceof ConstraintBlockPropertyCompositeEditPart) { + if (target instanceof CustomConstraintBlockPropertyCompositeEditPart) { return UnexecutableCommand.INSTANCE; } @@ -166,4 +168,72 @@ public class CustomParametricSemanticPolicy extends DiagramSemanticEditPolicy { return getSemanticCommand(semRequest); } + @Override + protected Command getReorientRefRelationshipSourceCommand( + ReconnectRequest request) { + + if(request.getConnectionEditPart() instanceof ContextLinkEditPart) { + org.eclipse.gef.ConnectionEditPart connectionEP = request.getConnectionEditPart(); + + if (connectionEP instanceof ConnectionEditPart) { + if (!((ConnectionEditPart) connectionEP).isSemanticConnection()) { + return null; + } + } + + EditPart sourceEditPart = connectionEP.getSource(); + EditPart targetEditPart = connectionEP.getTarget(); + EObject referenceOwner = ViewUtil + .resolveSemanticElement((View) targetEditPart.getModel()); + EObject oldTarget = ViewUtil + .resolveSemanticElement((View) sourceEditPart.getModel()); + EObject newTarget = ViewUtil + .resolveSemanticElement((View) request.getTarget().getModel()); + + TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()) + .getEditingDomain(); + + ReorientReferenceRelationshipRequestWithGraphical semRequest = new ReorientReferenceRelationshipRequestWithGraphical( + editingDomain, referenceOwner, newTarget, oldTarget, + ReorientReferenceRelationshipRequest.REORIENT_SOURCE, + sourceEditPart, targetEditPart); + return getGEFWrapper(new CustomParametricContextLinkReorientCommand(semRequest)); + } + return super.getReorientRefRelationshipTargetCommand(request); + } + + @Override + protected Command getReorientRefRelationshipTargetCommand( + ReconnectRequest request) { + if(request.getConnectionEditPart() instanceof ContextLinkEditPart) { + org.eclipse.gef.ConnectionEditPart connectionEP = request.getConnectionEditPart(); + + if (connectionEP instanceof ConnectionEditPart) { + if (!((ConnectionEditPart) connectionEP).isSemanticConnection()) { + return null; + } + } + + EditPart sourceEditPart = connectionEP.getSource(); + EditPart targetEditPart = connectionEP.getTarget(); + EObject referenceOwner = ViewUtil + .resolveSemanticElement((View) sourceEditPart.getModel()); + EObject oldTarget = ViewUtil + .resolveSemanticElement((View) targetEditPart.getModel()); + EObject newTarget = ViewUtil + .resolveSemanticElement((View) request.getTarget().getModel()); + + TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()) + .getEditingDomain(); + + ReorientReferenceRelationshipRequestWithGraphical semRequest = new ReorientReferenceRelationshipRequestWithGraphical( + editingDomain, referenceOwner, newTarget, oldTarget, + ReorientReferenceRelationshipRequest.REORIENT_TARGET, + sourceEditPart, targetEditPart); + return getGEFWrapper(new CustomParametricContextLinkReorientCommand(semRequest)); + } + return super.getReorientRefRelationshipTargetCommand(request); + } + + } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomStructureClassifierDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomStructureClassifierDropEditPolicy.java new file mode 100644 index 00000000000..9b3b018601a --- /dev/null +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomStructureClassifierDropEditPolicy.java @@ -0,0 +1,167 @@ +/***************************************************************************** + * Copyright (c) 2011 CEA LIST. + * + * 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: + * + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.diagram.parametric.policies; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand; +import org.eclipse.papyrus.sysml.constraints.ConstraintBlock; +import org.eclipse.papyrus.sysml.constraints.ConstraintProperty; +import org.eclipse.papyrus.sysml.diagram.parametric.utils.BlockDropHelper; +import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes; +import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.util.UMLUtil; + +/** + * <pre> + * Customization of the DND edit policy for the StructureClassifier compartments, that enables the direct + * creation of typed Part, Reference, Value, ActorPart or Property by dragging types in a Block structure compartment. + * </pre> + */ +public class CustomStructureClassifierDropEditPolicy extends CustomDragDropEditPolicy { + + /** Default constructor */ + public CustomStructureClassifierDropEditPolicy() { + super(); + } + + /** + * {@inheritedDoc}. + */ + @Override + public Command getDropObjectsCommand(DropObjectsRequest dropRequest) { + + BlockDropHelper helper = new BlockDropHelper(getEditingDomain()); + + // Single drop management possible drop action list can be proposed + if(dropRequest.getObjects().size() == 1) { + + // List of available drop commands + final List<Command> commandChoice = new ArrayList<Command>(); + + // 1. Try to create a Part typed by the dropped object + Command dropAsTypedPart = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), SysMLElementTypes.PART_PROPERTY); + if((dropAsTypedPart != null) && (dropAsTypedPart.canExecute())) { + commandChoice.add(dropAsTypedPart); + } + + // 2. Try to create a Reference typed by the dropped object + Command dropAsTypedReference = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), SysMLElementTypes.REFERENCE_PROPERTY); + if((dropAsTypedReference != null) && (dropAsTypedReference.canExecute())) { + commandChoice.add(dropAsTypedReference); + } + + // 3. Try to create an ActorPart typed by the dropped object + Command dropAsTypedActorPart = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), SysMLElementTypes.ACTOR_PART_PROPERTY); + if((dropAsTypedActorPart != null) && (dropAsTypedActorPart.canExecute())) { + commandChoice.add(dropAsTypedActorPart); + } + + // 4. Try to create a Value typed by the dropped object + Command dropAsTypedValue = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), SysMLElementTypes.VALUE_PROPERTY); + if((dropAsTypedValue != null) && (dropAsTypedValue.canExecute())) { + commandChoice.add(dropAsTypedValue); + } + + // 5. Try to create a Property typed by the dropped object + Command dropAsTypedProperty = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), UMLElementTypes.PROPERTY); + if((dropAsTypedProperty != null) && (dropAsTypedProperty.canExecute())) { + commandChoice.add(dropAsTypedProperty); + } + + // 6. Try to create a ConstraintProperty typed by the dropped object + Command dropAsTypedConstraintProperty = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), SysMLElementTypes.CONSTRAINT_PROPERTY); + if((dropAsTypedConstraintProperty != null) && (dropAsTypedConstraintProperty.canExecute())) { + commandChoice.add(dropAsTypedConstraintProperty); + } + + // 7. Build default drop command (show view of the dropped object) + Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); + defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); + if((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { + commandChoice.add(defaultDropCommand); + } + + // Prepare the selection command (if several command are available) or return the drop command + if(commandChoice.size() > 1) { + RunnableWithResult<ICommand> runnable; + Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() { + + public void run() { + setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice)); + } + }); + + ICommand selectCommand = runnable.getResult(); + + return new ICommandProxy(selectCommand); + + } else if(commandChoice.size() == 1) { + return commandChoice.get(0); + } + + // else (command choice is empty) + return UnexecutableCommand.INSTANCE; + + } + + return super.getDropObjectsCommand(dropRequest); + } + + /** + * {@inheritDoc} + */ + @Override + protected View getReferenceViewForConnectorEnd() { + return ViewUtil.getContainerView(super.getReferenceViewForConnectorEnd()); + } + + @Override + protected ICommand getDropObjectCommand(DropObjectsRequest dropRequest, EObject droppedObject) { + View dropTargetView = ((IGraphicalEditPart)getHost()).getNotationView(); + EObject dropTargetElement = dropTargetView.getElement(); + + EObject diagramOwner = getDiagramOwner(dropTargetView); + if (UMLUtil.getStereotypeApplication((Element)diagramOwner, ConstraintBlock.class) != null) { + // ConstraintBlock + if (UMLUtil.getStereotypeApplication((Element)dropTargetElement, ConstraintProperty.class) == null) { + // only ConstraintProperty can be dropped in structure compartment of a diagram owned by a ConstraintBlock + return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE; + } + } + return super.getDropObjectCommand(dropRequest, droppedObject); + } + + private EObject getDiagramOwner(View dropTargetView) { + Diagram diagram = dropTargetView.getDiagram(); + EObject diagramOwer = diagram.getElement(); + return diagramOwer; + } +} diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomStructureCompartmentSemanticEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomStructureCompartmentSemanticEditPolicy.java new file mode 100644 index 00000000000..2230f9b8c74 --- /dev/null +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomStructureCompartmentSemanticEditPolicy.java @@ -0,0 +1,52 @@ +package org.eclipse.papyrus.sysml.diagram.parametric.policies;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.sysml.constraints.ConstraintBlock;
+import org.eclipse.papyrus.sysml.diagram.common.edit.policy.StructureCompartmentSemanticEditPolicy;
+import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+public class CustomStructureCompartmentSemanticEditPolicy extends
+ StructureCompartmentSemanticEditPolicy {
+
+ @Override
+ protected Command getCreateCommand(CreateElementRequest req) {
+
+ View dropTargetView = ((IGraphicalEditPart) getHost()).getNotationView();
+ EObject eContainer = dropTargetView.eContainer();
+ Element parent = null;
+ if (eContainer != null && eContainer instanceof View) {
+ parent = (Element) ((View) eContainer).getElement();
+ }
+ if (parent instanceof Property) {
+ parent = ((Property) parent).getType();
+ }
+
+ if (parent != null) {
+ if (UMLUtil.getStereotypeApplication(parent, ConstraintBlock.class) != null) {
+ IElementType elementType = req.getElementType();
+ if (elementType != UMLElementTypes.CONSTRAINT
+ && elementType != UMLElementTypes.COMMENT) {
+ // ConstraintBlock
+ if (elementType != SysMLElementTypes.CONSTRAINT_PROPERTY) {
+ // only ConstraintProperty can be dropped in structure
+ // compartment of a diagram owned by a ConstraintBlock
+ // (except common Comment and Constraint)
+ return UnexecutableCommand.INSTANCE;
+ }
+ }
+ }
+ }
+
+ return super.getCreateCommand(req);
+ }
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomEditPolicyProvider.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomEditPolicyProvider.java index 8da62ad4c43..26ff42817b9 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomEditPolicyProvider.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomEditPolicyProvider.java @@ -25,8 +25,6 @@ import org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultGraphicalNodeEd import org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultXYLayoutEditPolicy; import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockPropertyCompositeEditPart; import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockPropertyStructureCompartmentEditPart; -import org.eclipse.papyrus.sysml.diagram.common.edit.part.ConstraintBlockPropertyCompositeEditPart; -import org.eclipse.papyrus.sysml.diagram.common.edit.part.FlowPortAffixedNodeEditPart; import org.eclipse.papyrus.sysml.diagram.common.edit.part.StructureCompartmentEditPart; import org.eclipse.papyrus.sysml.diagram.common.edit.policy.CustomDuplicatePasteEditPolicy; import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomBlockCompositeSemanticEditPolicy; @@ -35,25 +33,28 @@ import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomDiagram import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomDragDropEditPolicy; import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.TypedElementDropEditPolicy; import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomBlockCompositeEditPartTN; +import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomConstraintBlockPropertyCompositeEditPart; import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.ParametricDiagramEditPart; import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomBlockCompositeDropEditPolicy; import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomBlockPropertyCompositeDropEditPolicy; import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy; +import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomBlockPropertyStructureCompartmentSemanticEditPolicy; import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomParametricSemanticPolicy; -import org.eclipse.papyrus.sysml.diagram.parametric.policies.StructureClassifierDropEditPolicy; +import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomStructureClassifierDropEditPolicy; +import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomStructureCompartmentSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.common.edit.part.AbstractElementBorderEditPart; import org.eclipse.papyrus.uml.diagram.common.edit.part.AbstractElementEditPart; import org.eclipse.papyrus.uml.diagram.common.edit.part.AbstractElementLinkEditPart; import org.eclipse.papyrus.uml.diagram.common.edit.part.ConnectorEditPart; import org.eclipse.papyrus.uml.diagram.common.edit.part.ConstraintParameterAffixedNodeEditPart; import org.eclipse.papyrus.uml.diagram.common.edit.part.DependencyEditPart; -import org.eclipse.papyrus.uml.diagram.common.edit.part.PortAffixedNodeEditPart; import org.eclipse.papyrus.uml.diagram.common.edit.policy.StructuredClassifierCreationEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.edit.parts.CommentEditPart; import org.eclipse.papyrus.uml.diagram.composite.edit.parts.CommentEditPartCN; import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConstraintEditPart; import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConstraintEditPartCN; +import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConstraintSpecificationEditPartCN; /** * Custom edit policy provider. @@ -97,6 +98,14 @@ public class CustomEditPolicyProvider extends ParametricDiagramEditPolicyProvide return true; } + if(gep instanceof ConstraintSpecificationEditPartCN) { + return true; + } + + if(gep instanceof ConstraintEditPartCN) { + return true; + } + return super.provides(operation); } @@ -114,7 +123,7 @@ public class CustomEditPolicyProvider extends ParametricDiagramEditPolicyProvide editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDragDropEditPolicy()); if((editPart instanceof ConstraintEditPart) || (editPart instanceof ConstraintEditPartCN)) { - editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomDefaultSemanticEditPolicy()); + editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy()); editPart.installEditPolicy(EditPolicyRoles.CREATION_ROLE, new DefaultCreationEditPolicy()); editPart.installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new DefaultGraphicalNodeEditPolicy()); } @@ -125,22 +134,13 @@ public class CustomEditPolicyProvider extends ParametricDiagramEditPolicyProvide editPart.installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new DefaultGraphicalNodeEditPolicy()); } - if(editPart instanceof FlowPortAffixedNodeEditPart) { - editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new TypedElementDropEditPolicy()); - editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy()); - } - - if(editPart instanceof PortAffixedNodeEditPart) { - editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new TypedElementDropEditPolicy()); - editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy()); - } - if(editPart instanceof BlockPropertyCompositeEditPart) { editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomBlockPropertyCompositeDropEditPolicy()); editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy()); } if(editPart instanceof BlockPropertyStructureCompartmentEditPart) { + editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomBlockPropertyStructureCompartmentSemanticEditPolicy()); editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy()); editPart.installEditPolicy(EditPolicy.LAYOUT_ROLE, new DefaultXYLayoutEditPolicy()); } @@ -153,7 +153,8 @@ public class CustomEditPolicyProvider extends ParametricDiagramEditPolicyProvide } if(editPart instanceof StructureCompartmentEditPart) { - editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new StructureClassifierDropEditPolicy()); + editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomStructureCompartmentSemanticEditPolicy()); + editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomStructureClassifierDropEditPolicy()); editPart.installEditPolicy(EditPolicy.LAYOUT_ROLE, new DefaultXYLayoutEditPolicy()); } @@ -165,7 +166,7 @@ public class CustomEditPolicyProvider extends ParametricDiagramEditPolicyProvide editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomDefaultSemanticEditPolicy()); } - if(editPart instanceof ConstraintBlockPropertyCompositeEditPart) { + if(editPart instanceof CustomConstraintBlockPropertyCompositeEditPart) { editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomBlockPropertyCompositeDropEditPolicy()); editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy()); } @@ -176,7 +177,12 @@ public class CustomEditPolicyProvider extends ParametricDiagramEditPolicyProvide if(editPart instanceof CustomBlockCompositeEditPartTN) { editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy()); } - + if(editPart instanceof ConstraintSpecificationEditPartCN) { + editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy()); + } + if(editPart instanceof ConstraintEditPartCN) { + editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy()); + } } } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/utils/BlockDropHelper.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/utils/BlockDropHelper.java index a38ec492b49..d23441ab731 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/utils/BlockDropHelper.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/utils/BlockDropHelper.java @@ -43,6 +43,8 @@ import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes; import org.eclipse.uml2.uml.Actor; import org.eclipse.uml2.uml.Association; import org.eclipse.uml2.uml.DataType; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Property; import org.eclipse.uml2.uml.Type; import org.eclipse.uml2.uml.TypedElement; import org.eclipse.uml2.uml.UMLPackage; @@ -61,9 +63,37 @@ public class BlockDropHelper extends ElementHelper { String label = ""; if(elementType == SysMLElementTypes.PART_PROPERTY) { label = "Create a new Part"; + // Exclude ConstraintProperty + if (droppedEObject instanceof Type) { + if (((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches((Type)droppedEObject)) { + return UnexecutableCommand.INSTANCE; + } + } + // Exclude reference drop in diagram owned by a ConstraintBlock + Element editPartOwner = (Element)host.resolveSemanticElement(); + if (editPartOwner instanceof Property) { + editPartOwner = ((Property) editPartOwner).getType(); + } + if (editPartOwner != null && ((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches(editPartOwner)) { + return UnexecutableCommand.INSTANCE; + } } if(elementType == SysMLElementTypes.REFERENCE_PROPERTY) { label = "Create a new Reference"; + // Exclude ConstraintProperty + if (droppedEObject instanceof Type) { + if (((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches((Type)droppedEObject)) { + return UnexecutableCommand.INSTANCE; + } + } + // Exclude reference drop in diagram owned by a ConstraintBlock + Element editPartOwner = (Element)host.resolveSemanticElement(); + if (editPartOwner instanceof Property) { + editPartOwner = ((Property) editPartOwner).getType(); + } + if (editPartOwner != null && ((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches(editPartOwner)) { + return UnexecutableCommand.INSTANCE; + } } if(elementType == SysMLElementTypes.ACTOR_PART_PROPERTY) { label = "Create a new ActorPart"; @@ -135,9 +165,31 @@ public class BlockDropHelper extends ElementHelper { // Filter part/reference : a property type by a ConstraintBlock MUST be a ConstraintProperty if(elementType == SysMLElementTypes.PART_PROPERTY) { label = "Create a new Part"; + // Exclude ConstraintProperty + if (droppedEObject instanceof Type) { + if (((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches((Type)droppedEObject)) { + return UnexecutableCommand.INSTANCE; + } + } + // Exclude reference drop in diagram owned by a ConstraintBlock + Element diagramOwner = getDiagramOwner(host); + if (diagramOwner != null && ((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches(diagramOwner)) { + return UnexecutableCommand.INSTANCE; + } } if(elementType == SysMLElementTypes.REFERENCE_PROPERTY) { label = "Create a new Reference"; + // Exclude ConstraintProperty + if (droppedEObject instanceof Type) { + if (((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches((Type)droppedEObject)) { + return UnexecutableCommand.INSTANCE; + } + } + // Exclude reference drop in diagram owned by a ConstraintBlock + Element diagramOwner = getDiagramOwner(host); + if (diagramOwner != null && ((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches(diagramOwner)) { + return UnexecutableCommand.INSTANCE; + } } if(elementType == SysMLElementTypes.ACTOR_PART_PROPERTY) { label = "Create a new ActorPart"; @@ -190,6 +242,14 @@ public class BlockDropHelper extends ElementHelper { return cc; } + private Element getDiagramOwner(GraphicalEditPart host) { + Object model = host.getRoot().getContents().getModel(); + if (model instanceof View) { + return (Element)((View) model).getElement(); + } + return null; + } + private boolean isValidStructureItemType(Object object, IElementType elementType) { boolean isValid = false; |