Events Handling

GWT provides an advanced tools for browser events handling. As usual widgets have accessor methods to add and remove listeners and Advanced GWT Components is not an exception.

In most cases it uses standard interface to give an ability to handle mouse and keyboard events, but there are some specific events to be discussed here. The list of library listener interfaces is shown below.

Interface Description Used in Widgets
EditCellListener This lister is invoked on start and end edit cell events. Use it to validate entered values. If the entered value is invalid, it won't be placed in the data model, the old value will be restored instead. EditableGrid, HierarchicalGrid, TreeGrid
ExpandableCellListener This listener handles mouse clicks on the expand cell image (usually the gray cross). It is invoked after the cell is expanded or collapsed. HierarchicalGrid, TreeGrid
GridListener This listener handles data model and grid view synchronization. For instance it is invoked on sort, clean or on save events. You can attach your own listener via the EventMediator. GridPanel, EditableGrid, HierarchicalGrid, TreeGrid
GridToolbarListener This listener is invoked on grid toolbar button clicks. Each method of the listener is related to one particular button. There is really hard to imagine a situation when you have to provide your own implementation but if it's so you can attach it via the EventMediator. GridPanel, GridToolbar, EditableGrid, HierarchicalGrid, TreeGrid
PagerListener This is a listener that is invoked on data page change. Using it you can detect what is happening on the Pager widget. Attach your own implementation via the EventMediator. GridPanel, Pager, EditableGrid, HierarchicalGrid, TreeGrid
SelectRowListener This listener is invoked on grid row selection. It doesn't matter how the row has been selected: by a user or by a widget. The listener handling method will be called anyway. EditableGrid, HierarchicalGrid, TreeGrid
CalendarListener This listener is invoked on date change or cancelling. DatePicker
SuggestionBoxListener This listener is invoked when a user changes a value in the SuggestionBox. SuggestionBox
GridRowDrawCallbackHandler This is not a listener interface because it doesn't handles any input event. Use it cases when you need to display a progress of grid content rendereng, for example, in a progress bar. EditableGrid, HierarchicalGrid, TreeGrid

As you must be noticed some listeners may be attached only via EventMediator. This is an internal class which performs events firing in cases when you use the GridPanel. It's strongly recommended to use this panel even if you are not going to diplay toolbars and pagers. This widget simplifies UI maintenance and dispatches events via the EventMediator.

Another key entity related to events handling is the GridEventManager interface. Its implementations are able to handle mouse, keyboard and focus events occuring in the grids. If need centralized input controls management simply make your own implementation and inject it into a grid using the GridPanel.setGridEventManager() method.

By default all the grids already have managers assigned to them. And you can extend them instead of using interface implementation. Here is the sample illustrating how you can do it:

GridPanel panel = new GridPanel();
panel.setGridEventManager(new DefaultGridEventManager() {
    public boolean dispatch(GridPanel panel, char keyCode, int modifiers) {
        if (KeyboardListener.KEY_ENTER == keyCode) {
            Window.alert("Enter key pressed!");
            return false;
        return super.dispatch(panel, keyCode, modifiers);

This listing creates a new GridPanel and sets a new GridEventManager that displays the alert window when the Enter button is pressed.