How do I to fire a Gwt event from JavaScript ? 2010/4/12 Elmaho <elmaho...@gmail.com>
> Hey everyone, > > I want to integrate MooFlow external lib in my Gwt Application, so I > begin by reading the essentials of JSNI and doing my things. > So far it's OK, I create the Impl class to wrap the functions I need, > I create also the JSObject and finally the widget itself (called > CoverFlow). > > Now all I need is to add the possibility to catch the onClickView > Event in my widget (java widget). > With the implementation below, I can't see the HEY message when I > click on an image, it sounds like the line: > > cfo.addEvent('onClickView', ... > > don't work in my Impl class !!! > > this is my Impl class > > public class CoverFlowImpl { > > public native CoverFlowScriptObject create(Element container, int > startIndex, boolean useSlider) /*-{ > > var options = { > useSlider: useSlider, > useAutoPlay: false, > useCaption: false, > useResize: false, > useWindowResize: false, > useMouseWheel: true, > useKeyInput: true, > startIndex: startIndex > }; > > var mf = new $wnd.MooFlow(container, options); > return mf; > > }-*/; > > public native void loadJSON(CoverFlowScriptObject cfo, String json) > / > *-{ > cfo.loadJSONArray(json); > }-*/; > > public native void addClickViewHandler(CoverFlowScriptObject cfo, > HasSelectedItemChanged handler) /*-{ > > cfo.addEvent('onClickView', function(obj){ > > alert('HEY'); //just to indicate if the > event is fired > > var event = > @com.audaxis.gwt.ui.coverflow.client.SelectedItemChangedEvent::new() > (); > handl...@com.google.gwt.event.shared.hashandlers > ::fireEvent(Lcom/ > google/gwt/event/shared/GwtEvent;)(event); > }; > > }-*/; > } > > > The Opaque JS Object > > public final class CoverFlowScriptObject extends JavaScriptObject{ > > private final static CoverFlowImpl impl = new CoverFlowImpl(); > > protected CoverFlowScriptObject() {} > > public static CoverFlowScriptObject createCoverFlow(Element > container, int startIndex, boolean useSlider){ > return impl.create(container, startIndex, useSlider); > } > > public void laodJSON(String json){ > impl.loadJSON(this, json); > } > > public void addClickViewEvent(HasSelectedItemChanged handler){ > impl.addClickViewHandler(this, handler); > } > } > > > > My Widget > > public class CoverFlow extends Composite implements > HasSelectedItemChanged{ > > private Panel simplePanel; > private CoverFlowScriptObject cvo; > private Collection<CoverFlowItem> items; > > public CoverFlow() { > init(null); > } > > protected void init(Panel parent){ > simplePanel = parent != null ? parent : new SimplePanel(); > cvo = getCoverFlowJSObject(); > initWidget(simplePanel); > } > > @Override > public HandlerRegistration > addSelectedItemChanged(SelectedItemChangedHandler handler) { > cvo.addClickViewEvent(this); > return addHandler(handler, > SelectedItemChangedEvent.getType()); > } > } > > > And finally -----------HasSelectedItemChanged > > > public interface HasSelectedItemChanged extends HasHandlers{ > > HandlerRegistration > addSelectedItemChanged(SelectedItemChangedHandler > handler); > } > > Is my implementation correcte ? > Is this the right implementation to fire events from JavaScript to > Java ? > > Could anyone help me please !! > > Thanks in advance > > -- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit" group. > To post to this group, send email to google-web-tool...@googlegroups.com. > To unsubscribe from this group, send email to > google-web-toolkit+unsubscr...@googlegroups.com<google-web-toolkit%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/google-web-toolkit?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.