private void updateItems(final FileInfo parent) {
   if (fDisplay == null) return;
   assert Thread.currentThread() == fDisplay.getThread();
   TreeItem[] items = null;
   boolean expanded = true;
   if (parent.children == null || parent.children_error != null) {
     if (parent == fRootInfo) {
       fileTree.setItemCount(1);
       items = fileTree.getItems();
     } else {
       TreeItem item = findItem(parent);
       if (item == null) return;
       expanded = item.getExpanded();
       item.setItemCount(1);
       items = item.getItems();
     }
     assert items.length == 1;
     items[0].removeAll();
     if (parent.children_pending) {
       items[0].setForeground(fDisplay.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
       items[0].setText("Pending...");
     } else if (parent.children_error != null) {
       String msg = parent.children_error.getMessage();
       if (msg == null) msg = parent.children_error.getClass().getName();
       else msg = msg.replace('\n', ' ');
       items[0].setForeground(fDisplay.getSystemColor(SWT.COLOR_RED));
       items[0].setText(msg);
       items[0].setImage((Image) null);
     } else if (expanded) {
       loadChildren(parent);
       items[0].setForeground(fDisplay.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
       items[0].setText("Pending...");
     } else {
       items[0].setText("");
     }
   } else {
     FileInfo[] arr = parent.children;
     if (parent == fRootInfo) {
       fileTree.setItemCount(arr.length);
       items = fileTree.getItems();
     } else {
       TreeItem item = findItem(parent);
       if (item == null) return;
       expanded = item.getExpanded();
       item.setItemCount(expanded ? arr.length : 1);
       items = item.getItems();
     }
     if (expanded) {
       assert items.length == arr.length;
       for (int i = 0; i < items.length; i++) fillItem(items[i], arr[i]);
       expandSelect();
     } else {
       items[0].setText("");
     }
   }
 }
示例#2
0
  @Override
  public void setSources(String... sources) {
    TreeItem[] items = tree.getSelection();
    if (items.length < 1) return;
    TreeItem item = items[0];
    if (lastSelectedItem == item) return;

    if (lastSelectedItem != null && !lastSelectedItem.isDisposed()) {
      lastSelectedItem.setBackground(new Color(getDisplay(), 255, 255, 255));
      lastSelectedItem.setExpanded(false);
      lastSelectedItem.removeAll();
    }
    lastSelectedItem = item;
    lastSelectedItem.setBackground(new Color(getDisplay(), 190, 190, 255));

    if (sources == null || sources.length < 1) return;

    for (String source : sources) {
      item = new TreeItem(lastSelectedItem, SWT.NONE);
      item.setFont(UIDATA.FONT_9);
      int idx = source.indexOf('.');
      if (idx > -1) source = source.substring(idx + 1);
      item.setText(source);
    }
    if (!lastSelectedItem.getExpanded()) lastSelectedItem.setExpanded(true);
  }
 static TreeItem NextItem(Tree tree, TreeItem item) {
   if (item == null) return null;
   if (item.getExpanded()) {
     return item.getItem(0);
   } else {
     TreeItem childItem = item;
     TreeItem parentItem = childItem.getParentItem();
     int index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem);
     int count = parentItem == null ? tree.getItemCount() : parentItem.getItemCount();
     while (true) {
       if (index + 1 < count) {
         return parentItem == null ? tree.getItem(index + 1) : parentItem.getItem(index + 1);
       } else {
         if (parentItem == null) {
           return null;
         } else {
           childItem = parentItem;
           parentItem = childItem.getParentItem();
           index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem);
           count = parentItem == null ? tree.getItemCount() : parentItem.getItemCount();
         }
       }
     }
   }
 }
 private void addRow(
     TreeItem item,
     List<String[]> rowData,
     IXViewerLabelProvider labelProv,
     List<XViewerColumn> showCols,
     int level)
     throws XViewerException {
   List<String> cellData = new ArrayList<String>(showCols.size());
   boolean firstCell = true;
   for (XViewerColumn xCol : showCols) {
     StringBuffer str = new StringBuffer();
     if (firstCell) {
       for (int y = 1; y < level; y++) {
         str.append("__INSERT_TAB_HERE__"); // $NON-NLS-1$
       }
       firstCell = false;
     }
     str.append(labelProv.getColumnText(item.getData(), xColToColumnIndex.get(xCol)));
     String html = HtmlUtil.textToHtml(str.toString());
     html =
         html.replaceAll(
             "__INSERT_TAB_HERE__", "&nbsp;&nbsp;&nbsp;&nbsp;"); // $NON-NLS-1$ //$NON-NLS-2$
     cellData.add(html);
   }
   rowData.add(cellData.toArray(new String[cellData.size()]));
   if (item.getExpanded()) {
     for (TreeItem i : item.getItems()) {
       addRow(i, rowData, labelProv, showCols, level + 1);
     }
   }
 }
 /**
  * Expands subtrees of given items. Items of type <code>PluginExtensionNode</code> that have
  * multiple children to expand will only be expanded to the that level. Further expanding is
  * required to reveal the whole subtree. This is for reasons of convenience.
  *
  * @param items tree items to be expand with their children
  */
 private void traverseChildrenAndSetExpanded(TreeItem[] items) {
   for (int i = 0; i < items.length; i++) {
     TreeItem treeItem = items[i];
     TreeItem[] children = treeItem.getItems();
     int extensionsChildCount = getExtensionsChildCount((IPluginParent) treeItem.getData());
     boolean furtherExpanding = !(extensionsChildCount > 1 && (!treeItem.getExpanded()));
     treeItem.setExpanded(furtherExpanding);
     if (furtherExpanding) {
       traverseChildrenAndSetExpanded(children);
     }
   }
 }
 static TreeItem PreviousItem(Tree tree, TreeItem item) {
   if (item == null) return null;
   TreeItem childItem = item;
   TreeItem parentItem = childItem.getParentItem();
   int index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem);
   if (index == 0) {
     return parentItem;
   } else {
     TreeItem nextItem =
         parentItem == null ? tree.getItem(index - 1) : parentItem.getItem(index - 1);
     int count = nextItem.getItemCount();
     while (count > 0 && nextItem.getExpanded()) {
       nextItem = nextItem.getItem(count - 1);
       count = nextItem.getItemCount();
     }
     return nextItem;
   }
 }
 /**
  * @param items items to be traversed
  * @return <code>true</code> if at least one of the tree items could be expanded but is not.
  *     Otherwise <code>false</code> is returned.
  */
 protected boolean traverseStateChangeRequired(TreeItem[] items) {
   if (items != null) {
     for (int i = 0; i < items.length; i++) {
       TreeItem treeItem = items[i];
       TreeItem[] children = treeItem.getItems();
       if (children.length > 0) {
         if (treeItem.getExpanded()) {
           if (traverseStateChangeRequired(children)) {
             return true;
           }
         } else {
           return true;
         }
       }
     }
   }
   return false;
 }
 @Override
 public void handleTreeCollapse(TreeEvent event) {
   super.handleTreeCollapse(event);
   for (SynchronizedTreeViewer viewer : synchronizedViewers) {
     TreeItem otherItem = getMatchingItem(event.item.getData(), viewer);
     if (otherItem != null) {
       if (otherItem.getExpanded()) {
         Event rawEvent = new Event();
         rawEvent.doit = true;
         rawEvent.widget = viewer.getTree();
         rawEvent.display = event.display;
         TreeEvent otherEvent = new TreeEvent(rawEvent);
         otherEvent.item = otherItem;
         viewer.internalHandleTreeCollapse(otherEvent);
         viewer.setExpanded(otherItem, false);
       }
       viewer.getTree().redraw();
     }
   }
 }
 /**
  * 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;
 }
示例#10
0
 /**
  * Flips the TreeItem from expanded to not expanded or vice-versa.
  *
  * @param ti The TreeItem to flip.
  */
 public static final void flipExpanded(TreeItem ti) {
   ti.setExpanded(!ti.getExpanded());
 }
 protected void highlightDifferences(GC gc) {
   // if the differencer is null then we are currently
   // in the middle of a content update, skip this paint
   // request
   if (mergeViewer.getDifferencer() == null) {
     return;
   }
   gc.setAdvanced(true);
   gc.setAntialias(SWT.ON);
   Tree tree = getTree();
   List<TreeDifference> differences = mergeViewer.getDifferencer().getLeftDifferences();
   if (mergeViewer.getLeftViewer() != this && mergeViewer.getAncestorTree() != this) {
     differences = mergeViewer.getDifferencer().getRightDifferences();
   }
   for (TreeDifference difference : differences) {
     if (differenceIsGraphical(difference)) {
       // we do not include graphical differences
       // at this time
       continue;
     }
     gc.setForeground(
         getMergeViewer()
             .getColor(
                 PlatformUI.getWorkbench().getDisplay(),
                 getMergeViewer().getStrokeColor(difference)));
     TreeItem item = getItemForDifference(difference);
     if (item == null || item.isDisposed()) {
       continue;
     }
     Rectangle highlightBounds =
         buildHighlightRectangle(
             item, difference.getIncludeChildren() && item.getExpanded(), gc, false, true);
     Rectangle itemBounds = buildHighlightRectangle(item, false, gc, false, true);
     boolean itemMatchesDifference = difference.getElement().equals(item.getData());
     if (!itemMatchesDifference && !(item.getData() instanceof EmptyElement)) {
       gc.setLineDash(new int[] {3});
       gc.setLineStyle(SWT.LINE_CUSTOM);
     } else {
       gc.setLineStyle(SWT.LINE_SOLID);
     }
     gc.drawRoundRectangle(
         highlightBounds.x,
         highlightBounds.y,
         highlightBounds.width,
         highlightBounds.height,
         5,
         5);
     if (mergeViewer.getLeftViewer() == this) {
       gc.drawLine(
           highlightBounds.x + highlightBounds.width,
           highlightBounds.y + (itemBounds.height / 2),
           tree.getClientArea().x + tree.getClientArea().width,
           highlightBounds.y + (itemBounds.height / 2));
     } else {
       gc.drawLine(
           highlightBounds.x,
           highlightBounds.y + (itemBounds.height / 2),
           tree.getClientArea().x,
           highlightBounds.y + (itemBounds.height / 2));
     }
     gc.setLineStyle(SWT.LINE_SOLID);
   }
 }