Java 类org.eclipse.swt.dnd.TextTransfer 实例源码

项目:gama    文件:CopyAction.java   
/**
 * Set the clipboard contents. Prompt to retry if clipboard is busy.
 *
 * @param resources
 *            the resources to copy to the clipboard
 * @param fileNames
 *            file names of the resources to copy to the clipboard
 * @param names
 *            string representation of all names
 */
private void setClipboard(final IResource[] resources, final String[] fileNames, final String names) {
    try {
        // set the clipboard contents
        if (fileNames.length > 0) {
            clipboard.setContents(new Object[] { resources, fileNames, names }, new Transfer[] {
                    ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() });
        } else {
            clipboard.setContents(new Object[] { resources, names },
                    new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() });
        }
    } catch (final SWTError e) {
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; }
        if (MessageDialog.openQuestion(shell, "Problem with copy title", // TODO //$NON-NLS-1$
                                                                            // ResourceNavigatorMessages.CopyToClipboardProblemDialog_title,
                "Problem with copy.")) { //$NON-NLS-1$
            setClipboard(resources, fileNames, names);
        }
    }
}
项目:eclipse-plugin-commander    文件:InternalCommandContextProviderFactory.java   
private static void addDefaultInternalCommands(InternalCommandContextProvider provider, KaviPickListDialog kaviPickList) {
    provider.addCommand("list: toggle view selected", (currentProvider) -> {
        currentProvider.toggleViewOnlySelected();
        kaviPickList.togglePreviousProvider().refreshFromContentProvider();
    });

    provider.addCommand("list: selected to clipboard", (currentProvider) -> {

        Clipboard clipboard = new Clipboard(kaviPickList.getShell().getDisplay());
        final List<BiFunction<Object, Integer, String>> fieldResolvers = currentProvider.getKaviListColumns().getColumnOptions().stream()
                   .filter(column -> column.isSearchable())
                   .map(column -> column.getColumnContentFn())
                   .collect(Collectors.toList());

        FieldCollectorTransform transform = new FieldCollectorTransform(fieldResolvers, currentProvider.getSelectedEntriesImplied().stream().map(rankedItem -> rankedItem.dataItem).collect(Collectors.toList()));

        clipboard.setContents(new Object[] { transform.asAlignedColumns() },    new Transfer[] { TextTransfer.getInstance() });
        kaviPickList.togglePreviousProvider().refreshFromContentProvider();
        clipboard.dispose();
    });

    provider.addCommand("working", "list: toggle sort name", (currentProvider) -> {
        kaviPickList.togglePreviousProvider().sortDefault().refreshFromContentProvider();
    });     
}
项目:JavaFX-FrameRateMeter    文件:OldFXCanvas.java   
Transfer getTransferType(String mime) {
    if (mime.equals("text/plain")) {
      return TextTransfer.getInstance();
    }
    if (mime.equals("text/rtf")) {
      return RTFTransfer.getInstance();
    }
    if (mime.equals("text/html")) {
      return HTMLTransfer.getInstance();
    }
    if (mime.equals("text/uri-list")) {
      return URLTransfer.getInstance();
    }
    if (mime.equals("application/x-java-rawimage")) {
      return ImageTransfer.getInstance();
    }
    if (mime.equals("application/x-java-file-list") || mime.equals("java.file-list")) {
        return FileTransfer.getInstance();
    }
    return getCustomTransfer(mime);
}
项目:JavaFX-FrameRateMeter    文件:OldFXCanvas.java   
String getMime(Transfer transfer) {
    if (transfer.equals(TextTransfer.getInstance())) {
      return "text/plain";
    }
    if (transfer.equals(RTFTransfer.getInstance())) {
      return "text/rtf";
    } ;
    if (transfer.equals( HTMLTransfer.getInstance())) {
      return "text/html";
    }
    if (transfer.equals(URLTransfer.getInstance())) {
      return "text/uri-list";
    }
    if (transfer.equals( ImageTransfer.getInstance())) {
      return "application/x-java-rawimage";
    }
    if (transfer.equals(FileTransfer.getInstance())) {
      return "application/x-java-file-list";
    }
    if (transfer instanceof CustomTransfer) {
      return ((CustomTransfer)transfer).getMime();
    }
    return null;
}
项目:Hydrograph    文件:ELTSWTWidgets.java   
public void applyDragFromTableViewer(Control sourceControl, int index) {
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    final String portLabel = "in" + index + ".";
    int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
    final Table table = (Table) sourceControl;
    DragSource source = new DragSource(table, operations);
    source.setTransfer(types);
    final String[] columnData = new String[1];
    source.addDragListener(new DragSourceAdapter() {
        public void dragSetData(DragSourceEvent event) {
            // Set the data to be the first selected item's text
            event.data = addDelimeter(portLabel, table.getSelection());
        }
    });

}
项目:Hydrograph    文件:ExcelFormattingDialog.java   
private void attachDropListener() {
    dropTarget = new DropTarget(targetTable, DND.DROP_MOVE);
    dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
    dropTarget.addDropListener(new DropTargetAdapter() {
        public void drop(DropTargetEvent event) {
            for (String fieldName : getformatedData((String) event.data)) {
                if(isPropertyAlreadyExists(fieldName)){
                    return;
                }else{
                    ExcelConfigurationDataStructure excelConfigurationDataStructure = new ExcelConfigurationDataStructure();
                    excelConfigurationDataStructure.setFieldName(fieldName);
                    listOfExcelConfiguration.add(excelConfigurationDataStructure);
                    targetTableViewer.refresh();
                    draggedFields.add(fieldName);
                    enableDeleteButton();
                }
            }
            combo.setItems(convertToArray(draggedFields));
            combo.select(0);
            top_composite.layout();
            top_composite.getParent().layout();
            highlightDropFields();

        }
    });
}
项目:Hydrograph    文件:CopyAction.java   
private void copySelectedAsTabDelimited() {
    StringBuffer stringBuffer = new StringBuffer();
    int totalRowCount = debugDataViewer.getTableViewer().getTable().getItemCount();
    int totalColumnCount = debugDataViewer.getTableViewer().getTable().getColumnCount();
    boolean hasRow=false;
    for (int rowCount = 0; rowCount < totalRowCount; rowCount++) {
        for (int columnCount = 0; columnCount < totalColumnCount; columnCount++) {
            Point cell = new Point(rowCount, columnCount);
            if(debugDataViewer.getSelectedCell().contains(cell)){
                stringBuffer.append(debugDataViewer.getTableViewer().getTable().getItem(rowCount).getText(columnCount) + "\t");
                hasRow=true;
            }
            cell=null;
        }
        if(hasRow){
            stringBuffer.append("\n");
            hasRow=false;
        }               
    }
    Clipboard cb = new Clipboard(Display.getCurrent());
    TextTransfer textTransfer = TextTransfer.getInstance();
    String textData = stringBuffer.toString();
    cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
    cb.dispose();

}
项目:BiglyBT    文件:OpenTorrentWindow.java   
@Override
public void updateUI() {
    boolean bTorrentInClipboard = false;

    Clipboard clipboard = new Clipboard(Display.getDefault());

    String sClipText = (String) clipboard.getContents(TextTransfer.getInstance());
    if (sClipText != null)
        bTorrentInClipboard = addTorrentsFromTextList(sClipText, true) > 0;

    if (btnPasteOpen != null && !btnPasteOpen.isDisposed()
            && btnPasteOpen.isVisible() != bTorrentInClipboard) {
        btnPasteOpen.setVisible(bTorrentInClipboard);
        if (bTorrentInClipboard) {
            btnPasteOpen.setToolTipText(sClipText);
        }
    }

    clipboard.dispose();
}
项目:BiglyBT    文件:ClipboardCopy.java   
public static void
copyToClipBoard(
  final String    data )
{
 Runnable do_it =
new Runnable()
    {
  @Override
  public void
  run()
  {
      new Clipboard(Utils.getDisplay()).setContents(
              new Object[] {data.replaceAll("\\x00", " " )  },
              new Transfer[] {TextTransfer.getInstance()});
  }
    };

 if ( Utils.isSWTThread()){

  do_it.run();

 }else{

  Utils.execSWTThread( do_it );
 }
}
项目:BiglyBT    文件:ClipboardCopy.java   
public static void
 addCopyToClipMenu(
final Menu      menu,
final String    text )
 {
  MenuItem   item = new MenuItem( menu,SWT.NONE );

  String    msg_text_id= "label.copy.to.clipboard";

  item.setText( MessageText.getString( msg_text_id ));

  item.addSelectionListener(
      new SelectionAdapter()
      {
          @Override
          public void
          widgetSelected(
                  SelectionEvent arg0)
          {
              new Clipboard(menu.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()});
          }
      });
 }
项目:team-explorer-everywhere    文件:WorkingFolderDataTable.java   
public void pasteFromClipboard() {
    final String text = (String) getClipboard().getContents(TextTransfer.getInstance());
    if (text == null) {
        return;
    }

    final WorkingFolderData[] workingFolders = getWorkingFoldersFromClipboardText(text);
    if (workingFolders.length == 0) {
        return;
    }

    final WorkingFolderDataCollection collection = getWorkingFolderDataCollection();
    for (int i = 0; i < workingFolders.length; i++) {
        collection.add(workingFolders[i]);
    }

    refresh();
}
项目:Notepad4e    文件:NotepadView.java   
/**
 * Adds a new note to the notepad.
 */
public void addNewNote() {
    String noteText = "";
    if (preferences.getBoolean(PreferenceConstants.PREF_PASTE_CLIPBOARD_IN_NEW_NOTES,
            PreferenceConstants.PREF_PASTE_CLIPBOARD_IN_NEW_NOTES_DEFAULT)) {
        noteText = (String) clipboard.getContents(TextTransfer.getInstance(), DND.CLIPBOARD);
    }
    String noteTitle = preferences.get(PreferenceConstants.PREF_NAME_PREFIX,
            PreferenceConstants.PREF_NAME_PREFIX_DEFAULT) + " " + (tabFolder.getItemCount() + 1);
    // Add a new note tab with a number appended to its name (Note 1, Note 2, Note 3, etc.).
    addNewNoteTab(noteTitle, noteText, null, true, null);
    CTabItem previousSelectedTab = tabFolder.getSelection();
    // Remove lock for currently selected tab.
    if (previousSelectedTab != null && previousSelectedTab.getText().startsWith(LOCK_PREFIX)) {
        previousSelectedTab.setText(previousSelectedTab.getText().substring(LOCK_PREFIX.length()));
    }
    tabFolder.setSelection(tabFolder.getItemCount() - 1);
}
项目:javapasswordsafe    文件:TreeDragListener.java   
public void dragSetData(final DragSourceEvent event) {
    final IStructuredSelection selection = (IStructuredSelection) viewer
            .getSelection();

    if (selection.getFirstElement() instanceof PwsEntryBean) {
        final PwsEntryBean firstElement = (PwsEntryBean) selection.getFirstElement();
        if (PwsEntryBeanTransfer.getInstance().isSupportedType(event.dataType)) {
            event.data = firstElement.getStoreIndex();
        }
    } else if (selection.getFirstElement() instanceof PasswordTreeContentProvider.TreeGroup) {
        event.doit = false; // disable for now
        final PasswordTreeContentProvider.TreeGroup group =
                (PasswordTreeContentProvider.TreeGroup) selection.getFirstElement();

        if (PwsEntryBeanTransfer.getInstance().isSupportedType(event.dataType)) {
            event.data = group.getGroupPath();
        }
        if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
            event.data = group.getGroupPath();
        }
    } else {
        log.warn("Unknown type: " + selection.getFirstElement().getClass());
    }
}
项目:javapasswordsafe    文件:PwsEntryBeanTransfer.java   
@Override
protected void javaToNative(final Object object, final TransferData transferData) {
    if (object instanceof Integer) {
        final byte[] bytes = ByteBuffer.allocate(4).putInt((Integer) object).array();

        if (bytes != null) {
            super.javaToNative(bytes, transferData);
        }
    } else if (object instanceof String) {
        if (! TextTransfer.getInstance().isSupportedType(transferData)) {
            // FIXME this is a hack - works on Linux x64...
            // no danger for now as treegroups are disabled on drag side
            long type =  transferData.type;
            for (final TransferData data : TextTransfer.getInstance().getSupportedTypes()) {
                type = data.type;
            }
            // on 32bit you need int instead of long, to avoid compile errors there use this here
            transferData.type = (int) type;
        }
        TextTransfer.getInstance().javaToNative(object, transferData);
    }
}
项目:texlipse    文件:TexOutlineDNDAdapter.java   
/**
    * Set the text data into TextTransfer.
    * 
    * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
 */
   public void dragSetData(DragSourceEvent event) {

    // check that requested data type is supported
    if (!TextTransfer.getInstance().isSupportedType(event.dataType)) {
        return;
    }

       // get the source text
    int sourceOffset = this.dragSource.getPosition().getOffset();
    int sourceLength = this.dragSource.getPosition().getLength();

    Position sourcePosition = dragSource.getPosition();
    String sourceText = "";
    try {
        sourceText = getDocument().get(sourcePosition.getOffset(), sourcePosition.getLength());
    } catch (BadLocationException e) {
        TexlipsePlugin.log("Could not set drag data.", e);
        return;
    }

       // set the data
       event.data = sourceText;
}
项目:mesfavoris    文件:CopyBookmarkUrlHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
    String url = getBookmarkUrl(selection);
    if (url == null) {
        return null;
    }

    Clipboard clipboard = new Clipboard(null);
    try {
        TextTransfer textTransfer = TextTransfer.getInstance();
        Transfer[] transfers = new Transfer[] { textTransfer };
        Object[] data = new Object[] { url };
        clipboard.setContents(data, transfers);
    } finally {
        clipboard.dispose();
    }
    return null;
}
项目:mesfavoris    文件:PasteBookmarkOperation.java   
private IStructuredSelection getStructuredSelectionFromClipboard(Display display) {
    Clipboard clipboard = new Clipboard(display);
    try {
        String text = (String) clipboard.getContents(URLTransfer.getInstance());
        if (text == null) {
            text = (String) clipboard.getContents(TextTransfer.getInstance());
        }
        if (text != null) {
            try {
                URL url = new URL(text);
                return new StructuredSelection(url);
            } catch (MalformedURLException e) {

            }
        }
        String[] paths = (String[]) clipboard.getContents(FileTransfer.getInstance());
        if (paths != null) {
            return new StructuredSelection(Arrays.stream(paths).map(Path::new).collect(Collectors.toList()));
        }
        return new StructuredSelection();
    } finally {
        clipboard.dispose();
    }
}
项目:logbook    文件:TableToClipboardAdapter.java   
/**
 * テーブルの選択されている部分をヘッダー付きでクリップボードにコピーします
 *
 * @param header ヘッダー
 * @param table テーブル
 */
public static void copyTable(String[] header, Table table) {
    TableItem[] tableItems = table.getSelection();
    StringBuilder sb = new StringBuilder();
    sb.append(StringUtils.join(header, "\t"));
    sb.append("\r\n");
    for (TableItem column : tableItems) {
        String[] columns = new String[header.length];
        for (int i = 0; i < header.length; i++) {
            columns[i] = column.getText(i);
        }
        sb.append(StringUtils.join(columns, "\t"));
        sb.append("\r\n");
    }
    Clipboard clipboard = new Clipboard(Display.getDefault());
    clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() });
}
项目:logbook    文件:TreeToClipboardAdapter.java   
/**
 * ツリーの選択されている部分をヘッダー付きでクリップボードにコピーします
 * 
 * @param header ヘッダー
 * @param tree ツリー
 */
public static void copyTree(String[] header, Tree tree) {
    TreeItem[] treeItems = tree.getSelection();
    StringBuilder sb = new StringBuilder();
    sb.append(StringUtils.join(header, "\t"));
    sb.append("\r\n");
    for (TreeItem column : treeItems) {
        String[] columns = new String[header.length];
        for (int i = 0; i < header.length; i++) {
            columns[i] = column.getText(i);
        }
        sb.append(StringUtils.join(columns, "\t"));
        sb.append("\r\n");
    }
    Clipboard clipboard = new Clipboard(Display.getDefault());
    clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() });
}
项目:hssd    文件:AbstractCommandHandler.java   
protected String fromClipboard(IEditorPart editor) {
       Shell shell = editor.getSite().getShell();
       Display display = shell.getDisplay();
       Clipboard clip = new Clipboard(display);
       try {
           TextTransfer transfer = TextTransfer.getInstance();
           return (String)clip.getContents(transfer);
       }
       catch(Exception e) {
        ElementHelper.panic(log, "from clipboard", e);
        throw new RuntimeException(e);
       }
       finally {
           clip.dispose();
       }
}
项目:hssd    文件:ClipboardTester.java   
@Override
public boolean test(Object receiver, String property, Object[] args,
        Object expectedValue) {
    if("hasTextContent".equals(property)) {
        IWorkbenchPart part = Helper.getActivePart();
        if(part == null) {
            return false;
        }

        Display display = part.getSite().getShell().getDisplay();
        Clipboard clip = new Clipboard(display);
        Object content = clip.getContents(TextTransfer.getInstance());
        clip.dispose();
        return expectedValue.equals(content != null);
    }
    return false;
}
项目:SMVHunter    文件:NativeHeapPanel.java   
private void copyToClipboard(TreeItem[] items, Clipboard clipboard) {
    StringBuilder sb = new StringBuilder();

    for (TreeItem item : items) {
        Object data = item.getData();
        if (data != null) {
            sb.append(data.toString());
            sb.append('\n');
        }
    }

    String content = sb.toString();
    if (content.length() > 0) {
        clipboard.setContents(
                new Object[] {sb.toString()},
                new Transfer[] {TextTransfer.getInstance()}
                );
    }
}
项目:SMVHunter    文件:LogPanel.java   
/**
 * Copies the current selection of a Table into the provided Clipboard, as
 * multi-line text.
 *
 * @param clipboard The clipboard to place the copied content.
 * @param table The table to copy from.
 */
private static void copyTable(Clipboard clipboard, Table table) {
    int[] selection = table.getSelectionIndices();

    // we need to sort the items to be sure.
    Arrays.sort(selection);

    // all lines must be concatenated.
    StringBuilder sb = new StringBuilder();

    // loop on the selection and output the file.
    for (int i : selection) {
        TableItem item = table.getItem(i);
        LogMessage msg = (LogMessage)item.getData();
        String line = msg.toString();
        sb.append(line);
        sb.append('\n');
    }

    // now add that to the clipboard
    clipboard.setContents(new Object[] {
        sb.toString()
    }, new Transfer[] {
        TextTransfer.getInstance()
    });
}
项目:SMVHunter    文件:LogCatPanel.java   
/** Copy all selected messages to clipboard. */
public void copySelectionToClipboard(Clipboard clipboard) {
    StringBuilder sb = new StringBuilder();

    for (LogCatMessage m : getSelectedLogCatMessages()) {
        sb.append(m.toString());
        sb.append('\n');
    }

    if (sb.length() > 0) {
        clipboard.setContents(
                new Object[] {sb.toString()},
                new Transfer[] {TextTransfer.getInstance()}
                );
    }
}
项目:scouter    文件:WorkspaceExplorer.java   
public void run() {
    ISelection sel = viewer.getSelection();
    if (sel instanceof StructuredSelection) {
           StringBuilder sb = new StringBuilder();
           @SuppressWarnings("unchecked")
           Iterator<File> i = ((StructuredSelection)sel).iterator();
           while (i.hasNext()) {
               File file = i.next();
               sb.append(file.getAbsolutePath().replace("\\", "/"));
               if (i.hasNext()) {
                   sb.append(sep);
               }
           }
           Clipboard clipboard = new Clipboard(Display.getDefault());
           clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() });
           clipboard.dispose();
       }
}
项目:scouter    文件:AlertScriptingView.java   
private void addApiDescTableKeyListener() {
    table.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if(e.stateMask == SWT.CTRL || e.stateMask == SWT.COMMAND){
                if (e.keyCode == 'c' || e.keyCode == 'C') {
                    StructuredSelection selection = (StructuredSelection)viewer.getSelection();
                    if(selection == null)
                        return;
                    ApiDesc apiObject = (ApiDesc)selection.getFirstElement();
                    if(apiObject != null){
                        clipboard.setContents(new Object[] {apiObject.fullSignature}, new Transfer[] {TextTransfer.getInstance()});
                    }
                }
            }
        }
    });
}
项目:scouter    文件:XLogSelectionView.java   
private void copyToClipboard() {
    if (viewer != null) {
        TableItem[] items = viewer.getTable().getItems();
        int colCnt = viewer.getTable().getColumnCount();
        if (items != null && items.length > 0) {
            StringBuffer sb = new StringBuffer();
            for (TableItem item : items) {
                for (int i = 0; i < colCnt; i++) {
                    String value = item.getText(i);
                    value = value.replace("\n", "[\\n]");
                    value = value.replace("\t", "    ");
                    sb.append(value);
                    if (i == colCnt - 1) {
                        sb.append("\n");
                    } else {
                        sb.append("\t");
                    }
                }
            }
            clipboard.setContents(new Object[] {sb.toString()}, new Transfer[] {TextTransfer.getInstance()});
            MessageDialog.openInformation(getSite().getShell(), "Copy", "Copied to clipboard");
        }
    }
}
项目:SPELL    文件:CodeViewer.java   
/***************************************************************************
 * Copy selected source rows
 **************************************************************************/
public void copySelected()
{
    GridItem[] selection = getGrid().getSelection();
    Clipboard clipboard = new Clipboard(Display.getCurrent());
    String data = "";
    for (GridItem item : selection)
    {
        if (!data.isEmpty())
            data += "\n";
        String line = item.getText(CodeViewerColumn.CODE.ordinal());
        if (line != null)
        {
            line = line.trim();
        }
        else
        {
            line = "";
        }
        data += line;
    }
    clipboard.setContents(new Object[] { data }, new Transfer[] { TextTransfer.getInstance() });
    clipboard.dispose();
}
项目:pep-tools    文件:FeatureAndPluginCopyAction.java   
@Override
public void runWithEvent(Event event) {
    ISelection selection = selectionProvider.getSelection();
    Collection<IProductModel> productModels = ProductSupport.toProductModels(selection);
    Collection<IFeatureModel> featureModels = FeatureSupport.toFeatureModels(selection);
    Collection<IPluginModelBase> pluginModels = PluginSupport.toPluginModels(selection);

    Collection<IProject> projects = new HashSet<IProject>();
    addUnderlyingResources(projects, productModels);
    addUnderlyingResources(projects, featureModels);
    addUnderlyingResources(projects, pluginModels);

    String[] fileData = new String[projects.size()];
    int i = 0;
    for (IProject project : projects) {
        fileData[i++] = project.getLocation().toOSString();
    }

    String textData = getTextData(productModels, featureModels, pluginModels);

    Object[] data = { projects.toArray(new IResource[projects.size()]), textData, fileData };
    Transfer[] dataTypes = { ResourceTransfer.getInstance(), TextTransfer.getInstance(), FileTransfer.getInstance() };
    clipboard.setContents(data, dataTypes);
}
项目:IDRT-Import-and-Mapping-Tool    文件:NodeMoveDragListener.java   
@Override
public void dragSetData(DragSourceEvent event) {


    System.out.println("dragSetData");
    IStructuredSelection selection = (IStructuredSelection) viewer
            .getSelection();
    if (selection.getFirstElement() instanceof OntologyTreeNode) {
        OntologyTreeNode firstElement = (OntologyTreeNode) selection
                .getFirstElement();
        if (firstElement.isModifier()){
            event.data = null;
            System.out.println("Modifier!");
        }
        else if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
            event.data = firstElement.getTreePath();
        }
    }
    else if (selection.getFirstElement() instanceof OntologyTreeSubNode) {
        setSubNode((OntologyTreeSubNode) selection
                .getFirstElement());
        event.data = "subNode";
    }
}
项目:JFaceUtils    文件:SystemInformationDialog.java   
/**
 * Copies the current selection to the clipboard.
 * 
 * @param table the data source
 */
protected void copy(final Table table) {
    if (canCopy(table)) {
        final StringBuilder data = new StringBuilder();

        for (int row = 0; row < table.getSelectionCount(); row++) {
            for (int col = 0; col < table.getColumnCount(); col++) {
                data.append(table.getSelection()[row].getText(col));
                if (col == 0) {
                    data.append('=');
                }
                else if (row != table.getSelectionCount() - 1) {
                    data.append(NewLine.SYSTEM_LINE_SEPARATOR);
                }
            }
        }

        final Clipboard clipboard = new Clipboard(table.getDisplay());
        clipboard.setContents(new String[] { data.toString() }, new TextTransfer[] { TextTransfer.getInstance() });
        clipboard.dispose();
    }
}
项目:JFaceUtils    文件:SystemInformationDialog.java   
/**
 * Copies the current selection to the clipboard.
 * 
 * @param list the data source
 */
protected void copy(final List list) {
    if (canCopy(list)) {
        final StringBuilder data = new StringBuilder();

        for (int row = 0; row < list.getSelectionCount(); row++) {
            data.append(list.getSelection()[row]);
            if (row != list.getSelectionCount() - 1) {
                data.append(NewLine.SYSTEM_LINE_SEPARATOR);
            }
        }

        final Clipboard clipboard = new Clipboard(list.getDisplay());
        clipboard.setContents(new String[] { data.toString() }, new TextTransfer[] { TextTransfer.getInstance() });
        clipboard.dispose();
    }
}
项目:plugindependencies    文件:PluginTreeView.java   
protected void copyToClipboard(IStructuredSelection selection) {
    StringBuilder sb = new StringBuilder();
    for (Object object : (List<?>) selection.toList()) {
        if(object instanceof TreeParent){
            TreeParent tp = (TreeParent) object;
            object = tp.getNamedElement();
            if(object != null){
                NamedElement elt = (NamedElement) object;
                sb.append(elt.getNameAndVersion()).append("\n");
            } else if(tp instanceof TreeProblem) {
                sb.append(((TreeProblem) tp).getProblem()).append("\n");
            }
        }
    }
    TextTransfer textTransfer = TextTransfer.getInstance();
    final Clipboard cb = new Clipboard(getSite().getShell().getDisplay());
    try {
    cb.setContents(new Object[]{sb.toString()}, new Transfer[]{textTransfer});
    } finally {
        cb.dispose();
    }
}
项目:OpenSPIFe    文件:EditActionProvider.java   
/**
 * Set the clipboard contents. Prompt to retry if clipboard is busy.
 * 
 * @param resources
 *            the resources to copy to the clipboard
 * @param fileNames
 *            file names of the resources to copy to the clipboard
 * @param names
 *            string representation of all names
 */
private void setClipboard(IResource[] resources, String[] fileNames, String names) {
    try {
        // set the clipboard contents
        if (fileNames.length > 0) {
            clipboard.setContents(new Object[] { resources, fileNames, names }, new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() });
        } else {
            clipboard.setContents(new Object[] { resources, names }, new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() });
        }
    } catch (SWTError e) {
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
            throw e;
        }
        if (MessageDialog.openQuestion(shell, "Problem Copying to Clipboard", "There was a problem when accessing the system clipboard. Retry?")) {
            setClipboard(resources, fileNames, names);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:LocationCopyAction.java   
@Override
public void run() {
    IStructuredSelection selection= (IStructuredSelection) fLocationViewer.getSelection();
    StringBuffer buf= new StringBuffer();
    for (Iterator<?> iterator= selection.iterator(); iterator.hasNext();) {
        CallLocation location= (CallLocation) iterator.next();
        buf.append(location.getLineNumber()).append('\t').append(location.getCallText());
        buf.append('\n');
    }
    TextTransfer plainTextTransfer = TextTransfer.getInstance();
    try {
        fClipboard.setContents(
                new String[]{ CopyCallHierarchyAction.convertLineTerminators(buf.toString()) },
                new Transfer[]{ plainTextTransfer });
    } catch (SWTError e){
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
            throw e;
        if (MessageDialog.openQuestion(fViewSite.getShell(), CallHierarchyMessages.CopyCallHierarchyAction_problem, CallHierarchyMessages.CopyCallHierarchyAction_clipboard_busy))
            run();
    }
}
项目:translationstudio8    文件:SegmentViewer.java   
/**
 * 执行复制时对标记的处理,复制后在OS系统中不能包含标记占位符 ;
 */
private void copy() {
    super.doOperation(ITextOperationTarget.COPY);
    TextTransfer plainTextTransfer = TextTransfer.getInstance();
    XLiffTextTransfer hsTextTransfer = XLiffTextTransfer.getInstance();
    Clipboard clipboard = new Clipboard(getTextWidget().getDisplay());
    String plainText = (String) clipboard.getContents(plainTextTransfer);
    if (plainText == null || plainText.length() == 0) {
        return;
    }
    plainText = plainText.replaceAll(Utils.getLineSeparator(), "\n");
    plainText = plainText.replaceAll(Constants.LINE_SEPARATOR_CHARACTER + "", "");
    plainText = plainText.replaceAll(Constants.TAB_CHARACTER + "", "\t");
    plainText = plainText.replaceAll(Constants.SPACE_CHARACTER + "", " ");
    plainText = plainText.replaceAll("\u200B", "");
    clipboard.clearContents();
    Object[] data = new Object[] { PATTERN.matcher(plainText).replaceAll(""), plainText };
    Transfer[] types = new Transfer[] { plainTextTransfer, hsTextTransfer };

    clipboard.setContents(data, types, DND.CLIPBOARD);
    clipboard.dispose();
}
项目:translationstudio8    文件:CopyDataToClipboardSerializer.java   
public void serialize() {
    final Clipboard clipboard = command.getClipboard();
    final String cellDelimeter = command.getCellDelimeter();
    final String rowDelimeter = command.getRowDelimeter();

    final TextTransfer textTransfer = TextTransfer.getInstance();
    final StringBuilder textData = new StringBuilder();
    int currentRow = 0;
    for (LayerCell[] cells : copiedCells) {
        int currentCell = 0;
        for (LayerCell cell : cells) {
            final String delimeter = ++currentCell < cells.length ? cellDelimeter : "";
            if (cell != null) {
                textData.append(cell.getDataValue() + delimeter);
            } else {
                textData.append(delimeter);
            } 
        }
        if (++currentRow < copiedCells.length) {
            textData.append(rowDelimeter);
        }
    }
    clipboard.setContents(new Object[]{textData.toString()}, new Transfer[]{textTransfer});
}
项目:AcademicTorrents-Downloader    文件:OpenTorrentWindow.java   
public void updateUI() {
    boolean bTorrentInClipboard = false;

    Clipboard clipboard = new Clipboard(Display.getDefault());

    String sClipText = (String) clipboard.getContents(TextTransfer.getInstance());
    if (sClipText != null)
        bTorrentInClipboard = addTorrentsFromTextList(sClipText, true) > 0;

    if (btnPasteOpen != null && !btnPasteOpen.isDisposed()
            && btnPasteOpen.isVisible() != bTorrentInClipboard) {
        btnPasteOpen.setVisible(bTorrentInClipboard);
        if (bTorrentInClipboard) {
            btnPasteOpen.setToolTipText(sClipText);
        }
    }

    clipboard.dispose();
}
项目:ControlAndroidDeviceFromPC    文件:NativeHeapPanel.java   
private void copyToClipboard(TreeItem[] items, Clipboard clipboard) {
    StringBuilder sb = new StringBuilder();

    for (TreeItem item : items) {
        Object data = item.getData();
        if (data != null) {
            sb.append(data.toString());
            sb.append('\n');
        }
    }

    String content = sb.toString();
    if (content.length() > 0) {
        clipboard.setContents(
                new Object[] {sb.toString()},
                new Transfer[] {TextTransfer.getInstance()}
                );
    }
}
项目:ControlAndroidDeviceFromPC    文件:LogPanel.java   
/**
 * Copies the current selection of a Table into the provided Clipboard, as
 * multi-line text.
 *
 * @param clipboard The clipboard to place the copied content.
 * @param table The table to copy from.
 */
private static void copyTable(Clipboard clipboard, Table table) {
    int[] selection = table.getSelectionIndices();

    // we need to sort the items to be sure.
    Arrays.sort(selection);

    // all lines must be concatenated.
    StringBuilder sb = new StringBuilder();

    // loop on the selection and output the file.
    for (int i : selection) {
        TableItem item = table.getItem(i);
        LogMessage msg = (LogMessage)item.getData();
        String line = msg.toString();
        sb.append(line);
        sb.append('\n');
    }

    // now add that to the clipboard
    clipboard.setContents(new Object[] {
        sb.toString()
    }, new Transfer[] {
        TextTransfer.getInstance()
    });
}