diff options
| author | Maxime Porhel | 2015-08-14 14:56:43 +0000 |
|---|---|---|
| committer | Maxime Porhel | 2015-08-21 07:22:37 +0000 |
| commit | 93819d4d6e6f19c039f9e03d3ad9ae37af21be94 (patch) | |
| tree | 19c4b932db7ec93ce46b1f860210f84bfcc3123a | |
| parent | f437a4c8650386125ad2c036e466095c6dc01014 (diff) | |
| download | org.eclipse.sirius-93819d4d6e6f19c039f9e03d3ad9ae37af21be94.tar.gz org.eclipse.sirius-93819d4d6e6f19c039f9e03d3ad9ae37af21be94.tar.xz org.eclipse.sirius-93819d4d6e6f19c039f9e03d3ad9ae37af21be94.zip | |
[472036] Improve Region resize management
. Allow HStack first region resize from left
. Allow VStack first region resize from top
. Introduce RegionRegionContainer edit policy able to handle Regions
which are RegionContainer too.
. Handle recursive regions in resize propagation
. Start homogenization of children adjustment behavior with standard
containers. Manage ChildrenAdjustementCommand to have a similar behavior
than standard containers from a user perspective: adjust border nodes
and edges of RegionContainer but do not adjust regions locations, adjust
region children and border nodes locations. Recursive regions will
treated in further commits.
Bug: 472036
Change-Id: I57620e26844797280fdbd4517655242771cbbaa4
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
11 files changed, 481 insertions, 202 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramElementContainerEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramElementContainerEditPart.java index fb58e85b9a..039bc7bb1d 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramElementContainerEditPart.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramElementContainerEditPart.java @@ -47,6 +47,7 @@ import org.eclipse.gmf.runtime.draw2d.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.LayoutConstraint; import org.eclipse.gmf.runtime.notation.Location; import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.NotationPackage; @@ -89,6 +90,7 @@ import org.eclipse.sirius.diagram.ui.tools.api.layout.LayoutUtils; import org.eclipse.sirius.diagram.ui.tools.internal.figure.ContainerWithTitleBlockFigure; import org.eclipse.sirius.diagram.ui.tools.internal.figure.RegionRoundedGradientRectangle; import org.eclipse.sirius.diagram.ui.tools.internal.figure.RoundedCornerMarginBorder; +import org.eclipse.sirius.diagram.ui.tools.internal.util.NotificationQuery; import org.eclipse.sirius.ext.base.Option; import org.eclipse.sirius.ext.base.Options; import org.eclipse.sirius.viewpoint.DStylizable; @@ -151,6 +153,22 @@ public abstract class AbstractDiagramElementContainerEditPart extends AbstractBo AbstractDiagramNodeEditPartOperation.handleNotificationEvent(this, notification); handleDefaultSizeNotification(notification); + + if (isRegion() && getParent() != null && new NotificationQuery(notification).isNotationLayoutChange()) { + EditPart regionContainer = getParent().getParent(); + if (regionContainer instanceof AbstractDiagramContainerEditPart && shouldRefreshRegionContainerBounds(regionContainer)) { + ((AbstractDiagramContainerEditPart) regionContainer).refreshBounds(); + } + } + } + + private boolean shouldRefreshRegionContainerBounds(EditPart regionContainer) { + Object view = regionContainer.getModel(); + if (view instanceof Node) { + LayoutConstraint lc = ((Node) view).getLayoutConstraint(); + return lc instanceof Size && (((Size) lc).getHeight() == -1 || ((Size) lc).getWidth() == -1); + } + return false; } private void handleDefaultSizeNotification(Notification notification) { @@ -815,8 +833,8 @@ public abstract class AbstractDiagramElementContainerEditPart extends AbstractBo break; } } - final SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "Resize", new EObjectAdapter(graphicalEditPart.getNotationView()), - new Rectangle(position, dimension)); + final SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "Resize", new EObjectAdapter(graphicalEditPart.getNotationView()), new Rectangle(position, + dimension)); cmd = new ICommandProxy(setBoundsCommand); } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirResizableEditPolicy.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirResizableEditPolicy.java index 3d8b7b44ad..c3c40f2728 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirResizableEditPolicy.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirResizableEditPolicy.java @@ -187,25 +187,14 @@ public class AirResizableEditPolicy extends ResizableShapeEditPolicy { result = new ICommandProxy(solution); } } - - // we add a command to keep the edges centered (if they should be) - if (result != null && getHost() instanceof IGraphicalEditPart) { - CenterEditPartEdgesCommand centerEditPartEdgesCommand = new CenterEditPartEdgesCommand((IGraphicalEditPart) getHost(), request); - result = result.chain(new ICommandProxy(centerEditPartEdgesCommand)); - } return result; } /** * Build a specific command from the request that resize the edit part as - * the normal command and change the location of children if needed: - * <UL> - * <LI>border nodes: to avoid an unexpected change of side</LI> - * <LI>children nodes (container or not): The GMF coordinates of these nodes - * are moved in order to keep these nodes at the same location graphically - * (on screen). The GMF coordinates of these nodes are relative to its - * parent.</LI> - * </UL> + * the normal command and call completeResizeCommand to add sub-commands to + * handle children/sibling/parent elements if required. Then add a command + * to keep the edges centered if needed. * * @param request * the resize request @@ -217,11 +206,35 @@ public class AirResizableEditPolicy extends ResizableShapeEditPolicy { if (getHost() instanceof IGraphicalEditPart) { CompositeTransactionalCommand ctc = new CompositeTransactionalCommand(((IGraphicalEditPart) getHost()).getEditingDomain(), cmd.getLabel()); ctc.add(new CommandProxy(cmd)); - ctc.add(new ChildrenAdjustmentCommand((IGraphicalEditPart) getHost(), request)); + completeResizeCommand(ctc, request); + // we add a command to keep the edges centered (if they should be) + ctc.add(new CenterEditPartEdgesCommand((IGraphicalEditPart) getHost(), request)); result = ctc; } else if (cmd != null) { result = new CommandProxy(cmd); } return result; } + + /** + * Add a command to change the location of children if needed: + * <UL> + * <LI>border nodes: to avoid an unexpected change of side</LI> + * <LI>children nodes (container or not): The GMF coordinates of these nodes + * are moved in order to keep these nodes at the same location graphically + * (on screen). The GMF coordinates of these nodes are relative to its + * parent.</LI> + * </UL> + * + * This method can be overridden to add specific resize task to affect + * children, parent or sibling elements. + * + * @param ctc + * the {@link CompositeTransactionalCommand} to complete. + * @param request + * the initial request. + * */ + protected void completeResizeCommand(CompositeTransactionalCommand ctc, ChangeBoundsRequest request) { + ctc.add(new ChildrenAdjustmentCommand((IGraphicalEditPart) getHost(), request)); + } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirXYLayoutEditPolicy.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirXYLayoutEditPolicy.java index 6d7f735cd6..dc911853d8 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirXYLayoutEditPolicy.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/AirXYLayoutEditPolicy.java @@ -225,12 +225,19 @@ public class AirXYLayoutEditPolicy extends XYLayoutEditPolicy { EditPolicy childEditPolicy = new AirResizableEditPolicy(); if (isRegionContainerCompartment(getHost())) { + if (isRegionContainer(child)) { + /* + * If the added child is a region and a region container. + */ + childEditPolicy = new RegionRegionContainerResizableEditPolicy(); + } else { /* * If the current element is a region container, each added child * will be considered as a region and will receive the expected * resizable edit policy. */ childEditPolicy = new RegionResizableEditPolicy(); + } } else if (isRegionContainer(child)) { /* If the added element is a region container. */ childEditPolicy = new RegionContainerResizableEditPolicy(); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/RegionContainerResizableEditPolicy.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/RegionContainerResizableEditPolicy.java index 251951bff9..4fd8be0488 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/RegionContainerResizableEditPolicy.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/RegionContainerResizableEditPolicy.java @@ -21,10 +21,11 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gef.EditPart; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; -import org.eclipse.gef.commands.UnexecutableCommand; import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand; import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy; import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.sirius.diagram.DDiagramElement; @@ -33,6 +34,7 @@ import org.eclipse.sirius.diagram.business.internal.query.DNodeContainerExperime import org.eclipse.sirius.diagram.ui.business.internal.query.RequestQuery; import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramElementContainerEditPart; import org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart; +import org.eclipse.sirius.diagram.ui.internal.edit.commands.ChildrenAdjustmentCommand; import org.eclipse.sirius.diagram.ui.internal.edit.parts.AbstractDNodeContainerCompartmentEditPart; import org.eclipse.sirius.diagram.ui.internal.operation.RegionContainerUpdateLayoutOperation; import org.eclipse.sirius.diagram.ui.tools.internal.edit.command.CommandFactory; @@ -55,80 +57,93 @@ public class RegionContainerResizableEditPolicy extends AirResizableEditPolicy { protected static final String REGION_AUTO_SIZE_PROPAGATOR = "region_auto-size_propagator"; //$NON-NLS-1$ /** - * {@inheritDoc} + * Key to store the part responsible for resize propagation. */ + protected static final String REGION_RESIZE_PROPAGATOR = "region_resize_propagator"; + + /** + * Key to store the initial request for resize propragation. + */ + protected static final String REGION_RESIZE_INITIAL_REQUEST = "region_resize_initial_request"; + @Override protected Command getAutoSizeCommand(Request request) { Command autoSizeCommand = super.getAutoSizeCommand(request); if (concernRegionContainer()) { - IDiagramElementEditPart host = (IDiagramElementEditPart) getHost(); - TransactionalEditingDomain domain = host.getEditingDomain(); - CompositeTransactionalCommand ctc = new CompositeTransactionalCommand(domain, "Region Container Auto Size Command"); - ctc.add(new CommandProxy(autoSizeCommand)); - autoSizeCommand = new ICommandProxy(ctc); - - // Propagate the auto-size request to the regions. - Request req = new Request(); - req.setType(request.getType()); - req.getExtendedData().put(REGION_AUTO_SIZE_PROPAGATOR, getHost()); - - Object object = request.getExtendedData().get(REGION_AUTO_SIZE_PROPAGATOR); - for (EditPart regionPart : getRegionParts()) { - if (object != regionPart) { - ctc.add(new CommandProxy(regionPart.getCommand(req))); - } - } - - ctc.add(CommandFactory.createICommand(domain, new RegionContainerUpdateLayoutOperation((Node) host.getModel()))); + autoSizeCommand = getRegionContainerAutoSizeCommand(request, autoSizeCommand); } return autoSizeCommand; } /** - * {@inheritDoc} + * Returns a composite command with the given initial command and the + * RegionContainer specific auto-size commands to propagate the auto-size to + * the regions. + * + * @param request + * the initial request + * @param autoSizeCommand + * the initial command + * @return a composite command with the initial command and the region + * container specific additional commands. */ - @Override - protected Command getResizeCommand(ChangeBoundsRequest request) { - Command resizeCommand = super.getResizeCommand(request); - if (concernRegionContainer()) { - resizeCommand = getRegionContainerResizeCommand(request, resizeCommand); + protected Command getRegionContainerAutoSizeCommand(Request request, Command autoSizeCommand) { + IDiagramElementEditPart host = (IDiagramElementEditPart) getHost(); + TransactionalEditingDomain domain = host.getEditingDomain(); + CompositeTransactionalCommand ctc = new CompositeTransactionalCommand(domain, "Region Container Auto Size Command"); + ctc.add(new CommandProxy(autoSizeCommand)); + Command regionContainerAutoSizeCommand = new ICommandProxy(ctc); + + // Propagate the auto-size request to the regions. + Request req = new Request(); + req.setType(request.getType()); + req.getExtendedData().put(REGION_AUTO_SIZE_PROPAGATOR, host); + + Object object = request.getExtendedData().get(REGION_AUTO_SIZE_PROPAGATOR); + for (EditPart regionPart : getRegionParts()) { + if (object != regionPart) { + ctc.add(new CommandProxy(regionPart.getCommand(req))); + } } - return resizeCommand; + + ctc.add(CommandFactory.createICommand(domain, new RegionContainerUpdateLayoutOperation((Node) host.getModel()))); + return regionContainerAutoSizeCommand; } - private Command getRegionContainerResizeCommand(ChangeBoundsRequest request, Command command) { - if (request.getEditParts().size() > 1) { - return UnexecutableCommand.INSTANCE; + /** + * Complete the given composite command with RegionContainer specific resize + * commands: the commands to report the RegionContainer resize on its + * regions. + */ + @Override + protected void completeResizeCommand(CompositeTransactionalCommand ctc, ChangeBoundsRequest request) { + if (request.getEditParts().size() > 1 && !request.isConstrainedResize()) { + ctc.add(UnexecutableCommand.INSTANCE); + return; } - Command regionsResizeCommand = command; Collection<ChangeBoundsRequest> siblingRequests = getConstrainedRegionRequests(request); if (!siblingRequests.isEmpty()) { - String name = "Region Container Resize Composite Command"; - CompositeTransactionalCommand ctc = new CompositeTransactionalCommand(((IDiagramElementEditPart) getHost()).getEditingDomain(), name); - ctc.add(new CommandProxy(command)); - regionsResizeCommand = new ICommandProxy(ctc); - for (ChangeBoundsRequest siblingRequest : siblingRequests) { if (siblingRequest.getEditParts() != null) { - for (EditPart constrainedPart : Iterables.filter(siblingRequest.getEditParts(), EditPart.class)) { + for (IGraphicalEditPart constrainedPart : Iterables.filter(siblingRequest.getEditParts(), IGraphicalEditPart.class)) { Command constrainedCommand = constrainedPart.getCommand(siblingRequest); - if (constrainedCommand == null) { - constrainedCommand = UnexecutableCommand.INSTANCE; + ctc.add(UnexecutableCommand.INSTANCE); + } else { + ctc.add(new CommandProxy(constrainedCommand)); } - - ctc.add(new CommandProxy(constrainedCommand)); } } } } else if (!(request.isConstrainedMove() || request.isConstrainedResize())) { - // Deactivate the manual resize of RegionCotnainer when there are no + // Deactivate the manual resize of RegionContainer when there are no // regions. - regionsResizeCommand = UnexecutableCommand.INSTANCE; + ctc.add(UnexecutableCommand.INSTANCE); } - return regionsResizeCommand; + // Adjust border nodes and edges. + ctc.add(new ChildrenAdjustmentCommand((IGraphicalEditPart) getHost(), request, true, false)); } private Collection<ChangeBoundsRequest> getConstrainedRegionRequests(ChangeBoundsRequest request) { @@ -141,17 +156,18 @@ public class RegionContainerResizableEditPolicy extends AirResizableEditPolicy { List<AbstractDiagramElementContainerEditPart> regionToResize = getRegionParts(); int stackDirection = getStackDirection(); // Handle first and last regions. + Object resizePropagator = request.getExtendedData().get(REGION_RESIZE_PROPAGATOR); if (query.isResizeFromTop() && stackDirection == PositionConstants.NORTH_SOUTH || query.isResizeFromLeft() && stackDirection == PositionConstants.EAST_WEST) { Option<AbstractDiagramElementContainerEditPart> firstRegionPart = getFirstRegionPart(); - if (firstRegionPart.some() && !request.isConstrainedResize()) { + if (firstRegionPart.some() && (!request.isConstrainedResize() || resizePropagator != firstRegionPart.get())) { ChangeBoundsRequest req = initConstrainedRequest(request); req.setEditParts(firstRegionPart.get()); req.setSizeDelta(sizeDelta.getCopy()); constrainedRequests.add(req); - regionToResize.remove(firstRegionPart.get()); } // shift all other regions. - if (!regionToResize.isEmpty() && !request.isConstrainedResize()) { + regionToResize.remove(firstRegionPart.get()); + if (!regionToResize.isEmpty() && (!request.isConstrainedResize() || !regionToResize.contains(resizePropagator))) { ChangeBoundsRequest req = initConstrainedRequest(request); req.setEditParts(Lists.newArrayList(regionToResize)); @@ -168,7 +184,7 @@ public class RegionContainerResizableEditPolicy extends AirResizableEditPolicy { } else if (query.isResizeFromBottom() && stackDirection == PositionConstants.NORTH_SOUTH || query.isResizeFromRight() && stackDirection == PositionConstants.EAST_WEST) { // Resize the last region. Option<AbstractDiagramElementContainerEditPart> lastRegionPart = getLastRegionPart(); - if (lastRegionPart.some() && !request.isConstrainedResize()) { + if (lastRegionPart.some() && (!request.isConstrainedResize() || resizePropagator != lastRegionPart.get())) { ChangeBoundsRequest req = initConstrainedRequest(request); req.setEditParts(lastRegionPart.get()); req.setSizeDelta(sizeDelta.getCopy()); @@ -178,15 +194,16 @@ public class RegionContainerResizableEditPolicy extends AirResizableEditPolicy { } // Handle horizontal resize for vstacks and vertical resize for hstacks. - if (stackDirection == PositionConstants.NORTH_SOUTH && (query.isResizeFromLeft() || query.isResizeFromRight())) { - if (!regionToResize.isEmpty() && !request.isConstrainedResize()) { + if (request.isConstrainedResize() && resizePropagator != null) { + regionToResize.remove(resizePropagator); + } + if (!regionToResize.isEmpty()) { + if (stackDirection == PositionConstants.NORTH_SOUTH && (query.isResizeFromLeft() || query.isResizeFromRight()) && sizeDelta.width != 0) { ChangeBoundsRequest req = initConstrainedRequest(request); req.setEditParts(Lists.newArrayList(regionToResize)); req.setSizeDelta(new Dimension(sizeDelta.width, 0)); constrainedRequests.add(req); - } - } else if (stackDirection == PositionConstants.EAST_WEST && (query.isResizeFromTop() || query.isResizeFromBottom())) { - if (!regionToResize.isEmpty() && !request.isConstrainedResize()) { + } else if (stackDirection == PositionConstants.EAST_WEST && (query.isResizeFromTop() || query.isResizeFromBottom()) && sizeDelta.height != 0) { ChangeBoundsRequest req = initConstrainedRequest(request); req.setEditParts(Lists.newArrayList(regionToResize)); req.setSizeDelta(new Dimension(0, sizeDelta.height)); @@ -203,6 +220,9 @@ public class RegionContainerResizableEditPolicy extends AirResizableEditPolicy { req.setConstrainedMove(true); req.setType(request.getType()); req.setResizeDirection(request.getResizeDirection()); + req.getExtendedData().put(REGION_RESIZE_PROPAGATOR, getHost()); + req.getExtendedData().put(SiriusResizeTracker.CHILDREN_MOVE_MODE_KEY, request.getExtendedData().get(SiriusResizeTracker.CHILDREN_MOVE_MODE_KEY)); + req.getExtendedData().put(REGION_RESIZE_INITIAL_REQUEST, request); return req; } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/RegionRegionContainerResizableEditPolicy.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/RegionRegionContainerResizableEditPolicy.java new file mode 100644 index 0000000000..ba828cbce3 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/RegionRegionContainerResizableEditPolicy.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.graphical.edit.policies; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; +import org.eclipse.sirius.ext.base.Option; +import org.eclipse.sirius.ext.base.Options; + +/** + * A {@link AirResizableEditPolicy} able to handle containers which are both a + * Region and a RegionContainer. + * + * @author mporhel + */ +public class RegionRegionContainerResizableEditPolicy extends RegionResizableEditPolicy { + + private final RegionContainerResizableEditPolicy regionContainerPolicy = new RegionContainerResizableEditPolicy(); + + @Override + public void setHost(EditPart host) { + super.setHost(host); + regionContainerPolicy.setHost(host); + } + + @Override + protected void completeResizeCommand(CompositeTransactionalCommand ctc, ChangeBoundsRequest request) { + super.completeResizeCommand(ctc, request); + regionContainerPolicy.completeResizeCommand(ctc, request); + } + + /** + * Let the region container policy create the adjust children command. + */ + @Override + protected Option<ChangeBoundsRequest> getAdjustChildrenRequest(ChangeBoundsRequest request) { + return Options.newNone(); + } + + @Override + protected Command getAutoSizeCommand(Request request) { + Command autoSizeCommand = super.getAutoSizeCommand(request); + autoSizeCommand = regionContainerPolicy.getRegionContainerAutoSizeCommand(request, autoSizeCommand); + return autoSizeCommand; + } +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/RegionResizableEditPolicy.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/RegionResizableEditPolicy.java index ac5603a5aa..0d380b27b0 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/RegionResizableEditPolicy.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/RegionResizableEditPolicy.java @@ -21,7 +21,6 @@ import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.gef.EditPart; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; -import org.eclipse.gef.commands.CompoundCommand; import org.eclipse.gef.commands.UnexecutableCommand; import org.eclipse.gef.requests.AlignmentRequest; import org.eclipse.gef.requests.ChangeBoundsRequest; @@ -77,9 +76,6 @@ public class RegionResizableEditPolicy extends AirResizableEditPolicy { } } - /** - * {@inheritDoc} - */ @Override protected Command getMoveCommand(final ChangeBoundsRequest request) { if (concernRegion()) { @@ -89,21 +85,6 @@ public class RegionResizableEditPolicy extends AirResizableEditPolicy { return super.getMoveCommand(request); } - /** - * {@inheritDoc} - */ - @Override - protected Command getResizeCommand(ChangeBoundsRequest request) { - Command resizeCommand = super.getResizeCommand(request); - if (concernRegion()) { - resizeCommand = getRegionResizeCommand(request, resizeCommand); - } - return resizeCommand; - } - - /** - * {@inheritDoc} - */ @Override protected Command getAlignCommand(AlignmentRequest request) { if (concernRegion()) { @@ -112,9 +93,6 @@ public class RegionResizableEditPolicy extends AirResizableEditPolicy { return super.getAlignCommand(request); } - /** - * {@inheritDoc} - */ @Override protected Command getAutoSizeCommand(Request request) { Command autoSizeCommand = super.getAutoSizeCommand(request); @@ -129,18 +107,18 @@ public class RegionResizableEditPolicy extends AirResizableEditPolicy { req.setType(request.getType()); req.getExtendedData().put(RegionContainerResizableEditPolicy.REGION_AUTO_SIZE_PROPAGATOR, getHost()); - CompoundCommand cc = new CompoundCommand(); - cc.add(autoSizeCommand); - cc.add(regionContainerPart.getCommand(req)); - autoSizeCommand = cc; + Command regionContainerAutoSizeCommand = regionContainerPart.getCommand(req); + if (getHost() instanceof IDiagramElementEditPart && regionContainerAutoSizeCommand != null) { + CompositeTransactionalCommand ctc = new CompositeTransactionalCommand(((IDiagramElementEditPart) getHost()).getEditingDomain(), "Region Auto Size Composite Command"); + ctc.add(new CommandProxy(autoSizeCommand)); + ctc.add(new CommandProxy(regionContainerAutoSizeCommand)); + autoSizeCommand = new ICommandProxy(ctc); + } } } return autoSizeCommand; } - /** - * {@inheritDoc} - */ @Override protected void showChangeBoundsFeedback(ChangeBoundsRequest request) { super.showChangeBoundsFeedback(request); @@ -154,9 +132,6 @@ public class RegionResizableEditPolicy extends AirResizableEditPolicy { } } - /** - * {@inheritDoc} - */ @Override protected void eraseChangeBoundsFeedback(ChangeBoundsRequest request) { super.eraseChangeBoundsFeedback(request); @@ -170,22 +145,80 @@ public class RegionResizableEditPolicy extends AirResizableEditPolicy { } } - private Command getRegionResizeCommand(ChangeBoundsRequest request, Command command) { + @Override + protected Command getResizeCommand(ChangeBoundsRequest request) { + if (isFirstRegionPart()) { + request.getMoveDelta().setX(0); + request.getMoveDelta().setY(0); + } else if (getStackDirection() == PositionConstants.EAST_WEST) { + request.getMoveDelta().setY(0); + } + return super.getResizeCommand(request); + } + + /** + * Complete the given composite command with Region specific resize + * commands: the commands to report the resize on the RegionContainer or on + * the sibling regions. + */ + @Override + protected void completeResizeCommand(CompositeTransactionalCommand ctc, ChangeBoundsRequest request) { boolean invalidRequest = request.getEditParts().size() > 1 && !request.isConstrainedResize() || request.isCenteredResize(); if (invalidRequest || !validateResize(request)) { - return UnexecutableCommand.INSTANCE; + ctc.add(org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE); } - Command regionResizeCommand = command; Option<ChangeBoundsRequest> siblingRequest = getConstrainedSiblingRequest(request); if (siblingRequest.some() && siblingRequest.get().getEditParts() != null && siblingRequest.get().getEditParts().size() == 1) { EditPart siblingPart = (EditPart) siblingRequest.get().getEditParts().get(0); - regionResizeCommand = composeCommands(command, siblingPart.getCommand(siblingRequest.get())); + ctc.add(new CommandProxy(siblingPart.getCommand(siblingRequest.get()))); } else if (!(request.isConstrainedMove() || request.isConstrainedResize())) { - regionResizeCommand = UnexecutableCommand.INSTANCE; + ctc.add(org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE); + } + + Option<ChangeBoundsRequest> adjustChildrenRequest = getAdjustChildrenRequest(request); + if (adjustChildrenRequest.some()) { + super.completeResizeCommand(ctc, adjustChildrenRequest.get()); } + } - return regionResizeCommand; + /** + * Return true to add the default {@link AirResizableEditPolicy} behavior in + * completeResizeCommand: this will add the sub commands to adjust children + * position: see + * {@link org.eclipse.sirius.diagram.ui.internal.edit.commands.ChildrenAdjustmentCommand} + * . + * + * @param request + * the current change bounds request. + * @return true to add the default {@link AirResizableEditPolicy} behavior. + */ + protected Option<ChangeBoundsRequest> getAdjustChildrenRequest(ChangeBoundsRequest request) { + ChangeBoundsRequest requestToCompensate = null; + RequestQuery requestQuery = new RequestQuery(request); + if (request.getExtendedData().get(RegionContainerResizableEditPolicy.REGION_RESIZE_PROPAGATOR) == getRegionContainerPart()) { + Object object = request.getExtendedData().get(RegionContainerResizableEditPolicy.REGION_RESIZE_INITIAL_REQUEST); + int stackDirection = getStackDirection(); + boolean needsAdjust = false; + if (stackDirection == PositionConstants.NORTH_SOUTH) { + needsAdjust = requestQuery.isResizeFromLeft() || requestQuery.isResizeFromRight() || requestQuery.isResizeFromTop() && isFirstRegionPart(); + } else if (stackDirection == PositionConstants.EAST_WEST) { + needsAdjust = requestQuery.isResizeFromTop() || requestQuery.isResizeFromBottom() || requestQuery.isResizeFromLeft() && isFirstRegionPart(); + } + if (needsAdjust && object instanceof ChangeBoundsRequest) { + requestToCompensate = (ChangeBoundsRequest) object; + } + } else { + if (isFirstRegionPart() && (requestQuery.isResizeFromLeft() || requestQuery.isResizeFromTop())) { + // The move part has been canceled for the concrete resize of + // the region, because the move will be done on the region + // container but we need to compensate the move on the children. + Dimension delta = request.getSizeDelta().getNegated(); + request.setMoveDelta(new Point(delta.width, delta.height)); + } + requestToCompensate = request; + } + return Options.newSome(requestToCompensate); } private boolean validateResize(ChangeBoundsRequest request) { @@ -199,83 +232,164 @@ public class RegionResizableEditPolicy extends AirResizableEditPolicy { } private Option<ChangeBoundsRequest> getConstrainedSiblingRequest(ChangeBoundsRequest request) { - ChangeBoundsRequest constrainedRequest = null; + Option<ChangeBoundsRequest> constrainedRequest = Options.newNone(); RequestQuery query = new RequestQuery(request); Dimension sizeDelta = request.getSizeDelta().getCopy(); - ChangeBoundsRequest req = new ChangeBoundsRequest(); - req.setConstrainedResize(true); - req.setConstrainedMove(true); - req.setType(request.getType()); - int stackDirection = getStackDirection(); if (stackDirection == PositionConstants.NORTH_SOUTH) { - if (query.isResizeFromTop()) { - if (!isFirstRegionPart() && !request.isConstrainedResize()) { - Option<AbstractDiagramElementContainerEditPart> pred = getPrecedingRegion(); - if (pred.some()) { - req.setEditParts(pred.get()); - req.setResizeDirection(PositionConstants.SOUTH); - req.setSizeDelta(new Dimension(0, sizeDelta.getNegated().height)); - constrainedRequest = req; - } + constrainedRequest = Options.newSome(getVStackConstrainedSiblingRequest(request, query, sizeDelta)); + } else if (stackDirection == PositionConstants.EAST_WEST) { + constrainedRequest = Options.newSome(getHStackConstrainedSiblingRequest(request, query, sizeDelta)); + } + return constrainedRequest; + } + + private ChangeBoundsRequest getVStackConstrainedSiblingRequest(ChangeBoundsRequest request, RequestQuery query, Dimension sizeDelta) { + ChangeBoundsRequest constrainedRequest = null; + ChangeBoundsRequest req = initSiblingRequest(request); + + if (query.isResizeFromTop()) { + EditPart regionContainer = getRegionContainerPart(); + if (isFirstRegionPart()) { + if (!request.isConstrainedResize() || request.getExtendedData().get(RegionContainerResizableEditPolicy.REGION_RESIZE_PROPAGATOR) != regionContainer) { + // resize regioncontainer. + req.setEditParts(regionContainer); + req.setResizeDirection(request.getResizeDirection()); + req.setSizeDelta(new Dimension(0, sizeDelta.height)); + req.setMoveDelta(new Point(0, -sizeDelta.height)); + constrainedRequest = req; + } + } else { + Option<AbstractDiagramElementContainerEditPart> pred = getPrecedingRegion(); + if (pred.some() && !request.isConstrainedResize()) { + req.setEditParts(pred.get()); + req.setResizeDirection(PositionConstants.SOUTH); + req.setSizeDelta(new Dimension(0, sizeDelta.getNegated().height)); + constrainedRequest = req; } - } else if (query.isResizeFromBottom()) { - if (isLastRegionPart() && !request.isConstrainedResize()) { + } + } else if (query.isResizeFromBottom()) { + EditPart regionContainer = getRegionContainerPart(); + if (isLastRegionPart()) { + if (!request.isConstrainedResize() || request.getExtendedData().get(RegionContainerResizableEditPolicy.REGION_RESIZE_PROPAGATOR) != regionContainer) { // resize regioncontainer. - EditPart regionContainer = getRegionContainerPart(); req.setEditParts(regionContainer); req.setResizeDirection(request.getResizeDirection()); req.setSizeDelta(new Dimension(0, sizeDelta.height)); constrainedRequest = req; - } else if (!request.isConstrainedResize()) { - Option<AbstractDiagramElementContainerEditPart> follo = getFollowingRegion(); - if (follo != null) { - Point moveDelta = new Point(sizeDelta.width, sizeDelta.height); - - req.setEditParts(follo.get()); - req.setResizeDirection(PositionConstants.NORTH); - req.setSizeDelta(new Dimension(0, sizeDelta.getNegated().height)); - req.setMoveDelta(new Point(0, moveDelta.y)); - constrainedRequest = req; - } + } + } else { + Option<AbstractDiagramElementContainerEditPart> follo = getFollowingRegion(); + if (follo.some() && !request.isConstrainedResize()) { + Point moveDelta = new Point(sizeDelta.width, sizeDelta.height); + req.setEditParts(follo.get()); + req.setResizeDirection(PositionConstants.NORTH); + req.setSizeDelta(new Dimension(0, sizeDelta.getNegated().height)); + req.setMoveDelta(new Point(0, moveDelta.y)); + constrainedRequest = req; } } - } else if (stackDirection == PositionConstants.EAST_WEST) { - if (query.isResizeFromLeft()) { - if (!isFirstRegionPart() && !request.isConstrainedResize()) { - Option<AbstractDiagramElementContainerEditPart> pred = getPrecedingRegion(); - if (pred.some()) { - req.setEditParts(pred.get()); - req.setResizeDirection(PositionConstants.EAST); - req.setSizeDelta(new Dimension(sizeDelta.getNegated().width, 0)); - constrainedRequest = req; - } + } else if (query.isResizeFromRight()) { + EditPart regionContainer = getRegionContainerPart(); + if (!request.isConstrainedResize() || request.getExtendedData().get(RegionContainerResizableEditPolicy.REGION_RESIZE_PROPAGATOR) != regionContainer) { + // resize regioncontainer. + req.setEditParts(regionContainer); + req.setResizeDirection(request.getResizeDirection()); + req.setSizeDelta(new Dimension(sizeDelta.width, 0)); + constrainedRequest = req; + } + } else if (query.isResizeFromLeft()) { + EditPart regionContainer = getRegionContainerPart(); + if (!request.isConstrainedResize() || request.getExtendedData().get(RegionContainerResizableEditPolicy.REGION_RESIZE_PROPAGATOR) != regionContainer) { + // resize regioncontainer. + req.setEditParts(regionContainer); + req.setResizeDirection(request.getResizeDirection()); + req.setSizeDelta(new Dimension(sizeDelta.width, 0)); + req.setMoveDelta(new Point(-sizeDelta.width, 0)); + constrainedRequest = req; + } + + } + return constrainedRequest; + } + + private ChangeBoundsRequest getHStackConstrainedSiblingRequest(ChangeBoundsRequest request, RequestQuery query, Dimension sizeDelta) { + ChangeBoundsRequest constrainedRequest = null; + ChangeBoundsRequest req = initSiblingRequest(request); + + if (query.isResizeFromLeft()) { + EditPart regionContainer = getRegionContainerPart(); + if (isFirstRegionPart()) { + if (!request.isConstrainedResize() || request.getExtendedData().get(RegionContainerResizableEditPolicy.REGION_RESIZE_PROPAGATOR) != regionContainer) { + // resize regioncontainer. + req.setEditParts(regionContainer); + req.setResizeDirection(request.getResizeDirection()); + req.setSizeDelta(new Dimension(sizeDelta.width, 0)); + req.setMoveDelta(new Point(-sizeDelta.width, 0)); + constrainedRequest = req; + } + } else { + Option<AbstractDiagramElementContainerEditPart> pred = getPrecedingRegion(); + if (pred.some() && !request.isConstrainedResize()) { + req.setEditParts(pred.get()); + req.setResizeDirection(PositionConstants.EAST); + req.setSizeDelta(new Dimension(sizeDelta.getNegated().width, 0)); + constrainedRequest = req; } - } else if (query.isResizeFromRight()) { - if (isLastRegionPart() && !request.isConstrainedResize()) { + } + } else if (query.isResizeFromRight()) { + if (isLastRegionPart()) { + EditPart regionContainer = getRegionContainerPart(); + if (!request.isConstrainedResize() || request.getExtendedData().get(RegionContainerResizableEditPolicy.REGION_RESIZE_PROPAGATOR) != regionContainer) { // resize regioncontainer. - EditPart regionContainer = getRegionContainerPart(); req.setEditParts(regionContainer); req.setResizeDirection(request.getResizeDirection()); req.setSizeDelta(new Dimension(sizeDelta.width, 0)); constrainedRequest = req; - } else if (!request.isConstrainedResize()) { - Option<AbstractDiagramElementContainerEditPart> follo = getFollowingRegion(); - if (follo != null) { - Point moveDelta = new Point(sizeDelta.width, sizeDelta.height); - - req.setEditParts(follo.get()); - req.setResizeDirection(PositionConstants.LEFT); - req.setSizeDelta(new Dimension(sizeDelta.getNegated().width, 0)); - req.setMoveDelta(new Point(moveDelta.x, 0)); - constrainedRequest = req; - } } + } else { + Option<AbstractDiagramElementContainerEditPart> follo = getFollowingRegion(); + if (follo.some() && !request.isConstrainedResize()) { + req.setEditParts(follo.get()); + req.setResizeDirection(PositionConstants.WEST); + req.setSizeDelta(new Dimension(-sizeDelta.width, 0)); + req.setMoveDelta(new Point(sizeDelta.width, 0)); + constrainedRequest = req; + } + } + } else if (query.isResizeFromBottom()) { + EditPart regionContainer = getRegionContainerPart(); + if (!request.isConstrainedResize() || request.getExtendedData().get(RegionContainerResizableEditPolicy.REGION_RESIZE_PROPAGATOR) != regionContainer) { + // resize regioncontainer. + req.setEditParts(regionContainer); + req.setResizeDirection(request.getResizeDirection()); + req.setSizeDelta(new Dimension(0, sizeDelta.height)); + constrainedRequest = req; + } + } else if (query.isResizeFromTop()) { + EditPart regionContainer = getRegionContainerPart(); + if (!request.isConstrainedResize() || request.getExtendedData().get(RegionContainerResizableEditPolicy.REGION_RESIZE_PROPAGATOR) != regionContainer) { + // resize regioncontainer. + req.setEditParts(regionContainer); + req.setSizeDelta(new Dimension(0, sizeDelta.height)); + req.setMoveDelta(new Point(0, -sizeDelta.height)); + constrainedRequest = req; } } - return Options.newSome(constrainedRequest); + return constrainedRequest; + } + + private ChangeBoundsRequest initSiblingRequest(ChangeBoundsRequest request) { + ChangeBoundsRequest req = new ChangeBoundsRequest(); + req.setConstrainedResize(true); + req.setConstrainedMove(true); + req.setType(request.getType()); + req.getExtendedData().put(RegionContainerResizableEditPolicy.REGION_RESIZE_PROPAGATOR, getHost()); + req.getExtendedData().put(SiriusResizeTracker.CHILDREN_MOVE_MODE_KEY, request.getExtendedData().get(SiriusResizeTracker.CHILDREN_MOVE_MODE_KEY)); + req.getExtendedData().put(RegionContainerResizableEditPolicy.REGION_RESIZE_INITIAL_REQUEST, request); + return req; } private EditPart getRegionContainerPart() { @@ -286,17 +400,6 @@ public class RegionResizableEditPolicy extends AirResizableEditPolicy { return regionContainer; } - private Command composeCommands(Command initialcommand, Command constrainedCommand) { - Command regionResizeCommand = UnexecutableCommand.INSTANCE; - if (getHost() instanceof IDiagramElementEditPart && constrainedCommand != null) { - CompositeTransactionalCommand ctc = new CompositeTransactionalCommand(((IDiagramElementEditPart) getHost()).getEditingDomain(), "Region Resize Composite Command"); - ctc.add(new CommandProxy(initialcommand)); - ctc.add(new CommandProxy(constrainedCommand)); - regionResizeCommand = new ICommandProxy(ctc); - } - return regionResizeCommand; - } - private Option<AbstractDiagramElementContainerEditPart> getPrecedingRegion() { List<AbstractDiagramElementContainerEditPart> siblingRegions = getSiblingRegionPart(); int precedingIndex = siblingRegions.indexOf(getHost()) - 1; diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/ChildrenAdjustmentCommand.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/ChildrenAdjustmentCommand.java index f630d9e08a..bac3d614ee 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/ChildrenAdjustmentCommand.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/ChildrenAdjustmentCommand.java @@ -59,20 +59,42 @@ public class ChildrenAdjustmentCommand extends AbstractTransactionalCommand { ChangeBoundsRequest request; + private boolean adjustBorderNodes; + + private boolean adjustSubNodes; + /** * Default constructor. * * @param host * the <i>host</i> EditPart on which this policy is installed. - * @param moveDelta - * The move delta - * @param movedEditParts - * Selected edit parts that will be moved + * @param request + * the initial change bounds request */ public ChildrenAdjustmentCommand(IGraphicalEditPart host, ChangeBoundsRequest request) { + this(host, request, true, true); + } + + /** + * Default constructor. + * + * @param host + * the <i>host</i> EditPart on which this policy is installed. + * @param request + * the initial change bounds request + * @param borderNodes + * true to adjust border nodes positions + * @param subNodes + * true to adjust sub nodes positions (Containers and Nodes in + * the content pane) + */ + public ChildrenAdjustmentCommand(IGraphicalEditPart host, ChangeBoundsRequest request, boolean borderNodes, boolean subNodes) { super(host.getEditingDomain(), "Adapt children location", null); this.host = host; this.request = request; + this.adjustBorderNodes = borderNodes; + this.adjustSubNodes = subNodes; + } @Override @@ -86,7 +108,7 @@ public class ChildrenAdjustmentCommand extends AbstractTransactionalCommand { Object childrenMoveModeExtendedData = request.getExtendedData().get(SiriusResizeTracker.CHILDREN_MOVE_MODE_KEY); keepSameAbsoluteLocation = (childrenMoveModeExtendedData == null && SiriusResizeTracker.DEFAULT_CHILDREN_MOVE_MODE) || (childrenMoveModeExtendedData != null && ((Boolean) childrenMoveModeExtendedData).booleanValue()); - if (keepSameAbsoluteLocation) { + if (keepSameAbsoluteLocation && adjustSubNodes) { addChildrenAdjustmentCommands(host, wrappedCommand, request); } else { // Children have been indirectly moved so their edges must @@ -95,7 +117,7 @@ public class ChildrenAdjustmentCommand extends AbstractTransactionalCommand { } } - if (host instanceof IBorderedShapeEditPart) { + if (host instanceof IBorderedShapeEditPart && adjustBorderNodes) { addBorderChildrenAdjustmentCommands(host, wrappedCommand, request, keepSameAbsoluteLocation); } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/diagram/DDiagramCanonicalSynchronizer.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/diagram/DDiagramCanonicalSynchronizer.java index b2d742f26f..8238cbe012 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/diagram/DDiagramCanonicalSynchronizer.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/diagram/DDiagramCanonicalSynchronizer.java @@ -18,6 +18,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.ListIterator; import java.util.Map; import java.util.Set; @@ -58,6 +59,7 @@ import org.eclipse.sirius.viewpoint.description.AnnotationEntry; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; import com.google.common.collect.Sets; /** @@ -99,6 +101,7 @@ public class DDiagramCanonicalSynchronizer extends AbstractCanonicalSynchronizer * * @see org.eclipse.sirius.diagram.business.api.refresh.view.refresh.CanonicalSynchronizer#synchronize() */ + @Override public void synchronize() { refreshSemantic(); } @@ -125,19 +128,27 @@ public class DDiagramCanonicalSynchronizer extends AbstractCanonicalSynchronizer } private void manageRegions() { - for (View regionContainer : regionContainersToLayout) { + if (regionContainersToLayout.isEmpty()) { + return; + } + + // Step 1: update regions layout from the deepest ones. + List<View> newArrayList = Lists.newArrayList(regionContainersToLayout); + ListIterator<View> regionToLayoutListIterator = newArrayList.listIterator(newArrayList.size() - 1); + while (regionToLayoutListIterator.hasPrevious()) { + View regionContainer = regionToLayoutListIterator.previous(); int type = SiriusVisualIDRegistry.getVisualID(regionContainer.getType()); if (regionContainer instanceof Node && (type == DNodeContainerEditPart.VISUAL_ID || type == DNodeContainer2EditPart.VISUAL_ID)) { new RegionContainerUpdateLayoutOperation((Node) regionContainer).execute(); } } - regionContainersToLayout.clear(); } private void manageCreatedViewsLayout(Set<View> createdViews) { // get view to layout "normally" Set<View> filteredCreatedViewsToLayout = Sets.filter(createdViews, new Predicate<View>() { + @Override public boolean apply(View input) { return input.eAdapters().contains(SiriusLayoutDataManager.INSTANCE.getAdapterMarker()); } @@ -145,6 +156,7 @@ public class DDiagramCanonicalSynchronizer extends AbstractCanonicalSynchronizer // get view to center layout Set<View> filteredCreatedViewsWithCenterLayout = Sets.filter(createdViews, new Predicate<View>() { + @Override public boolean apply(View input) { return input.eAdapters().contains(SiriusLayoutDataManager.INSTANCE.getCenterAdapterMarker()); } @@ -264,6 +276,7 @@ public class DDiagramCanonicalSynchronizer extends AbstractCanonicalSynchronizer if (exist && diagramLinkSrc instanceof DEdge) { Predicate<SiriusLinkDescriptor> existingEdgeSource = new Predicate<SiriusLinkDescriptor>() { + @Override public boolean apply(SiriusLinkDescriptor input) { return input.getModelElement().equals(diagramLinkSrc); } @@ -274,6 +287,7 @@ public class DDiagramCanonicalSynchronizer extends AbstractCanonicalSynchronizer if (exist && diagramLinkDst instanceof DEdge) { Predicate<SiriusLinkDescriptor> existingEdgeTarget = new Predicate<SiriusLinkDescriptor>() { + @Override public boolean apply(SiriusLinkDescriptor input) { return input.getModelElement().equals(diagramLinkDst); } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/util/NotificationQuery.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/util/NotificationQuery.java index a02c19c6c0..24acc6c1fd 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/util/NotificationQuery.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/util/NotificationQuery.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 THALES GLOBAL SERVICES. + * Copyright (c) 2012, 2015 THALES GLOBAL SERVICES 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 @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.ui.tools.internal.util; +import java.util.Collection; + import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.gmf.runtime.notation.NotationPackage; @@ -17,6 +19,7 @@ import org.eclipse.sirius.diagram.DiagramPackage; import org.eclipse.sirius.diagram.HideFilter; import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; /** * Queries on EMF Notifications to identify what they are about. @@ -24,6 +27,11 @@ import com.google.common.base.Preconditions; * @author pcdavid */ public class NotificationQuery extends org.eclipse.sirius.common.tools.api.query.NotificationQuery { + + private static final Collection<EStructuralFeature> NOTATION_LAYOUT_FEATURES = Sets.newHashSet(NotationPackage.eINSTANCE.getRelativeBendpoints_Points(), NotationPackage.eINSTANCE.getEdge_Bendpoints(), + NotationPackage.eINSTANCE.getLocation_Y(), NotationPackage.eINSTANCE.getLocation_X(), NotationPackage.eINSTANCE.getSize_Width(), NotationPackage.eINSTANCE.getSize_Height(), + NotationPackage.eINSTANCE.getNode_LayoutConstraint()); + private final Notification notif; /** @@ -49,6 +57,16 @@ public class NotificationQuery extends org.eclipse.sirius.common.tools.api.query } /** + * Tests whether the notification concerns a GMF Notation layout element. + * + * @return <code>true</code> if the notification concerns a GMF Notation layout + * element. + */ + public boolean isNotationLayoutChange() { + return NOTATION_LAYOUT_FEATURES.contains(notif.getFeature()); + } + + /** * Tests whether the notification is a GMF view becoming invisible. * * @return <code>true</code> if the notification is a GMF view becoming diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index 38ad08473b..3818aea0d6 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -270,16 +270,6 @@ <code>org.eclipse.sirius</code> </h4> <ul> - <li><span class="label label-danger">Removed</span> - <code>org.eclipse.sirius.business.api.helper.task.ICommandTask.undo()/redo()</code> methods removed because they are useless since undo/redo is managed by EMF Transaction. - </li> - <li><span class="label label-danger">Removed</span> - <code>org.eclipse.sirius.tools.api.command.IUndoableCommand</code> interface removed because it is useless since undo/redo is managed by EMF Transaction. - </li> - <li><span class="label label-info">Modified</span> - <code>org.eclipse.sirius.tools.api.command.DCommand</code> no more inherits of - <code>IUndoableCommand</code> because useless since undo/redo is managed by EMF Transaction. - </li> <li><span class="label label-success">Added</span> The method <code>addEvaluateSelectionExpressionTask</code> has been added in class <code>org.eclipse.sirius.tools.api.command.AbstractCommandFactory</code> to allow selection after tool execution. @@ -290,16 +280,21 @@ <li><span class="label label-info">Modified</span> <code>org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority.canDeleteInstance(EObject)</code> when called for an object will not be called for children of this object as we know it will return true because if we can delete a parent object we can delete its children. </li> + <li><span class="label label-info">Modified</span> + <code>org.eclipse.sirius.tools.api.command.DCommand</code> no more inherits of + <code>IUndoableCommand</code> because useless since undo/redo is managed by EMF Transaction. + </li> + <li><span class="label label-danger">Removed</span> + <code>org.eclipse.sirius.business.api.helper.task.ICommandTask.undo()/redo()</code> methods removed because they are useless since undo/redo is managed by EMF Transaction. + </li> + <li><span class="label label-danger">Removed</span> + <code>org.eclipse.sirius.tools.api.command.IUndoableCommand</code> interface removed because it is useless since undo/redo is managed by EMF Transaction. + </li> </ul> <h4 id="Changesinorg.eclipse.sirius.ui">Changes in <code>org.eclipse.sirius.ui</code> </h4> <ul> - <li><span class="label label-warning">Deprecated</span> - <code>org.eclipse.sirius.ui.business.api.session.SessionEditorInput.dispose()</code> method has been deprecated as a - <code>IEditorInput</code> can be reused by several instances of - <code>IEditorPart</code> through the navigation history view. - </li> <li><span class="label label-success">Added</span> <code>org.eclipse.sirius.ui.business.api.session.SessionEditorInput.getInput()</code> method has been added to get the real input for a <code>DRepresentation</code>. @@ -309,11 +304,22 @@ <code>Session</code> or not when the known session is closed or does not exist. The <code>getSession</code> method calls getSession(true). </li> + <li><span class="label label-warning">Deprecated</span> + <code>org.eclipse.sirius.ui.business.api.session.SessionEditorInput.dispose()</code> method has been deprecated as a + <code>IEditorInput</code> can be reused by several instances of + <code>IEditorPart</code> through the navigation history view. + </li> </ul> <h4 id="Changesinorg.eclipse.sirius.diagram.ui">Changes in <code>org.eclipse.sirius.diagram.ui</code> </h4> <ul> + <li><span class="label label-success">Added</span> The class + <code>org.eclipse.sirius.diagram.ui.graphical.edit.policies.RegionRegionContainerResizableEditPolicy</code> has been added to handle + <code>DNodeContainer</code> which are both + <code>Region</code> and + <code>RegionContainer</code>: during resize they might have to propagate the resize to their children and/or parents. + </li> <li><span class="label label-success">Added</span> <code>org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramNodeEditPart/IDiagramBorderNodeEditPart.getNodeLabel()</code> methods has been moved up to <code>org.eclipse.sirius.diagram.ui.edit.api.part.IAbstractDiagramNodeEditPart.getNodeLabel()</code> as both diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index c091e4eff8..91fc801726 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -67,21 +67,22 @@ h4. Changes in @org.eclipse.sirius.ext.gmf.runtime@ h4. Changes in @org.eclipse.sirius@ -* <span class="label label-danger">Removed</span> @org.eclipse.sirius.business.api.helper.task.ICommandTask.undo()/redo()@ methods removed because they are useless since undo/redo is managed by EMF Transaction. -* <span class="label label-danger">Removed</span> @org.eclipse.sirius.tools.api.command.IUndoableCommand@ interface removed because it is useless since undo/redo is managed by EMF Transaction. -* <span class="label label-info">Modified</span> @org.eclipse.sirius.tools.api.command.DCommand@ no more inherits of @IUndoableCommand@ because useless since undo/redo is managed by EMF Transaction. * <span class="label label-success">Added</span> The method @addEvaluateSelectionExpressionTask@ has been added in class @org.eclipse.sirius.tools.api.command.AbstractCommandFactory@ to allow selection after tool execution. * <span class="label label-success">Added</span> The class @org.eclipse.sirius.common.tools.api.interpreter.StandardServices@ has been added. This class owns methods used for service: interpreter. * <span class="label label-info">Modified</span> @org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority.canDeleteInstance(EObject)@ when called for an object will not be called for children of this object as we know it will return true because if we can delete a parent object we can delete its children. +* <span class="label label-info">Modified</span> @org.eclipse.sirius.tools.api.command.DCommand@ no more inherits of @IUndoableCommand@ because useless since undo/redo is managed by EMF Transaction. +* <span class="label label-danger">Removed</span> @org.eclipse.sirius.business.api.helper.task.ICommandTask.undo()/redo()@ methods removed because they are useless since undo/redo is managed by EMF Transaction. +* <span class="label label-danger">Removed</span> @org.eclipse.sirius.tools.api.command.IUndoableCommand@ interface removed because it is useless since undo/redo is managed by EMF Transaction. h4. Changes in @org.eclipse.sirius.ui@ -* <span class="label label-warning">Deprecated</span> @org.eclipse.sirius.ui.business.api.session.SessionEditorInput.dispose()@ method has been deprecated as a @IEditorInput@ can be reused by several instances of @IEditorPart@ through the navigation history view. * <span class="label label-success">Added</span> @org.eclipse.sirius.ui.business.api.session.SessionEditorInput.getInput()@ method has been added to get the real input for a @DRepresentation@. * <span class="label label-success">Added</span> @org.eclipse.sirius.ui.business.api.session.SessionEditorInput.getSession(boolean)@ method has been added to let the caller choose to create and open a new @Session@ or not when the known session is closed or does not exist. The @getSession@ method calls getSession(true). +* <span class="label label-warning">Deprecated</span> @org.eclipse.sirius.ui.business.api.session.SessionEditorInput.dispose()@ method has been deprecated as a @IEditorInput@ can be reused by several instances of @IEditorPart@ through the navigation history view. h4. Changes in @org.eclipse.sirius.diagram.ui@ +* <span class="label label-success">Added</span> The class @org.eclipse.sirius.diagram.ui.graphical.edit.policies.RegionRegionContainerResizableEditPolicy@ has been added to handle @DNodeContainer@ which are both @Region@ and @RegionContainer@: during resize they might have to propagate the resize to their children and/or parents. * <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramNodeEditPart/IDiagramBorderNodeEditPart.getNodeLabel()@ methods has been moved up to @org.eclipse.sirius.diagram.ui.edit.api.part.IAbstractDiagramNodeEditPart.getNodeLabel()@ as both @IDiagramNodeEditPart@ and @IDiagramBorderNodeEditPart@ inherits of @IAbstractDiagramNodeEditPart@. * <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.tools.api.ui.actions.ActionIds.ARRANGE_BORDER_NODES@ added to replace @org.eclipse.sirius.diagram.ui.tools.api.ui.actions.ActionIds.ARRANGE_BORDERED_NODES_TOOLBAR@ which is deprecated * <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.tools.api.ui.actions.ActionIds.ARRANGE_BORDER_NODES_TOOLBAR@ added to replace @org.eclipse.sirius.diagram.ui.tools.api.ui.actions.ActionIds.ARRANGE_BORDERED_NODES@ which is deprecated |
