简体   繁体   English

GWT中tabPanel上的侦听器

[英]Listener on tabPanel in GWT

I am new new to GWT. 我是GWT的新手。

I have designed the Gui using GWT designer. 我使用GWT设计器设计了Gui。 I my GUI I have tabPanel with 4 tabs. 我的GUI有4个标签的tabPanel

private TabPanel getWorkplacePanel() {
    if (WorkplacePanel == null) {
        WorkplacePanel = new TabPanel();

        WorkplacePanel.setStyleName("Workpalce-MyWorkPlace");
        WorkplacePanel.add(getMyWorkPlacePanel(), "My Workplace", false);

        WorkplacePanel.add(getBrowsePanel(), "Browse", false);
        WorkplacePanel.add(getSearchPanel(), "Search", false);
        WorkplacePanel.add(getTaskPanel(), "Tasks", false);
        WorkplacePanel.setSize("1450px", "750px");

    }
    return WorkplacePanel;
}

In every Tabs I have composite widgets. 在每个选项卡中,我都有复合小部件。 For Example on Browse Tab i have 2 composite tree ans table. 例如,在“浏览”选项卡上,我有2个复合树ans表。

i want to click on the tabBrowse which is calling RPC.i know RPC call 我想单击正在调用RPC的tabBrowse,我知道RPC调用

But How to add click listener on the very particular tab as each Tab is calling different RPC. 但是如何在非常特殊的选项卡上添加单击侦听器,因为每个选项卡都调用不同的RPC。

The TabPanel in GWT implements HasSelectionHandlers and HasBeforeSelectionHandlers . GWT中的TabPanel实现了HasSelectionHandlersHasBeforeSelectionHandlers So you need to add a selection handler to your TabPanel. 因此,您需要在TabPanel中添加选择处理程序。 In the OnSelection method you can then figure out which Tab Item (ie Widget) has been selected using the Widget's index. 然后,在OnSelection方法中,您可以使用小部件的索引来确定选择了哪个选项卡项(即小部件)。 You can then either do a type check or use some custom type identifier (if you need to) to figure out which tab item has been selected (eg Browse, Search etc): 然后,您可以进行类型检查或使用一些自定义类型标识符(如果需要)来确定已选择了哪个选项卡项(例如,浏览,搜索等):

WorkplacePanel.addSelectionHandler(new SelectionHandler<Integer>(){
  public void onSelection(SelectionEvent<Integer> event){
   int tabId = event.getSelectedItem();
   Widget tabWidget = tabpanel.getWidget(tabId);
 }
});

The above code is from This thread which might help you further. 上面的代码来自此线程 ,可能会进一步帮助您。

note that using HasBeforeSelectionHandlers, you can cancel the BeforeSelectionEvent. 请注意,使用HasBeforeSelectionHandlers,可以取消BeforeSelectionEvent。 It let you do whatever you want and call yourself the SelectionEvent when you whant the tab to switch. 当您希望切换选项卡时,它可以让您执行所需的任何操作,并自称为SelectionEvent。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM