diff options
author | aradermache | 2013-05-21 13:48:08 +0000 |
---|---|---|
committer | aradermache | 2013-05-21 13:48:08 +0000 |
commit | f4dbd74cdf950e84b865008728376dc71a196fb2 (patch) | |
tree | fe54815fbcc58d00bb1da1e34f160668c873663a /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine | |
parent | 69426cef6e8af1090320bebb3ca965851ffd0712 (diff) | |
download | org.eclipse.papyrus-f4dbd74cdf950e84b865008728376dc71a196fb2.tar.gz org.eclipse.papyrus-f4dbd74cdf950e84b865008728376dc71a196fb2.tar.xz org.eclipse.papyrus-f4dbd74cdf950e84b865008728376dc71a196fb2.zip |
405589: [StateMachine Diagram Editor] Papyrus StateMachine Diagram Editor shall enable model elements to be moved inside or outside a composite state.
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine')
6 files changed, 415 insertions, 265 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/commands/CustomTransitionReorientCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/commands/CustomTransitionReorientCommand.java index 9f21e869076..a4bc10f1495 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/commands/CustomTransitionReorientCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/commands/CustomTransitionReorientCommand.java @@ -1,18 +1,10 @@ package org.eclipse.papyrus.uml.diagram.statemachine.custom.commands; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.common.core.command.CommandResult; import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; import org.eclipse.papyrus.uml.diagram.statemachine.edit.commands.TransitionReorientCommand; -import org.eclipse.uml2.uml.NamedElement; -import org.eclipse.uml2.uml.Pseudostate; -import org.eclipse.uml2.uml.PseudostateKind; -import org.eclipse.uml2.uml.Region; -import org.eclipse.uml2.uml.State; -import org.eclipse.uml2.uml.StateMachine; -import org.eclipse.uml2.uml.Transition; import org.eclipse.uml2.uml.Vertex; /** @@ -36,21 +28,21 @@ public class CustomTransitionReorientCommand extends TransitionReorientCommand { @Override protected CommandResult reorientSource() throws ExecutionException { getLink().setSource(getNewSource()); - changeContainer(getLink()); + EMFCustomTransitionRetargetContainerCommand.changeContainer(getLink()); return CommandResult.newOKCommandResult(getLink()); } @Override protected CommandResult reorientTarget() throws ExecutionException { getLink().setTarget(getNewTarget()); - changeContainer(getLink()); + EMFCustomTransitionRetargetContainerCommand.changeContainer(getLink()); return CommandResult.newOKCommandResult(getLink()); } @Override protected boolean canReorientSource() { Vertex target = getLink().getTarget(); - if (!CustomTransitionReorientCommand.isValid(newEnd, target)) { + if (!EMFCustomTransitionRetargetContainerCommand.isValid(newEnd, target)) { return false; } return super.canReorientSource(); @@ -59,248 +51,9 @@ public class CustomTransitionReorientCommand extends TransitionReorientCommand { @Override protected boolean canReorientTarget() { Vertex source = getLink().getSource(); - if (!CustomTransitionReorientCommand.isValid(source, newEnd)) { + if (!EMFCustomTransitionRetargetContainerCommand.isValid(source, newEnd)) { return false; } return super.canReorientTarget(); } - - - /** - * change the container of a transition, if necessary - */ - public static boolean changeContainer(Transition transition) { - // now change container - Region region = deduceContainer(transition.getSource(), transition.getTarget()); - if (region == null) { - return false; // transition is not valid - } - if (region != transition.getOwner()) { - region.getTransitions().add(transition); // will remove transition automatically from original region - } - return true; - } - - /** - * Check whether a transition from source to target is valid - */ - public static boolean isValid(EObject sourceE, EObject targetE) { - if (targetE == null) { - return true; // don't judge before knowing the target - } - NamedElement source = getNearestStateOrSM(sourceE); - NamedElement target = getNearestStateOrSM(targetE); - Region sourceRegion = getNearestRegion(source); - Region targetRegion = getNearestRegion(target); - - if (isChild(source, targetRegion)) { - // transition starts from a composite state (or state-machine) to a vertex within this state - // assure that source is not an exit point - if (isExitPoint(sourceE)) { - return false; // source is an exit point, but target is within the inner part of a class (inverse condition) - } - if (isExitPoint(targetE)) { - return false; // standard condition - } - return true; - } - else if (isChild(target, sourceRegion)) { - // transition from a vertex within the target points to target composite state (or state-machine) - // assure that target is not an entry point - if (isEntryPoint(sourceE)) { - return false; // standard condition - } - if (isEntryPoint(targetE)) { - return false; // source is an entry point, but target is outside the composite state - - } - return true; - } - else if (source == target) { - // source and target are on same state or state machine. Could be either an external or internal transition - // Allow transitions from entry to exit (internal) as well as from exit to entry (external) - // => only disallow from entry to entry and from exit to exit - if ( - (isEntryPoint(sourceE) && isEntryPoint(targetE)) || - (isExitPoint(sourceE) && isExitPoint(targetE))) { - return false; - } - return true; - } - - // standard conditions for external connections: start may not be a entry point, target not an exit point - if (isEntryPoint(sourceE)) { - return false; - } - if (isExitPoint(targetE)) { - return false; - } - return true; - } - - /** - * Calculate the container. Also checks whether a transition is possible - * - * @param sourceE - * @param targetE - * @return - */ - public static Region deduceContainer(EObject sourceE, EObject targetE) { - // Find container element for the new link. - NamedElement source = getNearestStateOrSM(sourceE); - if (targetE == null) { - // don't constraint until both source and target are given. - if (getNearestRegion(source) != null) { - return getNearestRegion(source); - } - else { - return firstRegion(source); - } - } - NamedElement target = getNearestStateOrSM(targetE); - Region sourceRegion = getNearestRegion(source); - Region targetRegion = getNearestRegion(target); - - if (isChild(source, targetRegion)) { - // transition starts from a composite state (or state-machine) to a vertex within this state - return childRegion(sourceRegion, source, targetRegion, target); - } - else if (isChild(target, sourceRegion)) { - // transition from a vertex within the target points to target composite state (or state-machine) - return childRegion(targetRegion, target, sourceRegion, source); - } - else if (source == target) { - // source and target are on same state or state machine. Could be either an external or internal transition - // Allow transitions from entry to exit (internal) as well as from exit to entry (external) - // => only disallow from entry to entry and from exit to exit - if (isEntryPoint(sourceE) || isExitPoint(targetE)) { - // is a local or internal transition, return first owned region - return firstRegion(source); - } - return sourceRegion; - } - - if (isChild(sourceRegion, targetRegion)) { - // region of target state is a child of region of source state, choose the letter as "more global" region - // also include standard case, a transition between two states within same region - return sourceRegion; - } - else { - return targetRegion; - } - } - - public static Region childRegion(Region sourceRegion, NamedElement source, Region targetRegion, NamedElement target) { - // source state is parent of targetRegion => transition from composite state - // (or entry point of this state) to a target within composite - // need to choose a region of the state depending on target - EList<Region> regions = null; - if (source instanceof State) { - regions = ((State) source).getRegions(); - } - else if (source instanceof StateMachine) { - regions = ((StateMachine) source).getRegions(); - } - if (regions != null) { - // should always be true, since we called getNearsetStateOrSM before - for (Region region : regions) { - if (isChild(region, targetRegion)) { - return region; - } - } - } - return null; - } - - /** - * Return the first region of a state or statemachine. - * @param source - * @return - */ - public static Region firstRegion(EObject source) { - EList<Region> regions = null; - if (source instanceof State) { - regions = ((State) source).getRegions(); - } - else if (source instanceof StateMachine) { - regions = ((StateMachine) source).getRegions(); - } - if ((regions != null) && (regions.size() > 0)) { - return regions.get(0); - } - else { - return null; - } - } - - public static boolean isChild(EObject parent, EObject child) { - for(EObject element = child; element != null; element = element.eContainer()) { - if(element == parent) { - return true; - } - } - return false; - } - - public static boolean isEntryPoint(EObject vertex) { - if (vertex instanceof Pseudostate) { - Pseudostate ps = (Pseudostate) vertex; - if (ps.getKind() == PseudostateKind.ENTRY_POINT_LITERAL) { - return true; - } - } - return false; - } - - public static boolean isExitPoint(EObject vertex) { - if (vertex instanceof Pseudostate) { - Pseudostate ps = (Pseudostate) vertex; - if (ps.getKind() == PseudostateKind.EXIT_POINT_LITERAL) { - return true; - } - } - return false; - } - - - /** - * Climb up by containment hierarchy starting from a given element - * and return the first region (as in default policy) - */ - public static Region getNearestRegion(EObject startFrom) { - for(EObject element = startFrom; element != null; element = element.eContainer()) { - if(element instanceof Region) { - return (Region) element; - } - } - return null; - } - - - /** - * Returns the nearest state or statemachine, if the passed element is a pseudo-state. - * This simplifies the calculation of a suitable container; - * @param vertex - * @return Return type is named element, since state and region have no other common superclass - */ - public static NamedElement getNearestStateOrSM(EObject vertex) { - if (vertex instanceof Pseudostate) { - Pseudostate ps = (Pseudostate) vertex; - if ((ps.getKind() == PseudostateKind.ENTRY_POINT_LITERAL) || - (ps.getKind() == PseudostateKind.EXIT_POINT_LITERAL)) { - State state = ps.getState(); - if (state != null) { - return state; - } - StateMachine sm = ps.getStateMachine(); - if (sm != null) { - return sm; - } - } - } - if (vertex instanceof Vertex) { - return (Vertex) vertex; - } - return null; - } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/commands/EMFCustomTransitionRetargetContainerCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/commands/EMFCustomTransitionRetargetContainerCommand.java new file mode 100644 index 00000000000..7204bb3f4e3 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/commands/EMFCustomTransitionRetargetContainerCommand.java @@ -0,0 +1,331 @@ +package org.eclipse.papyrus.uml.diagram.statemachine.custom.commands; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.emf.common.command.AbstractCommand; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.Transaction; +import org.eclipse.emf.transaction.impl.InternalTransaction; +import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain; +import org.eclipse.emf.transaction.util.TransactionUtil; +import org.eclipse.papyrus.uml.diagram.statemachine.part.UMLDiagramEditorPlugin; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Pseudostate; +import org.eclipse.uml2.uml.PseudostateKind; +import org.eclipse.uml2.uml.Region; +import org.eclipse.uml2.uml.State; +import org.eclipse.uml2.uml.StateMachine; +import org.eclipse.uml2.uml.Transition; +import org.eclipse.uml2.uml.Vertex; + +/** + * Customized transition-reorient command, takes changing of container into account. + * + * @author ansgar + * + */ +public class EMFCustomTransitionRetargetContainerCommand extends AbstractCommand { + + protected Transition transition; + + protected Region oldRegion; + + protected Region newRegion; + + public EMFCustomTransitionRetargetContainerCommand(Transition transition) { + this.transition = transition; + } + + + /** + * change the container of a transition, if necessary + */ + public static boolean changeContainer(Transition transition) { + // now change container + Region region = deduceContainer(transition.getSource(), transition.getTarget()); + if (region == null) { + return false; // transition is not valid + } + if (region != transition.getOwner()) { + region.getTransitions().add(transition); // will remove transition automatically from original region + } + return true; + } + + /** + * Check whether a transition from source to target is valid + */ + public static boolean isValid(EObject sourceE, EObject targetE) { + if (targetE == null) { + return true; // don't judge before knowing the target + } + NamedElement source = getNearestStateOrSM(sourceE); + NamedElement target = getNearestStateOrSM(targetE); + Region sourceRegion = getNearestRegion(source); + Region targetRegion = getNearestRegion(target); + + if (isChild(source, targetRegion)) { + // transition starts from a composite state (or state-machine) to a vertex within this state + // assure that source is not an exit point + if (isExitPoint(sourceE)) { + return false; // source is an exit point, but target is within the inner part of a class (inverse condition) + } + if (isExitPoint(targetE)) { + return false; // standard condition + } + return true; + } + else if (isChild(target, sourceRegion)) { + // transition from a vertex within the target points to target composite state (or state-machine) + // assure that target is not an entry point + if (isEntryPoint(sourceE)) { + return false; // standard condition + } + if (isEntryPoint(targetE)) { + return false; // source is an entry point, but target is outside the composite state + + } + return true; + } + else if (source == target) { + // source and target are on same state or state machine. Could be either an external or internal transition + // Allow transitions from entry to exit (internal) as well as from exit to entry (external) + // => only disallow from entry to entry and from exit to exit + if ( + (isEntryPoint(sourceE) && isEntryPoint(targetE)) || + (isExitPoint(sourceE) && isExitPoint(targetE))) { + return false; + } + return true; + } + + // standard conditions for external connections: start may not be a entry point, target not an exit point + if (isEntryPoint(sourceE)) { + return false; + } + if (isExitPoint(targetE)) { + return false; + } + return true; + } + + /** + * Calculate the container. Also checks whether a transition is possible + * + * @param sourceE + * @param targetE + * @return + */ + public static Region deduceContainer(EObject sourceE, EObject targetE) { + // Find container element for the new link. + NamedElement source = getNearestStateOrSM(sourceE); + if (targetE == null) { + // don't constraint until both source and target are given. + if (getNearestRegion(source) != null) { + return getNearestRegion(source); + } + else { + return firstRegion(source); + } + } + NamedElement target = getNearestStateOrSM(targetE); + Region sourceRegion = getNearestRegion(source); + Region targetRegion = getNearestRegion(target); + + if (isChild(source, targetRegion)) { + // transition starts from a composite state (or state-machine) to a vertex within this state + return childRegion(sourceRegion, source, targetRegion, target); + } + else if (isChild(target, sourceRegion)) { + // transition from a vertex within the target points to target composite state (or state-machine) + return childRegion(targetRegion, target, sourceRegion, source); + } + else if (source == target) { + // source and target are on same state or state machine. Could be either an external or internal transition + // Allow transitions from entry to exit (internal) as well as from exit to entry (external) + // => only disallow from entry to entry and from exit to exit + if (isEntryPoint(sourceE) || isExitPoint(targetE)) { + // is a local or internal transition, return first owned region + return firstRegion(source); + } + return sourceRegion; + } + + if (isChild(targetRegion, sourceRegion)) { + // region of target state is a child of region of source state, choose the letter as "more global" region + // also include standard case, a transition between two states within same region + return targetRegion; + } + else { + return sourceRegion; + } + } + + public static Region childRegion(Region sourceRegion, NamedElement source, Region targetRegion, NamedElement target) { + // source state is parent of targetRegion => transition from composite state + // (or entry point of this state) to a target within composite + // need to choose a region of the state depending on target + EList<Region> regions = null; + if (source instanceof State) { + regions = ((State) source).getRegions(); + } + else if (source instanceof StateMachine) { + regions = ((StateMachine) source).getRegions(); + } + if (regions != null) { + // should always be true, since we called getNearsetStateOrSM before + for (Region region : regions) { + if (isChild(region, targetRegion)) { + return region; + } + } + } + return null; + } + + /** + * Return the first region of a state or statemachine. + * @param source + * @return + */ + public static Region firstRegion(EObject source) { + EList<Region> regions = null; + if (source instanceof State) { + regions = ((State) source).getRegions(); + } + else if (source instanceof StateMachine) { + regions = ((StateMachine) source).getRegions(); + } + if ((regions != null) && (regions.size() > 0)) { + return regions.get(0); + } + else { + return null; + } + } + + public static boolean isChild(EObject parent, EObject child) { + for(EObject element = child; element != null; element = element.eContainer()) { + if(element == parent) { + return true; + } + } + return false; + } + + public static boolean isEntryPoint(EObject vertex) { + if (vertex instanceof Pseudostate) { + Pseudostate ps = (Pseudostate) vertex; + if (ps.getKind() == PseudostateKind.ENTRY_POINT_LITERAL) { + return true; + } + } + return false; + } + + public static boolean isExitPoint(EObject vertex) { + if (vertex instanceof Pseudostate) { + Pseudostate ps = (Pseudostate) vertex; + if (ps.getKind() == PseudostateKind.EXIT_POINT_LITERAL) { + return true; + } + } + return false; + } + + + /** + * Climb up by containment hierarchy starting from a given element + * and return the first region (as in default policy) + */ + public static Region getNearestRegion(EObject startFrom) { + for(EObject element = startFrom; element != null; element = element.eContainer()) { + if(element instanceof Region) { + return (Region) element; + } + } + return null; + } + + + /** + * Returns the nearest state or statemachine, if the passed element is a pseudo-state. + * This simplifies the calculation of a suitable container; + * @param vertex + * @return Return type is named element, since state and region have no other common superclass + */ + public static NamedElement getNearestStateOrSM(EObject vertex) { + if (vertex instanceof Pseudostate) { + Pseudostate ps = (Pseudostate) vertex; + if ((ps.getKind() == PseudostateKind.ENTRY_POINT_LITERAL) || + (ps.getKind() == PseudostateKind.EXIT_POINT_LITERAL)) { + State state = ps.getState(); + if (state != null) { + return state; + } + StateMachine sm = ps.getStateMachine(); + if (sm != null) { + return sm; + } + } + } + if (vertex instanceof Vertex) { + return (Vertex) vertex; + } + return null; + } + + + @Override + public void execute() { + Map<String,Boolean> options = new HashMap<String,Boolean>(); + options.put(Transaction.OPTION_UNPROTECTED, Boolean.TRUE); + try { + InternalTransaction it = ((InternalTransactionalEditingDomain) TransactionUtil.getEditingDomain(transition)).startTransaction(false, options); + oldRegion = (Region) transition.getOwner(); + changeContainer(transition); + newRegion = (Region) transition.getOwner(); + it.commit(); + } catch(Exception e){ + UMLDiagramEditorPlugin.getInstance().logError(e.getMessage()); + } + } + + @Override + public void undo() { + Map<String,Boolean> options = new HashMap<String,Boolean>(); + options.put(Transaction.OPTION_UNPROTECTED, Boolean.TRUE); + try { + InternalTransaction it = ((InternalTransactionalEditingDomain) TransactionUtil.getEditingDomain(transition)).startTransaction(false, options); + if (oldRegion != transition.getOwner()) { + oldRegion.getTransitions().add(transition); // will remove transition automatically from original region + } + it.commit(); + } catch(Exception e){ + UMLDiagramEditorPlugin.getInstance().logError(e.getMessage()); + } + } + + + @Override + public void redo() { + Map<String,Boolean> options = new HashMap<String,Boolean>(); + options.put(Transaction.OPTION_UNPROTECTED, Boolean.TRUE); + try { + InternalTransaction it = ((InternalTransactionalEditingDomain) TransactionUtil.getEditingDomain(transition)).startTransaction(false, options); + if (newRegion != transition.getOwner()) { + newRegion.getTransitions().add(transition); // will remove transition automatically from original region + } + it.commit(); + } catch(Exception e){ + UMLDiagramEditorPlugin.getInstance().logError(e.getMessage()); + } + } + + @Override + protected boolean prepare() { + return true; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomRegionCompartmentCreationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomRegionCompartmentCreationEditPolicy.java index 66a5c608ab3..088112254d5 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomRegionCompartmentCreationEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomRegionCompartmentCreationEditPolicy.java @@ -1,6 +1,5 @@ package org.eclipse.papyrus.uml.diagram.statemachine.custom.policies; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -14,6 +13,7 @@ import org.eclipse.draw2d.Shape; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PrecisionRectangle; import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gef.EditPart; import org.eclipse.gef.LayerConstants; @@ -22,23 +22,30 @@ import org.eclipse.gef.commands.Command; import org.eclipse.gef.editparts.LayerManager; import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; +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.GroupEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeCompartmentEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeRequest; -import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest; import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; import org.eclipse.gmf.runtime.emf.type.core.IElementType; import org.eclipse.gmf.runtime.emf.type.core.IHintedType; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper; import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter; import org.eclipse.papyrus.uml.diagram.statemachine.custom.commands.CustomRegionCreateElementCommand; +import org.eclipse.papyrus.uml.diagram.statemachine.custom.commands.EMFCustomTransitionRetargetContainerCommand; import org.eclipse.papyrus.uml.diagram.statemachine.custom.figures.RegionFigure; import org.eclipse.papyrus.uml.diagram.statemachine.custom.helpers.Zone; import org.eclipse.papyrus.uml.diagram.statemachine.edit.parts.RegionEditPart; import org.eclipse.papyrus.uml.diagram.statemachine.providers.UMLElementTypes; +import org.eclipse.uml2.uml.State; +import org.eclipse.uml2.uml.Transition; public class CustomRegionCompartmentCreationEditPolicy extends CreationEditPolicy { @@ -55,6 +62,50 @@ public class CustomRegionCompartmentCreationEditPolicy extends CreationEditPolic } @Override + protected Command getReparentCommand(ChangeBoundsRequest changeBoundsRequest) { + View container = (View)getHost().getAdapter(View.class); + EObject context = container == null ? null : ViewUtil.resolveSemanticElement(container); + + CompositeCommand cc = new CompositeCommand("move (re-parent) state"); + Iterator<EditPart> it = changeBoundsRequest.getEditParts().iterator(); + while(it.hasNext()) { + EditPart ep = it.next(); + if (ep instanceof LabelEditPart) { + continue; + } + if (ep instanceof GroupEditPart) { + cc.compose(getReparentGroupCommand((GroupEditPart) ep)); + } + View view = (View)ep.getAdapter(View.class); + if (view == null) { + continue; + } + + EObject semantic = ViewUtil.resolveSemanticElement(view); + if (semantic == null) { + cc.compose(getReparentViewCommand((IGraphicalEditPart)ep)); + } + else if (context != null && shouldReparent(semantic, context)) { + cc.compose(getReparentCommand((IGraphicalEditPart)ep)); + if (semantic instanceof State) { + State state = (State) semantic; + // correct container of transitions + for (Transition transition : state.getOutgoings()) { + cc.compose(new EMFtoGMFCommandWrapper( + new EMFCustomTransitionRetargetContainerCommand(transition))); + } + for (Transition transition : state.getIncomings()) { + cc.compose(new EMFtoGMFCommandWrapper( + new EMFCustomTransitionRetargetContainerCommand(transition))); + } + } + } + } + return cc.isEmpty() ? null : new ICommandProxy(cc.reduce()); + // return super.getReparentCommand(request); + } + + @Override public Command getCommand(Request request) { // CHECK THIS @@ -86,6 +137,8 @@ public class CustomRegionCompartmentCreationEditPolicy extends CreationEditPolic } } } else if(request instanceof ChangeBoundsRequest) { + return getReparentCommand((ChangeBoundsRequest) request); + /* ChangeBoundsRequest changeBoundsRequest = (ChangeBoundsRequest)request; Point mouseLocation = changeBoundsRequest.getLocation(); @@ -101,8 +154,11 @@ public class CustomRegionCompartmentCreationEditPolicy extends CreationEditPolic list.add(regionToDrag); } } + View container = (View)getHost().getAdapter(View.class); + EObject context = container == null ? null : ViewUtil.resolveSemanticElement(container); dropRequest.setObjects(list); return getHost().getCommand(dropRequest); + */ } return super.getCommand(request); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomRegionCompartmentXYLayoutEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomRegionCompartmentXYLayoutEditPolicy.java index 232bf1c2f4c..f22aee1b236 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomRegionCompartmentXYLayoutEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/policies/CustomRegionCompartmentXYLayoutEditPolicy.java @@ -37,7 +37,6 @@ public class CustomRegionCompartmentXYLayoutEditPolicy extends XYLayoutEditPolic * * @return */ - @Override public Command createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, Object constraint) { // precautionary test @@ -81,10 +80,22 @@ public class CustomRegionCompartmentXYLayoutEditPolicy extends XYLayoutEditPolic ResizableEditPolicy policy = new ResizableEditPolicy() { public void eraseSourceFeedback(Request request) { - if(RequestConstants.REQ_DROP.equals(request.getType())) + if(RequestConstants.REQ_DROP.equals(request.getType())) { eraseChangeBoundsFeedback((ChangeBoundsRequest)request); - else + } + else { super.eraseSourceFeedback(request); + } + } + + public void showSourceFeedback(Request request) { + if(RequestConstants.REQ_DROP.equals(request.getType())) { + // also show feedback in case of a drop request + showChangeBoundsFeedback((ChangeBoundsRequest) request); + } + else { + super.showSourceFeedback(request); + } } }; return policy; @@ -105,5 +116,4 @@ public class CustomRegionCompartmentXYLayoutEditPolicy extends XYLayoutEditPolic else return super.getTargetEditPart(request); } - } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src/org/eclipse/papyrus/uml/diagram/statemachine/edit/commands/TransitionCreateCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src/org/eclipse/papyrus/uml/diagram/statemachine/edit/commands/TransitionCreateCommand.java index 8e7c9b67353..3e5966f5a78 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src/org/eclipse/papyrus/uml/diagram/statemachine/edit/commands/TransitionCreateCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src/org/eclipse/papyrus/uml/diagram/statemachine/edit/commands/TransitionCreateCommand.java @@ -11,7 +11,7 @@ import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand; import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
-import org.eclipse.papyrus.uml.diagram.statemachine.custom.commands.CustomTransitionReorientCommand;
+import org.eclipse.papyrus.uml.diagram.statemachine.custom.commands.EMFCustomTransitionRetargetContainerCommand;
import org.eclipse.papyrus.uml.diagram.statemachine.edit.policies.UMLBaseItemSemanticEditPolicy;
import org.eclipse.papyrus.uml.diagram.statemachine.providers.ElementInitializers;
import org.eclipse.uml2.uml.Region;
@@ -32,7 +32,7 @@ public class TransitionCreateCommand extends EditElementCommand { */
protected Region deduceContainer(EObject source, EObject target) {
// TODO: avoid modification of generated code, problem is that model needs to be changed at many places ...
- return CustomTransitionReorientCommand.deduceContainer (source, target);
+ return EMFCustomTransitionRetargetContainerCommand.deduceContainer (source, target);
}
/**
@@ -80,7 +80,7 @@ public class TransitionCreateCommand extends EditElementCommand { if(getContainer() == null) {
return false;
}
- if(!CustomTransitionReorientCommand.isValid(source, target)) {
+ if(!EMFCustomTransitionRetargetContainerCommand.isValid(source, target)) {
return false;
}
return UMLBaseItemSemanticEditPolicy.getLinkConstraints().canCreateTransition_7000(getContainer(), getSource(), getTarget());
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src/org/eclipse/papyrus/uml/diagram/statemachine/edit/commands/TransitionReorientCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src/org/eclipse/papyrus/uml/diagram/statemachine/edit/commands/TransitionReorientCommand.java index 7147d22b996..5df3b201cb4 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src/org/eclipse/papyrus/uml/diagram/statemachine/edit/commands/TransitionReorientCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src/org/eclipse/papyrus/uml/diagram/statemachine/edit/commands/TransitionReorientCommand.java @@ -7,7 +7,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
-import org.eclipse.papyrus.uml.diagram.statemachine.custom.commands.CustomTransitionReorientCommand;
+import org.eclipse.papyrus.uml.diagram.statemachine.custom.commands.EMFCustomTransitionRetargetContainerCommand;
import org.eclipse.papyrus.uml.diagram.statemachine.edit.policies.UMLBaseItemSemanticEditPolicy;
import org.eclipse.uml2.uml.Region;
import org.eclipse.uml2.uml.Transition;
@@ -71,7 +71,7 @@ public class TransitionReorientCommand extends EditElementCommand { return false;
}
// TODO: avoid modifications here. Not done due to many required changes
- if (!CustomTransitionReorientCommand.isValid(newEnd, target)) {
+ if (!EMFCustomTransitionRetargetContainerCommand.isValid(newEnd, target)) {
return false;
}
Region container = (Region)getLink().eContainer();
@@ -90,7 +90,7 @@ public class TransitionReorientCommand extends EditElementCommand { return false;
}
// TODO: avoid modifications here. Not done due to many required changes
- if (!CustomTransitionReorientCommand.isValid(source, newEnd)) {
+ if (!EMFCustomTransitionRetargetContainerCommand.isValid(source, newEnd)) {
return false;
}
Region container = (Region)getLink().eContainer();
@@ -154,7 +154,7 @@ public class TransitionReorientCommand extends EditElementCommand { protected CommandResult reorientSource() throws ExecutionException {
getLink().setSource(getNewSource());
// TODO: avoid modifications here. Not done due to many required changes
- CustomTransitionReorientCommand.changeContainer(getLink());
+ EMFCustomTransitionRetargetContainerCommand.changeContainer(getLink());
return CommandResult.newOKCommandResult(getLink());
}
@@ -163,7 +163,7 @@ public class TransitionReorientCommand extends EditElementCommand { */
protected CommandResult reorientTarget() throws ExecutionException {
getLink().setTarget(getNewTarget());
- CustomTransitionReorientCommand.changeContainer(getLink());
+ EMFCustomTransitionRetargetContainerCommand.changeContainer(getLink());
return CommandResult.newOKCommandResult(getLink());
}
}
|