@Override
  public void setActivePage(IEditorPart part) {
    if (activeEditorPart == part) return;

    activeEditorPart = part;

    IActionBars actionBars = getActionBars();

    if (activeEditorPart != null && activeEditorPart instanceof ITextEditor) {
      IActionBars siteActionBars = ((IEditorSite) activeEditorPart.getEditorSite()).getActionBars();
      siteActionBars.setGlobalActionHandler(
          ITextEditorActionConstants.UNDO,
          getAction((ITextEditor) activeEditorPart, ITextEditorActionConstants.UNDO));
      siteActionBars.setGlobalActionHandler(
          ITextEditorActionConstants.REDO,
          getAction((ITextEditor) activeEditorPart, ITextEditorActionConstants.REDO));
      siteActionBars.updateActionBars();
    } else {
      if (part instanceof BPELEditor) {
        bpelEditor = (BPELEditor) part;
      }
      if (bpelEditor != null) {
        Object adapter = bpelEditor.getAdapter(ActionRegistry.class);
        if (adapter instanceof ActionRegistry) {
          ActionRegistry registry = (ActionRegistry) adapter;
          // COPY
          IAction action = registry.getAction(BPELCopyAction.ID);
          actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), action);
          // CUT
          action = registry.getAction(BPELCutAction.ID);
          actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), action);
          // PASTE
          action = registry.getAction(BPELPasteAction.ID);
          actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), action);
          // DELETE
          action = registry.getAction(BPELDeleteAction.ID);
          actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), action);
        }

        IWorkbenchPartSite site = bpelEditor.getSite();
        if (site instanceof IEditorSite) {
          ITextEditor textEditor = bpelEditor.getMultipageEditor().getTextEditor();
          IActionBars siteActionBars = ((IEditorSite) site).getActionBars();
          siteActionBars.setGlobalActionHandler(
              ITextEditorActionConstants.UNDO,
              getAction(textEditor, ITextEditorActionConstants.UNDO));
          siteActionBars.setGlobalActionHandler(
              ITextEditorActionConstants.REDO,
              getAction(textEditor, ITextEditorActionConstants.REDO));
          siteActionBars.updateActionBars();
        }
      }
    }

    if (actionBars != null) {
      // update menu bar and tool bar
      actionBars.updateActionBars();
    }
  }
  /** @see org.eclipse.bpel.ui.actions.BPELCopyAction#getCommand() */
  @Override
  protected Command getCommand() {

    CompoundCommand cmd = new CompoundCommand(Messages.BPELCopyAction_Copy_3);

    final BPELEditor bpelEditor = (BPELEditor) getWorkbenchPart();

    // 1. Restore selection
    cmd.add(new RestoreSelectionCommand(bpelEditor.getAdaptingSelectionProvider(), true, true));

    // 2. Copy the objects that are selected.
    BPELCopyCommand copyCmd = new BPELCopyCommand(bpelEditor);
    if (fSelection.isEmpty()) {
      for (Object o : ((IStructuredSelection) bpelEditor.getSelection()).toList()) {
        if (o instanceof EObject) {
          fSelection.add((EObject) o);
        }
      }
    }
    if (fSelection.isEmpty()) {
      return null;
    }
    copyCmd.setObjectList(new ArrayList<EObject>(fSelection));
    cmd.add(copyCmd);

    // 3. Immediately paste them
    BPELPasteCommand pasteCmd =
        new BPELPasteCommand(bpelEditor) {

          /**
           * We override the canDoExecute, because the compound command in GEF will check both of
           * the commands for canDoExecute() before running the compound command. Since the copy
           * command is a prerequisite for the paste here, this condition will never be true unless
           * we just allow it.
           *
           * @see org.eclipse.bpel.ui.commands.BPELPasteCommand#canDoExecute()
           */
          @Override
          public boolean canDoExecute() {
            return true;
          }
        };
    pasteCmd.setTargetObject(fSelection.get(0), true);
    cmd.add(pasteCmd);

    // 4. Add the command to select the pasted elements
    cmd.add(new SetSelectionCommand(pasteCmd, false));

    return cmd;
  }