public Rectangle buildHighlightRectangle(
     TreeItem item,
     boolean includeChildren,
     GC gc,
     boolean includeHeaderHeight,
     boolean adjustHeight) {
   TreeItem parentItem = item.getParentItem();
   Rectangle bounds = item.getBounds();
   if (parentItem != null) {
     bounds = parentItem.getBounds(0);
   }
   Rectangle itemBounds = item.getBounds();
   int x = bounds.x;
   int width = itemBounds.width + itemBounds.x - bounds.x;
   if (parentItem == null) {
     x = 0;
     width = bounds.width + bounds.x;
   }
   Rectangle highlight = new Rectangle(x, itemBounds.y, width, getTree().getItemHeight());
   // expand for column text
   String columnText = ((ITableLabelProvider) getLabelProvider()).getColumnText(item.getData(), 1);
   if (columnText != null) {
     Point textExtent = gc.textExtent(columnText);
     int textWidth = textExtent.x;
     Rectangle columnBounds = item.getBounds(1);
     highlight.width = (columnBounds.x + textWidth) - highlight.x;
     // increase width to account for space where icon would be
     // later we will need to account for the icons directly (currently
     // there are no icons for the second column)
     highlight.width = highlight.width + 16;
   }
   // expand for children if necessary
   if (includeChildren) {
     TreeItem[] children = item.getItems();
     if (children.length != 0) {
       expandHighlightRectangleForChildren(highlight, children, gc);
     }
   }
   // shrink the rectangle by one pixel so that back to back
   // highlights do not overlap
   if (adjustHeight) {
     int itemSpace = item.getBounds().height - getTree().getItemHeight();
     itemSpace = Math.abs(itemSpace);
     highlight.height = highlight.height - itemSpace;
   }
   if (SWT.getPlatform().equals("gtk") && item.getParentItem() != null) { // $NON-NLS-1$
     // GTK puts expansion handles directly
     // at the location of the parent bounds
     // we use that location to start the box
     // to allow better looking highlights
     // increase the size a bit for linux
     highlight.x = highlight.x - 5;
     highlight.width = highlight.width + 5;
   }
   if (includeHeaderHeight) {
     highlight.y = highlight.y + getTree().getHeaderHeight();
   }
   return highlight;
 }
 TreeItem getItemForDifference(TreeDifference difference) {
   for (int i = difference.getPath().getSegmentCount() - 1; i >= 0; i--) {
     Object segment = difference.getPath().getSegment(i);
     TreeItem item = (TreeItem) findItem(ComparableProvider.getComparableTreeObject(segment));
     // if item is null, check for a matching difference with
     // element type of EmptyElement
     if (item == null) {
       if (difference.getMatchingDifference().getElement() instanceof EmptyElement) {
         // if not found then locate the item for the empty element
         item = (TreeItem) findItem(difference.getMatchingDifference().getElement());
       }
     }
     if (item != null && !item.isDisposed()) {
       TreeItem[] topItems = getTree().getItems();
       for (TreeItem top : topItems) {
         if (top == item) {
           return item;
         }
       }
       // else check for expanded state
       if (item.getParentItem().getExpanded() && !item.getBounds().isEmpty()) {
         return item;
       }
     }
   }
   return null;
 }
 private boolean clickOccurredInIconArea(MouseEvent event, TreeItem item) {
   Integer columnNumber = xViewer.getColumnNumberUnderMouseClick(new Point(event.x, event.y));
   if (columnNumber == null) {
     return false;
   }
   Rectangle rect = item.getBounds(columnNumber);
   return (event.x <= (rect.x + 18));
 }
 /**
  * Calculates the index of the TreeItem at given point.
  *
  * @param pt the Point in the Viewer
  * @return the index of the TreeItem
  */
 protected final int findIndexOfTreeItemAt(org.eclipse.draw2d.geometry.Point pt) {
   int index = -1;
   TreeItem item = findTreeItemAt(pt);
   if (item != null) {
     index = getHost().getChildren().indexOf(item.getData());
     if (index >= 0 && !isInUpperHalf(item.getBounds(), pt)) index++;
   }
   return index;
 }
Exemplo n.º 5
0
 public static int getColumnAtPos(TreeItem item, int x, int y) {
   int columnCount = item.getParent().getColumnCount();
   for (int i = 0; i < columnCount; i++) {
     Rectangle rect = item.getBounds(i);
     if (rect.contains(x, y)) {
       return i;
     }
   }
   return -1;
 }
Exemplo n.º 6
0
 /** Repaints the connections on the canvas. */
 public void repaint() {
   // clear the parent figure
   parentFigure.removeAll();
   // for each connection create a connection figure and add it to the parent figure
   for (Connection c : description.getConnections()) {
     TreeItem outputItem =
         sourceTreeViewer.findEndpoint(c.getSourceNode(), c.getOutput().getName());
     TreeItem inputItem = targetTreeViewer.findEndpoint(c.getTargetNode(), c.getInput().getName());
     // calculate the coordinates of the connection figure (the line) on the canvas
     if (inputItem != null && outputItem != null) {
       int outputY = outputItem.getBounds().y + outputItem.getBounds().height / 2;
       int outputX = 0;
       int inputY = inputItem.getBounds().y + inputItem.getBounds().height / 2;
       int inputX = parentFigure.getBounds().width;
       // create the connection figure (the connection line)
       ConnectionFigure line =
           new ConnectionFigure(c, new Point(outputX, outputY), new Point(inputX, inputY));
       // add the connection figure to the parent figure
       line.setAntialias(SWT.ON);
       parentFigure.add(line);
     }
   }
 }
 private Rectangle expandHighlightRectangleForChildren(
     Rectangle highlight, TreeItem[] children, GC gc) {
   // gather and add all heights, also store the widest width
   for (TreeItem child : children) {
     if (child.getData() == null
         || child.getBounds().isEmpty()
         || !child.getParentItem().getExpanded()) {
       continue;
     }
     Rectangle childBounds = buildHighlightRectangle(child, true, gc, false, false);
     highlight.width = Math.max(highlight.width, childBounds.width + childBounds.x - highlight.x);
     highlight.height = highlight.height + childBounds.height;
   }
   return highlight;
 }
 /**
  * This returns the location of the mouse in the vertical direction, relative to the item widget,
  * from 0 (top) to 1 (bottom). NOTE : Copied from DragAndDropCommand.
  *
  * @param event the {@link DropTargetEvent}
  * @return the float representing the vertical direction
  */
 protected float getLocation(DropTargetEvent event) {
   float result = 0.0F;
   if (event.item instanceof TreeItem) {
     TreeItem treeItem = (TreeItem) event.item;
     Control control = treeItem.getParent();
     Point point = control.toControl(new Point(event.x, event.y));
     Rectangle bounds = treeItem.getBounds();
     result = (float) (point.y - bounds.y) / (float) bounds.height;
   } else if (event.item instanceof TableItem) {
     TableItem tableItem = (TableItem) event.item;
     Control control = tableItem.getParent();
     Point point = control.toControl(new Point(event.x, event.y));
     Rectangle bounds = tableItem.getBounds(0);
     result = (float) (point.y - bounds.y) / (float) bounds.height;
   }
   return result;
 }
 public void setErrorMessage(String errorMessage) {
   if (tip == null) {
     tip = new ErrorToolTip(getTree().getShell());
   }
   if (errorMessage != "") {
     tip.setVisible(false);
     TreeItem treeItem = getTree().getSelection()[0];
     TreeColumn column = getTree().getColumn(0);
     tip.setText(errorMessage);
     Point location = new Point(column.getWidth(), treeItem.getBounds().y);
     Point controlPoint = getTree().toDisplay(location);
     tip.autoSize();
     tip.setLocation(controlPoint.x, controlPoint.y - tip.getHeight() - 5);
     tip.setVisible(true);
   } else {
     tip.setVisible(false);
   }
 }
  private void showDropFeedback(DropRequest request) {
    Widget hostWidget = ((TreeEditPart) getHost()).getWidget();
    Tree tree = getTree();

    org.eclipse.draw2d.geometry.Point pt = request.getLocation();
    TreeItem item = findTreeItemAt(pt);
    if (item == null) {
      if (hostWidget == tree) {
        insertMarkAfterLastChild(tree.getItems());
      }
    } else if (item == hostWidget) {
      // UNSUPPORTED - api not implemented in RAP
      // tree.setInsertMark(null, true);
    } else {
      boolean before = isInUpperHalf(item.getBounds(), pt);
      // UNSUPPORTED - api not implemented in RAP
      // tree.setInsertMark(item, before);
    }
  }
 /**
  * Returns the host EditPart when appropriate. Targeting is done by checking if the mouse is
  * clearly over the host's TreeItem.
  *
  * @see org.eclipse.gef.EditPolicy#getTargetEditPart(Request)
  */
 public EditPart getTargetEditPart(Request req) {
   if (req.getType().equals(REQ_ADD)
       || req.getType().equals(REQ_MOVE)
       || req.getType().equals(REQ_CREATE)) {
     DropRequest drop = (DropRequest) req;
     Point where = new Point(drop.getLocation().x, drop.getLocation().y);
     Widget widget = ((TreeEditPart) getHost()).getWidget();
     if (widget instanceof Tree) return getHost();
     TreeItem treeitem = (TreeItem) widget;
     Rectangle bounds = treeitem.getBounds();
     int fudge = bounds.height / 5;
     Rectangle inner =
         new Rectangle(
             bounds.x,
             bounds.y + fudge,
             bounds.width,
             bounds.height - (treeitem.getExpanded() ? 0 : fudge * 2));
     // Point is either outside the Treeitem, or inside the inner Rect.
     if (!bounds.contains(where) || inner.contains(where)) return getHost();
   }
   return null;
 }
Exemplo n.º 12
0
 /**
  * Calculates the needed Y adjustment for the specified control for decorations inside the
  * control.
  *
  * <p>Needed for {@link Tree} under Windows.
  *
  * @param control the control to calculate the adjustment for
  * @return the adjustment in pixels
  */
 public static int calculateYAdjustment(final Control control) {
   int adjustY = 0;
   if (isWindows() && control instanceof Tree) {
     /*
      * BUG under Windows?
      *
      * Tree.getClientArea does not return the visible area of the tree, but rather the
      * complete area of the tree if there was "room" enough.
      *
      * The fix is to calculate the y of the top-index and correct with this when saving
      * locations inside a Tree.
      *
      * This code finds the bounds of the first root element. When this is not the top
      * element in the view of the tree, the bounds still returned with a negative y...
      */
     final Tree t = (Tree) control;
     if (t.getItemCount() == 0) return 0;
     final TreeItem rootItem = t.getItem(0);
     adjustY = -rootItem.getBounds().y;
     // LogUtils.debug(control, "Adjust y " + adjustY + " for " + rootItem.getData());
   }
   return adjustY;
 }