/** * Returns the direction to set the decorator for the node * * @param node the node * @return the direction to set the decorator for the node direction can be : * <ul> * <li>{@link PositionConstants#NORTH_WEST} or {@link PositionConstants#SOUTH_EAST} if the * node is an Affixed Child Node * <li>{@link PositionConstants#EAST} if the node is in a compartment list * <li>{@link PositionConstants#SOUTH_EAST} in other cases * </ul> */ protected Direction getDirection(Node node) { IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class); assert gep != null; // test if its an affixed ChildNode // if(Util.isAffixedChildNode(gep)) { // // IBorderItemLocator loc = // ((BorderNamedElementEditPart)gep).getBorderItemLocator(); // int location = loc.getCurrentSideOfParent(); // if(PositionConstants.NONE == location) { //sometimes // getBorderItemLocator doesn't work correctly! // location = PositionConstants.NORTH_WEST; // } // switch(location) { // case PositionConstants.NORTH: // case PositionConstants.NORTH_WEST: // case PositionConstants.WEST: // case PositionConstants.SOUTH_WEST: // // return IDecoratorTarget.Direction.NORTH_WEST; // default: // return IDecoratorTarget.Direction.SOUTH_EAST; // } // } if (gep.getParent() != null) { if (isInCompartmentList(node) && !Util.isAffixedChildNode(gep)) { return IDecoratorTarget.Direction.EAST; } } return IDecoratorTarget.Direction.SOUTH_WEST; }
@Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { parentTreeNodeEditPart.getParent().refresh(); final List<IGraphicalEditPart> treeChildren = TreeLayoutUtil.getOrderedTreeChildren(parentTreeNodeEditPart); treeChildren.remove(UIUtils.getEditPart(request.getElementToDestroy())); TreeLayoutUtil.setTreeNodesPositionAnnotation(TreeLayoutUtil.getViews(treeChildren)); return CommandResult.newOKCommandResult(); }
/** @return the bordered node edit part. */ private IBorderedShapeEditPart getContainerBorderedNodeEditpart() { IGraphicalEditPart current = this; IBorderedShapeEditPart borderedNodeEditPart = null; while (current != null && borderedNodeEditPart == null) { if (current instanceof AbstractBorderedShapeEditPart) { borderedNodeEditPart = (IBorderedShapeEditPart) current; } current = (IGraphicalEditPart) current.getParent(); } return borderedNodeEditPart; }
private Rectangle getAbsoluteBounds(IGraphicalEditPart editPart, Float[] preferPosition) { if (editPart == null) { return null; } Rectangle rect = editPart.getFigure().getBounds().getCopy(); if (rect.isEmpty() && rect.x == 0 && rect.y == 0) { // Not displayed yet. View view = editPart.getNotationView(); if (view instanceof Node) { LayoutConstraint constraint = ((Node) view).getLayoutConstraint(); if (constraint instanceof Bounds) { Bounds bounds = (Bounds) constraint; if (bounds.getX() > 0) { rect.x = bounds.getX(); } if (bounds.getY() > 0) { rect.y = bounds.getY(); } else if (preferPosition != null && preferPosition.length > 0 && preferPosition[0] != null) { rect.y = preferPosition[0].intValue(); } if (bounds.getWidth() != -1) { rect.width = bounds.getWidth(); } if (bounds.getHeight() != -1) { rect.height = bounds.getHeight(); } } } Rectangle parentRect = getAbsoluteBounds((IGraphicalEditPart) editPart.getParent(), null); rect.x += parentRect.x; rect.y += parentRect.y; } else { rect = SequenceUtil.getAbsoluteBounds(editPart); } return rect; }