コード例 #1
0
  // 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);
  }
コード例 #2
0
 /**
  * Replaces the handle's default DragEditPartsTracker with the extended DragEditPartsTrackerEx
  *
  * @param handle
  */
 protected void replaceHandleDragEditPartsTracker(Handle handle) {
   if (handle instanceof AbstractHandle) {
     AbstractHandle h = (AbstractHandle) handle;
     h.setDragTracker(new DragEditPartsTrackerEx(getHost()));
   }
 }