/** {@inheritDoc} */
 protected void internalExpandToLevel(Widget node, int level) {
   if (!fIsFiltering && node instanceof Item) {
     Item i = (Item) node;
     if (i.getData() instanceof IJavaElement) {
       IJavaElement je = (IJavaElement) i.getData();
       if (je.getElementType() == IJavaElement.IMPORT_CONTAINER || isInnerType(je)) {
         setExpanded(i, false);
         return;
       }
     }
   }
   super.internalExpandToLevel(node, level);
 }
 /**
  * Clear the table item at the specified index
  *
  * @param index the index of the table item to be cleared
  * @since 3.1
  */
 public void clear(int index) {
   Item item = doGetItem(index);
   if (item.getData() != null) {
     disassociate(item);
   }
   doClear(index);
 }
 @Override
 protected void internalExpandToLevel(Widget w, int level) {
   if ( // !(fIsFiltering && !getFilterText().getText().isEmpty()) &&
   getFilterText().getText().isEmpty() && w instanceof Item) {
     Item i = (Item) w;
     if (i.getData() instanceof CeylonOutlineNode) {
       CeylonOutlineNode node = (CeylonOutlineNode) i.getData();
       int cat = node.getCategory();
       // TODO: leave unshared declarations collapsed?
       if (cat == CeylonOutlineNode.IMPORT_LIST_CATEGORY) {
         setExpanded(i, false);
         return;
       }
     }
   }
   super.internalExpandToLevel(w, level);
 }
Example #4
0
 private RepositoryNode getRepositoryNode(Item node) {
   Object data = node.getData();
   RepositoryNode repositoryNode = null;
   if (data instanceof RepositoryNode) {
     repositoryNode = (RepositoryNode) data;
   }
   return repositoryNode;
 }
 /**
  * Returns the element with the given index from this table viewer. Returns <code>null</code> if
  * the index is out of range.
  *
  * <p>This method is internal to the framework.
  *
  * @param index the zero-based index
  * @return the element at the given index, or <code>null</code> if the index is out of range
  */
 public Object getElementAt(int index) {
   if (index >= 0 && index < doGetItemCount()) {
     Item i = doGetItem(index);
     if (i != null) {
       return i.getData();
     }
   }
   return null;
 }
Example #6
0
 @Override
 protected ClickEvent createClickEvent(final MouseEvent e) {
   final Grid grid = (Grid) e.widget;
   final int colIndex = findColumn(grid, new Point(e.x, e.y));
   // x = 0 gets us an item even not using SWT.FULL_SELECTION
   final Item item = getItem(new Point(0, e.y));
   final Object rowData = item != null ? item.getData() : null;
   final ClickEvent event = new ClickEvent(this, e.button, colIndex, rowData);
   return event;
 }
 /**
  * Gathers the grayed states of the given widget and its descendents, following a pre-order
  * traversal of the tree.
  *
  * @param result a writable list of elements (element type: <code>Object</code>)
  * @param widget the widget
  */
 private void internalCollectGrayed(List result, Widget widget) {
   Item[] items = getChildren(widget);
   for (int i = 0; i < items.length; i++) {
     Item item = items[i];
     if (item instanceof TreeItem && ((TreeItem) item).getGrayed()) {
       Object data = item.getData();
       if (data != null) {
         result.add(data);
       }
     }
     internalCollectGrayed(result, item);
   }
 }
  @Override
  protected Widget doFindItem(Object element) {

    Item[] children = doGetItems();
    for (int i = 0; i < children.length; i++) {
      Item item = children[i];
      Object data = item.getData();
      if (data != null && equals(data, element)) {
        return item;
      }
    }

    return null;
  }
 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;
 }
 /**
  * Sets the checked state for the children of the given item.
  *
  * @param item the item
  * @param state <code>true</code> if the item should be checked, and <code>false</code> if it
  *     should be unchecked
  */
 private void setCheckedChildren(Item item, boolean state) {
   createChildren(item);
   Item[] items = getChildren(item);
   if (items != null) {
     for (int i = 0; i < items.length; i++) {
       Item it = items[i];
       if (it.getData() != null && (it instanceof TreeItem)) {
         TreeItem treeItem = (TreeItem) it;
         treeItem.setChecked(state);
         setCheckedChildren(treeItem, state);
       }
     }
   }
 }
    public void drop(DropTargetEvent event) {
      DropTarget dropTarget = (DropTarget) event.getSource();
      Item targetItem = (Item) event.item;

      MetadataColumn targetColumn = null;
      if (targetItem != null) {
        targetColumn = (MetadataColumn) targetItem.getData();
      }
      if (targetColumn != null) {}

      EList columns =
          ConnectionHelper.getTables(connection).toArray(new MetadataTable[0])[0].getColumns();
      int maxColumnsNumber =
          CoreUIPlugin.getDefault()
              .getPreferenceStore()
              .getInt(ITalendCorePrefConstants.MAXIMUM_AMOUNT_OF_COLUMNS_FOR_XML);
      if (columns.size() >= maxColumnsNumber) {
        MessageDialog.openWarning(
            treeViewer.getTree().getShell(),
            "Columns Overflow",
            "The amount of schema columns has reached the max value. Please increase the max value on Preference Page(/Talend/Metadata) if you want to add new columns.");
        return;
      }

      Control control = dropTarget.getControl();
      LocalDraggedData draggedData = LocalDataTransfer.getInstance().getDraggedData();
      List<Object> transferableObjs = draggedData.getTransferableEntryList();
      for (Object obj : transferableObjs) {
        if (obj instanceof FOXTreeNode) {
          FOXTreeNode treeNode = (FOXTreeNode) obj;
          calcuAddedColumns(treeNode, targetColumn, columns);
        }
      }

      tableViewer.setInput(columns);
      tableViewer.refresh();
      treeViewer.refresh();

      Display display = tree.getDisplay();
      Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT);
      tree.getShell().setCursor(cursor);

      linker.valueChanged(targetItem);

      tree.getShell().setCursor(null);

      linker.updateLinksStyleAndControlsSelection(control, true);
      linker.updateConnection();
      linker.updateFormStatus();
    }
    public void modify(Object element, String property, Object newValue) {
      Item item = (Item) element;
      ItemString s = (ItemString) item.getData();

      // Same value, ignore
      if (newValue.equals(s.value)) {
        return;
      }

      s.value = (String) newValue;

      update(s, null);
      getTable().notifyListeners(SWT.Modify, null);
    }
 /**
  * Applies the checked and grayed states of the given widget and its descendents.
  *
  * @param checked a set of elements (element type: <code>Object</code>)
  * @param grayed a set of elements (element type: <code>Object</code>)
  * @param widget the widget
  */
 private void applyState(CustomHashtable checked, CustomHashtable grayed, Widget widget) {
   Item[] items = getChildren(widget);
   for (int i = 0; i < items.length; i++) {
     Item item = items[i];
     if (item instanceof TreeItem) {
       Object data = item.getData();
       if (data != null) {
         TreeItem ti = (TreeItem) item;
         ti.setChecked(checked.containsKey(data));
         ti.setGrayed(grayed.containsKey(data));
       }
     }
     applyState(checked, grayed, item);
   }
 }
 /**
  * Set the item count of the receiver.
  *
  * @param count the new table size.
  * @since 3.1
  */
 public void setItemCount(int count) {
   if (checkBusy()) return;
   int oldCount = doGetItemCount();
   if (count < oldCount) {
     // need to disassociate elements that are being disposed
     for (int i = count; i < oldCount; i++) {
       Item item = doGetItem(i);
       if (item.getData() != null) {
         disassociate(item);
       }
     }
   }
   doSetItemCount(count);
   if (virtualManager != null) {
     virtualManager.adjustCacheSize(count);
   }
   getControl().redraw();
 }
 /**
  * Gathers the checked and grayed states of the given widget and its descendents.
  *
  * @param checked a writable set of elements (element type: <code>Object</code>)
  * @param grayed a writable set of elements (element type: <code>Object</code>)
  * @param widget the widget
  */
 private void gatherState(CustomHashtable checked, CustomHashtable grayed, Widget widget) {
   Item[] items = getChildren(widget);
   for (int i = 0; i < items.length; i++) {
     Item item = items[i];
     if (item instanceof TreeItem) {
       Object data = item.getData();
       if (data != null) {
         TreeItem ti = (TreeItem) item;
         if (ti.getChecked()) {
           checked.put(data, data);
         }
         if (ti.getGrayed()) {
           grayed.put(data, data);
         }
       }
     }
     gatherState(checked, grayed, item);
   }
 }
  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);
      }
    }
  }
  @Override
  public void remove(Object[] elements) {
    assertElementsNotNull(elements);
    if (checkBusy()) return;
    if (elements.length == 0) {
      return;
    }

    // deselect any items that are being removed, see bug 97786
    boolean deselectedItems = false;
    Object elementToBeRemoved = null;
    CustomHashtable elementsToBeRemoved = null;
    if (elements.length == 1) {
      elementToBeRemoved = elements[0];
    } else {
      elementsToBeRemoved = new CustomHashtable(getComparer());
      for (Object element : elements) {
        elementsToBeRemoved.put(element, element);
      }
    }
    int[] selectionIndices = doGetSelectionIndices();
    for (int index : selectionIndices) {
      Item item = doGetItem(index);
      Object data = item.getData();
      if (data != null) {
        if ((elementsToBeRemoved != null && elementsToBeRemoved.containsKey(data))
            || equals(elementToBeRemoved, data)) {
          table.deselect(index);
          deselectedItems = true;
        }
      }
    }
    super.remove(elements);

    if (deselectedItems) {
      ISelection sel = getSelection();
      updateSelection(sel);
      firePostSelectionChanged(new SelectionChangedEvent(this, sel));
    }
  }
  /**
   * Get the virtual selection. Avoid calling SWT whenever possible to prevent extra widget
   * creation.
   *
   * @return List of Object
   */
  private List getVirtualSelection() {

    List result = new ArrayList();
    int[] selectionIndices = doGetSelectionIndices();
    if (getContentProvider() instanceof ILazyContentProvider) {
      ILazyContentProvider lazy = (ILazyContentProvider) getContentProvider();
      for (int i = 0; i < selectionIndices.length; i++) {
        int selectionIndex = selectionIndices[i];
        lazy.updateElement(selectionIndex); // Start the update
        // check for the case where the content provider changed the number of items
        if (selectionIndex < doGetItemCount()) {
          Object element = doGetItem(selectionIndex).getData();
          // Only add the element if it got updated.
          // If this is done deferred the selection will
          // be incomplete until selection is finished.
          if (element != null) {
            result.add(element);
          }
        }
      }
    } else {
      for (int i = 0; i < selectionIndices.length; i++) {
        Object element = null;
        // See if it is cached
        int selectionIndex = selectionIndices[i];
        if (selectionIndex < virtualManager.cachedElements.length) {
          element = virtualManager.cachedElements[selectionIndex];
        }
        if (element == null) {
          // Not cached so try the item's data
          Item item = doGetItem(selectionIndex);
          element = item.getData();
        }
        if (element != null) {
          result.add(element);
        }
      }
    }
    return result;
  }
  @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);
    }
  }
Example #20
0
 @Override
 public void widgetSelected(SelectionEvent e) {
   final Item column = (Item) e.widget;
   final ISTDataViewersField field = (ISTDataViewersField) column.getData();
   resortTable(column, field);
 }
  /**
   * Set the selection on a virtual table
   *
   * @param list The elements to set
   * @param reveal Whether or not reveal the first item.
   */
  private void virtualSetSelectionToWidget(List list, boolean reveal) {
    int size = list.size();
    int[] indices = new int[list.size()];

    Item firstItem = null;
    int count = 0;
    HashSet virtualElements = new HashSet();
    for (int i = 0; i < size; ++i) {
      Object o = list.get(i);
      Widget w = findItem(o);
      if (w instanceof Item) {
        Item item = (Item) w;
        indices[count++] = doIndexOf(item);
        if (firstItem == null) {
          firstItem = item;
        }
      } else {
        virtualElements.add(o);
      }
    }

    if (getContentProvider() instanceof ILazyContentProvider) {
      ILazyContentProvider provider = (ILazyContentProvider) getContentProvider();

      // Now go through it again until all is done or we are no longer
      // virtual
      // This may create all items so it is not a good
      // idea in general.
      // Use #setSelection (int [] indices,boolean reveal) instead
      for (int i = 0; virtualElements.size() > 0 && i < doGetItemCount(); i++) {
        provider.updateElement(i);
        Item item = doGetItem(i);
        if (virtualElements.contains(item.getData())) {
          indices[count++] = i;
          virtualElements.remove(item.getData());
          if (firstItem == null) {
            firstItem = item;
          }
        }
      }
    } else {

      if (count != list.size()) { // As this is expensive skip it if all
        // have been found
        // If it is not lazy we can use the cache
        for (int i = 0; i < virtualManager.cachedElements.length; i++) {
          Object element = virtualManager.cachedElements[i];
          if (virtualElements.contains(element)) {
            Item item = doGetItem(i);
            item.getText(); // Be sure to fire the update
            indices[count++] = i;
            virtualElements.remove(element);
            if (firstItem == null) {
              firstItem = item;
            }
          }
        }
      }
    }

    if (count < size) {
      System.arraycopy(indices, 0, indices = new int[count], 0, count);
    }

    if (reveal) {
      doSetSelection(indices);
    } else {
      doDeselectAll();
      doSelect(indices);
    }
  }
 public void refresh(TreeEditor editor) {
   Button button = (Button) editor.getEditor();
   Item item = editor.getItem();
   Boolean value = (Boolean) getValue(item.getData());
   button.setSelection(value.booleanValue());
 }
  /**
   * Refresh all of the elements of the table. update the labels if updatLabels is true;
   *
   * @param updateLabels
   * @since 3.1
   */
  private void internalRefreshAll(boolean updateLabels) {
    // the parent

    // in the code below, it is important to do all disassociates
    // before any associates, since a later disassociate can undo an
    // earlier associate
    // e.g. if (a, b) is replaced by (b, a), the disassociate of b to
    // item 1 could undo
    // the associate of b to item 0.

    Object[] children = getSortedChildren(getRoot());
    Item[] items = doGetItems();
    int min = Math.min(children.length, items.length);
    for (int i = 0; i < min; ++i) {

      Item item = items[i];

      // if the element is unchanged, update its label if appropriate
      if (equals(children[i], item.getData())) {
        if (updateLabels) {
          updateItem(item, children[i]);
        } else {
          // associate the new element, even if equal to the old
          // one,
          // to remove stale references (see bug 31314)
          associate(children[i], item);
        }
      } else {
        // updateItem does an associate(...), which can mess up
        // the associations if the order of elements has changed.
        // E.g. (a, b) -> (b, a) first replaces a->0 with b->0, then
        // replaces b->1 with a->1, but this actually removes b->0.
        // So, if the object associated with this item has changed,
        // just disassociate it for now, and update it below.
        // we also need to reset the item (set its text,images etc. to
        // default values) because the label decorators rely on this
        disassociate(item);
        doClear(i);
      }
    }
    // dispose of all items beyond the end of the current elements
    if (min < items.length) {
      for (int i = items.length; --i >= min; ) {

        disassociate(items[i]);
      }
      if (virtualManager != null) {
        virtualManager.removeIndicesFromTo(min, items.length - 1);
      }
      doRemove(min, items.length - 1);
    }
    // Workaround for 1GDGN4Q: ITPUI:WIN2000 - TableViewer icons get
    // scrunched
    if (doGetItemCount() == 0) {
      doRemoveAll();
    }
    // Update items which were disassociated above
    for (int i = 0; i < min; ++i) {

      Item item = items[i];
      if (item.getData() == null) {
        updateItem(item, children[i]);
      }
    }
    // add any remaining elements
    for (int i = min; i < children.length; ++i) {
      createItem(children[i], i);
    }
  }