| //------------------------------------------------------------------------------ |
| // 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.util; |
| |
| import java.util.ArrayList; |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.draw2d.IFigure; |
| import org.eclipse.draw2d.PositionConstants; |
| import org.eclipse.draw2d.geometry.Rectangle; |
| import org.eclipse.epf.diagramming.edit.parts.ActivityEditPart; |
| import org.eclipse.epf.diagramming.edit.parts.ActivityPartitionEditPart; |
| import org.eclipse.gef.EditPart; |
| import org.eclipse.gef.GraphicalEditPart; |
| import org.eclipse.gef.commands.Command; |
| 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.editparts.DiagramEditPart; |
| import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel; |
| import org.eclipse.gmf.runtime.notation.Node; |
| import org.eclipse.uml2.uml.ActivityNode; |
| import org.eclipse.uml2.uml.ActivityPartition; |
| |
| /** |
| * @author skannoor |
| * |
| */ |
| public final class ADDiagramUtil { |
| |
| public static List getNodesInPartition(ActivityPartitionEditPart child) { |
| List nodes = new ArrayList(); |
| ActivityPartition partition = (ActivityPartition)((Node)child.getModel()).getElement(); |
| List list = partition.getNodes(); |
| for (Iterator iter = list.iterator(); iter.hasNext();) { |
| Object element = (Object) iter.next(); |
| nodes.add(findEditPartyByElement(child.getParent(), element)); |
| } |
| return nodes; |
| } |
| public static EditPart findEditPartyByElement(EditPart parent, |
| Object element) { |
| List list = parent.getChildren(); |
| for (Iterator iter = list.iterator(); iter.hasNext();) { |
| EditPart editPart = (EditPart) iter.next(); |
| if (((Node) editPart.getModel()).getElement() == element) { |
| return editPart; |
| } |
| } |
| return null; |
| } |
| public static EditPart getPartitionWhereChildIn(EditPart child, Object constraint) { |
| DiagramEditPart parent = (DiagramEditPart) child.getParent(); |
| if (!(child instanceof ActivityPartitionEditPart) |
| && parent instanceof ActivityEditPart) { |
| Object element = ((Node) child.getModel()).getElement(); |
| if (element instanceof ActivityNode) { |
| List list = ((ActivityNode) element).getInPartitions(); |
| for (Iterator iter = list.iterator(); iter.hasNext();) { |
| // ActivityPartition partition = (ActivityPartition) iter |
| // .next(); |
| EditPart part = findEditPartyByElement(parent, element); |
| if (part != null) { |
| // Node node = (Node)part.getModel(); |
| // Object x = ViewUtil.getStructuralFeatureValue(node, |
| // NotationPackage.eINSTANCE.getLocation_X()); |
| // Object y = ViewUtil.getStructuralFeatureValue(node, |
| // NotationPackage.eINSTANCE.getLocation_Y()); |
| // Object width = |
| // ViewUtil.getStructuralFeatureValue(node, |
| // NotationPackage.eINSTANCE.getSize_Width()); |
| // Object height = |
| // ViewUtil.getStructuralFeatureValue(node, |
| // NotationPackage.eINSTANCE.getSize_Height()); |
| // Rectangle rect = new Rectangle(x,y,width, height); |
| Rectangle bounds = ((GraphicalEditPart) part) |
| .getFigure().getBounds(); |
| if (bounds.contains((Rectangle) constraint)) { |
| return part; |
| } |
| } |
| } |
| } |
| } |
| return null; |
| } |
| |
| public static void nouse(){ |
| // if (child instanceof ActivityPartitionEditPart) { |
| // List childs = getNodesInPartition((ActivityPartitionEditPart)child); |
| // for (Iterator iter = childs.iterator(); iter.hasNext();) { |
| // EditPart element = (EditPart) iter.next(); |
| // //cmd.chain(super.createChangeConstraintCommand(element, constraint)); |
| // } |
| // |
| // } else { |
| // |
| // EditPart part = childInAnyPartitionArea(child, constraint); |
| // if (part instanceof ActivityPartitionEditPart) { |
| // // Rectangle bounds = |
| // // ((GraphicalEditPart)part).getFigure().getBounds(); |
| // // Rectangle constaintr = (Rectangle)constraint; |
| // // bounds = bounds.expand(constaintr.width, constaintr.height); |
| // // ((GraphicalEditPart)part).getFigure().setBounds(bounds); |
| //// Command cmdx = super.createChangeConstraintCommand(part, |
| //// constraint); |
| //// cmd.chain(cmdx); |
| // |
| // } |
| // } |
| } |
| |
| /** |
| * @generated |
| */ |
| public static Command getCommandWrapper(ICommand cmd) { |
| return new ICommandProxy(cmd); |
| } |
| } |