Jelajahi Sumber

Added PreferredSizeRequest

Andreas Mülder 13 tahun lalu
induk
melakukan
36b413412f

+ 13 - 1
plugins/org.yakindu.sct.refactoring/src/org/yakindu/sct/refactoring/handlers/impl/InlineSubdiagramHandler.java

@@ -12,6 +12,9 @@ package org.yakindu.sct.refactoring.handlers.impl;
 
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
 import org.eclipse.gmf.runtime.notation.View;
 import org.eclipse.ui.handlers.HandlerUtil;
 import org.yakindu.sct.refactoring.handlers.AbstractViewRefactoringHandler;
@@ -19,6 +22,7 @@ import org.yakindu.sct.refactoring.refactor.AbstractRefactoring;
 import org.yakindu.sct.refactoring.refactor.impl.InlineSubdiagramRefactoring;
 import org.yakindu.sct.ui.editor.editparts.StateEditPart;
 import org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil;
+import org.yakindu.sct.ui.editor.policies.SetPreferredSizeRequest;
 
 /**
  * Handler for {@link InlineSubdiagramRefactoring}.
@@ -36,7 +40,15 @@ public class InlineSubdiagramHandler extends AbstractViewRefactoringHandler {
 	@Override
 	public Object execute(ExecutionEvent event) throws ExecutionException {
 		if (allEditorsAreClosed(event))
-			return super.execute(event);
+			super.execute(event);
+		setPreferredSize(event);
+		return null;
+	}
+
+	private Object setPreferredSize(ExecutionEvent event) {
+		IGraphicalEditPart editPart = (IGraphicalEditPart) getFirstElement(HandlerUtil.getCurrentSelection(event));
+		Command cmd = editPart.getCommand(new SetPreferredSizeRequest(editPart));
+		AbstractRefactoring.executeCommand(new CommandProxy(cmd), editPart.resolveSemanticElement().eResource());
 		return null;
 	}
 

+ 1 - 1
plugins/org.yakindu.sct.refactoring/src/org/yakindu/sct/refactoring/refactor/AbstractRefactoring.java

@@ -160,7 +160,7 @@ public abstract class AbstractRefactoring<T extends Object> implements IRefactor
 	 * @param resource
 	 *            the resource used for enabling/disabling its serializer
 	 */
-	protected void executeCommand(IUndoableOperation command, Resource resource) {
+	public static void executeCommand(IUndoableOperation command, Resource resource) {
 		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
 
 		if (resource instanceof StextResource) {

+ 10 - 0
plugins/org.yakindu.sct.refactoring/src/org/yakindu/sct/refactoring/refactor/impl/ExtractSubdiagramRefactoring.java

@@ -24,8 +24,10 @@ import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
 import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
 import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
 import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
+import org.eclipse.gmf.runtime.notation.Bounds;
 import org.eclipse.gmf.runtime.notation.Diagram;
 import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.Node;
 import org.eclipse.gmf.runtime.notation.Style;
 import org.eclipse.gmf.runtime.notation.View;
 import org.yakindu.sct.model.sgraph.Entry;
@@ -65,6 +67,7 @@ public class ExtractSubdiagramRefactoring extends AbstractRefactoring<View> {
 		setNotationStyle();
 		subdiagram = createSubdiagram();
 		createEntryExitPoints(subdiagram);
+		setPreferredSize();
 	}
 
 	@Override
@@ -189,4 +192,11 @@ public class ExtractSubdiagramRefactoring extends AbstractRefactoring<View> {
 		}
 		return subdiagram;
 	}
+
+	protected void setPreferredSize() {
+		Node node = (Node) getContextObject();
+		Bounds bounds = (Bounds) node.getLayoutConstraint();
+		bounds.setWidth(-1);
+		bounds.setHeight(-1);
+	}
 }

+ 1 - 6
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/policies/PreferredSizeEditPolicy.java

@@ -41,7 +41,7 @@ public class PreferredSizeEditPolicy extends PreferredSizeCompartmentEditPolicy
 	public class PreferredSizeDragTracker extends SimpleDragTracker {
 		@Override
 		protected Request createSourceRequest() {
-			return new ChangeBoundsRequest(REQ_RESIZE);
+			return new SetPreferredSizeRequest(getHost());
 		}
 
 		@Override
@@ -56,11 +56,6 @@ public class PreferredSizeEditPolicy extends PreferredSizeCompartmentEditPolicy
 
 		@Override
 		protected boolean handleButtonDown(int button) {
-			Dimension prefSize = getHostFigure().getLayoutManager().getPreferredSize(getHostFigure(), -1, -1);
-			Dimension currentSize = getHostFigure().getSize();
-			getSourceRequest().setSizeDelta(
-					new Dimension(prefSize.width - currentSize.width, prefSize.height - currentSize.height));
-			getSourceRequest().setEditParts(getOperationSet());
 			setCurrentCommand(getCommand());
 			executeCurrentCommand();
 			getHost().refresh();

+ 36 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/policies/SetPreferredSizeRequest.java

@@ -0,0 +1,36 @@
+/**
+ * Copyright (c) 2013 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 org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+
+/**
+ * Extends {@link ChangeBoundsRequest} to calculate the preferred size delta.
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class SetPreferredSizeRequest extends ChangeBoundsRequest {
+
+	public SetPreferredSizeRequest(IGraphicalEditPart host) {
+		super(RequestConstants.REQ_RESIZE);
+		setEditParts(host);
+		IFigure figure = host.getFigure();
+		Dimension prefSize = figure.getLayoutManager().getPreferredSize(figure, -1, -1);
+		Dimension currentSize = figure.getSize();
+		setSizeDelta(new Dimension(prefSize.width - currentSize.width, prefSize.height - currentSize.height));
+	}
+
+}