diff options
author | Camille Letavernier | 2018-04-19 15:55:10 +0000 |
---|---|---|
committer | Camille Letavernier | 2018-04-19 15:55:10 +0000 |
commit | f18293d352fca8812eadae92c3e2e817095e31ef (patch) | |
tree | ad8070f9d0c3b96355d7b7fecb810b9e0cea4622 | |
parent | c303ad37c80ed467ab62237359cd016bfe5a6a59 (diff) | |
download | org.eclipse.papyrus-bug/533770-CFLayout.tar.gz org.eclipse.papyrus-bug/533770-CFLayout.tar.xz org.eclipse.papyrus-bug/533770-CFLayout.zip |
Bug 533770: [Sequence Diagram] Layout operands in a CombinedFragmentbug/533770-CFLayout
https://bugs.eclipse.org/bugs/show_bug.cgi?id=533770
- Add policies to resize operands, via a virtual separator (Handle)
between two operands.
Note: this is work-in-progress; the CF still needs to handle properly
its own change bounds requests, by properly resizing its operands.
Feedback is also missing.
Change-Id: Id1c9d9352b2eaca76f720255dce2a78b9fb5cba2
Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
7 files changed, 442 insertions, 232 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentEditPart.java index 064e67e396b..027ace577e4 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentEditPart.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2017 CEA LIST and others. + * Copyright (c) 2017, 2018 CEA LIST, EclipseSource and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,6 +9,7 @@ * Contributors: * CEA LIST - Initial API and implementation * C�line Janssens (celine.janssens@all4tec.net) - Add Coregion functionnality + * EclipseSource - Bug 533770 * *****************************************************************************/ @@ -16,10 +17,11 @@ package org.eclipse.papyrus.uml.diagram.sequence.edit.parts; import org.eclipse.draw2d.geometry.Point; import org.eclipse.emf.common.notify.Notification; +import org.eclipse.gef.EditPolicy; import org.eclipse.gef.Request; import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.uml.diagram.sequence.figures.CombinedFragmentFigure; +import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.CombinedFragmentResizeEditPolicy; import org.eclipse.uml2.uml.CombinedFragment; import org.eclipse.uml2.uml.ConsiderIgnoreFragment; import org.eclipse.uml2.uml.Element; @@ -28,7 +30,7 @@ import org.eclipse.uml2.uml.InteractionOperatorKind; /** * @author Patrick Tessier * @since 3.0 - * this class has been customized to prevent the strange feedback of lifeline during the move + * this class has been customized to prevent the strange feedback of lifeline during the move * */ public class CCombinedFragmentEditPart extends CombinedFragmentEditPart { @@ -57,6 +59,16 @@ public class CCombinedFragmentEditPart extends CombinedFragmentEditPart { getPrimaryShape().setName(((CombinedFragment) this.resolveSemanticElement()).getInteractionOperator().getLiteral()); } + /** + * @see org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart#createDefaultEditPolicies() + * + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new CombinedFragmentResizeEditPolicy()); + } + /** * Get the Notation Value of the CoRegion boolean @@ -95,6 +107,7 @@ public class CCombinedFragmentEditPart extends CombinedFragmentEditPart { super.refresh(); } + /** * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#showTargetFeedback(org.eclipse.gef.Request) * @@ -102,11 +115,11 @@ public class CCombinedFragmentEditPart extends CombinedFragmentEditPart { */ @Override public void showTargetFeedback(Request request) { - if(request instanceof ChangeBoundsRequest){ - ChangeBoundsRequest changeBoundsRequest= (ChangeBoundsRequest)request; + if (request instanceof ChangeBoundsRequest) { + ChangeBoundsRequest changeBoundsRequest = (ChangeBoundsRequest) request; - if( changeBoundsRequest.getEditParts().get(0) instanceof LifelineEditPart) { - changeBoundsRequest.setMoveDelta(new Point(changeBoundsRequest.getMoveDelta().x,0)); + if (changeBoundsRequest.getEditParts().get(0) instanceof LifelineEditPart) { + changeBoundsRequest.setMoveDelta(new Point(changeBoundsRequest.getMoveDelta().x, 0)); } } super.showTargetFeedback(request); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CombinedFragmentResizeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CombinedFragmentResizeEditPolicy.java new file mode 100644 index 00000000000..10169f112b4 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CombinedFragmentResizeEditPolicy.java @@ -0,0 +1,230 @@ +/***************************************************************************** + * Copyright (c) 2018 EclipseSource and others. + * + * 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: + * EclipseSource - Initial API and implementation (Bug 533770) + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.sequence.edit.policies; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.eclipse.draw2d.Cursors; +import org.eclipse.draw2d.Locator; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.DragTracker; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Handle; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gef.editpolicies.ResizableEditPolicy; +import org.eclipse.gef.handles.RelativeHandleLocator; +import org.eclipse.gef.handles.SquareHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentCombinedFragmentCompartmentEditPart; +import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart; +import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart; +import org.eclipse.papyrus.uml.diagram.sequence.figures.layout.SwimlanesCompartmentLayout; +import org.eclipse.papyrus.uml.diagram.sequence.requests.MoveSeparatorRequest; +import org.eclipse.papyrus.uml.diagram.sequence.tools.SeparatorResizeTracker; +import org.eclipse.uml2.uml.CombinedFragment; + +/** + * <p> + * An edit policy to resize the {@link CombinedFragment} and its operands. + * This policy works together with {@link SwimlanesCompartmentLayout}, + * and is allowed to resize the entire {@link CombinedFragmentEditPart}, + * as well as to change the Size of its {@link InteractionOperandEditPart InteractionOperandEditParts} + * </p> + * + * @since 5.0 + */ +public class CombinedFragmentResizeEditPolicy extends ResizableEditPolicy { + + /** + * @see org.eclipse.gef.editpolicies.ResizableEditPolicy#createSelectionHandles() + * + * @return + */ + @Override + protected List<Handle> createSelectionHandles() { + @SuppressWarnings("unchecked") + List<Handle> handles = super.createSelectionHandles(); + + List<GraphicalEditPart> operands = getOperands(); + int separators = operands.size() - 1; + + if (getHost().getSelected() == EditPart.SELECTED_PRIMARY) { + for (int i = 0; i < separators; i++) { + handles.add(createSeparatorHandle(i, operands)); + } + } + + return handles; + } + + @Override + public GraphicalEditPart getHost() { + return (GraphicalEditPart) super.getHost(); + } + + private Handle createSeparatorHandle(int separatorIndex, List<GraphicalEditPart> operands) { + GraphicalEditPart resizedOperand = operands.get(separatorIndex + 1); + Locator locator = new RelativeHandleLocator(resizedOperand.getFigure(), PositionConstants.NORTH); + Handle handle = new SquareHandle(getHost(), locator, Cursors.SIZENS) { + + @Override + protected DragTracker createDragTracker() { + return new SeparatorResizeTracker(CombinedFragmentResizeEditPolicy.this.getHost(), PositionConstants.NORTH, separatorIndex); + } + + }; + return handle; + } + + /** + * @see org.eclipse.gef.editpolicies.ResizableEditPolicy#getCommand(org.eclipse.gef.Request) + * + * @param request + * @return + */ + @Override + public Command getCommand(Request request) { + if (request instanceof MoveSeparatorRequest) { + return getMoveSeparatorCommand((MoveSeparatorRequest) request); + } else if (request instanceof ChangeBoundsRequest) { + // TODO Update the size of the first/last Operand(s) + } + return super.getCommand(request); + } + + protected Command getMoveSeparatorCommand(MoveSeparatorRequest request) { + int separatorIndex = request.getSeparatorIndex(); + if (separatorIndex < 0 || separatorIndex > getOperands().size() - 1) { + return UnexecutableCommand.INSTANCE; + } + + double moveDistance = request.getMoveDelta().getDistance(new Point(0, 0)); + if (moveDistance < 5) { + return UnexecutableCommand.INSTANCE; + } + + + ChangeBoundsRequest requestAbove = getResizeAboveRequest(request); + ChangeBoundsRequest requestBelow = getResizeBelowRequest(request); + + CompoundCommand moveSeparatorCommand = new CompoundCommand("Move Operands Separator"); + moveSeparatorCommand.add(getOperandAbove(request).getCommand(requestAbove)); + moveSeparatorCommand.add(getOperandBelow(request).getCommand(requestBelow)); + + return moveSeparatorCommand; + } + + protected GraphicalEditPart getOperandAbove(MoveSeparatorRequest request) { + return getOperandAbove(request.getSeparatorIndex()); + } + + protected GraphicalEditPart getOperandAbove(int separatorIndex) { + return getOperands().get(separatorIndex); + } + + protected GraphicalEditPart getOperandBelow(MoveSeparatorRequest request) { + return getOperandBelow(request.getSeparatorIndex()); + } + + protected GraphicalEditPart getOperandBelow(int separatorIndex) { + return getOperands().get(separatorIndex + 1); + } + + protected ChangeBoundsRequest getResizeAboveRequest(MoveSeparatorRequest request) { + ChangeBoundsRequest requestAbove = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE); + requestAbove.setMoveDelta(request.getMoveDelta()); + requestAbove.setSizeDelta(new Dimension(request.getMoveDelta().x, request.getMoveDelta().y)); + requestAbove.setResizeDirection(PositionConstants.SOUTH); + requestAbove.setLocation(request.getLocation()); + requestAbove.setEditParts(getOperandAbove(request.getSeparatorIndex())); + return requestAbove; + } + + protected ChangeBoundsRequest getResizeBelowRequest(MoveSeparatorRequest request) { + ChangeBoundsRequest requestBelow = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE); + requestBelow.setMoveDelta(request.getMoveDelta()); + requestBelow.setSizeDelta(new Dimension(-request.getMoveDelta().x, -request.getMoveDelta().y)); + requestBelow.setResizeDirection(PositionConstants.NORTH); + requestBelow.setLocation(request.getLocation()); + requestBelow.setEditParts(getOperandBelow(request.getSeparatorIndex())); + return requestBelow; + } + + @Override + public void showTargetFeedback(Request request) { + if (request instanceof MoveSeparatorRequest) { + showMoveSeparatorFeedback((MoveSeparatorRequest) request); + } + super.showTargetFeedback(request); + } + + protected void showMoveSeparatorFeedback(MoveSeparatorRequest request) { + // getOperandAbove(request).showTargetFeedback(getResizeAboveRequest(request)); + // getOperandBelow(request).showTargetFeedback(getResizeBelowRequest(request)); + } + + /** + * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#eraseTargetFeedback(org.eclipse.gef.Request) + * + * @param request + */ + @Override + public void eraseTargetFeedback(Request request) { + if (request instanceof MoveSeparatorRequest) { + eraseMoveSeparatorFeedback((MoveSeparatorRequest) request); + } + super.eraseTargetFeedback(request); + } + + protected void eraseMoveSeparatorFeedback(MoveSeparatorRequest request) { + // getOperandAbove(request).eraseTargetFeedback(getResizeAboveRequest(request)); + // getOperandBelow(request).eraseTargetFeedback(getResizeBelowRequest(request)); + } + + /** + * @return + * The host's children edit parts (Excluding border items) + */ + private List<GraphicalEditPart> getOperands() { + List<?> children = getHost().getChildren(); + + CompartmentEditPart cfCompartment = children.stream() + .filter(CombinedFragmentCombinedFragmentCompartmentEditPart.class::isInstance) + .map(CombinedFragmentCombinedFragmentCompartmentEditPart.class::cast) + .findFirst().orElse(null); + + if (cfCompartment == null) { + return Collections.emptyList(); + } + + List<?> compartmentChildren = cfCompartment.getChildren(); + + return compartmentChildren.stream() + .filter(part -> !(part instanceof IBorderItemEditPart)) + .filter(GraphicalEditPart.class::isInstance) + .map(GraphicalEditPart.class::cast) + .collect(Collectors.toList()); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java index cfb39f660ad..edaec79134f 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2009 Atos Origin. + * Copyright (c) 2009, 2018 Atos Origin, EclipseSource and others. * * * All rights reserved. This program and the accompanying materials @@ -9,13 +9,13 @@ * * Contributors: * Atos Origin - Initial API and implementation + * EclipseSource - Bug 533770 * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.sequence.edit.policies; -import org.eclipse.gef.commands.Command; +import org.eclipse.draw2d.PositionConstants; import org.eclipse.gef.editpolicies.ResizableEditPolicy; -import org.eclipse.gef.requests.ChangeBoundsRequest; /** * The customn DragDropEditPolicy for InteractionOperandEditPart. @@ -32,14 +32,6 @@ public class InteractionOperandDragDropEditPolicy extends ResizableEditPolicy { // Bug 533770: The layout is now handled exclusively by the parent. // The operand is no longer directly resizable. It may still provide // a height hint (Integer or Rectangle, height in pixels) - setResizeDirections(0); - } - - /** - * Handle resize InteractionOperand {@inheritDoc} - */ - @Override - protected Command getResizeCommand(ChangeBoundsRequest request) { - return super.getResizeCommand(request); + setResizeDirections(PositionConstants.NONE); } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/layout/SwimlanesCompartmentLayout.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/layout/SwimlanesCompartmentLayout.java index 925925120a3..b8d783fbf85 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/layout/SwimlanesCompartmentLayout.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/layout/SwimlanesCompartmentLayout.java @@ -10,7 +10,6 @@ * EclipseSource - Initial API and implementation: Bug 533770 * *****************************************************************************/ - package org.eclipse.papyrus.uml.diagram.sequence.figures.layout; import java.util.ArrayList; @@ -193,7 +192,6 @@ public class SwimlanesCompartmentLayout extends ConstrainedToolbarLayout { } newBounds.height -= amntShrinkCurrentHeight; child.setBounds(transposer.t(newBounds)); - System.out.println(child.getBounds()); amntShrinkHeight -= amntShrinkCurrentHeight; prefMinSumHeight -= (prefHeight - minHeight); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ResizeOperandEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ResizeOperandEditPolicy.java index 3d4ed01d70f..26f4ba96145 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ResizeOperandEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ResizeOperandEditPolicy.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2017 CEA LIST and others. + * Copyright (c) 2017, 2018 CEA LIST, EclipseSource and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,19 +8,17 @@ * * Contributors: * CEA LIST - Initial API and implementation + * EclipseSource - Bug 533770 * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling; -import java.util.Iterator; import java.util.List; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gef.Request; import org.eclipse.gef.RequestConstants; @@ -29,9 +27,6 @@ import org.eclipse.gef.editpolicies.GraphicalEditPolicy; import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; import org.eclipse.gmf.runtime.common.core.command.ICommand; -import org.eclipse.gmf.runtime.common.core.command.IdentityCommand; -import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker; -import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener; 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; @@ -41,12 +36,8 @@ import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; import org.eclipse.gmf.runtime.emf.type.core.IElementType; import org.eclipse.gmf.runtime.notation.Bounds; import org.eclipse.gmf.runtime.notation.Node; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.AutomaticNotationEditPolicy; -import org.eclipse.papyrus.uml.diagram.sequence.command.SetLocationCommand; import org.eclipse.papyrus.uml.diagram.sequence.command.SetResizeAndLocationCommand; import org.eclipse.papyrus.uml.diagram.sequence.command.SetResizeCommand; -import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CCombinedFragmentEditPart; import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CInteractionOperandEditPart; import org.eclipse.papyrus.uml.service.types.element.UMLDIElementTypes; import org.eclipse.papyrus.uml.service.types.utils.ElementUtil; @@ -56,7 +47,7 @@ import org.eclipse.papyrus.uml.service.types.utils.ElementUtil; * This class is used to allow the resize and adding of children of the combined Fragment * */ -public class ResizeOperandEditPolicy extends GraphicalEditPolicy implements AutomaticNotationEditPolicy, NotificationListener { +public class ResizeOperandEditPolicy extends GraphicalEditPolicy { /** @@ -66,7 +57,6 @@ public class ResizeOperandEditPolicy extends GraphicalEditPolicy implements Auto @Override public void activate() { super.activate(); - getDiagramEventBroker().addNotificationListener(((EObject) getHost().getModel()), this); } /** @@ -75,23 +65,9 @@ public class ResizeOperandEditPolicy extends GraphicalEditPolicy implements Auto */ @Override public void deactivate() { - getDiagramEventBroker().removeNotificationListener(((EObject) getHost().getModel()), this); super.activate(); } - /* - * Gets the diagram event broker from the editing domain. - * - * @return the diagram event broker - */ - protected DiagramEventBroker getDiagramEventBroker() { - TransactionalEditingDomain theEditingDomain = getEditingDomain(); - if (null != theEditingDomain) { - return DiagramEventBroker.getInstance(theEditingDomain); - } - return null; - } - /** * Factors incoming requests into various specific methods. * @@ -126,50 +102,7 @@ public class ResizeOperandEditPolicy extends GraphicalEditPolicy implements Auto TransactionalEditingDomain editingDomain = getEditingDomain(); Object currentEditPart = editParts.get(0); - if (changeBoundsRequest.getMoveDelta().y == 0) { - if (currentEditPart instanceof GraphicalEditPart) { - if (istheFirstDisplayedOperand((GraphicalEditPart) currentEditPart)) { - compositeCommand.add(new SetLocationCommand(editingDomain, "Set Position of the first operand", new EObjectAdapter(((GraphicalEditPart) currentEditPart).getNotationView()), new Point(0, 0))); - } - // update the current Node - updateCurrentChildSize(compositeCommand, changeBoundsRequest, editingDomain, currentEditPart); - - // update the combinedfragment if this the last - if (istheLastDisplayedOperand((GraphicalEditPart) currentEditPart)) { - compositeCommand.add(getResizeCompartmentCommand(changeBoundsRequest)); - } else { - // update the next view if this is not the last - View nextView = getNextView((GraphicalEditPart) currentEditPart); - Dimension size = new Dimension(BoundForEditPart.getWidthFromView((Node) nextView), BoundForEditPart.getHeightFromView((Node) nextView)); - size.expand(changeBoundsRequest.getSizeDelta().width * -1, changeBoundsRequest.getSizeDelta().height * -1); - Point locationNext = new Point(((Bounds) ((Node) nextView).getLayoutConstraint()).getX(), ((Bounds) ((Node) nextView).getLayoutConstraint()).getY()); - locationNext.y = locationNext.y + changeBoundsRequest.getSizeDelta().height; - ICommand setBoundsCommand = new SetResizeAndLocationCommand(editingDomain, "Resize Operands", new EObjectAdapter(nextView), new Rectangle(locationNext, size)); - compositeCommand.add(setBoundsCommand); - } - } - } else if (changeBoundsRequest.getMoveDelta().y != 0) { - if (currentEditPart instanceof GraphicalEditPart) { - updateCurrentChildSize(compositeCommand, changeBoundsRequest, editingDomain, currentEditPart); - } - if (istheFirstDisplayedOperand((GraphicalEditPart) currentEditPart)) { - compositeCommand.add(getMoveCompartmentCommand(changeBoundsRequest)); - compositeCommand.add(new SetLocationCommand(editingDomain, "Resize Operands", new EObjectAdapter(((GraphicalEditPart) currentEditPart).getNotationView()), new Point(0, 0))); - for (int i = 1; i < getHost().getChildren().size(); i++) { - GraphicalEditPart graphicalEditPart = (GraphicalEditPart) getHost().getChildren().get(i); - int y = ((Bounds) ((Node) graphicalEditPart.getNotationView()).getLayoutConstraint()).getY() - changeBoundsRequest.getMoveDelta().y; - compositeCommand.add(new SetLocationCommand(editingDomain, "Resize Operands", new EObjectAdapter((graphicalEditPart.getNotationView())), new Point(0, y))); - } - - } else { - // update the previous view if this is not the last - View previousView = getPreviousView((GraphicalEditPart) currentEditPart); - Dimension size = new Dimension(BoundForEditPart.getWidthFromView((Node) previousView), BoundForEditPart.getHeightFromView((Node) previousView)); - size.expand(changeBoundsRequest.getSizeDelta().width * -1, changeBoundsRequest.getSizeDelta().height * -1); - ICommand setBoundsCommand = new SetResizeCommand(editingDomain, "Resize Operands", new EObjectAdapter(previousView), size); - compositeCommand.add(setBoundsCommand); - } - } + updateCurrentChildSize(compositeCommand, changeBoundsRequest, editingDomain, currentEditPart); return new ICommandProxy(compositeCommand); } return null; @@ -184,150 +117,12 @@ public class ResizeOperandEditPolicy extends GraphicalEditPolicy implements Auto Node shapeView = (Node) ((GraphicalEditPart) currentEditPart).getNotationView(); Dimension size = new Dimension(BoundForEditPart.getWidthFromView(shapeView), BoundForEditPart.getHeightFromView(shapeView)); size.expand(changeBoundsRequest.getSizeDelta().width, changeBoundsRequest.getSizeDelta().height); + Point location = new Point(0, ((Bounds) shapeView.getLayoutConstraint()).getY() + changeBoundsRequest.getMoveDelta().y); Rectangle rect = new Rectangle(location, size); + ICommand setBoundsCommand = new SetResizeAndLocationCommand(editingDomain, "Resize Operands", new EObjectAdapter(shapeView), rect); compositeCommand.add(setBoundsCommand); } - /** - * - * @param operandEditPart - * @return true if this the last children of the compartment. - */ - protected boolean istheLastDisplayedOperand(GraphicalEditPart operandEditPart) { - View operandView = operandEditPart.getNotationView(); - int index = ((View) operandView.eContainer()).getChildren().indexOf(operandView); - int listSize = ((View) operandView.eContainer()).getChildren().size(); - return index == listSize - 1; - } - - /** - * - * @param operandEditPart - * @return true if this the first children of the compartment. - */ - protected boolean istheFirstDisplayedOperand(GraphicalEditPart operandEditPart) { - View operandView = operandEditPart.getNotationView(); - int index = ((View) operandView.eContainer()).getChildren().indexOf(operandView); - return index == 0; - } - - /** - * get the next view at the same level at the current editPart - * - * @param operandEditPart - * @return can return null if this the last; - */ - protected View getNextView(GraphicalEditPart operandEditPart) { - View operandView = operandEditPart.getNotationView(); - int index = ((View) operandView.eContainer()).getChildren().indexOf(operandView); - int listSize = ((View) operandView.eContainer()).getChildren().size(); - if (index + 1 < listSize) { - return (View) ((View) operandView.eContainer()).getChildren().get(index + 1); - } - return null; - } - - /** - * get the previous view at the same level at the current editPart - * - * @param operandEditPart - * @return can return null if this the last; - */ - protected View getPreviousView(GraphicalEditPart operandEditPart) { - View operandView = operandEditPart.getNotationView(); - int index = ((View) operandView.eContainer()).getChildren().indexOf(operandView); - if (index - 1 >= 0) { - return (View) ((View) operandView.eContainer()).getChildren().get(index - 1); - } - return null; - } - - /** - * the border effect is to resize the combined fragment - * - * @param changeBoundsRequest - * @return a command to to resize the combinedfragment - */ - protected ICommand getResizeCompartmentCommand(ChangeBoundsRequest changeBoundsRequest) { - TransactionalEditingDomain editingDomain = getEditingDomain(); - Node combinedFragmentNode = (Node) ((GraphicalEditPart) (getHost().getParent())).getNotationView(); - int combinedFragmentHeight = BoundForEditPart.getHeightFromView(combinedFragmentNode); - int newHeight = getComputedCombinedFragmentHeight() + changeBoundsRequest.getSizeDelta().height; - if (newHeight != combinedFragmentHeight) { - return new SetResizeCommand(editingDomain, "Resize Operands", new EObjectAdapter(combinedFragmentNode), new Dimension(BoundForEditPart.getWidthFromView(combinedFragmentNode), newHeight)); - } - return IdentityCommand.INSTANCE; - } - - /** - * the border effect is to move the combined fragment - * - * @param changeBoundsRequest - * @return a command to to resize the combinedfragment - */ - protected ICommand getMoveCompartmentCommand(ChangeBoundsRequest changeBoundsRequest) { - TransactionalEditingDomain editingDomain = getEditingDomain(); - // 1 get all children size - Node combinedFragmentNode = (Node) ((GraphicalEditPart) (getHost().getParent())).getNotationView(); - int newHeight = getComputedCombinedFragmentHeight() + changeBoundsRequest.getSizeDelta().height; - - int combinedFragmentHeight = BoundForEditPart.getHeightFromView(combinedFragmentNode); - Bounds combinedFragmentBound = BoundForEditPart.getBounds(combinedFragmentNode); - int newY = combinedFragmentBound.getY() + changeBoundsRequest.getMoveDelta().y; - - if (newHeight != combinedFragmentHeight) { - return new SetResizeAndLocationCommand(editingDomain, "Resize Operands", new EObjectAdapter(combinedFragmentNode), new Rectangle(combinedFragmentBound.getX(), newY, BoundForEditPart.getWidthFromView(combinedFragmentNode), newHeight)); - } - return IdentityCommand.INSTANCE; - } - - /** - * @see org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener#notifyChanged(org.eclipse.emf.common.notify.Notification) - * - * @param notification - */ - @Override - public void notifyChanged(Notification notification) { - if (notification.getEventType() == Notification.REMOVE && (notification.getNotifier().equals(getHost().getModel()))) { - // 1 get all children size - Node combinedFragmentNode = (Node) ((GraphicalEditPart) (getHost().getParent())).getNotationView(); - int newHeight = getComputedCombinedFragmentHeight(); - int combinedFragmentHeight = BoundForEditPart.getHeightFromView(combinedFragmentNode); - if (newHeight != combinedFragmentHeight) { - execute(new SetResizeCommand(getEditingDomain(), "Resize Operands", new EObjectAdapter(combinedFragmentNode), new Dimension(BoundForEditPart.getWidthFromView(combinedFragmentNode), newHeight))); - } - } - } - - /** - * - * @return the height of the combined fragment by computing the size of interaction operand - */ - protected int getComputedCombinedFragmentHeight() { - double childrenCumulativeHeight = getOperandCumulativeHeight(); - - // add the size of the label - int newHeight = (int) childrenCumulativeHeight + CCombinedFragmentEditPart.DEFAULT_HEIGHT - CInteractionOperandEditPart.DEFAULT_HEIGHT; - // there is a minimum size - if (newHeight < CCombinedFragmentEditPart.DEFAULT_HEIGHT) { - newHeight = CCombinedFragmentEditPart.DEFAULT_HEIGHT; - } - return newHeight; - } - - /** - * @return the Height of all interaction operand inside the compartment - **/ - protected double getOperandCumulativeHeight() { - Node compartmentNode = (Node) ((GraphicalEditPart) (getHost())).getNotationView(); - double childrenCumulativeHeight = 0.0; - for (Iterator<?> iterator = compartmentNode.getChildren().iterator(); iterator.hasNext();) { - Node childView = (Node) iterator.next(); - childrenCumulativeHeight = childrenCumulativeHeight + BoundForEditPart.getHeightFromView(childView); - } - return childrenCumulativeHeight; - } - } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/requests/MoveSeparatorRequest.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/requests/MoveSeparatorRequest.java new file mode 100644 index 00000000000..e9beea66dfa --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/requests/MoveSeparatorRequest.java @@ -0,0 +1,91 @@ +/***************************************************************************** + * Copyright (c) 2018 EclipseSource and others. + * + * 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: + * EclipseSource - Initial API and implementation (Bug 533770) + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.sequence.requests; + +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; + +/** + * <p> + * A request to move the separator between two Operands in a CombinedFragment. + * This should expand one of the Operands, and shrink the other one of the same + * amount. + * </p> + */ +public class MoveSeparatorRequest extends Request { + + public static final String REQ_MOVE_SEPARATOR = "MoveSeparatorRequest"; + private final int separatorIndex; + private Point moveDelta; + private Point location; + private List<? extends EditPart> editParts; + + public MoveSeparatorRequest(int separatorIndex) { + this.separatorIndex = separatorIndex; + } + + @Override + public Object getType() { + return REQ_MOVE_SEPARATOR; + } + + /** + * @return + * The index of the separator being moved + */ + public int getSeparatorIndex() { + return separatorIndex; + } + + /** + * @param moveDelta + */ + public void setMoveDelta(Point moveDelta) { + this.moveDelta = moveDelta; + } + + public Point getMoveDelta() { + return moveDelta; + } + + /** + * @param location + */ + public void setLocation(Point location) { + this.location = location; + } + + /** + * @return the location + */ + public Point getLocation() { + return location; + } + + /** + * @param editParts + */ + public void setEditParts(List<? extends EditPart> editParts) { + this.editParts = editParts; + } + + /** + * @return the editParts + */ + public List<? extends EditPart> getEditParts() { + return editParts; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/tools/SeparatorResizeTracker.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/tools/SeparatorResizeTracker.java new file mode 100644 index 00000000000..f64cb6e446a --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/tools/SeparatorResizeTracker.java @@ -0,0 +1,91 @@ +/***************************************************************************** + * Copyright (c) 2018 EclipseSource and others. + * + * 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: + * EclipseSource - Initial API and implementation (Bug 533770) + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.sequence.tools; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.tools.ResizeTracker; +import org.eclipse.papyrus.uml.diagram.sequence.requests.MoveSeparatorRequest; + +/** + * A special resize tracker for separators in a Swimlanes compartment, + * that can be used to resize elements on both sides of the separator. + */ +public class SeparatorResizeTracker extends ResizeTracker { + + private int separatorIndex; + private List<GraphicalEditPart> ownerChildren; + + /** + * Constructor. + * + * @param owner + * @param direction + */ + public SeparatorResizeTracker(GraphicalEditPart owner, int direction, int separatorIndex) { + super(owner, direction); + assert separatorIndex < ownerChildren.size() - 1; // Make sure the separator has at least one element above, and one below + this.separatorIndex = separatorIndex; + } + + @Override + protected List<EditPart> createOperationSet() { + // The request only applies to the owner of the handle. We don't support multi-selection + return Collections.singletonList(getOwner()); + } + + /** + * @see org.eclipse.gef.tools.ResizeTracker#updateSourceRequest() + * + */ + @Override + protected void updateSourceRequest() { + MoveSeparatorRequest request = (MoveSeparatorRequest) getSourceRequest(); + Dimension d = getDragMoveDelta(); + Point location = new Point(getLocation()); + Point moveDelta = new Point(0, 0); + + moveDelta.y += d.height; + + request.setMoveDelta(moveDelta); + request.setLocation(location); + request.setEditParts(getOperationSet()); + request.getExtendedData().clear(); + + enforceConstraintsForResize(request); + } + + /** + * @param request + */ + private void enforceConstraintsForResize(MoveSeparatorRequest request) { + // TODO Make sure we don't go further than the Owner's bounds, or further than the previous/next separator + } + + /** + * @see org.eclipse.gef.tools.SimpleDragTracker#getSourceRequest() + * + * @return + */ + @Override + protected Request createSourceRequest() { + return new MoveSeparatorRequest(separatorIndex); + } + +} |