SmartGWT Custom Events

Ok, so working with the SmartGWT framework on top of Google Web Toolkit. The goal was to fire a custom even from a ToolStrip when one of its members fired a ClickEvent.

This is relatively easily accomplished by subclassing ToolStrip and implementing the HasDataChangedHandlers interface. The only thing that took a bit of time to figure out was that I needed to use the SmartGWT function doAddHandler in BaseWidget instead of the GWT addHandler method in order to properly register the handler with the HandlerManager

Main Class

package test.client;
 
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.events.DataChangedEvent;
import com.smartgwt.client.data.events.DataChangedHandler;
 
public class CustomEvents implements EntryPoint {
    public void onModuleLoad() {
        MyStrip t = new MyStrip();
        t.addDataChangedHandler(new DataChangedHandler() {
            @Override
            public void onDataChanged(DataChangedEvent event) {
                // Handle the event here
            }
        });
        t.test();
    }
}

Subclassed ToolStrip

package test.client;
 
import com.google.gwt.event.shared.HandlerRegistration;
import com.smartgwt.client.data.events.DataChangedEvent;
import com.smartgwt.client.data.events.DataChangedHandler;
import com.smartgwt.client.data.events.HasDataChangedHandlers;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
 
public class MyStrip extends ToolStrip implements HasDataChangedHandlers {
 
    public void test() {
        fireEvent(new DataChangedEvent(this.getJsObj()));
    }
 
    @Override
    public HandlerRegistration addDataChangedHandler(DataChangedHandler handler) {
        return doAddHandler(handler, DataChangedEvent.getType());
    }
}