Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordstadnik2008-05-15 08:22:08 -0400
committerdstadnik2008-05-15 08:22:08 -0400
commitddfb967dedbe9d650af0f61ba4ce3d310f151b40 (patch)
tree0d75a05c94a70abf4d0c55187e2874c6ef989d4c /examples
parent15923224e524674d9bc4361e21402a8aaf55ef6d (diff)
downloadorg.eclipse.gmf-tooling-ddfb967dedbe9d650af0f61ba4ce3d310f151b40.tar.gz
org.eclipse.gmf-tooling-ddfb967dedbe9d650af0f61ba4ce3d310f151b40.tar.xz
org.eclipse.gmf-tooling-ddfb967dedbe9d650af0f61ba4ce3d310f151b40.zip
layout on changes
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.port.diagram/src/org/eclipse/gmf/examples/taipan/port/diagram/edit/parts/PortEditPart.java83
1 files changed, 77 insertions, 6 deletions
diff --git a/examples/org.eclipse.gmf.examples.taipan.port.diagram/src/org/eclipse/gmf/examples/taipan/port/diagram/edit/parts/PortEditPart.java b/examples/org.eclipse.gmf.examples.taipan.port.diagram/src/org/eclipse/gmf/examples/taipan/port/diagram/edit/parts/PortEditPart.java
index e4a25633d..7d5756de6 100644
--- a/examples/org.eclipse.gmf.examples.taipan.port.diagram/src/org/eclipse/gmf/examples/taipan/port/diagram/edit/parts/PortEditPart.java
+++ b/examples/org.eclipse.gmf.examples.taipan.port.diagram/src/org/eclipse/gmf/examples/taipan/port/diagram/edit/parts/PortEditPart.java
@@ -13,20 +13,37 @@ package org.eclipse.gmf.examples.taipan.port.diagram.edit.parts;
import java.util.ArrayList;
import java.util.List;
+import java.util.ListIterator;
+import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.draw2d.XYLayout;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.requests.GroupRequest;
import org.eclipse.gmf.examples.taipan.layouts.PortLayoutProvider;
import org.eclipse.gmf.examples.taipan.port.diagram.edit.policies.PortCanonicalEditPolicy;
import org.eclipse.gmf.examples.taipan.port.diagram.edit.policies.PortItemSemanticEditPolicy;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.util.ObjectAdapter;
+import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
+import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ContainerEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
+import org.eclipse.gmf.runtime.diagram.ui.internal.services.layout.IInternalLayoutRunnable;
+import org.eclipse.gmf.runtime.diagram.ui.internal.services.layout.LayoutNode;
import org.eclipse.gmf.runtime.diagram.ui.requests.ArrangeRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
+import org.eclipse.gmf.runtime.diagram.ui.services.layout.LayoutType;
+import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
/**
@@ -71,23 +88,77 @@ public class PortEditPart extends DiagramEditPart {
if (layoutProvider.isWorking()) {
return null;
}
- return super.getArrangeCommand(request);
+ // DeferredCommand is patched to arrange all children when no viewAdapters is specified
+ if (RequestConstants.REQ_ARRANGE_DEFERRED.equals(request.getType())) {
+ String layoutType = request.getLayoutType();
+ TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
+ return new ICommandProxy(new DeferredLayoutCommand(editingDomain, request.getViewAdaptersToArrange(), (IGraphicalEditPart) getHost(), layoutType) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ if (viewAdapters == null || viewAdapters.isEmpty()) {
+ viewAdapters = new ArrayList(PortEditPart.this.getChildren());
+ }
+ return super.doExecuteWithResult(progressMonitor, info);
+ }
+ });
+ }
+ // Snap to grid command is stripped off to prevent loops
+ String layoutDesc = request.getLayoutType() != null ? request.getLayoutType() : LayoutType.DEFAULT;
+ boolean offsetFromBoundingBox = false;
+ List editparts = new ArrayList();
+
+ if ((ActionIds.ACTION_ARRANGE_ALL.equals(request.getType())) || (ActionIds.ACTION_TOOLBAR_ARRANGE_ALL.equals(request.getType()))) {
+ editparts = ((IGraphicalEditPart) getHost()).getChildren();
+ request.setPartsToArrange(editparts);
+ }
+ if ((ActionIds.ACTION_ARRANGE_SELECTION.equals(request.getType())) || (ActionIds.ACTION_TOOLBAR_ARRANGE_SELECTION.equals(request.getType()))) {
+ editparts = request.getPartsToArrange();
+ if (!(((GraphicalEditPart) ((EditPart) editparts.get(0)).getParent()).getContentPane().getLayoutManager() instanceof XYLayout)) {
+ return null;
+ }
+ offsetFromBoundingBox = true;
+ }
+ if (RequestConstants.REQ_ARRANGE_RADIAL.equals(request.getType())) {
+ editparts = request.getPartsToArrange();
+ offsetFromBoundingBox = true;
+ layoutDesc = LayoutType.RADIAL;
+ }
+ if (editparts.isEmpty()) {
+ return null;
+ }
+ List nodes = new ArrayList(editparts.size());
+ ListIterator li = editparts.listIterator();
+ while (li.hasNext()) {
+ IGraphicalEditPart ep = (IGraphicalEditPart) li.next();
+ View view = ep.getNotationView();
+ if (ep.isActive() && view != null && view instanceof Node) {
+ Rectangle bounds = ep.getFigure().getBounds();
+ nodes.add(new LayoutNode((Node) view, bounds.width, bounds.height));
+ }
+ }
+ if (nodes.isEmpty()) {
+ return null;
+ }
+
+ List hints = new ArrayList(2);
+ hints.add(layoutDesc);
+ hints.add(getHost());
+ IAdaptable layoutHint = new ObjectAdapter(hints);
+ Runnable layoutRun = layoutNodes(nodes, offsetFromBoundingBox, layoutHint);
+ return ((IInternalLayoutRunnable) layoutRun).getCommand();
}
- @SuppressWarnings("unchecked")
public Runnable layoutNodes(List nodes, boolean offsetFromBoundingBox, IAdaptable layoutHint) {
return layoutProvider.layoutLayoutNodes(nodes, offsetFromBoundingBox, layoutHint);
}
});
}
- @SuppressWarnings("unchecked")
public Command getCommand(Request request) {
Command command = super.getCommand(request);
if (request.getType().equals(REQ_CREATE) || request.getType().equals(REQ_MOVE_CHILDREN) || request.getType().equals(REQ_RESIZE_CHILDREN)) {
ArrangeRequest layoutRequest = new ArrangeRequest(RequestConstants.REQ_ARRANGE_DEFERRED);
- List editParts = request instanceof GroupRequest ? ((GroupRequest) request).getEditParts() : getChildren();
- layoutRequest.setViewAdaptersToArrange(new ArrayList(editParts));
Command layoutCommand = super.getCommand(layoutRequest);
if (layoutCommand != null) {
command = command.chain(layoutCommand);

Back to the top