@Override protected EditPolicy createChildEditPolicy(EditPart child) { EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); } return result; }
// We override reveal to show the Handles of the selected EditPart when // scrolling public void reveal(EditPart part) { // In some case, the editor control is not created, but get the sync selection event. // Fix this problem temporary. if (getFigureCanvas() == null || getFigureCanvas().isDisposed()) { return; } Viewport port = getFigureCanvas().getViewport(); IFigure target = ((GraphicalEditPart) part).getFigure(); Rectangle exposeRegion = target.getBounds().getCopy(); // Get the primary editpolicy EditPolicy policy = part.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); // If the policy let us access the handles, proceed, otherwise // default to original behaviour if (!(policy instanceof ISelectionHandlesEditPolicy)) { super.reveal(part); return; } // First translate exposeRegion to the root level target = target.getParent(); while (target != null && target != port) { target.translateToParent(exposeRegion); target = target.getParent(); } // Merge selection handles if any to the exposeRegion List handles = ((ISelectionHandlesEditPolicy) policy).getHandles(); for (Iterator iter = handles.iterator(); iter.hasNext(); ) { AbstractHandle handle = (AbstractHandle) iter.next(); Locator locator = handle.getLocator(); locator.relocate(handle); exposeRegion.union(handle.getBounds().getCopy()); } exposeRegion.getExpanded(5, 5); Dimension viewportSize = port.getClientArea().getSize(); Point topLeft = exposeRegion.getTopLeft(); Point bottomRight = exposeRegion.getBottomRight().translate(viewportSize.getNegated()); Point finalLocation = new Point(); if (viewportSize.width < exposeRegion.width) finalLocation.x = Math.min(bottomRight.x, Math.max(topLeft.x, port.getViewLocation().x)); else finalLocation.x = Math.min(topLeft.x, Math.max(bottomRight.x, port.getViewLocation().x)); if (viewportSize.height < exposeRegion.height) finalLocation.y = Math.min(bottomRight.y, Math.max(topLeft.y, port.getViewLocation().y)); else finalLocation.y = Math.min(topLeft.y, Math.max(bottomRight.y, port.getViewLocation().y)); getFigureCanvas().scrollSmoothTo(finalLocation.x, finalLocation.y); }
/** * Returns the primary edit policy * * @return THe primary edit policy */ private MarkerEventListenerEditPolicy getPrimaryEditPolicy() { EditPart current = getHost(); EditPart parent = current.getParent(); while (parent != null && semanticCompareEditParts(parent, getHost())) { current = parent; parent = parent.getParent(); } return (MarkerEventListenerEditPolicy) current.getEditPolicy(ROLE); }
@Override protected EditPolicy createChildEditPolicy(final EditPart child) { final View childView = (View) child.getModel(); if (UMLVisualIDRegistry.getVisualID(childView) == this.labelVisualId) { return new ExternalLabelPrimaryDragRoleEditPolicy(); } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); } return result; }
@Override protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { case PseudostateEntryPointEditPart.VISUAL_ID: case PseudostateExitPointEditPart.VISUAL_ID: case ConnectionPointReferenceEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); } return result; }
/** * Tests if the compartment is a compartment list * * @param node the node on which we want add an Overlay * @return <code>true</code> if the compartment is managed by an {@link XYLayoutEditPolicy} */ protected boolean isInCompartmentList(Node node) { IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class); if (gep != null && gep.getRoot() != null) { EObject container = node.eContainer(); if (container instanceof View) { EditPart EP = DiagramEditPartsUtil.getEditPartFromView((View) container, gep); EditPolicy editPolicy = EP.getEditPolicy(EditPolicy.LAYOUT_ROLE); if (!(editPolicy instanceof XYLayoutEditPolicy)) { // we are in a // compartment // list return true; } } } return false; }
/** * Set all part specify and its descendant to "Moving State" * * @param targetedEditPart */ protected void stopMovingParts(Iterable<IGraphicalEditPart> targetedEditPart) { if (targetedEditPart != null) { for (EditPart part : targetedEditPart) { EditPolicy editPolicy = part.getEditPolicy(IGroupEditPolicies.GROUP_FRAMEWORK_NOTIFYING_ON_MOVE_EDIT_POLICY); if (editPolicy instanceof GroupNotifyingOnMoveEditPolicy) { GroupNotifyingOnMoveEditPolicy editPolicy2 = (GroupNotifyingOnMoveEditPolicy) editPolicy; if (DebugUtils.isDebugging()) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(Utils.getCorrectLabel(editPolicy2.getEObject())); stringBuilder.append(" is stoping to move"); DebugUtils.getLog().debug(stringBuilder.toString()); } editPolicy2.stopMoving(); } stopMovingParts(part.getChildren()); } } }
/** @param editPart */ public void setEditPart(EditPart editPart) { this.editPart = editPart; editPart.installEditPolicy( EditPolicy.SELECTION_FEEDBACK_ROLE, new FeedbackEditPolicy(this, editPart.getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE))); }