| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2007 IBM Corporation 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: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| /** |
| * |
| */ |
| package org.eclipse.epf.diagramming.base.policies; |
| |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.draw2d.geometry.Point; |
| import org.eclipse.draw2d.geometry.Rectangle; |
| import org.eclipse.epf.diagramming.base.util.ADDiagramUtil; |
| import org.eclipse.epf.diagramming.edit.parts.ActivityPartitionEditPart; |
| import org.eclipse.gef.EditPart; |
| import org.eclipse.gef.Request; |
| import org.eclipse.gef.commands.Command; |
| import org.eclipse.gef.requests.ChangeBoundsRequest; |
| import org.eclipse.gmf.runtime.common.core.command.ICommand; |
| 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.ShapeEditPart; |
| import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; |
| import org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy; |
| import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; |
| import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; |
| import org.eclipse.gmf.runtime.notation.View; |
| |
| /** |
| * @author Shashidhar Kannoori |
| * @author Shilpa Toraskar |
| * |
| */ |
| public class ActivityXYLayoutEditPolicy extends XYLayoutEditPolicy { |
| |
| /** |
| * |
| */ |
| public ActivityXYLayoutEditPolicy() { |
| } |
| |
| protected Command createAddCommand(EditPart child, Object constraint) { |
| Object parent = child.getParent(); |
| if ((parent instanceof ActivityPartitionEditPart) && |
| ( child instanceof ShapeEditPart && constraint instanceof Rectangle)) { |
| |
| Rectangle rect = (Rectangle) constraint; |
| int x = rect.x - ((ActivityPartitionEditPart) parent).getLocation().x; |
| int y = rect.y - ((ActivityPartitionEditPart) parent).getLocation().y; |
| |
| ICommand boundsCommand = |
| new SetBoundsCommand(((ShapeEditPart) child).getEditingDomain(), |
| DiagramUIMessages.SetLocationCommand_Label_Resize, |
| new EObjectAdapter((View) child.getModel()), |
| new Point(x, y)); |
| |
| return new ICommandProxy(boundsCommand); |
| } |
| |
| return super.createAddCommand(child, constraint); |
| } |
| |
| protected Command getMoveChildrenCommand(Request request) { |
| return super.getMoveChildrenCommand(request); |
| } |
| |
| |
| protected Command createChangeConstraintCommand(EditPart child, |
| Object constraint) { |
| return super.createChangeConstraintCommand(child, constraint); |
| } |
| |
| |
| protected Command createChangeConstraintCommand( |
| ChangeBoundsRequest request, EditPart child, Object constraint) { |
| Command cmd = super.createChangeConstraintCommand(request, child, |
| constraint); |
| if (child instanceof ActivityPartitionEditPart) { |
| List list = ADDiagramUtil |
| .getNodesInPartition((ActivityPartitionEditPart) child); |
| if (list != null && !list.isEmpty()) { |
| for (Iterator iter = list.iterator(); iter.hasNext();) { |
| EditPart element = (EditPart) iter.next(); |
| if (element instanceof ShapeNodeEditPart) { |
| ChangeBoundsRequest req = new ChangeBoundsRequest( |
| REQ_RESIZE_CHILDREN); |
| req.setEditParts(element); |
| req.setMoveDelta(request.getMoveDelta()); |
| req.setSizeDelta(request.getSizeDelta()); |
| req.setLocation(request.getLocation()); |
| req.setExtendedData(request.getExtendedData()); |
| req.setResizeDirection(request.getResizeDirection()); |
| cmd = cmd.chain(element.getParent().getCommand(req)); |
| } |
| } |
| } |
| } |
| return cmd; |
| } |
| |
| } |