コード例 #1
0
  @Override
  public Object doGetValue() {
    if (attribute.equals(Constants.ATTR_TEXT)) return item.getText();
    if (attribute.equals(Constants.ATTR_IMAGE)) return item.getImage();
    if (attribute.equals(Constants.ATTR_TOOLTIP)) {
      if (item instanceof TableColumn) return ((TableColumn) item).getToolTipText();
      if (item instanceof TreeColumn) return ((TreeColumn) item).getToolTipText();
      if (item instanceof ToolItem) return ((ToolItem) item).getToolTipText();
      if (item instanceof TabItem) return ((TabItem) item).getToolTipText();
    }
    if (attribute.equals(Constants.ATTR_ALIGNMENT)) {
      if (item instanceof TableColumn) return ((TableColumn) item).getAlignment();
      if (item instanceof TreeColumn) return ((TreeColumn) item).getAlignment();
    }
    if (attribute.equals(Constants.ATTR_WIDTH)) {
      if (item instanceof TableColumn) return ((TableColumn) item).getWidth();
      if (item instanceof TreeColumn) return ((TreeColumn) item).getWidth();
      if (item instanceof ToolItem) return ((ToolItem) item).getWidth();
    }
    if (attribute.equals(Constants.ATTR_ENABLED)) {
      if (item instanceof ToolItem) return ((ToolItem) item).getEnabled();
    }

    return null;
  }
コード例 #2
0
  private void updateItem(Item item) {
    if (!item.isDisposed()) { // defensive code
      ILabelProvider lprovider = (ILabelProvider) fContentViewer.getLabelProvider();

      Object data = item.getData();

      String oldText = item.getText();
      String text = lprovider.getText(data);
      if (text != null && !text.equals(oldText)) {
        item.setText(text);
      }

      Image oldImage = item.getImage();
      Image image = lprovider.getImage(data);
      if (image != null && !image.equals(oldImage)) {
        item.setImage(image);
      }
    }
  }