Skip to content

feat: extract interface HierarchicalTreeData from TreeData#23950

Open
sclassen wants to merge 5 commits intovaadin:mainfrom
sclassen:hierarchicalTreeDataInterface
Open

feat: extract interface HierarchicalTreeData from TreeData#23950
sclassen wants to merge 5 commits intovaadin:mainfrom
sclassen:hierarchicalTreeDataInterface

Conversation

@sclassen
Copy link

Description

TreeDataProvider currently takes a TreeData as its source. But it relies only on a few methods of TreeData.
This change extracts those methods into an interface. It then introduces a super class to TreeDataProvider which accepts a HierarchicalTreeData instead of a TreeData. A client has now the choice to either use the TreeData and the TreeDataProvider, or it can implement the HierarchicalTreeData interface and use the HierarchicalTreeDataProvider.

This change introduces a new interface and a new class but does not change or break any existing API.

Fixes #9808

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

@CLAassistant
Copy link

CLAassistant commented Mar 19, 2026

CLA assistant check
All committers have signed the CLA.

TreeDataProvider currently takes a TreeData as its source.
But it relies only on a few methods of TreeData.
This change extracts those methods into an interface.
It then introduces a super class to TreeDataProvider which accepts a HierarchicalTreeData instead of a TreeData.
A client has now the choice to either use the TreeData and the TreeDataProvider, or it can implement the HierarchicalTreeData interface and use the HierarchicalTreeDataProvider.

This change introduces a new interface and a class but does not change or break any existing API.

Fixes vaadin#9808
@sclassen
Copy link
Author

This is the minimal change I could find to satisfy the desire to have a custom tree data implementation as it is expressed in #9808.

  • The extracted interface has only the minimal set of method required.
  • All existing code is moved or untouched so no changes in behavior results.

The name of the new interface is semi optimal, as "hierarchical" is already used in other class names with a slightly different semantics.

This second gerenic parameter represents the concrete type of the HierarchicalTreeData.
Having this as a generic parameter allows for better type safty.
The client of the provider can get the underlying data structure in a type safe manner.
This eases writing stable code.
@mshabarov mshabarov added the Contribution PRs coming from the community or external to the team label Mar 20, 2026
@sonarqubecloud
Copy link

@github-actions
Copy link

Test Results

 1 386 files  ±0   1 386 suites  ±0   1h 24m 56s ⏱️ - 3m 33s
 9 907 tests ±0   9 836 ✅ ±0  71 💤 ±0  0 ❌ ±0 
10 380 runs  ±0  10 300 ✅ ±0  80 💤 ±0  0 ❌ ±0 

Results for commit 1224857. ± Comparison against base commit e66174e.

* @param <T>
* data type
*/
public interface HierarchicalTreeData<T> extends Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better name is HierarchicalData IMHO.

* @return {@code true} if the item is in this hierarchy, {@code false} if
* not
*/
boolean contains(T item);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to add List<T> getRootItems(); as a convenient shorthand even though it's not currently used by TreeDataProvider.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not agree.
This would require that every implementation can produce the list of all roots from any given item. This is demanding if the underlying implementation relies on references instead of a central map.
For me this is a high barrier to pass especially for a functionality which is not used by flow at all.

- rename HierarchicalTreeDataProvider.java -> InMemoryHierarchicalDataProvider.java
- rename HierarchicalTreeData.java -> HierarchicalData.java
- add method InMemoryHierarchicalDataProvider.getHierarchicalData()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Contribution PRs coming from the community or external to the team +1.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce Interface for TreeData used by TreeDataProvider

4 participants