Cell Browser External Listener

36 views
Skip to first unread message

Sam Wootton

unread,
Feb 26, 2016, 8:13:44 AM2/26/16
to GWT Users
Dear GWT Users,

Thanks in advance for any help.

I have working CellBrowser that I want to add an external listener to (so that I can display data clicked on... but outside and in another panel).  I see CellBrowser implements HasClickHandlers (and addClickHandler).

http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/cellview/client/CellBrowser.html

I can successfully handle an event internally in my Cell i.e.

public void onBrowserEvent(Context context, Element parent, Track value, NativeEvent event, ValueUpdater<Track> valueUpdater) {

super.onBrowserEvent(context, parent, value, event, valueUpdater);

if ("click".equals(event.getType())) {

EventTarget eventTarget = event.getEventTarget();
GWT.log("You selected " + value.getName() + " by " + value.getArtist());
}
}

I thought (given the interfaces it implements) I could do something like

CellBrowser cellBrowser = cbb.build();

cellBrowser.addHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {

}
});


But it appears not. What and how is the best way to externally listen to CellBrowser and Cell events, so that I can display the event info "outside" in another e.g. Panel?

Regards, Sam



Jens

unread,
Feb 26, 2016, 8:38:23 AM2/26/16
to GWT Users
Since "click" is a browser event you would need to use addDomHandler() instead of addHandler().

If that does not work either then I would let the Cell publish a custom Event on the EventBus. Maybe using custom events via EventBus is more readable anyways.

-- J.

Sam Wootton

unread,
Feb 26, 2016, 10:43:36 AM2/26/16
to google-we...@googlegroups.com
Hello Jens,

Thanks for your help.  I managed to add
cellBrowser.addDomHandler(new ClickHandler() {

@Override
public void onClick(ClickEvent clickEvent) {
        GWT.log("DownloadPanel.onClick "+clickEvent.getNativeEvent().toString());
}
}, ClickEvent.getType());

But that doesn't get me the domain / model data I need (logical event data I guess).  So i ended up being a bit hacky and firing event from within the Cell
TreeViewModelListener listenerObj = (TreeViewModelListener) listeners.get(i);
DownloadSelectedEvent downloadSelectedEvent = new DownloadSelectedEvent(param1, param2, param3...);
listenerObj.onDownloadSelected(downloadSelectedEvent);

and implemented listener interface and implemented

public void onDownloadSelected(DownloadSelectedEvent event){}
well it worked :]
Regards, Sam




--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/6eUspwFcq0g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Thomas Broyer

unread,
Feb 26, 2016, 11:49:47 AM2/26/16
to GWT Users
Have a look at the ActionCell and ButtonCell's API.
ActionCell has its own Delegate, while ButtonCell will use the ValueUpdater, but in the end they're very similar.


On Friday, February 26, 2016 at 4:43:36 PM UTC+1, Sam Wootton wrote:
Hello Jens,

Thanks for your help.  I managed to add
cellBrowser.addDomHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
GWT.log("DownloadPanel.onClick "+clickEvent.getNativeEvent().toString());
}
}, ClickEvent.getType());

But that doesn't get me the domain / model data I need (logical event data I guess).  So i ended up being a bit hacky and firing event from within the Cell
TreeViewModelListener listenerObj = (TreeViewModelListener) listeners.get(i);
DownloadSelectedEvent downloadSelectedEvent = new DownloadSelectedEvent(param1, param2, param3...);
listenerObj.onDownloadSelected(downloadSelectedEvent);

and implemented listener interface and implemented

public void onDownloadSelected(DownloadSelectedEvent event){}
well it worked :]
Regards, Sam



On 26 February 2016 at 13:38, Jens <jens.ne...@gmail.com> wrote:
Since "click" is a browser event you would need to use addDomHandler() instead of addHandler().

If that does not work either then I would let the Cell publish a custom Event on the EventBus. Maybe using custom events via EventBus is more readable anyways.

-- J.

--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/6eUspwFcq0g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-toolkit+unsub...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages