简体   繁体   中英

JFace TreeViewer, how to notify the tree, when some empty folder was popluted

I build a TreeViewer with a tree structure advisor like this:

public class ExplorerTreeStructureAdvisor extends TreeStructureAdvisor {

    @Override
    public Object getParent(Object element) {
        return ((Node)element).getParent();
    }

    @Override
    public Boolean hasChildren(Object element) {
        if(element instanceof Folder){
            Folder folder = (Folder)element;
            return !folder.getChildren().isEmpty();
        }
        return false;
    }

}

with such a TreeStructureAdvisor , empty folders in that tree will have no expand button. when some user action happend, some child nodes will be added to that empty folder, what's the best way to notify the tree that tree structure has been changed ?

I think, TreeViewer#refresh() may work, but for performance consideration, it's not good to refresh the whole tree when we know that there is just only one node has been changed.

In situation like these you should really depend on your data model to notify about changed data. This means that when some user action modifies your data model, it should be responsible for notifying concerned components about the change. You can then add a "data changed listener" to the model and refresh only the changed object through TreeViewer#refresh(Object) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM