I am using a tree to display different objects in hierarchical structure. Each element in the tree are of different object type and based on selection of the tree node i display different view in UI. Here is an example of Tree:-
Current Tree code allows only one dataProvider of specific object type.
How do I handle the about usecase, I dont want to convert these objects to string and display tree of string. What is the alternate approach? This is a basic tree usecase.
You will need a wrapper object in that case - something that contains a reference to the actual object, but allows you to specify just a single data type for the Tree. Either that or your data objects could implement a common interface.
Olli Tietäväinen:
You will need a wrapper object in that case - something that contains a reference to the actual object, but allows you to specify just a single data type for the Tree. Either that or your data objects could implement a common interface.
-Olli
Thanks Olli for quick reply. Cant we not implement HierarchicalDataProvider?? and do //connectionTree.setDataProvider(new ConnectionTreeDataProvider()); and connectionTree.setData(connectionList);
Unfortunately, I am finding it hard to find good example for HierarchicalDataProvider. Appreciate if you could give me good example for this problem.
It’s not just about the DataProvider, I think you would need to reimplement the whole DataCommunicator mechanism too. I’m not saying it’s not possible, but you will have an easier time by using a wrapper.
Olli Tietäväinen:
You will need a wrapper object in that case - something that contains a reference to the actual object, but allows you to specify just a single data type for the Tree. Either that or your data objects could implement a common interface.
-Olli
Thank you for the solution, implemented a common interface for all objects in the tree and using single data provider I was able to get the tree loaded.
Olli Tietäväinen:
You will need a wrapper object in that case - something that contains a reference to the actual object, but allows you to specify just a single data type for the Tree. Either that or your data objects could implement a common interface.
-Olli
Thank you for the solution, implemented a common interface for all objects in the tree and using single data provider I was able to get the tree loaded.
I am trying to add multiple Connection on add new Connection Action. Should I reconstruct the tree data provider from Root node?? I am doing the below code
Collection<ABSWrapper> aliasList = AbsUI.get().getAliasManager().getABSWrapper();
TreeData<ABSWrapper> data = new TreeData<>();
// add root level items
data.addItems(null, aliasList);
for (ABSWrapper alias : aliasList) {
User user = alias.getUser();
data.addItem(alias, user);
List<ABSWrapperEnvironment> userEnvList = user.getUserWrapperEnvList();
for (ABSWrapperEnvironment absWrapperEnvironment : userEnvList) {
data.addItem(user, absWrapperEnvironment);
}
}
// construct the data provider for the hierarchical data we've built
TreeDataProvider<ABSWrapper> dataProvider = new TreeDataProvider<>(data);
connectionTree.setDataProvider(dataProvider);
However it is throwing java.lang.IllegalArgumentException: Cannot add the same item multiple times: user1
at com.vaadin.data.TreeData.addItem(TreeData.java:166)
How do i solve this problem?? Appreciate if you could provide links to examples or document which will help me solve these problems.