Search code examples
javagwtfile-uploadgxt

Key press events for GXT FileUploadField


GXT 3.x only.

It is becoming apparent to me that Sencha had deliberately designed FileUploadField to shunt off all key press events from ever being detected.

I tried to intercept onBrowserEvent(Event) and could not detect any key press events which I would have generated by keypresses while having focus on the FileUploadField component.

Where is the key-press event shunt?

I could not find any keypress handler insertion methods.

I wish to allow triggering the file upload by either press on the space-bar or enter key.

Short of rewriting a whole new component from scratch, could someone advise me what I could do to achieve my goal of a keyboard activated file upload?


Solution

  • onBrowserEvent won't recieve any events unless you sink them - did you make sure to call sinkEvents? How are you adding handlers? If you use addDomHandler, it will sink them for you, but addHandler either assumes that they are not dom events, or that you already called sinkEvents. Without sinking an event, the browser doesn't know to pass that event on to a GWT widget. If all events were sunk automatically, then every time you moved the mouse across the page you would see a firestorm of events as mousemove fired for every widget you passed, and all of its parents.

    If you override onBrowserEvent, then you are building the method that describes how to handle the actual event that comes from the browser - that is where the com.google.gwt.user.client.DOM class wires into the Widget to give it events. Short of making that method final, there is no way to prevent you, the widget user, from getting those events as long as the browser is generating them and passing them through the event listener.

    Even if onBrowserEvent has been overridden and made final, you can still get access to many events by creating a NativePreviewHandler and checking where the event is occurring. This gets you in to the event before it even goes to the widget itself - there you can call NativePreviewEvent.cancel() to prevent it from happening on the widget itself, or you can handle it early in the handler.