Search in sources :

Example 1 with PluginTransfer

use of org.eclipse.ui.part.PluginTransfer in project polymap4-core by Polymap4.

the class CommonDragAdapter method dragSetData.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
	 */
public void dragSetData(final DragSourceEvent event) {
    final ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
    if (Policy.DEBUG_DND) {
        System.out.println(// $NON-NLS-1$ //$NON-NLS-2$
        "CommonDragAdapter.dragSetData: event" + event + " selection=" + selection);
    }
    if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
        event.data = selection;
        if (Policy.DEBUG_DND) {
            System.out.println(// $NON-NLS-1$
            "CommonDragAdapter.dragSetData set LocalSelectionTransfer: " + event.data);
        }
    } else if (PluginTransfer.getInstance().isSupportedType(event.dataType)) {
        event.data = NavigatorPluginDropAction.createTransferData(contentService);
        if (Policy.DEBUG_DND) {
            System.out.println(// $NON-NLS-1$
            "CommonDragAdapter.dragSetData set PluginTransfer: " + event.data);
        }
    } else if (selection instanceof IStructuredSelection) {
        if (Policy.DEBUG_DND) {
            System.out.println(// $NON-NLS-1$
            "CommonDragAdapter.dragSetData looking for assistants");
        }
        for (int i = 0, len = assistantsToUse.size(); i < len; i++) {
            final CommonDragAdapterAssistant assistant = (CommonDragAdapterAssistant) assistantsToUse.get(i);
            if (Policy.DEBUG_DND) {
                System.out.println(// $NON-NLS-1$
                "CommonDragAdapter.dragSetData assistant: " + assistant);
            }
            Transfer[] supportedTransferTypes = assistant.getSupportedTransferTypes();
            final boolean[] getOut = new boolean[1];
            for (int j = 0; j < supportedTransferTypes.length; j++) {
                if (supportedTransferTypes[j].isSupportedType(event.dataType)) {
                    SafeRunner.run(new NavigatorSafeRunnable() {

                        public void run() throws Exception {
                            if (Policy.DEBUG_DND) {
                                System.out.println(// $NON-NLS-1$
                                "CommonDragAdapter.dragSetData supported xfer type");
                            }
                            if (assistant.setDragData(event, (IStructuredSelection) selection)) {
                                if (Policy.DEBUG_DND) {
                                    System.out.println(// $NON-NLS-1$
                                    "CommonDragAdapter.dragSetData set data " + event.data);
                                }
                                setDataAssistant = assistant;
                                getOut[0] = true;
                            }
                        }
                    });
                    if (getOut[0])
                        return;
                }
            }
        }
        if (Policy.DEBUG_DND) {
            System.out.println(// $NON-NLS-1$
            "CommonDragAdapter.dragSetData FAILED no assistant handled it");
        }
        event.doit = false;
    } else {
        if (Policy.DEBUG_DND) {
            System.out.println(// $NON-NLS-1$
            "CommonDragAdapter.dragSetData FAILED can't identify transfer type");
        }
        event.doit = false;
    }
}
Also used : NavigatorSafeRunnable(org.eclipse.ui.internal.navigator.NavigatorSafeRunnable) ISelection(org.eclipse.jface.viewers.ISelection) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) PluginTransfer(org.eclipse.ui.part.PluginTransfer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with PluginTransfer

use of org.eclipse.ui.part.PluginTransfer in project polymap4-core by Polymap4.

the class CommonDragAdapter method getSupportedDragTransfers.

/**
 * @return An array of supported Drag Transfer types. The list contains [
 *         {@link LocalSelectionTransfer#getTransfer()},
 *         {@link PluginTransfer#getInstance()}] in addition to any
 *         supported types contributed by the
 *         {@link CommonDragAdapterAssistant assistants}.
 * @see CommonDragAdapterAssistant
 * @see LocalSelectionTransfer
 * @see PluginTransfer
 */
public Transfer[] getSupportedDragTransfers() {
    CommonDragAdapterAssistant[] assistants = contentService.getDnDService().getCommonDragAssistants();
    Set supportedTypes = new LinkedHashSet();
    supportedTypes.add(PluginTransfer.getInstance());
    supportedTypes.add(LocalSelectionTransfer.getTransfer());
    Transfer[] transferTypes = null;
    for (int i = 0; i < assistants.length; i++) {
        transferTypes = assistants[i].getSupportedTransferTypes();
        for (int j = 0; j < transferTypes.length; j++) {
            if (transferTypes[j] != null) {
                supportedTypes.add(transferTypes[j]);
            }
        }
    }
    Transfer[] transfers = (Transfer[]) supportedTypes.toArray(new Transfer[supportedTypes.size()]);
    return transfers;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) PluginTransfer(org.eclipse.ui.part.PluginTransfer)

Aggregations

LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)2 Transfer (org.eclipse.swt.dnd.Transfer)2 PluginTransfer (org.eclipse.ui.part.PluginTransfer)2 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 NavigatorSafeRunnable (org.eclipse.ui.internal.navigator.NavigatorSafeRunnable)1