TabSheet tab API improvements
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.8k
- Forks
- 717
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 3
Description
Originally by @hezamu
Currently it is possible to add closeable, lazily initialized tabs in a TabSheet, but it requires unnecessary scaffolding code that is mostly identical in all applications. The common use case is
0. Create a CustomComponent implementing the UI in the tab with lazy initialization and optionally tab switching logic
0. Add SelectedTabChangeListener that finds out which tab was opened
0. Call custom logic in the component to initialize the contents only when the tab is opened the first time
0. Optionally store the opened tab reference to be able to call "navigate from" logic if required
It would be better if there was a abstract superclass extending CustomComponent that would handle all the legwork internally. Something like
public abstract class AbstractTab extends CustomComponent {
private boolean isInitialized = false;
abstract protected void init();
public void switchTo() {
if (!isInitialized) {
init();
}
}
public void switchFrom() {
}
public void close() {
}
}
This would also require a little code in TabSheet to wire the methods to corresponding events automatically when such a component is added as a tab. It would be best if the wiring logic was executed only if the component being added was extended from the abstract class, so the enhancement would not affect backward compatibility.
This improvement would simplify the usage of TabSheet significantly, as the steps 2-4 above would be unnecessary.
Imported from https://dev.vaadin.com/ issue #4378
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading TabSheet and CustomComponent, then trace how tab selection and close events are currently handled. Define the AbstractTab lifecycle and automatic wiring for components added as tabs, while preserving existing behavior for other components; done means lazy initialization, switch-to, switch-from, and close handling work without the current scaffolding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100