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;
}
}
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;
}
Aggregations