java - Cellbrowser click event on cell - Stack Overflow

I can't figure out how I can add a click handler on a cell in a cellbrowser in GWT.I found anothe

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 badges
Add a ment  | 

3 Answers 3

Reset to default 3

In your TreeViewModel, you give a SelectionModel to the returned NodeInfo. You can listen for SelectionChangeEvents 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

相关推荐

  • java - Cellbrowser click event on cell - Stack Overflow

    I can't figure out how I can add a click handler on a cell in a cellbrowser in GWT.I found anothe

    3天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信