It will be perfect if developer can have access to expandedNodes Set in TreeState. This will help to restore expansion state after dynamic model change.
Example:
public void remove() { log.info("Remove"); root.remove(0); rebuild(); } private void rebuild() { uiRoot = builder.build(root); if (tree != null) { TreeState treeState = ((TreeState) tree.getComponentState()); List<TreeRowKey> rowsToExpand = new ArrayList(treeState.getExpandedNodes()); tree.resetDataModel(); for (TreeRowKey key : rowsToExpand) { try { tree.queueNodeExpand(key); } catch (IOException e) { log.error("Error", e); } } } }