I can't figure out how I can add a click handler on a cell in a cellbrowser in GWT. I found another question here on StackOverFlow related to my question, but it was for a double click handler. I can't figure out how to add just a normal click handler.
My purpose is when a user clicks on a cell in the cellbrowser it downloads the child notes from a server. I already played around with onBrowserEvent but I could not get it work.
I can't figure out how I can add a click handler on a cell in a cellbrowser in GWT. I found another question here on StackOverFlow related to my question, but it was for a double click handler. I can't figure out how to add just a normal click handler.
My purpose is when a user clicks on a cell in the cellbrowser it downloads the child notes from a server. I already played around with onBrowserEvent but I could not get it work.
Share Improve this question edited May 23, 2017 at 9:58 CommunityBot 11 silver badge asked Apr 6, 2011 at 18:11 tim_atim_a 9601 gold badge7 silver badges21 bronze badges3 Answers
Reset to default 3In your TreeViewModel
, you give a SelectionModel
to the returned NodeInfo
. You can listen for SelectionChangeEvent
s on the SelectionModel
(and given your use case, you'll likely use a NoSelectionModel
, most probably a single one shared by all levels that need that onclick behavior)
You can't add a ClickHandler
like normal because a Cell
is not a Widget.
AbstractCell
does have some methods that make it convenient for you to handle events, but you have to call its constructor with the names of the events you'd like to listen to. For instance, you'd pass "click" to the constructor of your cell, override onBrowserEvent
, and check for "click" events there.
Look at the source for the ClickableTextCell
to see how Google added click listeners to a cell.
Maybe this is also interesting for other web developers using GWT so this is how I did it:
// Create a clickable cell.
Cell<C> cell = new ClickCell() {
@Override
public void render(Context context, C value, SafeHtmlBuilder sb) {
if (value != null) {
sb.appendEscaped(value.getName());
}
}
@Override
public void onBrowserEvent(Context context, Element parent, C value,
NativeEvent event, ValueUpdater<C> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);
if ("click".equals(event.getType())) {
onEnterKeyDown(context, parent, value, event, valueUpdater);
}
}
@Override
protected void onEnterKeyDown(Context context, Element parent, C value,
NativeEvent event, ValueUpdater<C> valueUpdater) {
if (valueUpdater != null) {
valueUpdater.update(value);
}
}
};
And this is the class ClickCell that extends the AbstractCell class:
public abstract class ClickCell extends AbstractCell<C> {
public ClickCell() {
super("click", "keydown");
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745533870a4631817.html
评论列表(0条)