浏览代码

The choice can now be resized with fix aspect ratio (#1351)

This fixes #1241 and #432
Andreas Mülder 8 年之前
父节点
当前提交
8a9ccb5c2a

+ 0 - 2
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/figures/ChoiceFigure.java

@@ -12,14 +12,12 @@ package org.yakindu.sct.ui.editor.editor.figures;
 
 import org.eclipse.draw2d.Graphics;
 import org.eclipse.draw2d.Shape;
-import org.eclipse.draw2d.geometry.Dimension;
 import org.eclipse.draw2d.geometry.PointList;
 import org.eclipse.draw2d.geometry.Rectangle;
 
 public class ChoiceFigure extends Shape {
 
 	public ChoiceFigure() {
-		this.setSize(new Dimension(15, 15));
 		setLineWidth(2);
 	}
 

+ 8 - 7
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/ChoiceEditPart.java

@@ -11,25 +11,26 @@
 package org.yakindu.sct.ui.editor.editparts;
 
 import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.StackLayout;
 import org.eclipse.draw2d.geometry.Dimension;
 import org.eclipse.draw2d.geometry.PointList;
 import org.eclipse.draw2d.geometry.Rectangle;
 import org.eclipse.gef.EditPolicy;
-import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
 import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
 import org.eclipse.gmf.runtime.notation.View;
-import org.yakindu.base.gmf.runtime.editparts.FixedSizeShapeNodeEditPart;
 import org.yakindu.sct.ui.editor.editor.figures.ChoiceFigure;
 import org.yakindu.sct.ui.editor.editor.figures.utils.MapModeUtils;
 import org.yakindu.sct.ui.editor.policies.EnlargeContainerEditPolicy;
 import org.yakindu.sct.ui.editor.policies.FeedbackGraphicalNodeEditPolicy;
+import org.yakindu.sct.ui.editor.policies.FixedAspectRatioResizableEditPolicy;
 
 /**
  * 
  * @author andreas muelder - Initial contribution and API
  * 
  */
-public class ChoiceEditPart extends FixedSizeShapeNodeEditPart {
+public class ChoiceEditPart extends ShapeNodeEditPart {
 
 	public ChoiceEditPart(View view) {
 		super(view);
@@ -40,11 +41,12 @@ public class ChoiceEditPart extends FixedSizeShapeNodeEditPart {
 		super.createDefaultEditPolicies();
 		installEditPolicy(EnlargeContainerEditPolicy.ROLE, new EnlargeContainerEditPolicy());
 		installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new FeedbackGraphicalNodeEditPolicy());
+		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new FixedAspectRatioResizableEditPolicy());
 	}
 
 	@Override
 	protected NodeFigure createNodeFigure() {
-		final NodeFigure figure = new DefaultSizeNodeFigure(getDefaultSize()) {
+		final NodeFigure figure = new NodeFigure() {
 			@Override
 			public PointList getPolygonPoints() {
 				PointList points = new PointList(5);
@@ -57,19 +59,18 @@ public class ChoiceEditPart extends FixedSizeShapeNodeEditPart {
 				return points;
 			}
 		};
-		figure.setLayoutManager(getLayoutManager());
+		figure.setLayoutManager(new StackLayout());
 		figure.add(createPrimaryShape());
 		figure.setBackgroundColor(org.eclipse.draw2d.ColorConstants.white);
 		figure.setForegroundColor(org.eclipse.draw2d.ColorConstants.black);
+		figure.setMinimumSize(getDefaultSize());
 		return figure;
 	}
 
-	@Override
 	public Dimension getDefaultSize() {
 		return MapModeUtils.getMappedDimensions(getMapMode(), MapModeUtils.DEFAULT_SMALL_NODE_DIMENSION);
 	}
 
-	@Override
 	public IFigure createPrimaryShape() {
 		return new ChoiceFigure();
 	}

+ 66 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/policies/FixedAspectRatioResizableEditPolicy.java

@@ -0,0 +1,66 @@
+/**
+ * Copyright (c) 2017 committers of YAKINDU 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.ui.editor.policies;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.gef.DragTracker;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.handles.ResizeHandle;
+import org.eclipse.gef.tools.ResizeTracker;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableEditPolicyEx;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class FixedAspectRatioResizableEditPolicy extends ResizableEditPolicyEx {
+
+	@SuppressWarnings("rawtypes")
+	protected List createSelectionHandles() {
+		List list = new ArrayList();
+		createMoveHandle(list);
+		createResizeHandle(list, PositionConstants.SOUTH_EAST);
+		createResizeHandle(list, PositionConstants.SOUTH_WEST);
+		createResizeHandle(list, PositionConstants.NORTH_WEST);
+		createResizeHandle(list, PositionConstants.NORTH_EAST);
+		return list;
+	}
+
+	@Override
+	@SuppressWarnings({ "rawtypes", "unchecked" })
+	protected void createResizeHandle(List handles, final int direction) {
+		handles.add(new ResizeHandle(getHost(), direction) {
+			@Override
+			protected DragTracker createDragTracker() {
+				return new ResizeTracker(getHost(), direction) {
+					@Override
+					public void mouseDrag(MouseEvent event, EditPartViewer viewer) {
+						event.stateMask |= SWT.SHIFT;
+						super.mouseDrag(event, viewer);
+					}
+				};
+			};
+		});
+	}
+
+	@Override
+	public IGraphicalEditPart getHost() {
+		return (IGraphicalEditPart) super.getHost();
+	}
+
+}