Custom Event in GWT widget is not working

I am working on application in Vaadin for my classes. I have to draw some map on the screen so I’m using gwt-graphics lib. I have also some servlet which is waiting for requests. When some specific request will come view of the map should be changed. It lead me to prepare custom event:

// class NewModulePositionHandler package com.example.locator; import com.google.gwt.event.shared.EventHandler; public interface NewModulePositionHandler extends EventHandler { void onNewModulePosition(NewModulePositionEvent event); } Below implementation of my custom event:

import com.google.gwt.event.shared.GwtEvent; public class NewModulePositionEvent extends GwtEvent<NewModulePositionHandler> { private static final Type<NewModulePositionHandler> TYPE = new Type<NewModulePositionHandler>(); private final String m_Color; public NewModulePositionEvent(String color) { m_Color = color; } public static Type<NewModulePositionHandler> getType() { return TYPE; } public String getColor() { return m_Color; } @Override public com.google.gwt.event.shared.GwtEvent.Type<NewModulePositionHandler> getAssociatedType() { // TODO Auto-generated method stub return TYPE; } @Override protected void dispatch(NewModulePositionHandler handler) { handler.onNewModulePosition(this); } }

And it’s time for implementation of my custom widget:

a) MyComp.java

import com.google.gwt.event.shared.GwtEvent; public class NewModulePositionEvent extends GwtEvent<NewModulePositionHandler> { private static final Type<NewModulePositionHandler> TYPE = new Type<NewModulePositionHandler>(); private final String m_Color; public NewModulePositionEvent(String color) { m_Color = color; } public static Type<NewModulePositionHandler> getType() { return TYPE; } public String getColor() { return m_Color; } @Override public com.google.gwt.event.shared.GwtEvent.Type<NewModulePositionHandler> getAssociatedType() { // TODO Auto-generated method stub return TYPE; } @Override protected void dispatch(NewModulePositionHandler handler) { handler.onNewModulePosition(this); } } b) MyCompClientRpc.java

import com.vaadin.shared.communication.ClientRpc; public interface MyCompClientRpc extends ClientRpc { // TODO example API public void alert(String message); public void changeColor(String color); }

c) MyCompConnector.java

package com.example.locator.widgetset.client.mycomp; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.shared.ui.Connect; import com.example.locator.MyComp; import com.example.locator.NewModulePositionEvent; import com.example.locator.NewModulePositionHandler; import com.example.locator.widgetset.client.mycomp.MyCompWidget; import com.example.locator.widgetset.client.mycomp.MyCompServerRpc; import com.vaadin.client.communication.RpcProxy; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.vaadin.shared.MouseEventDetails; import com.vaadin.client.MouseEventDetailsBuilder; import com.example.locator.widgetset.client.mycomp.MyCompClientRpc; import com.example.locator.widgetset.client.mycomp.MyCompState; import com.vaadin.client.communication.StateChangeEvent; @Connect(MyComp.class) public class MyCompConnector extends AbstractComponentConnector { MyCompServerRpc rpc = RpcProxy .create(MyCompServerRpc.class, this); public MyCompConnector() { registerRpc(MyCompClientRpc.class, new MyCompClientRpc() { public void alert(String message) { // TODO Do something useful Window.alert(message); } public void changeColor(String color) { getWidget().InitMap(color); } }); // TODO ServerRpc usage example, do something useful instead getWidget().addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final MouseEventDetails mouseDetails = MouseEventDetailsBuilder .buildMouseEventDetails(event.getNativeEvent(), getWidget().getElement()); rpc.clicked(mouseDetails); } }); getWidget().addNewModulePositionHandler(new NewModulePositionHandler() { public void onNewModulePosition(NewModulePositionEvent event) { // TODO Auto-generated method stub rpc.newModulePosition(event.getColor()); } }); } @Override protected Widget createWidget() { return GWT.create(MyCompWidget.class); } @Override public MyCompWidget getWidget() { return (MyCompWidget) super.getWidget(); } @Override public MyCompState getState() { return (MyCompState) super.getState(); } @Override public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); // TODO do something useful final String color = getState().color; getWidget().InitMap(color); } } d) MyCompServerRpc.java

package com.example.locator.widgetset.client.mycomp; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.communication.ServerRpc; public interface MyCompServerRpc extends ServerRpc { // TODO example API public void clicked(MouseEventDetails mouseDetails); public void newModulePosition(String color); } e) MyCompState.java

package com.example.locator.widgetset.client.mycomp; public class MyCompState extends com.vaadin.shared.AbstractComponentState { // TODO example state public String color = "#000000"; } And finally implementation of the widget:

f) MyCompWidget.java

package com.example.locator.widgetset.client.mycomp; import org.vaadin.gwtgraphics.client.DrawingArea; import org.vaadin.gwtgraphics.client.Line; import org.vaadin.gwtgraphics.client.shape.Rectangle; import com.example.locator.NewModulePositionEvent; import com.example.locator.NewModulePositionHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.touch.client.Point; // TODO extend any GWT Widget public class MyCompWidget extends DrawingArea { public static final String CLASSNAME = "mycomp"; public static double m_AreaWidth = 64.355; public static double m_AreaHeight = 17.385; public static int m_PictureWidth; public static int m_PictureHeight; public static double m_AreaToMapRatio; public static double m_RouteWidth = 3.5; public static double m_MainRouteCoordinateY = 8.0828; final private HandlerManager handlerManager = new HandlerManager(this); public MyCompWidget(){ super(640, 320); double xRatio = m_AreaWidth / 640; double yRatio = m_AreaHeight / 320; m_AreaToMapRatio = xRatio > yRatio ? xRatio : yRatio; InitMap("#919491"); setStyleName(CLASSNAME); } public void InitMap(String color) { m_PictureWidth = (int)TranslateCoordinate(m_AreaWidth); m_PictureHeight = (int)TranslateCoordinate(m_AreaHeight); Rectangle rectangle = new Rectangle(0, 0, m_PictureWidth, m_PictureHeight); rectangle.setFillColor(color); add(rectangle); Point point1Beg = new Point(0.0, 8.0828); Point point1End = new Point(64.355, 8.0838); Point point2Beg = new Point(20.2825, 8.0828); Point point2End = new Point(20.2825, 17.385); Point point3Beg = new Point(59.325, 0.0); Point point3End = new Point(59.325, 8.0828); point1Beg = TranslatePoint(point1Beg); point1End = TranslatePoint(point1End); point2Beg = TranslatePoint(point2Beg); point2End = TranslatePoint(point2End); point3Beg = TranslatePoint(point3Beg); point3End = TranslatePoint(point3End); Line line1 = new Line((int)point1Beg.getX(), (int)point1Beg.getY(), (int)point1End.getX(), (int)point1End.getY()); Line line2 = new Line((int)point2Beg.getX(), (int)point2Beg.getY(), (int)point2End.getX(), (int)point2End.getY()); Line line3 = new Line((int)point3Beg.getX(), (int)point3Beg.getY(), (int)point3End.getX(), (int)point3End.getY()); line1.setStrokeColor("#FFFFFF"); line2.setStrokeColor("#FFFFFF"); line3.setStrokeColor("#FFFFFF"); line1.setStrokeWidth((int)TranslateCoordinate(m_RouteWidth)); line2.setStrokeWidth((int)TranslateCoordinate(m_RouteWidth)); line3.setStrokeWidth((int)TranslateCoordinate(m_RouteWidth)); add(line1); add(line2); add(line3); DrawWall(TranslateCoordinate(10.0)); DrawWall(TranslateCoordinate(20.0)); DrawWall(TranslateCoordinate(30.0)); DrawWall(TranslateCoordinate(40.0)); DrawWall(TranslateCoordinate(50.0)); DrawWall(TranslateCoordinate(60.0)); DrawDoor(3.0, 3.0); DrawDoor(13.0, 3.0); DrawDoor(23.0, 3.0); DrawDoor(33.0, 3.0); DrawDoor(43.0, 3.0); DrawDoor(53.0, 3.0); System.out.println("DUPA"); } public void DrawWall(double a_Place) { Line line = new Line((int)a_Place, 0, (int)a_Place, (int)TranslateCoordinate(m_AreaHeight)); line.setStrokeColor("#FFFFFF"); add(line); } public void DrawDoor(double a_Position, double a_Width) { double realDoorPositionY = m_MainRouteCoordinateY - (m_RouteWidth / 2); int doorPositionYTop = (int)TranslateCoordinate(realDoorPositionY) - 1; int doorPositionYBottom = (int)TranslateCoordinate(realDoorPositionY + m_RouteWidth) + 1; Line line = new Line((int)TranslateCoordinate(a_Position), doorPositionYTop, (int)TranslateCoordinate(a_Position) + (int)TranslateCoordinate(a_Width), doorPositionYTop); line.setStrokeColor("#000000"); line.setStrokeWidth(2); add(line); Line line2 = new Line((int)TranslateCoordinate(a_Position), doorPositionYBottom, (int)TranslateCoordinate(a_Position) + (int)TranslateCoordinate(a_Width), doorPositionYBottom); line2.setStrokeColor("#000000"); line2.setStrokeWidth(2); add(line2); } public Point TranslatePoint(Point a_Point) { Point translatedPoint = new Point(TranslateCoordinate(a_Point.getX()), TranslateCoordinate(a_Point.getY())); return translatedPoint; } public double TranslateCoordinate(double a_Coordinate) { return (a_Coordinate) / (m_AreaToMapRatio); } public void addNewModulePositionHandler( NewModulePositionHandler handler) { handlerManager.addHandler(NewModulePositionEvent.getType(), handler); // TODO Auto-generated method stub } } If I compile the widgets set containing MyCompWidget and then run my application on glassfish I get the following message:
“Widgetset ‘com.example.locator.widgetset.LocatorWidgetset’ does not contain implementation for com.example.locator.MyComp. Check its component connector’s @Connect mapping, widgetsets GWT module description file and re-compile your widgetset. In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions.”

If I cut

public void addNewModulePositionHandler( NewModulePositionHandler handler) { handlerManager.addHandler(NewModulePositionEvent.getType(), handler); // TODO Auto-generated method stub } widget works properly (of course I have to comment out these lines from MyCompConnector as well):

getWidget().addNewModulePositionHandler(new NewModulePositionHandler() { public void onNewModulePosition(NewModulePositionEvent event) { // TODO Auto-generated method stub rpc.newModulePosition(event.getColor()); } });

Can anyone tell me where is the problem? It seems that compilation of the widget failes but I can’t find any information about that. Please, help me. Thanks in advance.
14414.java (1011 Bytes)
14415.java (203 Bytes)
14416.java (326 Bytes)
14417.java (190 Bytes)
14418.java (4.51 KB)
14419.java (257 Bytes)
14420.java (766 Bytes)
14421.java (2.48 KB)