wuppi
wuppi

Reputation: 1004

Eclipse RCP drop file from external explorer not accepted

I have an Eclipse RCP application which should open files via drag & drop from the windows explorer. So I implemented this:

public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

    @Override
    public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        configurer.addEditorAreaTransfer(FileTransfer.getInstance());
        configurer.configureEditorAreaDropListener(editorDropListener);
        return new ApplicationWorkbenchWindowAdvisor(configurer);
    }
[...]
}

editorDropListener is of type DropTargetAdapter and implements the drop() method.

Now if I drag a file from my explorer into my application, I get that "Windows Unavailable" mouse icon and the drop will not work. The editorDropListener.drop() is not called.

If I drag the file with CTRL or ALT key pressed, I get the "windows copy" mouse icon. The drop works and editorDropListener.drop() is successfully called.

Where can I configure, which kind of drop is allowed?

Upvotes: 2

Views: 1041

Answers (3)

sid
sid

Reputation: 11

Use this code in your listener. it will work.

                @Override
        public void dragEnter(final DropTargetEvent event) {

            if (event.detail == DND.DROP_DEFAULT) {
                if ((event.operations & DND.DROP_COPY) != 0) {
                    event.detail = DND.DROP_COPY;
                } else {
                    event.detail = DND.DROP_NONE;
                }
            }
        }

Upvotes: 0

Kevin
Kevin

Reputation: 131

It seems this problem has not been solve from above. I just have look up the apis of DND and solve this problem, eliminate the Ctrl or Alt press. Drag and Drop We just need to add some code in you EditorAreaDropAdapter:

        @Override
public void dragEnter(DropTargetEvent event) {
    // TODO Auto-generated method stub
    event.detail = DND.DROP_COPY;
    super.dragEnter(event);
}

event.detail has to be set as DND.DROP_COPY for acceptence.

Upvotes: 1

Tonny Madsen
Tonny Madsen

Reputation: 12718

It is a little more complicated than that, as the editor area does not accept a MOVE DND request.

Have a look at org.eclipse.ui.internal.ide.EditorAreaDropAdapter for the details.

Upvotes: 0

Related Questions