Handling drag and drop files inside the Eclipse Package Explorer

I am trying to create an Eclipse plugin to support a project file format. My goal is to be able to drag and drop a file in Project Explorer (any type of file) into a file of a supported type, and have the name of the dragged file added to the end of the proprietary file.

Currently, I have a special editor that can process some data from an existing file in a controlled manner. This means that I have an editor associated with the file type, so my special icon appears next to it. I do not know how relevant this is.

I'm trying to use the extension point "org.eclipse.ui.dropActions", but I'm not sure how to register my DropActionDelegate (implements org.eclipse.ui.part.IDropActionDelegate) so that it is called when the file is dropped to one of my types in Project Explorer

Does anyone have any ideas? Am I even on the right track with DropActionDelegate?

+4
source share
1 answer

You are on the right track by implementing IDropActionDelegate :

class DropActionDelegate implements IDropActionDelegate { @Override public boolean run(Object source, Object target) { String transferredData (String) target; // whatever type is needed return true; // if drop successful } } 

The purpose of the org.eclipse.ui.dropActions extension point is to provide transition behavior for views that you did not define yourself (for example, Project Explorer).

You register the action action extension as follows:

 <extension point="org.eclipse.ui.dropActions"> <action id="my_drop_action" class="com.xyz.DropActionDelegate"> </action> </extension> 

Remember to add an adequate listener to your editor in your plugin code:

 class DragListener implements DragSourceListener { @Override public void dragStart(DragSourceEvent event) { } @Override public void dragSetData(DragSourceEvent event) { PluginTransferData p; p = new PluginTransferData( "my_drop_action", // must be id of registered drop action "some_data" // may be of arbitrary type ); event.data = p; } @Override public void dragFinished(DragSourceEvent event) { } } 
+2
source

Source: https://habr.com/ru/post/1338342/


All Articles