private void doCutCopyWithImportsOperation() {
    ITextEditor editor = getTextEditor();
    ITypeRoot inputElement = JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
    ISelection selection = editor.getSelectionProvider().getSelection();

    Object clipboardData = null;
    if (inputElement != null && selection instanceof ITextSelection && !selection.isEmpty()) {
      ITextSelection textSelection = (ITextSelection) selection;
      if (isNonTrivialSelection(textSelection)) {
        clipboardData =
            getClipboardData(inputElement, textSelection.getOffset(), textSelection.getLength());
      }
    }

    fOperationTarget.doOperation(fOperationCode);

    if (clipboardData != null) {
      /*
       * We currently make assumptions about what the styled text widget sets,
       * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=61876
       */
      Clipboard clipboard = new Clipboard(getDisplay());
      try {
        Object textData = clipboard.getContents(TextTransfer.getInstance());
        /*
         * Don't add if we didn't get any text data from the clipboard, see:
         * - https://bugs.eclipse.org/bugs/show_bug.cgi?id=70077
         * - https://bugs.eclipse.org/bugs/show_bug.cgi?id=200743
         */
        if (textData == null) return;

        ArrayList<Object> datas = new ArrayList<Object>(3);
        ArrayList<ByteArrayTransfer> transfers = new ArrayList<ByteArrayTransfer>(3);
        datas.add(textData);
        transfers.add(TextTransfer.getInstance());

        Object rtfData = clipboard.getContents(RTFTransfer.getInstance());
        if (rtfData != null) {
          datas.add(rtfData);
          transfers.add(RTFTransfer.getInstance());
        }

        datas.add(clipboardData);
        transfers.add(fgTransferInstance);

        Transfer[] dataTypes = transfers.toArray(new Transfer[transfers.size()]);
        Object[] data = datas.toArray();
        setClipboardContents(clipboard, data, dataTypes);
      } finally {
        clipboard.dispose();
      }
    }
  }
 public boolean canPaste(Clipboard clipboard) {
   TransferData[] types = clipboard.getAvailableTypes();
   Transfer[] transfers = new Transfer[] {TextTransfer.getInstance(), RTFTransfer.getInstance()};
   for (int i = 0; i < types.length; i++) {
     for (int j = 0; j < transfers.length; j++) {
       if (transfers[j].isSupportedType(types[i])) return true;
     }
   }
   return false;
 }