Re-styling Tree component

Hello,

I’m working with Vaadin 8 latest (8.7.0).

I have a doubt about how to re-style an item of a tree component.

I have two browsers opened with the same view. If I check the “checked” button in one of them, the change has to be reflected in both browsers.

What I do, is to push the change when the button is pressed, but I don´t know how to keep the styles of the items that are not affected with the change, which, basically, it’s to put the checked items in green color.

	public void reStyleTreeMenu(WorkProjectModuleDTO modifiedModuleItem) {		
		final StringBuilder style = new StringBuilder();
		
		ModuleItem forRefreshing = new ModuleItem(modifiedModuleItem);
		
		this.setStyleGenerator(item ->{
			style.setLength(0);
			
			if(item.getClass().isAssignableFrom(ModuleItem.class)) {
				WorkProjectModuleDTO currentItem = ((ModuleItem) item).getModuleItem();							
				if(currentItem.isSameItemAs(modifiedModuleItem) ) {
					style.append("tree-sidenav-menu-item ");
					if( modifiedModuleItem.isChecked()) {
						style.append("tree-sidenav-menu-item-checked ");
					}					
				} else {
					
					// HOW TO GET THE CURRENT STYLE ¿?
				}
			}
			return style.toString();
		});
		
		treeDataProvider.refreshItem((ModuleComponent)forRefreshing);
	}

By the way…
Is this proper way of refreshing an specific tree item??

treeDataProvider.refreshItem((ModuleComponent)forRefreshing);

Thanks in advance !!!

17549327.png

Hi there…

I finally found that the solution was simple like all I did.
As the tree.setStyleGenerator is done when the component is created, just calling

treeDataProvider.refreshItem((ModuleComponent)forRefreshing);

is enough for re-styling an item.
(keep in mind a properly overriding of equals and hashcode object methods)

So, the reStyleTreeMenu shows now like that:

    public void refreshItem(WorkProjectModuleDTO modifiedModuleItem) {                
        treeDataProvider.refreshItem(modifiedModuleItem);
    }

Thanks!