Exemplo 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);
  }
  /** Unconfigure the content outline page */
  private void unconfigure() {
    if (getTreeViewer() != null) {
      // remove the key listeners
      if (getControl() != null && !getControl().isDisposed()) {
        KeyListener[] listeners = getConfiguration().getKeyListeners(getTreeViewer());
        if (listeners != null) {
          for (int i = 0; i < listeners.length; i++) {
            getControl().removeKeyListener(listeners[i]);
          }
        }
      }

      IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
      if (toolbar != null && !toolbar.isEmpty()) {
        IContributionItem[] toolbarItems =
            getConfiguration().getToolbarContributions(getTreeViewer());
        if (toolbarItems != null && toolbarItems.length > 0) {
          for (int i = 0; i < toolbarItems.length; i++) {
            toolbar.remove(toolbarItems[i]);
          }
          toolbar.update(false);
        }
      }

      IContributionManager menubar = getSite().getActionBars().getMenuManager();
      if (menubar != null && !menubar.isEmpty()) {
        IContributionItem[] menuItems = getConfiguration().getMenuContributions(getTreeViewer());
        if (menuItems != null && menuItems.length > 0) {
          for (int i = 0; i < menuItems.length; i++) {
            menubar.remove(menuItems[i]);
          }
          menubar.remove(IWorkbenchActionConstants.MB_ADDITIONS);
          menubar.update(false);
        }
      }
      // clear the DnD listeners and transfer types
      if (fDragAdapter != null
          && !fDragAdapter.isEmpty()
          && fDragSource != null
          && !fDragSource.isDisposed()
          && fDragSource.getTransfer().length > 0) {
        if (fActiveDragListeners != null) {
          for (int i = 0; i < fActiveDragListeners.length; i++) {
            fDragAdapter.removeDragSourceListener(fActiveDragListeners[i]);
          }
        }
        fActiveDragListeners = null;
        fDragSource.removeDragListener(fDragAdapter);
        fDragSource.setTransfer(new Transfer[0]);
      }
      if (fDropAdapter != null
          && !fDropAdapter.isEmpty()
          && fDropTarget != null
          && !fDropTarget.isDisposed()
          && fDropTarget.getTransfer().length > 0) {
        if (fActiveDropListeners != null) {
          for (int i = 0; i < fActiveDropListeners.length; i++) {
            fDropAdapter.removeDropTargetListener(fActiveDropListeners[i]);
          }
        }
        fActiveDropListeners = null;
        fDropTarget.removeDropListener(fDropAdapter);
        fDropTarget.setTransfer(new Transfer[0]);
      }
      getConfiguration()
          .getContentProvider(getTreeViewer())
          .inputChanged(getTreeViewer(), fInput, null);
      // release any ties to this tree viewer
      getConfiguration().unconfigure(getTreeViewer());
    }
  }
  /**
   * 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);
    }
  }