コード例 #1
0
 private void refresh(Item[] items) {
   for (int i = 0; i < items.length; i++) {
     Item item = items[i];
     item.setData(COLORED_LABEL_KEY, null);
     String text = item.getText();
     item.setText(""); // $NON-NLS-1$
     item.setText(text);
     if (item instanceof TreeItem) {
       refresh(((TreeItem) item).getItems());
     }
   }
 }
コード例 #2
0
 private ColoredString getColoredLabelForView(Item item) {
   ColoredString oldLabel = (ColoredString) item.getData(COLORED_LABEL_KEY);
   String itemText = item.getText();
   if (oldLabel != null && oldLabel.getString().equals(itemText)) {
     // avoid accesses to the label provider if possible
     return oldLabel;
   }
   ColoredString newLabel = null;
   IBaseLabelProvider labelProvider = fViewer.getLabelProvider();
   if (labelProvider instanceof IRichLabelProvider) {
     newLabel = ((IRichLabelProvider) labelProvider).getRichTextLabel(item.getData());
   }
   if (newLabel == null) {
     newLabel = new ColoredString(itemText); // fallback. Should never happen.
   } else if (!newLabel.getString().equals(itemText)) {
     // the decorator manager has already queued an new update
     newLabel =
         ColoredDartElementLabels.decorateColoredString(
             newLabel, itemText, ColoredDartElementLabels.DECORATIONS_STYLE);
   }
   item.setData(COLORED_LABEL_KEY, newLabel); // cache the result
   return newLabel;
 }
コード例 #3
0
  /**
   * Incrementally builds the menu from the contribution items. This method leaves out double
   * separators and separators in the first or last position.
   *
   * @param force <code>true</code> means update even if not dirty, and <code>false</code> for
   *     normal incremental updating
   * @param recursive <code>true</code> means recursively update all submenus, and <code>false
   *     </code> means just this menu
   */
  protected void update(boolean force, boolean recursive) {
    if (isDirty() || force) {
      if (menuExist()) {
        // clean contains all active items without double separators
        IContributionItem[] items = getItems();
        List clean = new ArrayList(items.length);
        IContributionItem separator = null;
        for (int i = 0; i < items.length; ++i) {
          IContributionItem ci = items[i];
          if (!isChildVisible(ci)) {
            continue;
          }
          if (ci.isSeparator()) {
            // delay creation until necessary
            // (handles both adjacent separators, and separator at end)
            separator = ci;
          } else {
            if (separator != null) {
              if (clean.size() > 0) {
                clean.add(separator);
              }
              separator = null;
            }
            clean.add(ci);
          }
        }

        // remove obsolete (removed or non active)
        Item[] mi = getMenuItems();

        for (int i = 0; i < mi.length; i++) {
          Object data = mi[i].getData();

          if (data == null || !clean.contains(data)) {
            mi[i].dispose();
          } else if (data instanceof IContributionItem
              && ((IContributionItem) data).isDynamic()
              && ((IContributionItem) data).isDirty()) {
            mi[i].dispose();
          }
        }

        // add new
        mi = getMenuItems();
        int srcIx = 0;
        int destIx = 0;

        for (Iterator e = clean.iterator(); e.hasNext(); ) {
          IContributionItem src = (IContributionItem) e.next();
          IContributionItem dest;

          // get corresponding item in SWT widget
          if (srcIx < mi.length) {
            dest = (IContributionItem) mi[srcIx].getData();
          } else {
            dest = null;
          }

          if (dest != null && src.equals(dest)) {
            srcIx++;
            destIx++;
          } else if (dest != null && dest.isSeparator() && src.isSeparator()) {
            mi[srcIx].setData(src);
            srcIx++;
            destIx++;
          } else {
            int start = getMenuItemCount();
            doItemFill(src, destIx);
            int newItems = getMenuItemCount() - start;
            for (int i = 0; i < newItems; i++) {
              Item item = getMenuItem(destIx++);
              item.setData(src);
            }
          }

          // May be we can optimize this call. If the menu has just
          // been created via the call src.fill(fMenuBar, destIx) then
          // the menu has already been updated with update(true)
          // (see MenuManager). So if force is true we do it again. But
          // we can't set force to false since then information for the
          // sub sub menus is lost.
          if (recursive) {
            IContributionItem item = src;
            if (item instanceof SubContributionItem) {
              item = ((SubContributionItem) item).getInnerItem();
            }
            if (item instanceof IMenuManager) {
              ((IMenuManager) item).updateAll(force);
            }
          }
        }

        // remove any old menu items not accounted for
        for (; srcIx < mi.length; srcIx++) {
          mi[srcIx].dispose();
        }

        setDirty(false);
      }
    } else {
      // I am not dirty. Check if I must recursivly walk down the hierarchy.
      if (recursive) {
        IContributionItem[] items = getItems();
        for (int i = 0; i < items.length; ++i) {
          IContributionItem ci = items[i];
          if (ci instanceof IMenuManager) {
            IMenuManager mm = (IMenuManager) ci;
            if (isChildVisible(mm)) {
              mm.updateAll(force);
            }
          }
        }
      }
    }
    updateMenuItem();
  }
コード例 #4
0
 private void loadCommon(Item column) {
   column.setData(DescriptorKey, this);
   if (imagePath != null) column.setImage(ResourceManager.imageFor(imagePath));
 }
コード例 #5
0
  @Override
  protected void doUpdateItem(Widget widget, Object element, boolean fullMap) {
    boolean oldBusy = isBusy();
    setBusy(true);
    try {
      if (widget instanceof Item) {
        final Item item = (Item) widget;

        // remember element we are showing
        if (fullMap) {
          associate(element, item);
        } else {
          Object data = item.getData();
          if (data != null) {
            unmapElement(data, item);
          }
          item.setData(element);
          mapElement(element, item);
        }

        int columnCount = doGetColumnCount();
        if (columnCount == 0) columnCount = 1; // If there are no columns do the first one

        ViewerRow viewerRowFromItem = getViewerRowFromItem(item);

        boolean isVirtual = (getControl().getStyle() & SWT.VIRTUAL) != 0;

        // If the control is virtual, we cannot use the cached viewer row object. See bug 188663.
        if (isVirtual) {
          viewerRowFromItem = (ViewerRow) viewerRowFromItem.clone();
        }

        // Also enter loop if no columns added. See 1G9WWGZ: JFUIF:WINNT -
        // TableViewer with 0 columns does not work
        for (int column = 0; column < columnCount || column == 0; column++) {
          ViewerColumn columnViewer = getViewerColumn(column);
          ViewerCell cellToUpdate = updateCell(viewerRowFromItem, column, element);

          // If the control is virtual, we cannot use the cached cell object. See bug 188663.
          if (isVirtual) {
            cellToUpdate =
                new ViewerCell(cellToUpdate.getViewerRow(), cellToUpdate.getColumnIndex(), element);
          }

          columnViewer.refresh(cellToUpdate);

          // clear cell (see bug 201280)
          updateCell(null, 0, null);

          // As it is possible for user code to run the event
          // loop check here.
          if (item.isDisposed()) {
            unmapElement(element, item);
            return;
          }
        }
      }
    } finally {
      setBusy(oldBusy);
    }
  }