I try in GWT to create a Tree with multiple selection for the nodes and ran into a problem similar to this question Shift Key in GWT?.
When a selectionEvent is raised from the Tree, I would like to know if the Shift key is pressed or not.
SelectionHandler<TreeItem> getSelectionHandler() {
return new SelectionHandler<TreeItem>(){
@Override
public void onSelection(SelectionEvent<TreeItem> event) {
// is shift key pressed ?
}
};
}
The solution in the question above cannot apply in this case as the SelectionHandler class does not inherit from DOMEvent and then does not have a getNativeEvent() function.
I tried a dirty solution by adding keyDownEventHandler and keyUpEventHandler to the Tree with a boolean flag but the handlers are only called when the focus is on the tree so this doesn’t work.
Is there a simple solution (or just a solution even if it’s not simple) ? Thanks.
Edit on aem response :
The solution can work by enclosing the components in a FocusPanel with a keyUp/DownHandler but then I can’t add any component needing keyboard input such as TextArea as the “global” handler takes the priority… So it don’t really solve my problem.
My suggestion is to create a custom Tree class that temporary store the event and store this event by overriding the
onBrowseEventmethod. Then you can, in youronSelectionmethod, check if the shift key was pressed by checking this stored event. Since JavaScript is not concurrent it should be no problem using the private variable. The code would be something like this: