Search code examples
javagwtgwt2gwt-tablayoutpanel

Listener on tabPanel in GWT


I am new new to GWT.

I have designed the Gui using GWT designer. I my GUI I have tabPanel with 4 tabs.

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.

i want to click on the tabBrowse which is calling RPC.i know RPC call

But How to add click listener on the very particular tab as each Tab is calling different RPC.


Solution

  • The TabPanel in GWT implements HasSelectionHandlers and HasBeforeSelectionHandlers. So you need to add a selection handler to your TabPanel. In the OnSelection method you can then figure out which Tab Item (i.e. Widget) has been selected using the Widget's index. 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 (e.g. 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.