How to fire an event whenever a tab got inserted into or got removed out of TabLayoutPanel in Gwt?

StackOverflow https://stackoverflow.com/questions/19247153

  •  30-06-2022
  •  | 
  •  

Question

I have a TabLayoutPanel. At the beginning, TabLayoutPanel has no Tab. Users can add as many tabs into it as they can. They can also remove all the tabs.

My requirement is:

I want to set button enabled = true whenever the TabLayoutPanel has at least 1 tab. If it has no tab, then set button enabled = false.

       getView().getMainTabLayoutPanel().addAttachHandler(new AttachEvent.Handler(){

            @Override
            public void onAttachOrDetach(AttachEvent event) {

                int currentSelectedTabInt=getView().getMainTabLayoutPanel().getSelectedIndex();
                if(currentSelectedTabInt>-1){
                    getView().getMyButton().setEnabled(true);

                }
            }

        });

The above code doesn't work.

So how to fire an event whenever a tab got inserted into or got removed out of TabLayoutPanel in Gwt?

Was it helpful?

Solution

You can set button enabled = true or false on the handler wherein you listens to the event of buttons AddTabButton and RemoveTabButton. You have to check there the number of tabs visible/present.

myTabLayoutPanel.getWidgetCount(); //Returns the number of tabs and widgets.

OTHER TIPS

You can create a subclass of TabLayoutPanel and override doAttachChildren and doDetachChildren. The event you are catching pertains to the attach/detach of the tab panel itself, not its children.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top