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

项目: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;
}
项目:mesfavoris    文件:BookmarksViewerDropListener.java   
private IStructuredSelection getStructuredSelection(Object data, TransferData currentDataType) {
    if (LocalSelectionTransfer.getTransfer().isSupportedType(currentDataType)) {
        return (IStructuredSelection) data;
    }
    if (URLTransfer.getInstance().isSupportedType(currentDataType)) {
        try {
            return new StructuredSelection(new URL((String) data));
        } catch (MalformedURLException e) {
            // ignore
        }
    }
    if (FileTransfer.getInstance().isSupportedType(currentDataType)) {
        return new StructuredSelection(Arrays.stream((String[]) data).map(Path::new).collect(Collectors.toList()));
    }
    return new StructuredSelection();
}
项目: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();
    }
}
项目:statecharts    文件:ExampleDropTargetInstaller.java   
protected void registerWithExistingTarget(DropTarget target) {
    Transfer[] transfers = target.getTransfer();
    boolean exists = false;
    if (transfers != null) {
        for (Transfer transfer : transfers) {
            if (transfer instanceof URLTransfer) {
                exists = true;
                break;
            }
        }
        if (!exists) {
            Transfer[] newTransfers = new Transfer[transfers.length + 1];
            System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
            newTransfers[transfers.length] = URLTransfer.getInstance();
            target.setTransfer(newTransfers);
        }
    }
}
项目:statecharts    文件:ExampleDropTargetListener.java   
private boolean dropTargetIsValid(DropTargetEvent e, boolean isDrop) {
    if (URLTransfer.getInstance().isSupportedType(e.currentDataType)) {
        // on Windows, we get the URL already during drag operations...
        // FIXME find a way to check the URL early on other platforms,
        // too...
        if (isDrop || Util.isWindows()) {
            if (e.data == null && !extractEventData(e)) {
                // ... but if we don't, it's no problem, unless this is
                // already
                // the final drop event
                return !isDrop;
            }
            final String url = getUrl(e.data);
            if (!ExampleURLHandler.isValidExample(url)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
项目:statecharts    文件:ExampleDropTargetListener.java   
@Override
public void drop(DropTargetEvent event) {
    if (!URLTransfer.getInstance().isSupportedType(event.currentDataType)) {
        return;
    }
    final String url = getUrl(event.data);

    if (ExampleURLHandler.isValidExample(url)) {
        DropTarget source = (DropTarget) event.getSource();
        Display display = source.getDisplay();
        display.asyncExec(new Runnable() {
            public void run() {
                proceedInstallation(url);
            }
        });
    }
}
项目:idecore    文件:ForceIdeUrlDropHandler.java   
@Override
public void drop(DropTargetEvent event) {
    if (!URLTransfer.getInstance().isSupportedType(event.currentDataType)) {
        traceUnsupportedDataType(event);
        //ignore
        return;
    }
    if (event.data == null) {
        traceMissingEventData(event);
        //reject
        event.detail = DND.DROP_NONE;
        return;
    }
    if (!dropTargetIsValid(event, true)) {
        //reject
        event.detail = DND.DROP_NONE;
        return;
    }
    final String url = getUrl(event.data);
    ForceIdeUrlActionHandler urlActionHandler = new ForceIdeUrlActionHandler(url, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay());
    ForceIdeUrlActionHandler.ProjectAction result = urlActionHandler.processCommand();
    if (result == ForceIdeUrlActionHandler.ProjectAction.IGNORE || result == ForceIdeUrlActionHandler.ProjectAction.INVALID)
        traceInvalidEventData(event);
}
项目:egitblit    文件:RepoDragListener.java   
@Override
public void dragSetData(DragSourceEvent event) {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    GitBlitViewModel model= (ProjectViewModel) selection.getFirstElement();

    String gitURL=null;
    if(model instanceof ProjectViewModel){
        ProjectViewModel pm = (ProjectViewModel)model;
        gitURL = pm.getGitUrl();
    }
    if(gitURL == null){
        return;
    }
    if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
        event.data = gitURL;
    }
    if (URLTransfer.getInstance().isSupportedType(event.dataType)) {
        try{
            event.data = new URL(gitURL);
        }
        catch(Exception e){
            Activator.logError("Error while performin drag & drop",e);
        }
    }
}
项目:neoscada    文件:CommonDragAdapterAssistant.java   
@Override
public boolean setDragData ( final DragSourceEvent event, final IStructuredSelection selection )
{
    logger.debug ( "setDragData ( event: {}, selection: {}", event, selection );

    final Collection<Item> items = ItemSelectionHelper.getSelection ( selection );
    if ( items.isEmpty () )
    {
        logger.info ( "Empty item set for setDragData" );
        return false;
    }

    if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = items.toArray ( new Item[items.size ()] );
        return true;
    }
    else if ( TextTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = getItemUriData ( items );
        return true;
    }
    else if ( URLTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = getItemUriData ( items );
        return true;
    }

    logger.debug ( "No possible transfer" );

    return false;
}
项目:neoscada    文件:RealtimeListDragSourceListener.java   
@Override
public void dragSetData ( final DragSourceEvent event )
{
    try
    {
        final IStructuredSelection selection = (IStructuredSelection)LocalSelectionTransfer.getTransfer ().getSelection ();
        if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) )
        {
            final List<Item> items = new ArrayList<Item> ();
            for ( final Iterator<?> i = selection.iterator (); i.hasNext (); )
            {
                final ListEntry entry = (ListEntry)i.next ();
                items.add ( entry.getItem () );
            }
            event.data = items.toArray ( new Item[items.size ()] );
        }
        else if ( TextTransfer.getInstance ().isSupportedType ( event.dataType ) )
        {
            setItemUriData ( event, selection );
        }
        else if ( URLTransfer.getInstance ().isSupportedType ( event.dataType ) )
        {
            setItemUriData ( event, selection );
        }
    }
    catch ( final Exception e )
    {
        event.doit = false;
    }
}
项目:neoscada    文件:CommonDragAdapterAssistant.java   
@Override
public boolean setDragData ( final DragSourceEvent event, final IStructuredSelection selection )
{
    logger.debug ( "setDragData ( event: {}, selection: {}", event, selection );

    final Collection<Item> items = ItemSelectionHelper.getSelection ( selection );
    if ( items.isEmpty () )
    {
        logger.info ( "Empty item set for setDragData" );
        return false;
    }

    if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = items.toArray ( new Item[items.size ()] );
        return true;
    }
    else if ( TextTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = getItemUriData ( items );
        return true;
    }
    else if ( URLTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = getItemUriData ( items );
        return true;
    }

    logger.debug ( "No possible transfer" );

    return false;
}
项目:mesfavoris    文件:BookmarksTreeViewer.java   
private void installDragAndDropSupport() {
    int operations = DND.DROP_MOVE;
    addDragSupport(operations, new Transfer[] { LocalSelectionTransfer.getTransfer() },
            new BookmarksViewerDragListener(this));
    addDropSupport(DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK,
            new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(),
                    URLTransfer.getInstance() },
            new BookmarksViewerDropListener(this, bookmarkDatabase, bookmarkPropertiesProvider));
}
项目:mesfavoris    文件:PasteBookmarkOperationTest.java   
@Test
public void testPasteUrl() throws BookmarksException {
    // Given
    // on mac, when you copy from chrome
    copyToClipboard("http://www.google.com", URLTransfer.getInstance());
    int numberOfBookmarksBefore = bookmarkDatabase.getBookmarksTree().size();

    // When
    pasteBookmarkOperation.paste(getBookmarkFolder(bookmarkDatabase.getBookmarksTree(), 0, 0, 0).getId(),
            new NullProgressMonitor());

    // Then
    assertEquals(numberOfBookmarksBefore + 1, bookmarkDatabase.getBookmarksTree().size());      
}
项目:statecharts    文件:ExampleDropTargetListener.java   
private boolean extractEventData(DropTargetEvent e) {
    TransferData transferData = e.currentDataType;
    if (transferData != null) {
        Object data = URLTransfer.getInstance().nativeToJava(transferData);
        if (data != null && getUrl(data) != null) {
            e.data = data;
            return true;
        }
    }
    return false;
}
项目:mytourbook    文件:Map.java   
private void onDropRunnable(final DropTargetEvent event) {

        final TransferData transferDataType = event.currentDataType;

        boolean isPOI = false;

        if (TextTransfer.getInstance().isSupportedType(transferDataType)) {

            if (event.data instanceof String) {
                isPOI = parsePOIText((String) event.data);
            }

        } else if (URLTransfer.getInstance().isSupportedType(transferDataType)) {
            isPOI = parsePOIText((String) event.data);
        }

        if (isPOI == false) {

            String poiText = Messages.Dialog_DropNoPOI_InvalidData;

            if (event.data instanceof String) {

                poiText = (String) event.data;

                final int maxLength = 1000;
                if (poiText.length() > maxLength) {
                    poiText = poiText.substring(0, maxLength) + "..."; //$NON-NLS-1$
                }
            }

            MessageDialog.openInformation(
                    getShell(), //
                    Messages.Dialog_DropNoPOI_Title,
                    NLS.bind(Messages.Dialog_DropNoPOI_Message, poiText));
        }
    }
项目:mytourbook    文件:Map.java   
private void onDropRunnable(final DropTargetEvent event) {

        final TransferData transferDataType = event.currentDataType;

        boolean isPOI = false;

        if (TextTransfer.getInstance().isSupportedType(transferDataType)) {

            if (event.data instanceof String) {
                isPOI = parsePOIText((String) event.data);
            }

        } else if (URLTransfer.getInstance().isSupportedType(transferDataType)) {
            isPOI = parsePOIText((String) event.data);
        }

        if (isPOI == false) {

            String poiText = Messages.Dialog_DropNoPOI_InvalidData;

            if (event.data instanceof String) {

                poiText = (String) event.data;

                final int maxLength = 1000;
                if (poiText.length() > maxLength) {
                    poiText = poiText.substring(0, maxLength) + "..."; //$NON-NLS-1$
                }
            }

            MessageDialog.openInformation(getShell(), //
                    Messages.Dialog_DropNoPOI_Title,
                    NLS.bind(Messages.Dialog_DropNoPOI_Message, poiText));
        }
    }
项目:idecore    文件:ForceIdeUrlDropHandler.java   
private void registerWithExistingTarget(DropTarget target) {
    Transfer[] transfers = target.getTransfer();
    if (transfers != null) {
        for (Transfer transfer : transfers) {
            if (transfer instanceof URLTransfer) 
                return;
        }

        Transfer[] newTransfers = new Transfer[transfers.length + 1];
        System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
        newTransfers[transfers.length] = URLTransfer.getInstance();
        target.setTransfer(newTransfers);
    }
}
项目:idecore    文件:ForceIdeUrlDropHandler.java   
private boolean dropTargetIsValid(DropTargetEvent e, boolean isDrop) {
    if (URLTransfer.getInstance().isSupportedType(e.currentDataType)){
        //on Windows, we get the URL already during drag operations...
        //FIXME find a way to check the URL early on other platforms, too...
        if (isDrop || Util.isWindows()) {
            if (e.data == null && !extractEventData(e)) {
                traceMissingEventData(e);
                return !isDrop;
            }
        }
        return true;
    }
    return false;
}
项目:idecore    文件:ForceIdeUrlDropHandler.java   
private boolean extractEventData(DropTargetEvent e) {
    TransferData transferData = e.currentDataType;
    if (transferData != null) {
        Object data = URLTransfer.getInstance().nativeToJava(transferData);
        if (data != null && getUrl(data) != null) {
            e.data = data;
            return true;
        }
    }
    return false;
}
项目:JXTN    文件:FXCanvas.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);
}
项目:JXTN    文件:FXCanvas.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;
}
项目:neoscada    文件:CommonDragAdapterAssistant.java   
@Override
public Transfer[] getSupportedTransferTypes ()
{
    return new Transfer[] { ItemTransfer.getInstance (), TextTransfer.getInstance (), URLTransfer.getInstance () };
}
项目:neoscada    文件:RealTimeListViewer.java   
private void addDragSupport ()
{
    this.viewer.addDragSupport ( DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK, new Transfer[] { ItemTransfer.getInstance (), URLTransfer.getInstance (), TextTransfer.getInstance () }, new RealtimeListDragSourceListener ( this.viewer ) );
}
项目:neoscada    文件:CommonDragAdapterAssistant.java   
@Override
public Transfer[] getSupportedTransferTypes ()
{
    return new Transfer[] { ItemTransfer.getInstance (), TextTransfer.getInstance (), URLTransfer.getInstance () };
}
项目:mytourbook    文件:PrefPageMapProviders.java   
private void runnableDropMapProvider(final DropTargetEvent event) {

        final TransferData transferDataType = event.currentDataType;

        if (FileTransfer.getInstance().isSupportedType(transferDataType)) {

            Assert.isTrue(event.data instanceof String[]);

            final String[] paths = (String[]) event.data;
            Assert.isTrue(paths.length > 0);

            final String importFilePath = paths[0];

            if (isXmlFile(importFilePath)) {
                doImportMP(importFilePath);
            }

        } else if (URLTransfer.getInstance().isSupportedType(transferDataType)) {

            final String dndData = (String) event.data;

            // linux has 2 lines: 1: url, 2. text
            final String[] urlSplitted = dndData.split(UI.NEW_LINE);
            if (urlSplitted.length == 0) {
                return;
            }

            final String url = urlSplitted[0];

            if (isXmlFile(url) == false) {
                return;
            }

            // create temp file name
            final IPath stateLocation = Platform.getStateLocation(TourbookPlugin.getDefault().getBundle());
            final String tempFilePath = stateLocation
                    .append(Long.toString(System.nanoTime()) + XML_EXTENSION)
                    .toOSString();

            // load file from internet
            if (loadFile(url, tempFilePath) == false) {
                deleteFile(tempFilePath);
                return;
            }

            doImportMP(tempFilePath);

            // delete temp file
            deleteFile(tempFilePath);
        }
    }
项目:mytourbook    文件:PrefPageMapProviders.java   
private void runnableDropMapProvider(final DropTargetEvent event) {

        final TransferData transferDataType = event.currentDataType;

        if (FileTransfer.getInstance().isSupportedType(transferDataType)) {

            Assert.isTrue(event.data instanceof String[]);

            final String[] paths = (String[]) event.data;
            Assert.isTrue(paths.length > 0);

            final String importFilePath = paths[0];

            if (isXmlFile(importFilePath)) {
                doImportMP(importFilePath);
            }

        } else if (URLTransfer.getInstance().isSupportedType(transferDataType)) {

            final String dndData = (String) event.data;

            // linux has 2 lines: 1: url, 2. text
            final String[] urlSplitted = dndData.split(UI.NEW_LINE);
            if (urlSplitted.length == 0) {
                return;
            }

            final String url = urlSplitted[0];

            if (isXmlFile(url) == false) {
                return;
            }

            // create temp file name
            final IPath stateLocation = Platform.getStateLocation(Activator.getDefault().getBundle());
            final String tempFilePath = stateLocation
                    .append(Long.toString(System.nanoTime()) + XML_EXTENSION)
                    .toOSString();

            // load file from internet
            if (loadFile(url, tempFilePath) == false) {
                deleteFile(tempFilePath);
                return;
            }

            doImportMP(tempFilePath);

            // delete temp file
            deleteFile(tempFilePath);
        }
    }