Exemplo n.º 1
0
  /**
   * Add image to a widget or window
   *
   * @param parent
   * @param image
   * @throws JellyTagException
   */
  protected void setImage(Object parent, Image image) throws GroovyException {
    if (parent instanceof Label) {
      Label label = (Label) parent;
      label.setImage(image);

    } else if (parent instanceof Button) {
      Button button = (Button) parent;
      button.setImage(image);

    } else if (parent instanceof Item) {
      Item item = (Item) parent;
      item.setImage(image);

    } else if (parent instanceof Decorations) {
      Decorations item = (Decorations) parent;
      item.setImage(image);

    } else if (parent instanceof Form) {
      Form form = (Form) parent;
      form.setBackgroundImage(image);

    } else if (parent instanceof ScrolledForm) {
      ScrolledForm form = (ScrolledForm) parent;
      form.setBackgroundImage(image);

    } else if (parent instanceof Window) {
      Window window = (Window) parent;
      window.getShell().setImage(image);

    } else {
      throw new GroovyException("This tag must be nested inside a <label>, <button> or <item> tag");
    }
  }
  @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;
  }
 /**
  * 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);
 }
 /**
  * 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;
 }
Exemplo n.º 5
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;
 }
 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());
     }
   }
 }
 /**
  * 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);
   }
 }
 /** {@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);
 }
 /**
  * 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);
       }
     }
   }
 }
Exemplo n.º 10
0
    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);
    }
  @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;
  }
    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();
    }
 /**
  * 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);
   }
 }
 /**
  * Method itemsUpdated.
  *
  * @param aItems Item[]
  * @param aInstanceId int
  * @see org.eclipse.mylyn.reviews.r4e.ui.internal.utils.IEditableListListener#itemsUpdated(Item[],
  *     int)
  */
 public void itemsUpdated(Item[] aItems, int aInstanceId) {
   if (fSelectedParticipantIndex >= 0) {
     final R4EParticipant participant = fParticipants.get(fSelectedParticipantIndex);
     if (0 == aInstanceId) {
       // Update roles
       participant.getRoles().clear();
       for (Item item : aItems) {
         R4EUserRole role = R4EUIParticipant.mapStringToRole(item.getText());
         if (null != role) {
           participant.getRoles().add(role);
         }
       }
     }
   }
 }
 /*
  * Extends this method to update check box states.
  */
 protected void doUpdateItem(Item item, Object element) {
   super.doUpdateItem(item, element);
   if (!item.isDisposed() && checkStateProvider != null) {
     setChecked(element, checkStateProvider.isChecked(element));
     setGrayed(element, checkStateProvider.isGrayed(element));
   }
 }
Exemplo n.º 16
0
 @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);
 }
Exemplo n.º 17
0
 private RepositoryNode getRepositoryNode(Item node) {
   Object data = node.getData();
   RepositoryNode repositoryNode = null;
   if (data instanceof RepositoryNode) {
     repositoryNode = (RepositoryNode) data;
   }
   return repositoryNode;
 }
Exemplo n.º 18
0
  /*
   * @see org.eclipse.swt.widgets.Item#setText(java.lang.String)
   */
  @Override
  public void setText(String string) {
    super.setText(string);
    fDetailsBlock.setText(string);

    // more or less space might be required for the label
    if (fIsLast) fContainer.layout(true, true);
  }
    @Override
    public void handleEvent(Event e) {

      Item selection = getSelection(e.widget);

      if (selection == null || selection.isDisposed() || this.selection == selection) {
        return;
      }

      Item[] items = getItems(e.widget);
      int selectionIndex = getSelectionIndex(e.widget);

      boolean selectionSet = false;

      CSSStyleDeclaration selectedStyle =
          engine.getViewCSS().getComputedStyle(engine.getElement(selection), "selected");
      if (selectedStyle != null) {
        CSSValue value = selectedStyle.getPropertyCSSValue("show-close");
        if (value != null) {
          setShowClose(selection, Boolean.parseBoolean(value.getCssText()));
          selectionSet = true;
        }
      }

      CSSStyleDeclaration unselectedStyle =
          engine.getViewCSS().getComputedStyle(engine.getElement(selection), null);
      if (unselectedStyle == null) {
        for (int i = 0; i < items.length; i++) {
          if (selectionSet && i != selectionIndex) {
            setShowClose(items[i], false);
          }
        }
      } else {
        CSSValue value = unselectedStyle.getPropertyCSSValue("show-close");
        boolean unselectedShowClose =
            value == null ? false : Boolean.parseBoolean(value.getCssText());
        for (int i = 0; i < items.length; i++) {
          if (selectionSet && i != selectionIndex) {
            setShowClose(items[i], unselectedShowClose);
          }
        }
      }

      this.selection = selection;
    }
 /**
  * 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();
 }
 @Override
 public void doSetValue(Object value) {
   final Object oldValue = doGetValue();
   if (attribute.equals(Constants.ATTR_IMAGE)) {
     item.setImage((Image) value);
   } else if (attribute.equals(Constants.ATTR_TEXT)) {
     item.setText((String) value);
   } else if (attribute.equals(Constants.ATTR_TOOLTIP)) {
     if (item instanceof TableColumn) {
       ((TableColumn) item).setToolTipText((String) value);
     }
     if (item instanceof TreeColumn) {
       ((TreeColumn) item).setToolTipText((String) value);
     }
     if (item instanceof ToolItem) {
       ((ToolItem) item).setToolTipText((String) value);
     }
     if (item instanceof TabItem) {
       ((TabItem) item).setToolTipText((String) value);
     }
   } else if (attribute.equals(Constants.ATTR_ALIGNMENT)) {
     if (item instanceof TableColumn) {
       ((TableColumn) item).setAlignment((Integer) value);
     }
     if (item instanceof TreeColumn) {
       ((TreeColumn) item).setAlignment((Integer) value);
     }
   } else if (attribute.equals(Constants.ATTR_WIDTH)) {
     if (item instanceof TableColumn) {
       ((TableColumn) item).setWidth((Integer) value);
     }
     if (item instanceof TreeColumn) {
       ((TreeColumn) item).setWidth((Integer) value);
     }
     if (item instanceof ToolItem) {
       ((ToolItem) item).setWidth((Integer) value);
     }
   } else if (attribute.equals(Constants.ATTR_ENABLED)) {
     if (item instanceof ToolItem) {
       ((ToolItem) item).setEnabled(value == Boolean.TRUE);
     }
   }
   fireValueChange(Diffs.createValueDiff(oldValue, value));
 }
 /**
  * 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);
   }
 }
  /**
   * 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
  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));
    }
  }
 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;
 }
Exemplo n.º 26
0
  /**
   * Resort the table based on field.
   *
   * @param column the column being updated
   * @param field
   */
  private void resortTable(final Item column, final ISTDataViewersField field) {
    STDataViewersComparator sorter = stViewer.getTableSorter();

    if (column.equals(sorter.getTopColumn())) {
      sorter.reverseTopPriority();
    } else {
      sorter.setTopPriority(column, field);
    }

    BusyIndicator.showWhile(
        null,
        () -> {
          stViewer.getViewer().refresh();
          stViewer.updateDirectionIndicator(column);
        });
  }
  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);
      }
    }
  }
Exemplo n.º 28
0
 public void refresh(TreeEditor editor) {
   Button button = (Button) editor.getEditor();
   Item item = editor.getItem();
   Boolean value = (Boolean) getValue(item.getData());
   button.setSelection(value.booleanValue());
 }
Exemplo n.º 29
0
 @Override
 public void widgetSelected(SelectionEvent e) {
   final Item column = (Item) e.widget;
   final ISTDataViewersField field = (ISTDataViewersField) column.getData();
   resortTable(column, field);
 }
Exemplo n.º 30
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();
  }