admin管理员组文章数量:1022944
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");
}
}
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");
}
}
本文标签: javaCellbrowser click event on cellStack Overflow
版权声明:本文标题:java - Cellbrowser click event on cell - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745533868a2154872.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论