Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Drag and drop file from Windows into RCP application
Drag and drop file from Windows into RCP application [message #322934] Mon, 03 December 2007 15:09 Go to next message
Conor O'Mahony is currently offline Conor O'MahonyFriend
Messages: 108
Registered: July 2009
Senior Member
Hi,

I have an RCP application and I need to be able to drag a file from the Windows Explorer and drop it
into the Project View in my application to open the project.

I have looked at the Eclipse drag and drop article-
http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html

and have tried adding DropSupport to the TreeViewer in my Project View
int ops = DND.DROP_COPY | DND.DROP_DEFAULT;
Transfer[] transfers = new Transfer[] { FileTransfer.getInstance()};
treeViewer.addDropSupport(ops, transfers, new FileViewerDropAdapter(treeViewer));


However I am getting the below error -

org.eclipse.swt.SWTError: Cannot initialize Drop
at org.eclipse.swt.dnd.DND.error(DND.java:247)
at org.eclipse.swt.dnd.DND.error(DND.java:208)
at org.eclipse.swt.dnd.DropTarget.<init>(DropTarget.java:130)

After debugging through the application, it is failing on this line -
if (control.getData(DROPTARGETID) != null) {
DND.error(DND.ERROR_CANNOT_INIT_DROP);
}

I'm guessing this means that it has a problem with the fact that there is already a DROPTARGETID set
in the treeViewer, which is the case since there is Drag and drop implemented for this view already
for copying/moving elements/selections of a project within the viewer.

Does this mean I can only call addDropSupport once for my TreeViewer? I'd like to keep the logic for
dealing with FileTransfers and LocalSelectionTransfers separate if possible, but it looks like I
would have to implement this logic in the same ViewerDropAdapter for both?
Re: Drag and drop file from Windows into RCP application [message #322947 is a reply to message #322934] Mon, 03 December 2007 19:19 Go to previous messageGo to next message
Duong Nguyen is currently offline Duong NguyenFriend
Messages: 7
Registered: July 2009
Junior Member
You are correct. The current implementation of SWT DND will only allow on
drop target to be registered against an existing control.

Duong

Conor O'Mahony wrote:

> Hi,

> I have an RCP application and I need to be able to drag a file from the
Windows Explorer and drop it
> into the Project View in my application to open the project.

> I have looked at the Eclipse drag and drop article-
> http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html

> and have tried adding DropSupport to the TreeViewer in my Project View
> int ops = DND.DROP_COPY | DND.DROP_DEFAULT;
> Transfer[] transfers = new Transfer[] { FileTransfer.getInstance()};
> treeViewer.addDropSupport(ops, transfers, new
FileViewerDropAdapter(treeViewer));


> However I am getting the below error -

> org.eclipse.swt.SWTError: Cannot initialize Drop
> at org.eclipse.swt.dnd.DND.error(DND.java:247)
> at org.eclipse.swt.dnd.DND.error(DND.java:208)
> at org.eclipse.swt.dnd.DropTarget.<init>(DropTarget.java:130)

> After debugging through the application, it is failing on this line -
> if (control.getData(DROPTARGETID) != null) {
> DND.error(DND.ERROR_CANNOT_INIT_DROP);
> }

> I'm guessing this means that it has a problem with the fact that there is
already a DROPTARGETID set
> in the treeViewer, which is the case since there is Drag and drop
implemented for this view already
> for copying/moving elements/selections of a project within the viewer.

> Does this mean I can only call addDropSupport once for my TreeViewer? I'd
like to keep the logic for
> dealing with FileTransfers and LocalSelectionTransfers separate if
possible, but it looks like I
> would have to implement this logic in the same ViewerDropAdapter for both?
Re: Drag and drop file from Windows into RCP application [message #322952 is a reply to message #322934] Mon, 03 December 2007 19:33 Go to previous messageGo to next message
Conor O'Mahony is currently offline Conor O'MahonyFriend
Messages: 108
Registered: July 2009
Senior Member
Many thanks for your help,

I am now trying to handle both SelectionTransfers and FileTransfers in the same DropAdapter-

int ops = DND.DROP_COPY | DND.DROP_DEFAULT;
Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer(),
FileTransfer.getInstance()};
treeViewer.addDropSupport(operations, transfers, new TreeViewerDropAdapter(treeViewer));

However I am still having a problem with dropping a file from Windows Explorer into the View. I want
to be able to validate the file being dropped in some way, and disallow the drop (e.g. if the file
doesn't have the correct extension). I thought I could do the validation by testing the event data
in the dropAccept method, or in validateDrop method, but the event data is null at this point. How
can I validate the file? I do have access to the data containing the file path string from within
the performDrop method, but by then it's too late as I want to disallow the drop before this?

Or is there an easier way to accomplish what I am trying to do? I basically just want to drop a file
from Windows Explorer into the viewer. It is not important which object or target I am dropping
onto, I don't need to drop it into an existing item in the treeViewer, I just need to open the file
as a new project and add it to the view.

Regards,

Conor

Conor O'Mahony wrote:
> Hi,
>
> I have an RCP application and I need to be able to drag a file from the
> Windows Explorer and drop it into the Project View in my application to
> open the project.
>
> I have looked at the Eclipse drag and drop article-
> http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html
>
> and have tried adding DropSupport to the TreeViewer in my Project View
> int ops = DND.DROP_COPY | DND.DROP_DEFAULT;
> Transfer[] transfers = new Transfer[] { FileTransfer.getInstance()};
> treeViewer.addDropSupport(ops, transfers, new
> FileViewerDropAdapter(treeViewer));
>
>
> However I am getting the below error -
>
> org.eclipse.swt.SWTError: Cannot initialize Drop
> at org.eclipse.swt.dnd.DND.error(DND.java:247)
> at org.eclipse.swt.dnd.DND.error(DND.java:208)
> at org.eclipse.swt.dnd.DropTarget.<init>(DropTarget.java:130)
>
> After debugging through the application, it is failing on this line -
> if (control.getData(DROPTARGETID) != null) {
> DND.error(DND.ERROR_CANNOT_INIT_DROP);
> }
>
> I'm guessing this means that it has a problem with the fact that there
> is already a DROPTARGETID set in the treeViewer, which is the case since
> there is Drag and drop implemented for this view already for
> copying/moving elements/selections of a project within the viewer.
>
> Does this mean I can only call addDropSupport once for my TreeViewer?
> I'd like to keep the logic for dealing with FileTransfers and
> LocalSelectionTransfers separate if possible, but it looks like I would
> have to implement this logic in the same ViewerDropAdapter for both?
Re: Drag and drop file from Windows into RCP application [message #322966 is a reply to message #322952] Mon, 03 December 2007 22:10 Go to previous messageGo to next message
Duong Nguyen is currently offline Duong NguyenFriend
Messages: 7
Registered: July 2009
Junior Member
I don't think you need DND.DROP_DEFAULT in your code.

The event.data is not available until the drop occurs. I believe you can
still validate the data in the performDrop method and return false to
disallow the drop.

Duong

Conor O'Mahony wrote:

> Many thanks for your help,

> I am now trying to handle both SelectionTransfers and FileTransfers in the
same DropAdapter-

> int ops = DND.DROP_COPY | DND.DROP_DEFAULT;
> Transfer[] transfers = new Transfer[] {
LocalSelectionTransfer.getTransfer(),
> FileTransfer.getInstance()};
> treeViewer.addDropSupport(operations, transfers, new
TreeViewerDropAdapter(treeViewer));

> However I am still having a problem with dropping a file from Windows
Explorer into the View. I want
> to be able to validate the file being dropped in some way, and disallow the
drop (e.g. if the file
> doesn't have the correct extension). I thought I could do the validation by
testing the event data
> in the dropAccept method, or in validateDrop method, but the event data is
null at this point. How
> can I validate the file? I do have access to the data containing the file
path string from within
> the performDrop method, but by then it's too late as I want to disallow the
drop before this?

> Or is there an easier way to accomplish what I am trying to do? I basically
just want to drop a file
> from Windows Explorer into the viewer. It is not important which object or
target I am dropping
> onto, I don't need to drop it into an existing item in the treeViewer, I
just need to open the file
> as a new project and add it to the view.

> Regards,

> Conor

> Conor O'Mahony wrote:
>> Hi,
>>
>> I have an RCP application and I need to be able to drag a file from the
>> Windows Explorer and drop it into the Project View in my application to
>> open the project.
>>
>> I have looked at the Eclipse drag and drop article-
>> http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html
>>
>> and have tried adding DropSupport to the TreeViewer in my Project View
>> int ops = DND.DROP_COPY | DND.DROP_DEFAULT;
>> Transfer[] transfers = new Transfer[] { FileTransfer.getInstance()};
>> treeViewer.addDropSupport(ops, transfers, new
>> FileViewerDropAdapter(treeViewer));
>>
>>
>> However I am getting the below error -
>>
>> org.eclipse.swt.SWTError: Cannot initialize Drop
>> at org.eclipse.swt.dnd.DND.error(DND.java:247)
>> at org.eclipse.swt.dnd.DND.error(DND.java:208)
>> at org.eclipse.swt.dnd.DropTarget.<init>(DropTarget.java:130)
>>
>> After debugging through the application, it is failing on this line -
>> if (control.getData(DROPTARGETID) != null) {
>> DND.error(DND.ERROR_CANNOT_INIT_DROP);
>> }
>>
>> I'm guessing this means that it has a problem with the fact that there
>> is already a DROPTARGETID set in the treeViewer, which is the case since
>> there is Drag and drop implemented for this view already for
>> copying/moving elements/selections of a project within the viewer.
>>
>> Does this mean I can only call addDropSupport once for my TreeViewer?
>> I'd like to keep the logic for dealing with FileTransfers and
>> LocalSelectionTransfers separate if possible, but it looks like I would
>> have to implement this logic in the same ViewerDropAdapter for both?
Re: Drag and drop file from Windows into RCP application [message #322984 is a reply to message #322966] Tue, 04 December 2007 10:07 Go to previous messageGo to next message
Conor O'Mahony is currently offline Conor O'MahonyFriend
Messages: 108
Registered: July 2009
Senior Member
How can I validate the data in performDrop if the event.data is not available until the drop occurs?
Is there any other way to access the data?

Thanks for your help.
Conor

Duong Nguyen wrote:
> I don't think you need DND.DROP_DEFAULT in your code.
>
> The event.data is not available until the drop occurs. I believe you can
> still validate the data in the performDrop method and return false to
> disallow the drop.
>
> Duong
> Conor O'Mahony wrote:
>
>> Many thanks for your help,
>
>> I am now trying to handle both SelectionTransfers and FileTransfers in
>> the
> same DropAdapter-
>
>> int ops = DND.DROP_COPY | DND.DROP_DEFAULT;
>> Transfer[] transfers = new Transfer[] {
> LocalSelectionTransfer.getTransfer(),
>> FileTransfer.getInstance()};
>> treeViewer.addDropSupport(operations, transfers, new
> TreeViewerDropAdapter(treeViewer));
>
>> However I am still having a problem with dropping a file from Windows
> Explorer into the View. I want
>> to be able to validate the file being dropped in some way, and
>> disallow the
> drop (e.g. if the file
>> doesn't have the correct extension). I thought I could do the
>> validation by
> testing the event data
>> in the dropAccept method, or in validateDrop method, but the event
>> data is
> null at this point. How
>> can I validate the file? I do have access to the data containing the file
> path string from within
>> the performDrop method, but by then it's too late as I want to
>> disallow the
> drop before this?
>
>> Or is there an easier way to accomplish what I am trying to do? I
>> basically
> just want to drop a file
>> from Windows Explorer into the viewer. It is not important which
>> object or
> target I am dropping
>> onto, I don't need to drop it into an existing item in the treeViewer, I
> just need to open the file
>> as a new project and add it to the view.
>
>> Regards,
>
>> Conor
>
>> Conor O'Mahony wrote:
>>> Hi,
>>>
>>> I have an RCP application and I need to be able to drag a file from
>>> the Windows Explorer and drop it into the Project View in my
>>> application to open the project.
>>>
>>> I have looked at the Eclipse drag and drop article-
>>> http://www.eclipse.org/articles/Article-Workbench-DND/drag_d rop.html
>>>
>>> and have tried adding DropSupport to the TreeViewer in my Project View
>>> int ops = DND.DROP_COPY | DND.DROP_DEFAULT;
>>> Transfer[] transfers = new Transfer[] {
>>> FileTransfer.getInstance()};
>>> treeViewer.addDropSupport(ops, transfers, new
>>> FileViewerDropAdapter(treeViewer));
>>>
>>>
>>> However I am getting the below error -
>>>
>>> org.eclipse.swt.SWTError: Cannot initialize Drop
>>> at org.eclipse.swt.dnd.DND.error(DND.java:247)
>>> at org.eclipse.swt.dnd.DND.error(DND.java:208)
>>> at org.eclipse.swt.dnd.DropTarget.<init>(DropTarget.java:130)
>>>
>>> After debugging through the application, it is failing on this line -
>>> if (control.getData(DROPTARGETID) != null) {
>>> DND.error(DND.ERROR_CANNOT_INIT_DROP);
>>> }
>>>
>>> I'm guessing this means that it has a problem with the fact that
>>> there is already a DROPTARGETID set in the treeViewer, which is the
>>> case since there is Drag and drop implemented for this view already
>>> for copying/moving elements/selections of a project within the viewer.
>>>
>>> Does this mean I can only call addDropSupport once for my TreeViewer?
>>> I'd like to keep the logic for dealing with FileTransfers and
>>> LocalSelectionTransfers separate if possible, but it looks like I
>>> would have to implement this logic in the same ViewerDropAdapter for
>>> both?
>
>
Re: Drag and drop file from Windows into RCP application [message #323000 is a reply to message #322984] Tue, 04 December 2007 18:13 Go to previous messageGo to next message
Duong Nguyen is currently offline Duong NguyenFriend
Messages: 7
Registered: July 2009
Junior Member
May be I'm a bit confused but in your first message, you said

> I do have access to the data containing the file path string from within the
> performDrop method

Now you're saying:

> How can I validate the data in performDrop if the event.data is not
> available until the drop occurs?

When a drop occurs, the performDrop method is called. There should be data
in the event.data.

Duong
Re: Drag and drop file from Windows into RCP application [message #323004 is a reply to message #323000] Tue, 04 December 2007 19:04 Go to previous messageGo to next message
Conor O'Mahony is currently offline Conor O'MahonyFriend
Messages: 108
Registered: July 2009
Senior Member
Apologies Duong, I was referring to the incorrect method

As you said, I do have access to the data in performDrop, but I was hoping to validate the file
being dragged first in the *validateDrop* method, so that I could show that it is an illegal drop if
that is the case. Do you know if this is possible? Or will i just have to disallow the drop once
they have dropped it in the performDrop method?

Many thanks,
Conor

Duong Nguyen wrote:
> May be I'm a bit confused but in your first message, you said
>
>> I do have access to the data containing the file path string from
>> within the performDrop method
>
> Now you're saying:
>
>> How can I validate the data in performDrop if the event.data is not
>> available until the drop occurs?
>
> When a drop occurs, the performDrop method is called. There should be
> data in the event.data.
>
> Duong
>
>
Re: Drag and drop file from Windows into RCP application [message #323034 is a reply to message #323004] Wed, 05 December 2007 15:36 Go to previous messageGo to next message
Duong Nguyen is currently offline Duong NguyenFriend
Messages: 7
Registered: July 2009
Junior Member
Some platforms may support pre-fetch of the data but SWT does not provide
pre-fetch before the drop. To answer your question, it's not possible with
SWT.

Duong

Conor O'Mahony wrote:

> Apologies Duong, I was referring to the incorrect method

> As you said, I do have access to the data in performDrop, but I was hoping
to validate the file
> being dragged first in the *validateDrop* method, so that I could show that
it is an illegal drop if
> that is the case. Do you know if this is possible? Or will i just have to
disallow the drop once
> they have dropped it in the performDrop method?

> Many thanks,
> Conor

> Duong Nguyen wrote:
>> May be I'm a bit confused but in your first message, you said
>>
>>> I do have access to the data containing the file path string from
>>> within the performDrop method
>>
>> Now you're saying:
>>
>>> How can I validate the data in performDrop if the event.data is not
>>> available until the drop occurs?
>>
>> When a drop occurs, the performDrop method is called. There should be
>> data in the event.data.
>>
>> Duong
>>
>>
Re: Drag and drop file from Windows into RCP application [message #805805 is a reply to message #323034] Fri, 24 February 2012 06:51 Go to previous message
Anil Kap is currently offline Anil KapFriend
Messages: 3
Registered: February 2012
Junior Member
I solved this problem using SWT.DROP_MOVE, if you want snippet i will attach please reply back because after dropping, my other files in the directory from where i have dropped the file are getting deleted.
Previous Topic:Can't Arrange ViewPart's on a Second Monitor
Next Topic:Unable to create new project in Eclipse - URGENT HELP!!
Goto Forum:
  


Current Time: Fri Apr 19 06:16:12 GMT 2024

Powered by FUDForum. Page generated in 0.02523 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top