Ejemplo 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;
  }
  /**
   * @param element Object the Object
   * @return Image an Image
   */
  public Image getImage(Object element) {
    Image image = null;
    if (element instanceof IComponentNamePO) {
      image = IconConstants.LOGICAL_NAME_IMAGE;
    } else if (element instanceof IObjectMappingAssoziationPO) {
      int status = getQualitySeverity(((IObjectMappingAssoziationPO) element).getCompIdentifier());
      switch (status) {
        case IStatus.OK:
          image = IconConstants.TECH_NAME_OK_IMAGE;
          break;
        case IStatus.WARNING:
          image = IconConstants.TECH_NAME_WARNING_IMAGE;
          break;
        case IStatus.ERROR:
          image = IconConstants.TECH_NAME_ERROR_IMAGE;
          break;
        default:
          image = IconConstants.TECHNICAL_NAME_IMAGE;
          break;
      }
    } else if (element instanceof IObjectMappingCategoryPO) {
      image = IconConstants.CATEGORY_IMAGE;
    } else if (element instanceof String) {
      // Missing Component Name
      image = IconConstants.LOGICAL_NAME_IMAGE;
    } else {
      String elementType = element != null ? element.getClass().getName() : "null"; // $NON-NLS-1$
      StringBuilder msg = new StringBuilder();
      msg.append(Messages.ElementType)
          .append(StringConstants.SPACE)
          .append(StringConstants.APOSTROPHE)
          .append(elementType)
          .append(StringConstants.APOSTROPHE)
          .append(StringConstants.SPACE)
          .append(Messages.NotSupported)
          .append(StringConstants.DOT);
      Assert.notReached(msg.toString());
      return null;
    }

    Object cbContents = m_clipboard.getContents(LocalSelectionClipboardTransfer.getInstance());
    if (cbContents instanceof IStructuredSelection) {
      IStructuredSelection sel = (IStructuredSelection) cbContents;
      if (sel.toList().contains(element)) {
        image = Plugin.getCutImage(image);
      }
    }

    return image;
  }