Ejemplo n.º 1
0
  /** Adds drag and drop support to the tree viewer. */
  private void addDragAndDropSupport() {
    final DelegatingDropAdapter dropAdapter = new DelegatingDropAdapter();
    dropAdapter.addDropTargetListener(
        new AlarmTreeLocalSelectionDropListener(this, _ldapModificationItems));
    dropAdapter.addDropTargetListener(
        new AlarmTreeProcessVariableDropListener(this, _ldapModificationItems));
    _viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, dropAdapter.getTransfers(), dropAdapter);

    final DelegatingDragAdapter dragAdapter = new DelegatingDragAdapter();
    dragAdapter.addDragSourceListener(new AlarmTreeLocalSelectionDragListener(this));
    dragAdapter.addDragSourceListener(new AlarmTreeProcessVariableDragListener(this));
    dragAdapter.addDragSourceListener(new AlarmTreeTextDragListener(this));
    _viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, dragAdapter.getTransfers(), dragAdapter);
  }
  /**
   * Configures (or reconfigures) the page according to the given configuration.
   *
   * @param configuration
   */
  public void setConfiguration(ContentOutlineConfiguration configuration) {
    // intentionally do not check to see if the new configuration != old
    // configuration
    unconfigure();

    fConfiguration = configuration;

    if (getTreeViewer() != null && getControl() != null && !getControl().isDisposed()) {
      // (re)set the providers
      ILabelProvider labelProvider = getConfiguration().getLabelProvider(getTreeViewer());
      if (labelProvider instanceof IStyledLabelProvider) {
        getTreeViewer()
            .setLabelProvider(
                new DelegatingStyledCellLabelProvider((IStyledLabelProvider) labelProvider));
      } else {
        getTreeViewer().setLabelProvider(labelProvider);
      }
      getTreeViewer().setContentProvider(getConfiguration().getContentProvider(getTreeViewer()));

      // view toolbar
      IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
      if (toolbar != null) {
        IContributionItem[] toolbarItems =
            getConfiguration().getToolbarContributions(getTreeViewer());
        if (toolbarItems != null) {
          for (int i = 0; i < toolbarItems.length; i++) {
            toolbar.add(toolbarItems[i]);
          }
          toolbar.update(true);
        }
      }
      // view menu
      IContributionManager menu = getSite().getActionBars().getMenuManager();
      if (menu != null) {
        IContributionItem[] menuItems = getConfiguration().getMenuContributions(getTreeViewer());
        if (menuItems != null) {
          for (int i = 0; i < menuItems.length; i++) {
            menuItems[i].setVisible(true);
            menu.add(menuItems[i]);
            menuItems[i].update();
          }
          menu.update(true);
        }
      }
      // add the allowed DnD listeners and types
      TransferDragSourceListener[] dragListeners =
          getConfiguration().getTransferDragSourceListeners(getTreeViewer());
      if (fDragAdapter != null && dragListeners.length > 0) {
        for (int i = 0; i < dragListeners.length; i++) {
          fDragAdapter.addDragSourceListener(dragListeners[i]);
        }
        fActiveDragListeners = dragListeners;
        fDragSource.addDragListener(fDragAdapter);
        fDragSource.setTransfer(fDragAdapter.getTransfers());
      }
      TransferDropTargetListener[] dropListeners =
          getConfiguration().getTransferDropTargetListeners(getTreeViewer());
      if (fDropAdapter != null && dropListeners.length > 0) {
        for (int i = 0; i < dropListeners.length; i++) {
          fDropAdapter.addDropTargetListener(dropListeners[i]);
        }
        fActiveDropListeners = dropListeners;
        fDropTarget.addDropListener(fDropAdapter);
        fDropTarget.setTransfer(fDropAdapter.getTransfers());
      }
      // add the key listeners
      KeyListener[] listeners = getConfiguration().getKeyListeners(getTreeViewer());
      if (listeners != null) {
        for (int i = 0; i < listeners.length; i++) {
          getControl().addKeyListener(listeners[i]);
        }
      }
    }

    if (fInput != null) {
      setInput(fInput);
    }
  }