Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » RAP Drag-and-Drop from Windows Explorer queries(Drag-and-Drop from OS, how to get full file, and what URL to upload to)
RAP Drag-and-Drop from Windows Explorer queries [message #1654306] Fri, 06 March 2015 16:30 Go to next message
John Gymer is currently offline John GymerFriend
Messages: 279
Registered: November 2012
Location: UK
Senior Member
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 #1660518 is a reply to message #1654306] Mon, 09 March 2015 07:57 Go to previous messageGo to next message
Aleksander   is currently offline Aleksander Friend
Messages: 44
Registered: May 2014
Location: France
Member
For 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);

[Updated on: Mon, 09 March 2015 08:07]

Report message to a moderator

Re: RAP Drag-and-Drop from Windows Explorer queries [message #1660584 is a reply to message #1654306] Mon, 09 March 2015 08:36 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi John,
FileDialog is using drag & drop. Look at FileDialog implementation [1]
for complete working example.
You need to create FileUploadHandler with the corresponding receiver like:
DiskFileUploadReceiver receiver = new DiskFileUploadReceiver();
FileUploadHandler handler = new FileUploadHandler( receiver );

The URL used in submit method is obtained from handler:
handler.getUploadUrl();
The absolute path on the server of uploaded files can be obtained from
receiver: receiver.getTargetFiles();

[1]
http://git.eclipse.org/c/rap/incubator/org.eclipse.rap.incubator.fileupload.git/tree/bundles/org.eclipse.rap.addons.filedialog/src/org/eclipse/swt/widgets/FileDialog.java

HTH,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: RAP Drag-and-Drop from Windows Explorer queries [message #1660991 is a reply to message #1660518] Mon, 09 March 2015 12:35 Go to previous messageGo to next message
John Gymer is currently offline John GymerFriend
Messages: 279
Registered: November 2012
Location: UK
Senior Member
Thanks, but are you sure about this?...

Aleksander wrote on Mon, 09 March 2015 07:57
For 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 #1661045 is a reply to message #1660991] Mon, 09 March 2015 13:02 Go to previous messageGo to next message
Aleksander   is currently offline Aleksander Friend
Messages: 44
Registered: May 2014
Location: France
Member
Sorry I didn't mention the ViewerDropAdapter.
This code should work for you
		viewer.addDropSupport(DND.DROP_COPY , new Transfer[] { LocalSelectionTransfer.getTransfer() }, new ViewerDropAdapter(viewer) {

			@Override
			public boolean validateDrop(Object target, int operation, TransferData transferType) {
				overrideOperation(DND.DROP_COPY );
				return true;
			}

			@Override
			public boolean performDrop(Object data) {
				// TODO Auto-generated method stub
				return false;
			}
		});
Re: RAP Drag-and-Drop from Windows Explorer queries [message #1661082 is a reply to message #1661045] Mon, 09 March 2015 13:24 Go to previous messageGo to next message
John Gymer is currently offline John GymerFriend
Messages: 279
Registered: November 2012
Location: UK
Senior Member
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 Go to previous message
John Gymer is currently offline John GymerFriend
Messages: 279
Registered: November 2012
Location: UK
Senior Member
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
Previous Topic:Random HTTP 500
Next Topic:Strange line
Goto Forum:
  


Current Time: Thu Apr 25 04:38:23 GMT 2024

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

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

Back to the top