GWT单元格树右键单击选择 [英] GWT Cell Tree Right Click Selection

查看:151
本文介绍了GWT单元格树右键单击选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我创建了一个CellTree,我想要做的是选择接收右键单击的单元格,以便当我打开我的上下文菜单来完成任务时,我将知道我正在使用的单元格。也许我错了,我可以重写onBrowserEvent方法,并检测某人何时右键单击树,但我不知道哪个单元格被点击,所以我可以手动选择它。有没有人找到解决这个问题的解决方案?

解决方案

我找到了解决方案,我希望这可以帮助其他人,因为我一直在寻找这很长一段时间。可能有更好的方法,但这里是我如何完成我所期望的功能:

在我的树中使用的单元格中,我对onbrowserevent捕获鼠标事件并设置选择模型。使用抽象单元格可以吸收您希望它听到的事件,而在我的情况下,我选择了鼠标向下。

  public class CustomContactCell extends AbstractCell<&的ContactInfo GT; {

private SetSelectionModel< ContactInfo> selectionModel设置;

public CustomContactCell(SetSelectionModel< ContactInfo> selectionModel){
super(mousedown);
this.selectionModel = selectionModel;
}

@Override
public void render(Context context,ContactInfo value,SafeHtmlBuilder sb){
...
}

@Override
public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context,Element parent,ContactInfo value,NativeEvent event,ValueUpdater< ContactInfo> valueUpdater){
if( event.getButton()== NativeEvent.BUTTON_RIGHT){
if(selectionModel!= null){
selectionModel.clear();
selectionModel.setSelected(value,true);
}
}
super.onBrowserEvent(context,parent,value,event,valueUpdater);
}
}


So I have created a CellTree and what I want to do is select the cell that receives a right click so that when I open my context menu to do things, I will know what cell I am working with. Maybe I am going about it the wrong way, I can override the onBrowserEvent method and detect when someone right clicks on the tree but I can't figure out which cell is being clicked so I can manually select it. Has anyone found a solution for this problem?

解决方案

I found a solution, I hope this helps others as I have been searching for this for a long time. There might be a better way, but here is how I accomplished the functionality that I desired:

In the cells that I used inside my tree, I did an override on the onbrowserevent to catch the mouse events and set the selection model. With abstract cells you can sink events you want it to listen to and in my case I chose mouse down.

public class CustomContactCell extends AbstractCell<ContactInfo> {

    private SetSelectionModel<ContactInfo> selectionModel;

    public CustomContactCell(SetSelectionModel<ContactInfo> selectionModel) {
        super("mousedown");
        this.selectionModel = selectionModel;
    }

    @Override
    public void render(Context context, ContactInfo value, SafeHtmlBuilder sb) {
        ...
    }

    @Override
    public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context, Element parent, ContactInfo value, NativeEvent event, ValueUpdater<ContactInfo> valueUpdater) {
        if (event.getButton() == NativeEvent.BUTTON_RIGHT) {
            if (selectionModel != null) {
                selectionModel.clear();
                selectionModel.setSelected(value, true);
            }
        }
        super.onBrowserEvent(context, parent, value, event, valueUpdater);
    }
}

这篇关于GWT单元格树右键单击选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆