GWT单元格树右键单击选择 [英] GWT Cell Tree Right Click Selection
问题描述
我找到了解决方案,我希望这可以帮助其他人,因为我一直在寻找这很长一段时间。可能有更好的方法,但这里是我如何完成我所期望的功能:
在我的树中使用的单元格中,我对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屋!