Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2014-02-28 16:10:45 +0000
committerCamille Letavernier2014-02-28 16:12:23 +0000
commitcf877e02fdccd456722f7be0daa3898bb0551c63 (patch)
tree7ceaefcd5cc30c0e4b094d936069414e4f490349
parente3398b400bf67da3d5209eca31733c98e110e6b0 (diff)
parent9b11d4e998698a1f5d458fbd3edcc5eeb3af78fe (diff)
downloadorg.eclipse.papyrus-cf877e02fdccd456722f7be0daa3898bb0551c63.tar.gz
org.eclipse.papyrus-cf877e02fdccd456722f7be0daa3898bb0551c63.tar.xz
org.eclipse.papyrus-cf877e02fdccd456722f7be0daa3898bb0551c63.zip
Synchronize with master
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusResizableShapeEditPolicy.java25
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PreferencesConstantsHelper.java18
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/ResizeTrackerWithPreferences.java195
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/SnapUtils.java59
4 files changed, 291 insertions, 6 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusResizableShapeEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusResizableShapeEditPolicy.java
index f5c83a5c8c4..134a94ffbf3 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusResizableShapeEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusResizableShapeEditPolicy.java
@@ -13,27 +13,34 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.tools.ResizeTracker;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableShapeEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.snap.ResizeTrackerWithPreferences;
/**
- *
+ *
* See Bug 424943 ResizableEditPolicy#getResizeCommand duplicates request ignoring some request values
- * TODO : remove this class when the bug will be fixed
+ *
*/
public class PapyrusResizableShapeEditPolicy extends ResizableShapeEditPolicy {
/**
+ * See Bug 424943 ResizableEditPolicy#getResizeCommand duplicates request ignoring some request values
+ * TODO : remove this override when the bug will be fixed
+ *
* Returns the command contribution for the given resize request. By
* default, the request is re-dispatched to the host's parent as a {@link org.eclipse.gef.RequestConstants#REQ_RESIZE_CHILDREN}. The
* parent's edit policies determine how to perform the resize based on the
* layout manager in use.
- *
+ *
* @param request
* the resize request
* @return the command contribution obtained from the parent
*/
+
@Override
protected Command getResizeCommand(ChangeBoundsRequest request) {
ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_RESIZE_CHILDREN);
@@ -56,4 +63,16 @@ public class PapyrusResizableShapeEditPolicy extends ResizableShapeEditPolicy {
return getHost().getParent().getCommand(req);
}
+ /**
+ *
+ * @see org.eclipse.gef.editpolicies.ResizableEditPolicy#getResizeTracker(int)
+ *
+ * @param direction
+ * @return
+ */
+ @Override
+ protected ResizeTracker getResizeTracker(int direction) {
+ return new ResizeTrackerWithPreferences((GraphicalEditPart)getHost(), direction);
+ }
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PreferencesConstantsHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PreferencesConstantsHelper.java
index 1ff44b8c5a6..81b39f9a956 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PreferencesConstantsHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/PreferencesConstantsHelper.java
@@ -142,6 +142,9 @@ public class PreferencesConstantsHelper {
public final static String DRAW_CONNECTION_POINT_CONSTANT = "drawConnectionPoint"; //$NON-NLS-1$
+ public final static String INVERT_BINDING_FOR_DEFAULT_RESIZE_AND_CONSTRAINED_RESIZE_CONSTANT = "invertBindingForDefaultResizeAndConstrainedResize"; //$NON-NLS-1$
+
+
/**
* A preference of type COLOR FILL
*/
@@ -308,12 +311,21 @@ public class PreferencesConstantsHelper {
* A preference to view the page break on the diagram
*/
public static final int VIEW_PAGE_BREAK = GRID_LINE_STYLE + 1;
-
+
/**
* A preference to draw big point when 2 links have a common part
*/
- public static final int DRAW_CONNECTION_POINT = VIEW_PAGE_BREAK +1;
+ public static final int DRAW_CONNECTION_POINT = VIEW_PAGE_BREAK + 1;
+ /**
+ * A Papyrus preference to define the if the default resize action is constrained or not.
+ * if the preference is <code>false</code>
+ * <ul>
+ * <li>default resize is not constraint</li>
+ * <li>resize + SHIFT is constrained</li>
+ * </ul>
+ */
+ public static final int INVERT_BINDING_FOR_DEFAULT_RESIZE_AND_CONSTRAINED_RESIZE = DRAW_CONNECTION_POINT + 1;
/**
* Get the preference constant used to store the preference of an element.
@@ -428,7 +440,7 @@ public class PreferencesConstantsHelper {
break;
case VIEW_PAGE_BREAK:
sb.append(VIEW_PAGE_BREAK_CONSTANT);
- break;
+ break;
default:
break;
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/ResizeTrackerWithPreferences.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/ResizeTrackerWithPreferences.java
new file mode 100644
index 00000000000..498c0885b38
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/ResizeTrackerWithPreferences.java
@@ -0,0 +1,195 @@
+package org.eclipse.papyrus.infra.gmfdiag.common.snap;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionDimension;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.SnapToHelper;
+import org.eclipse.gef.handles.HandleBounds;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.tools.ResizeTracker;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PreferencesConstantsHelper;
+
+/**
+ * Adapted code from ResizeTracker
+ * A resize tracker managing a preference for constrained resize
+ *
+ */
+public class ResizeTrackerWithPreferences extends ResizeTracker {
+
+ /**
+ * the snap helper to use
+ */
+ private SnapToHelper localSnapToHelper;
+
+ /**
+ * the source rect bounds
+ */
+ private PrecisionRectangle localSourceRect;
+
+ public ResizeTrackerWithPreferences(GraphicalEditPart owner, int direction) {
+ super(owner, direction);
+ }
+
+ @Override
+ public void activate() {
+ super.activate();
+ if(getOwner() != null) {
+ if(getTargetEditPart() != null)
+ localSnapToHelper = (SnapToHelper)getTargetEditPart().getAdapter(SnapToHelper.class);
+
+ IFigure figure = getOwner().getFigure();
+ if(figure instanceof HandleBounds)
+ localSourceRect = new PrecisionRectangle(((HandleBounds)figure).getHandleBounds());
+ else
+ localSourceRect = new PrecisionRectangle(figure.getBounds());
+ figure.translateToAbsolute(localSourceRect);
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gef.tools.ResizeTracker#updateSourceRequest()
+ *
+ */
+ @Override
+ protected void updateSourceRequest() {
+ ChangeBoundsRequest request = (ChangeBoundsRequest)getSourceRequest();
+ Dimension d = getDragMoveDelta();
+
+ Point location = new Point(getLocation());
+ Point moveDelta = new Point(0, 0);
+ Dimension resizeDelta = new Dimension(0, 0);
+
+ request.setConstrainedResize(isConstrainedResizeAccordingToPreference());
+ request.setCenteredResize(getCurrentInput().isModKeyDown(SnapUtils.MODIFIER_CENTERED_RESIZE));
+ request.setSnapToEnabled(!getCurrentInput().isModKeyDown(SnapUtils.MODIFIER_NO_SNAPPING));
+
+ if(request.isConstrainedResize() && getOwner() != null) {
+ request.setConstrainedResize(true);
+
+ int origHeight = getOwner().getFigure().getBounds().height;
+ int origWidth = getOwner().getFigure().getBounds().width;
+ float ratio = 1;
+
+ if(origWidth != 0 && origHeight != 0)
+ ratio = ((float)origHeight / (float)origWidth);
+
+ if(getResizeDirection() == PositionConstants.SOUTH_EAST) {
+ if(d.height > (d.width * ratio))
+ d.width = (int)(d.height / ratio);
+ else
+ d.height = (int)(d.width * ratio);
+ } else if(getResizeDirection() == PositionConstants.NORTH_WEST) {
+ if(d.height < (d.width * ratio))
+ d.width = (int)(d.height / ratio);
+ else
+ d.height = (int)(d.width * ratio);
+ } else if(getResizeDirection() == PositionConstants.NORTH_EAST) {
+ if(-(d.height) > (d.width * ratio))
+ d.width = -(int)(d.height / ratio);
+ else
+ d.height = -(int)(d.width * ratio);
+ } else if(getResizeDirection() == PositionConstants.SOUTH_WEST) {
+ if(-(d.height) < (d.width * ratio))
+ d.width = -(int)(d.height / ratio);
+ else
+ d.height = -(int)(d.width * ratio);
+ }
+ }
+
+ if((getResizeDirection() & PositionConstants.NORTH) != 0) {
+ if(request.isCenteredResize()) {
+ resizeDelta.height -= d.height;
+ }
+ moveDelta.y += d.height;
+ resizeDelta.height -= d.height;
+ }
+ if((getResizeDirection() & PositionConstants.SOUTH) != 0) {
+ if(request.isCenteredResize()) {
+ moveDelta.y -= d.height;
+ resizeDelta.height += d.height;
+ }
+ resizeDelta.height += d.height;
+ }
+ if((getResizeDirection() & PositionConstants.WEST) != 0) {
+ if(request.isCenteredResize()) {
+ resizeDelta.width -= d.width;
+ }
+ moveDelta.x += d.width;
+ resizeDelta.width -= d.width;
+ }
+ if((getResizeDirection() & PositionConstants.EAST) != 0) {
+ if(request.isCenteredResize()) {
+ moveDelta.x -= d.width;
+ resizeDelta.width += d.width;
+ }
+ resizeDelta.width += d.width;
+ }
+
+ request.setMoveDelta(moveDelta);
+ request.setSizeDelta(resizeDelta);
+ request.setLocation(location);
+ request.setEditParts(getOperationSet());
+ request.getExtendedData().clear();
+ request.setResizeDirection(getResizeDirection());
+
+ if(request.isSnapToEnabled() && localSnapToHelper != null) {
+ PrecisionRectangle rect = localSourceRect.getPreciseCopy();
+ rect.translate(moveDelta);
+ rect.resize(resizeDelta);
+ PrecisionRectangle result = new PrecisionRectangle();
+
+ localSnapToHelper.snapRectangle(request, request.getResizeDirection(), rect, result);
+ if(request.isCenteredResize()) {
+ if(result.preciseX() != 0.0)
+ result.setPreciseWidth(result.preciseWidth() - result.preciseX());
+ else if(result.preciseWidth() != 0.0) {
+ result.setPreciseX(-result.preciseWidth());
+ result.setPreciseWidth(result.preciseWidth() * 2.0);
+ }
+
+ if(result.preciseY() != 0.0)
+ result.setPreciseHeight(result.preciseHeight() - result.preciseY());
+ else if(result.preciseHeight() != 0.0) {
+ result.setPreciseY(-result.preciseHeight());
+ result.setPreciseHeight(result.preciseHeight() * 2.0);
+ }
+ }
+
+ PrecisionPoint preciseMove = new PrecisionPoint(result.preciseX() + moveDelta.x, result.preciseY() + moveDelta.y);
+
+ PrecisionDimension preciseResize = new PrecisionDimension(result.preciseWidth() + resizeDelta.width, result.preciseHeight() + resizeDelta.height);
+
+ request.setMoveDelta(preciseMove);
+ request.setSizeDelta(preciseResize);
+ }
+
+ enforceConstraintsForResize(request);
+ }
+
+ /**
+ *
+ * @return
+ * <code>true</code> if the current resize must be constrained and <code>false</code> if not
+ */
+ private final boolean isConstrainedResizeAccordingToPreference() {
+ IPreferenceStore store = Activator.getInstance().getPreferenceStore();
+ boolean isInverted = false;
+ if(store.contains(PreferencesConstantsHelper.getPapyrusEditorConstant(PreferencesConstantsHelper.INVERT_BINDING_FOR_DEFAULT_RESIZE_AND_CONSTRAINED_RESIZE))) {
+ isInverted = store.getBoolean(PreferencesConstantsHelper.getPapyrusEditorConstant(PreferencesConstantsHelper.INVERT_BINDING_FOR_DEFAULT_RESIZE_AND_CONSTRAINED_RESIZE));
+ }
+ //to activate this preference use this code during the preference initialization of Papyrus
+ //org.eclipse.papyrus.infra.gmfdiag.common.Activator.getInstance().getPreferenceStore().setValue(PreferencesConstantsHelper.getPapyrusEditorConstant(PreferencesConstantsHelper.INVERT_BINDING_FOR_DEFAULT_RESIZE_AND_CONSTRAINED_RESIZE),true);
+ if(isInverted) {
+ return !getCurrentInput().isModKeyDown(SnapUtils.MODIFIER_CONSTRAINED_RESIZE);
+ }
+ return getCurrentInput().isModKeyDown(SnapUtils.MODIFIER_CONSTRAINED_RESIZE);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/SnapUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/SnapUtils.java
new file mode 100644
index 00000000000..33b4cac3b65
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/SnapUtils.java
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.snap;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.swt.SWT;
+
+
+public class SnapUtils {
+
+ private SnapUtils() {
+ //to prevent instanciation
+ }
+
+ /**
+ * Key modifier for centered resizing. It's ALT on the Mac and MOD1 on all
+ * other platforms.
+ */
+ public static final int MODIFIER_CENTERED_RESIZE;
+
+ static {
+ if(Platform.OS_MACOSX.equals(Platform.getOS())) {
+ MODIFIER_CENTERED_RESIZE = SWT.ALT;
+ } else {
+ MODIFIER_CENTERED_RESIZE = SWT.MOD1;
+ }
+ }
+
+ /**
+ * Key modifier for constrained resizing. It's SHIFT on all platforms.
+ */
+ public static final int MODIFIER_CONSTRAINED_RESIZE = SWT.SHIFT;
+
+ /**
+ * Key modifier for ignoring snap while dragging. It's CTRL on Mac, and ALT
+ * on all other platforms.
+ */
+ public static final int MODIFIER_NO_SNAPPING;
+
+ static {
+ if (Platform.OS_MACOSX.equals(Platform.getOS())) {
+ MODIFIER_NO_SNAPPING = SWT.CTRL;
+ } else {
+ MODIFIER_NO_SNAPPING = SWT.ALT;
+ }
+ }
+
+}

Back to the top