RAP Drag-and-Drop from Windows Explorer queries [message #1654306] |
Fri, 06 March 2015 16:30 |
|
I would like to use RAP's ability to Drag-and-Drop from the native OS (Windows in this case) desktop (Explorer) a file(s) into a RAP widget.
I'm on RAP 2.3, as I'm using it in conjunction with Tabris, although not the Drag-and-Drop from mobile of course!
My DropTargetListener gets its' drop method triggered, being given a ClientFileImpl[] as the event.data, which I cast to ClientFile[]. OK so far.
Each ClientFile in the list of dragged files has properties for Name, Type and Size. The Name ONLY includes the raw file name, without any path information, so I don't know what path it came from on the client side.
So, first question... can I get the path somehow (primarily just for informational purposes)? I can imagine it being useful anyway, as you might choose 2 files with the same name, but from different paths on the client.
Next, I'd like to upload the selected files to the RAP sever, but I'm unsure how to specify the URL:
ClientFileUploader uploader = RWT.getClient().getService(ClientFileUploader.class);
uploader.submit(<<<<myURL>>>>, clientFiles);
It would be good if they went into the rwt-resources location, but what do I specify?
I was struggling to find a good example, even in the Incubator, as that doesn't appear to use the submit method.
Final question... the mouse cursor in RAP when hoverring over the DropTarget is an arrow with the text 'MOVE' attached. Can I override the cursor, or this text? It is not a 'MOVE', it is an 'UPLOAD'... so the cursor is potentially confusing?
Thanks, John
---
Just because you can doesn't mean you should
|
|
|
|
|
Re: RAP Drag-and-Drop from Windows Explorer queries [message #1660991 is a reply to message #1660518] |
Mon, 09 March 2015 12:35 |
|
Thanks, but are you sure about this?...
Aleksander wrote on Mon, 09 March 2015 07:57For your last question, you can specify the type of supported operations when you add drop support on your viewer. And at the end of your validateDrop method you overide the operation type you want to execute eg : overrideOperation(DND.DROP_LINK);
No matter what I specify, I always get the "MOVE" cursor.
I try to set event.detail = DND.DROP_COPY in all of my drop handler methods, and also on the dropTarget creation, but still get the "MOVE" cursor.
What did you mean by "validateDrop"? This is not a method of the dropTarget Listener?
---
Just because you can doesn't mean you should
|
|
|
|
Re: RAP Drag-and-Drop from Windows Explorer queries [message #1661082 is a reply to message #1661045] |
Mon, 09 March 2015 13:24 |
|
Ah OK, I'm not using a viewer... here is how I'm adding drop support (as compatible as I can get it with SWT)...
DropTarget dt = new DropTarget(myLabel, DND.DROP_COPY);
Transfer[] types = new Transfer[] { ClientFileTransfer.getInstance(), TextTransfer.getInstance() };
dt.setTransfer(types);
dt.addDropListener(myDropTargetListener);
Then, the listener...
public DropTargetListener myDropTargetListener = new DropTargetListener() {
@Override
public void dragEnter(DropTargetEvent e) {
e.detail = DND.DROP_COPY;
}
@Override
public void dragLeave(DropTargetEvent e) {
e.detail = DND.DROP_COPY;
}
@Override
public void dragOperationChanged(DropTargetEvent e) {
e.detail = DND.DROP_COPY;
}
@Override
public void dragOver(DropTargetEvent e) {
e.detail = DND.DROP_COPY;
}
@Override
public void drop(DropTargetEvent e) {
if (e.data.getClass().equals(ClientFileImpl[].class)) {
ClientFile[] lst = (ClientFile[])e.data;
if (lst != null && lst.length > 0) {
for (int i = 0; i < lst.length; i++) {
System.out.println(" ClientFile[" + i + "]=" + lst[i] + " class: " + lst[i].getClass() + " name: " + lst[i].getName();
}
}
}
}
@Override
public void dropAccept(DropTargetEvent e) {
e.detail = DND.DROP_COPY;
}
};
You'll notice that I'm setting e.detail to DND.DROP_COPY in all the methods, which is obviously not necessary, but even so, I still get the MOVE cursor!
---
Just because you can doesn't mean you should
|
|
|
Re: RAP Drag-and-Drop from Windows Explorer queries [message #1661138 is a reply to message #1661082] |
Mon, 09 March 2015 13:54 |
|
In terms of the transfer, that part is now working, so for information to others who may wish to do the same in the simplest possible way in the future, this is how I've coded it...
In the DropTargetListener...
...
@Override
public void drop(DropTargetEvent e) {
if (e.data.getClass().equals(ClientFileImpl[].class)) { // list of files
ClientFile[] lst = (ClientFile[])e.data;
if (lst != null && lst.length > 0) {
ClientFileUploader uploader = RWT.getClient().getService(ClientFileUploader.class);
receiver = new DiskFileUploadReceiver(); // globally defined in owning class
FileUploadHandler handler = new FileUploadHandler(receiver);
String url = handler.getUploadUrl();
handler.addUploadListener(fuListener);
uploader.submit(url, lst);
}
}
}
...
Then, the FileUploadListener to monitor progress of the uploads...
public FileUploadListener fuListener = new FileUploadListener() {
@Override
public void uploadProgress(FileUploadEvent e) {
System.out.println("fuListener.uploadProgress: " + e);
}
@Override
public void uploadFinished(FileUploadEvent e) {
System.out.println("fuListener.uploadFinished: " + e);
File[] files = receiver.getTargetFiles();
if (files != null && files.length > 0) {
for (int f = 0; f < files.length; f++) {
System.out.println("file[" + f + "]=" + files[f]);
}
}
}
@Override
public void uploadFailed(FileUploadEvent e) {
System.out.println("fuListener.uploadFailed: " + e);
}
};
Hope that proves useful to someone!
Meanwhile, I still only get a 'MOVE' cursor when I drag from my Windows desktop to this control within RAP!
---
Just because you can doesn't mean you should
|
|
|
Powered by
FUDForum. Page generated in 0.03619 seconds