Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TabSheet lazy tabs #3029

Closed
glebfox opened this issue Mar 21, 2024 · 1 comment · Fixed by #3094
Closed

Implement TabSheet lazy tabs #3029

glebfox opened this issue Mar 21, 2024 · 1 comment · Fixed by #3094
Assignees
Milestone

Comments

@glebfox
Copy link
Contributor

glebfox commented Mar 21, 2024

Similar to Classic https://docs.jmix.io/1.x/jmix/1.5/ui/vcl/containers/tab-sheet.html#lazy-loading-tab-content

The TabSheet component switches tabs and each tab can have many components. To descrease loading time of a view we can set attribute lazy=true to some tabs. In that case the vew won't load components from lazy tabs. Those components will load automatically if user activates a tab.

Descriptor example:

<tabSheet id="tabSheet">
    <tab id="tab1" label="Tab1">
        <button id="tab1Button" text="Tab1 Button"/>
    </tab>
    <tab id="tab2" label="Tab2" lazy="true">
        <vbox>
            <button id="tab2Button" text="Tab2 Button"/>    
        </vbox>
    </tab>
</tabShee>

Controller example:

@ViewComponent(value="tabSheet.tab1")
private Tab tab1;

@ViewComponent(value="tabSheet.tab2")
private Tab tab2;

@ViewComponent
private JmixTabSheet tabSheet;

@Subscribe
public void onInit(final InitEvent event) {
    updateTabLabels();

    tabSheet.addSelectedChangeListener(new ComponentEventListener<JmixTabSheet.SelectedChangeEvent>() {
        @Override
        public void onComponentEvent(JmixTabSheet.SelectedChangeEvent event) {
            updateTabLabels();
        }
    });
}

private void updateTabLabels() {
    tab1.setLabel(String.format("Tab1 [component: %s]", getTabLabel("tab1Button")));
    tab2.setLabel(String.format("Tab2 [lazy] [component: %s]", getTabLabel("tab2Button")));
}

private String getTabLabel(String tabId) {
    return tabSheet.findComponent(tabId).isPresent()
            ? ((JmixButton) tabSheet.findComponent(tabId).get()).getText()
            : "Empty";
}

In this example we have two tabs: tab1 and tab2. Tab2 is marked as lazy. Thus when the view is opened only components from tab1 are loaded.

The view is opened: tab1Button is loaded and tab2Button is empty.
The tab2 is activated: tab1Button is loaded and tab2Button is loaded.

We should be carefull about injecting components from lazy tabs in a controller because they wouldn't be initialised.

@ViewComponent
private JmixButton tab1Button;

@ViewComponent
private JmixButton tab2Button;

In this example, tab1Button is initialised and tab2Button is equals null. Even after the lazy tab activation tab2Button won't be initialised. We should handle this case manually.

@glebfox glebfox added in: flowui triage Issue is waiting for triage labels Mar 21, 2024
@gorbunkov gorbunkov added size: M and removed triage Issue is waiting for triage labels Mar 22, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Release 2.3 Mar 22, 2024
@ilushaaa ilushaaa moved this from Backlog to In progress in Release 2.3 Apr 2, 2024
@ilushaaa ilushaaa linked a pull request Apr 3, 2024 that will close this issue
@ilushaaa ilushaaa moved this from In progress to Review in Release 2.3 Apr 3, 2024
ilushaaa added a commit that referenced this issue Apr 11, 2024
@github-project-automation github-project-automation bot moved this from Review to Done in Release 2.3 Apr 11, 2024
@ilushaaa ilushaaa reopened this Apr 11, 2024
@github-project-automation github-project-automation bot moved this from Done to Next in Release 2.3 Apr 11, 2024
@ilushaaa ilushaaa moved this from Next to QA in Release 2.3 Apr 11, 2024
@SergeiAksenov2
Copy link

Tested on Java:

  1. Jmix version: 2.3.999-SNAPSHOT
    Jmix Studio plugin version: 2.3.SNAPSHOT6350-233
    IntelliJ version: IntelliJ IDEA 2023.3.6 (Community Edition)
  2. Jmix version: 2.3.999-SNAPSHOT
    Jmix Studio plugin version: 2.3.SNAPSHOT6351-241
    IntelliJ version: IntelliJ IDEA 2024.1 (Community Edition)

The button 'tab2Button' always equals null - Ok

@github-project-automation github-project-automation bot moved this from QA to Done in Release 2.3 Apr 27, 2024
ilushaaa added a commit that referenced this issue Jun 13, 2024
ilushaaa added a commit that referenced this issue Jun 15, 2024
@gorbunkov gorbunkov added this to the 2.3.0 milestone Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants