本文介绍了GWT:用鼠标右键选择一个TreeItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我捕捉一个右键单击事件来显示一个上下文菜单。我无法弄清楚的是,如何在显示上下文菜单之前实际选择TreeItem。

I'm capturing a right click event to show a context menu. What I haven't been able to figure out, is how to make the right click actually select the TreeItem, prior to showing of context menu.

所有帮助表示感谢。

All help is appreciated.

 private Tree tree = new Tree() {
  @Override
  public void onBrowserEvent(Event event) {   
    if (event.getTypeInt() == Event.ONCONTEXTMENU) {
     DOM.eventPreventDefault(event);          
     showContextMenu(event);
    }   
   super.onBrowserEvent(event);
  }

  @Override
  protected void setElement(Element elem) {
   super.setElement(elem);
   sinkEvents(Event.ONCONTEXTMENU);
  }

 };


推荐答案

您可以使用专用的重载TreeItem:

You can use dedicated overloaded TreeItem :

public class MyTreeItem extends TreeItem implements ContextMenuHandler {


    public SBTreeItem(SBItemTree tree, String name) {
        super();
        Label w = new Label(name);
        w.addDomHandler(this, ContextMenuEvent.getType());
        setWidget(w);
    }

            public void onContextMenu(ContextMenuEvent event) {
        Window.alert(getSBItem().getName());
        event.getNativeEvent().stopPropagation();

    }

   }

这篇关于GWT:用鼠标右键选择一个TreeItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 06:56