Good day @Jean_Louis ,
Yes, a sidebar is based on a tree view. However, it is more related to its expanded state. When collapsed, it is only partly a tree that shows the first level of data, the other data levels are in a popup with a menu. So, depending on the state the sidebar has a different structure. And when you add or remove items to or from the expanded sidebar, you will need to reflect the changes in the menu also.
You can get the menu via sidebar.getPopup().queryView({view:"menu"});
Then, after adding (and removing) an item to the tree, you could serialize the data, clear the tree and parse the updated data so that it will be shown in the menu also.
When removing, the items should be removed both from the sidebar tree and the sidebar menu.
Have a look at the example: Code Snippet .