Add lazy tab to a tabsheet through code

Hello,

I’m in a need to be able to add lazy tabs to a tabsheet through code but I see the addLazyTab method is annotated as internal and the lazy property is available only through descriptor and used in component loader afterwards.
So is what I’m trying to do possible right now?

Thanks!
Konstantin

Hi,

the lazy attribute is needed only for XML loading. Programmatically you can directly subscribe on SelectedTabChangeEvent and generate layout when a particular tab is opened, e.g.:

@Autowired
private TabSheet tabSheet;
@Autowired
protected Label<String> info;

@Autowired
private UiComponents uiComponents;

boolean tab2Initialized = false;

@Subscribe
public void onInit(InitEvent event) {
    VBoxLayout tab2Layout = uiComponents.create(VBoxLayout.class);
    tab2Layout.setMargin(true);
    TabSheet.Tab tab2 = tabSheet.addTab("tab2", tab2Layout);
    tab2.setCaption("Tab 2");
}

@Subscribe("tabSheet")
public void onTabSheetSelectedTabChange(TabSheet.SelectedTabChangeEvent event) {
    if (event.getSelectedTab().getName().equals("tab2")) {
        if (tab2Initialized) return;

        ComponentContainer tab2 = (ComponentContainer) event.getSource().getTabComponent("tab2");
        Label<String> label = uiComponents.create(Label.TYPE_STRING);
        label.setId("label2");
        label.setValue("Label 2");
        tab2.add(label);
        tab2Initialized = true;
    }
}

Regards,
Gleb