Question

I have a GXT 3 TabPanel and would like to disable one or more tabs in response to an event.
There does not seem to be a way to do this.

Was it helpful?

Solution 2

I figured this out a while back and forgot to post the answer. Here's a way to do this that works reliably :

public class SimpleTabPanel extends com.sencha.gxt.widget.core.client.PlainTabPanel
    implements TabPanel {
Tab currentActiveTab;

private Map<SimpleTab,TabItemConfig> tabConfigs = new HashMap<SimpleTab,TabItemConfig>();



// a map sorted by priority used to keep the expected tab order
SortedMap<TabData, SimpleTab> tabsConfig = new TreeMap<TabData, SimpleTab>(
        new Comparator<TabData>() {
            @Override
            public int compare(TabData o1, TabData o2) {
                return Float.compare(o1.getPriority(), o2.getPriority());
            }
        });

@Override
public Tab addTab(TabData tabData, String historyToken) {
    SimpleTab newTab = createNewTab(tabData);
    tabsConfig.put(tabData, newTab);
    newTab.setTargetHistoryToken(historyToken);
    return newTab;
}


private void disableTab(SimpleTab tab, TabData key){

    // get and save tab's config.
    TabItemConfig tic = getConfig(tab);
    tabConfigs.put(tab, tic);

    // put new one on tab to disable it.
    tic = new TabItemConfig(key.getLabel());
    tic.setEnabled(false);
    update(tab, tic);
}

public void enableAllTabs(){
    for(TabData key : tabsConfig.keySet()){
        SimpleTab tab = tabsConfig.get(key);
        TabItemConfig tic = tabConfigs.get(tab);
        if(tic!=null){
            tic.setEnabled(true);
            update(tab, tic);
        }
    }
}

}

OTHER TIPS

PlainTabPanel panel = new PlainTabPanel();
TabItemConfig config = new TabItemConfig("Disabled");
Label disabled = new Label("This tab should be disabled");

config.setEnabled(false);    // here what you need

panel.add(disabled, config);

I had the same issue happening in my project.

The way I solved it is really simple and I hope that it answers your need.

public void enableTab(IsWidget item, Boolean enable) {
    TabItemConfig config = tabPanel.getConfig(item.asWidget());
    config.setEnabled(enable);
    tabPanel.update(item.asWidget(), config);
}

I call that method every time I need to change a tab state.

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