Paste from clipboard via Ctrl+V keys onto the table

Hi guys!

Here the thing I’ve faced with while developing my app. My need is to paste some info to the table via combinations like Ctrl+C and Ctrl+V. Is there some handlers or events for this? Thanks in advance.

There is no built-in support for that kind of thing, you need to add it with some client-side (GWT) development.

If everything you need is paste event, then you can use this sample from StackOverflow:
http://stackoverflow.com/questions/4018118/gwt-pasting-event
. Extend the Table class on the client side, and add that.

Be aware though, that copy and cut events are going to be much more complicated. Also, thanks to the unique way the Table is built, the onPaste event might not fire. I recently had big issues determining from which DIV and when the onPaste event is fired; the more complex the DOM, the more issues you will have making it work consistently.

What I ended up with was the most fool-proof way to do it, since I had to support all major browsers in a DOM more complex than table (the upcoming Spreadsheet component, actually), was to have a hidden text field embedded inside the component. I caught the copy, cut and paste keyboard shortcuts with a event preview handler (fired before operating system copy etc commands), and moved focus to my textfield. I let the operating system do the copy, and moved back focus to where it was with a 100ms timer. Depending on the operation, you either fill the textfield before copy and select all, or get the text from it after the paste operation. Additionally, most browsers will block the operation if the textfield isn’t visible, so I had to find CSS that tricked the browser into thinking the field is visible to the user, even though it wasn’t. I used opacity:0; for that.

Hope this helps to get you started :slight_smile: