Home » Eclipse Projects » Eclipse Platform » Drag and drop file from Windows into RCP application
| |
Re: Drag and drop file from Windows into RCP application [message #322952 is a reply to message #322934] |
Mon, 03 December 2007 19:33 |
Conor O'Mahony 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 |
Duong Nguyen 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 |
Conor O'Mahony 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?
>
>
|
|
| | | | |
Goto Forum:
Current Time: Tue Sep 24 11:52:45 GMT 2024
Powered by FUDForum. Page generated in 0.03146 seconds
|