Exemplo n.º 1
0
  /** {@inheritDoc} */
  public Object execute(ExecutionEvent event) {
    AbstractJBEditor jbe = (AbstractJBEditor) Plugin.getActiveEditor();
    LocalSelectionClipboardTransfer transfer = LocalSelectionClipboardTransfer.getInstance();

    if (!(jbe.getEditorHelper().getClipboard().getContents(transfer)
        instanceof IStructuredSelection)) {
      return null;
    }
    IStructuredSelection pasteSelection =
        (IStructuredSelection) jbe.getEditorHelper().getClipboard().getContents(transfer);
    if (pasteSelection != null && jbe.getSelection() instanceof IStructuredSelection) {

      // Paste will always occur at the most recently selected node.
      IStructuredSelection selection = (IStructuredSelection) jbe.getSelection();
      Object[] selArray = selection.toArray();

      INodePO target;
      if (jbe.getSelection().isEmpty()) {
        target = (INodePO) jbe.getTreeViewer().getTree().getTopItem().getData();
      } else {
        target = (INodePO) selArray[selArray.length - 1];
      }

      if (!transfer.getIsItCut()) {
        if (jbe instanceof TestCaseEditor) {
          TCEditorDndSupport.copyPaste((TestCaseEditor) jbe, pasteSelection, target);
        } else if (jbe instanceof TestSuiteEditor) {
          new TSEditorDndSupport().copyPaste((TestSuiteEditor) jbe, pasteSelection, target);
        } else if (jbe instanceof TestJobEditor) {
          TJEditorDndSupport.copyPaste(jbe, pasteSelection, target);
        }
      } else if (jbe instanceof AbstractTestCaseEditor) {
        if (TCEditorDndSupport.performDrop(
            (AbstractTestCaseEditor) jbe, pasteSelection, target, ViewerDropAdapter.LOCATION_ON)) {
          jbe.getEditorHelper().getClipboard().clearContents();
          transfer.setSelection(null, null, false);
        }
      }
    }

    return null;
  }