diff options
| author | Florian Barbin | 2017-10-16 15:38:49 +0000 |
|---|---|---|
| committer | Laurent Redor | 2017-12-18 16:06:34 +0000 |
| commit | 22cf133b0952855f749a391d2d1e0dead3685f8b (patch) | |
| tree | de8f34d965f90fe47235d1626bec7fb351a0f188 | |
| parent | f568f7e4a60be596c97b1dba99761663177659d4 (diff) | |
| download | org.eclipse.sirius-22cf133b0952855f749a391d2d1e0dead3685f8b.tar.gz org.eclipse.sirius-22cf133b0952855f749a391d2d1e0dead3685f8b.tar.xz org.eclipse.sirius-22cf133b0952855f749a391d2d1e0dead3685f8b.zip | |
[526073] Activates "Make Same Size" for region and region container
Bug: 526073
Change-Id: Ic43a145da9733c08b4052d43547590334e151890
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
5 files changed, 133 insertions, 10 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/SizeBothAction.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/SizeBothAction.java index 3d24493e57..42aad55fe7 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/SizeBothAction.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/SizeBothAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Obeo. + * Copyright (c) 2015, 2017 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 @@ -10,19 +10,39 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.ui.tools.internal.actions; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; + +import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.DNodeContainer; +import org.eclipse.sirius.diagram.business.internal.query.DNodeContainerExperimentalQuery; import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramContainerEditPart; import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramElementContainerEditPart; +import org.eclipse.sirius.diagram.ui.internal.edit.parts.AbstractDNodeContainerCompartmentEditPart; import org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor; import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority; import org.eclipse.sirius.ecore.extender.business.api.permission.PermissionAuthorityRegistry; import org.eclipse.ui.IWorkbenchPage; import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; /** - * Sirius specifc size both action: + * Sirius specific size both action: * <UL> * <LI>disable the action on Region and Region container.</LI> * <LI>check authority permission in calculateEnabled()./LI> @@ -31,6 +51,7 @@ import com.google.common.collect.Iterables; * @author mporhel * */ +@SuppressWarnings("restriction") public class SizeBothAction extends org.eclipse.gmf.runtime.diagram.ui.actions.internal.SizeBothAction { /** @@ -46,15 +67,98 @@ public class SizeBothAction extends org.eclipse.gmf.runtime.diagram.ui.actions.i @Override protected boolean calculateEnabled() { boolean enabled = super.calculateEnabled(); - if (enabled) { - for (AbstractDiagramElementContainerEditPart container : Iterables.filter(getSelectedObjects(), AbstractDiagramElementContainerEditPart.class)) { - if (container.isRegion() || (container instanceof AbstractDiagramContainerEditPart && ((AbstractDiagramContainerEditPart) container).isRegionContainer())) { - enabled = false; - break; + return enabled && canEditInstance(); + } + + /** + * Inspired from org.eclipse.gmf.runtime.diagram.ui.actions.internal.SizeBothAction.getCommand(). + */ + @SuppressWarnings("rawtypes") + @Override + protected Command getCommand() { + // Create a compound command to hold the resize commands + CompoundCommand doResizeCmd = new CompoundCommand(); + + // Create an iterator for the selection + Iterator iter = getSelectedObjects().iterator(); + + // Get the Primary Selection + int last = getSelectedObjects().size() - 1; + IGraphicalEditPart primary = (IGraphicalEditPart) getSelectedObjects().get(last); + + if (concernRegion(primary)) { + List<AbstractDiagramElementContainerEditPart> primaryRegions = getRegionParts((AbstractDiagramContainerEditPart) primary); + + while (iter.hasNext()) { + IGraphicalEditPart toResize = (IGraphicalEditPart) iter.next(); + if (toResize != primary && concernRegion(toResize)) { + List<AbstractDiagramElementContainerEditPart> toResizeRegions = getRegionParts((AbstractDiagramContainerEditPart) toResize); + int toResizeSize = toResizeRegions.size(); + int primarySize = primaryRegions.size(); + if (toResizeSize <= primarySize) { + for (int i = 0; i < toResizeSize; i++) { + AbstractDiagramElementContainerEditPart toResizeRegion = toResizeRegions.get(i); + AbstractDiagramElementContainerEditPart primaryRegion = primaryRegions.get(i); + + Dimension newDimension = null; + + // Case where there is more region in the primary container than the one we are resizing. In + // that case, the last region takes the size of the remaining regions in the primary region + // container. + if (i == toResizeSize - 1 && primarySize > toResizeSize) { + newDimension = computeLastRegionDimension(primary, primaryRegions, primarySize, i, primaryRegion); + + } + if (newDimension == null) { + newDimension = getPrimaryRegionSize(primaryRegion); + } + View resizeView = (View) toResizeRegion.getModel(); + + doResizeCmd.add(new ICommandProxy(new SetBoundsCommand(toResize.getEditingDomain(), "", new EObjectAdapter(resizeView), newDimension))); //$NON-NLS-1$ + } + + } + } + } + + return doResizeCmd.unwrap(); + } else { + return super.getCommand(); + } + + } + + private Dimension computeLastRegionDimension(IGraphicalEditPart primary, List<AbstractDiagramElementContainerEditPart> primaryRegions, int primarySize, int currentIndex, + AbstractDiagramElementContainerEditPart primaryRegion) { + Dimension newDimension = null; + Optional<DNodeContainer> optional = Optional.of(((AbstractDiagramContainerEditPart) primary).resolveDiagramElement()).filter(DNodeContainer.class::isInstance).map(DNodeContainer.class::cast); + if (optional.isPresent()) { + DNodeContainerExperimentalQuery query = new DNodeContainerExperimentalQuery(optional.get()); + newDimension = getPrimaryRegionSize(primaryRegion); + for (int j = currentIndex + 1; j < primarySize; j++) { + Dimension tempDim = getPrimaryRegionSize(primaryRegions.get(j)); + + if (query.isHorizontaltackContainer()) { + newDimension.expand(tempDim.width, 0); + } else { + + newDimension.expand(0, tempDim.height); } } } - return enabled && canEditInstance(); + return newDimension; + } + + private Dimension getPrimaryRegionSize(AbstractDiagramElementContainerEditPart primaryRegion) { + Dimension newDimension; + View primaryView = (View) primaryRegion.getModel(); + Integer width = (Integer) ViewUtil.getStructuralFeatureValue(primaryView, NotationPackage.eINSTANCE.getSize_Width()); + Integer height = (Integer) ViewUtil.getStructuralFeatureValue(primaryView, NotationPackage.eINSTANCE.getSize_Height()); + if (width.intValue() == -1 || height.intValue() == -1) + newDimension = primaryRegion.getFigure().getSize().getCopy(); + else + newDimension = new Dimension(width.intValue(), height.intValue()); + return newDimension; } /** @@ -76,4 +180,19 @@ public class SizeBothAction extends org.eclipse.gmf.runtime.diagram.ui.actions.i return canEditInstance; } + + private boolean concernRegion(EditPart hostPart) { + if (hostPart instanceof AbstractDiagramContainerEditPart) { + return ((AbstractDiagramContainerEditPart) hostPart).isRegionContainer(); + } + return false; + } + + private List<AbstractDiagramElementContainerEditPart> getRegionParts(AbstractDiagramContainerEditPart host) { + AbstractDNodeContainerCompartmentEditPart comp = Iterables.getFirst(Iterables.filter(host.getChildren(), AbstractDNodeContainerCompartmentEditPart.class), null); + if (comp != null) { + return Lists.newArrayList(Iterables.filter(comp.getChildren(), AbstractDiagramElementContainerEditPart.class)); + } + return Collections.emptyList(); + } } diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index 05826a9c64..8e36e58abc 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -126,6 +126,9 @@ <li><span class="label label-info">Modified</span> The " <em>Auto Size</em>" action can now be applied on region container. Before that, the action was available only for regions. </li> + <li><span class="label label-info">Modified</span> The " + <em>Make Same Size</em>" action can now be applied on region container. If selected region containers have the same number of regions, the regions will have the same size. If the region container used for reference has more regions than the other(s), the last region of others will have the size of all remaining regions in the one used for reference. + </li> </ul> <h3 id="DeveloperVisibleChanges">Developer-Visible Changes</h3> <ul> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index 5a7d6ebfa7..4c21a5ffa6 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -10,6 +10,7 @@ h3. User-Visible Changes * <span class="label label-info">Modified</span> When exporting a diagram as an image, it is now possible to choose an image size level. Before this, a preference called _AutoScale_ was available and when it was enable, the diagram was scaled to the maximum size safely allowed by the system. Now, a new preference named _Size of exported images_ is available in the _Sirius > Sirius Diagram_ preference page and offer this possibility. Setting size to _Max_ generates same diagrams as by using the previous preference _AutoScale_. This can produce image with big size in long generation time. If _Size of exported images_ is set to level _Nominal_, diagram will be exported with nominal size (quality will be lower but export time will be shorter). This new preference allows you to choose the tradeoff you want. The "user documentation ":user/diagrams/Diagrams.html#Exportingimages details this change with an example. * <span class="label label-info">Modified</span> The "_Auto Size_" action can now be applied on region container. Before that, the action was available only for regions. +* <span class="label label-info">Modified</span> The "_Make Same Size_" action can now be applied on region container. If selected region containers have the same number of regions, the regions will have the same size. If the region container used for reference has more regions than the other(s), the last region of others will have the size of all remaining regions in the one used for reference. h3. Developer-Visible Changes diff --git a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html index 9ae4df9167..c014c5db76 100644 --- a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html +++ b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html @@ -1418,7 +1418,7 @@ </p> <p> <img border="0" src="images/tabbar_make_same_size.png"/> - <em>Make Same Size</em>. When multiple elements are selected, clicking on this tool will resize all of them to have the same size (both width and height). The element used for reference to decide the size to apply is the last selected. + <em>Make Same Size</em>. When multiple elements are selected, clicking on this tool will resize all of them to have the same size (both width and height). The element used for reference to decide the size to apply is the last selected. For region containers, if the selected region containers have the same number of regions, the regions will have the same size. If the region container used for reference has more regions than the other(s), the last region of others will have the size of all remaining regions in the one used for reference. If the region container used for reference has less region than the other(s), the action has no effect. </p> <p> <img border="0" src="images/tabbar_auto_size.png"/> diff --git a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile index 50eb563c9d..b0fcc22bdc 100644 --- a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile +++ b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile @@ -917,7 +917,7 @@ The tab-bar contains a different set of actions when at least one element is sel !images/tabbar_apply_style.png! _Apply Style_. Use this button to reproduce the visual style of an element onto others. This action will apply the style of the last selected element to the others. When you click on this button, all the visual attributes from the last element which can are compatible with the other elements will be applied to them. -!images/tabbar_make_same_size.png! _Make Same Size_. When multiple elements are selected, clicking on this tool will resize all of them to have the same size (both width and height). The element used for reference to decide the size to apply is the last selected. +!images/tabbar_make_same_size.png! _Make Same Size_. When multiple elements are selected, clicking on this tool will resize all of them to have the same size (both width and height). The element used for reference to decide the size to apply is the last selected. For region containers, if the selected region containers have the same number of regions, the regions will have the same size. If the region container used for reference has more regions than the other(s), the last region of others will have the size of all remaining regions in the one used for reference. If the region container used for reference has less region than the other(s), the action has no effect. !images/tabbar_auto_size.png! _Auto-Size_. This button marks the selected elements as auto-sized. Auto-sized elements will adjust their width an height dynamically according to their contents. |
