mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add ability to invalidate cached entries in async tree model
This commit is contained in:
+5
-2
@@ -77,6 +77,7 @@ public class FileSystemTreeImpl implements FileSystemTree {
|
||||
private final Project myProject;
|
||||
private final ArrayList<Runnable> myOkActions = new ArrayList<>(2);
|
||||
private final FileChooserDescriptor myDescriptor;
|
||||
private final FileTreeModel myFileTreeModel;
|
||||
private final AsyncTreeModel myAsyncTreeModel;
|
||||
|
||||
private final List<Listener> myListeners = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
@@ -99,10 +100,12 @@ public class FileSystemTreeImpl implements FileSystemTree {
|
||||
myProject = project;
|
||||
if (renderer == null && Registry.is("file.chooser.async.tree.model")) {
|
||||
renderer = new FileRenderer().forTree();
|
||||
myAsyncTreeModel = new AsyncTreeModel(new FileTreeModel(descriptor, new FileRefresher(true, 3)));
|
||||
myFileTreeModel = new FileTreeModel(descriptor, new FileRefresher(true, 3));
|
||||
myAsyncTreeModel = new AsyncTreeModel(myFileTreeModel);
|
||||
myTreeStructure = null;
|
||||
}
|
||||
else {
|
||||
myFileTreeModel = null;
|
||||
myAsyncTreeModel = null;
|
||||
myTreeStructure = new FileTreeStructure(project, descriptor);
|
||||
}
|
||||
@@ -244,7 +247,7 @@ public class FileSystemTreeImpl implements FileSystemTree {
|
||||
public void showHiddens(boolean showHidden) {
|
||||
if (myAsyncTreeModel != null) {
|
||||
myDescriptor.withShowHiddenFiles(showHidden);
|
||||
//TODO:refresh
|
||||
if (myFileTreeModel != null) myFileTreeModel.invalidate();
|
||||
}
|
||||
else {
|
||||
myTreeStructure.showHiddens(showHidden);
|
||||
|
||||
@@ -79,6 +79,17 @@ public final class FileTreeModel extends AbstractTreeModel implements Disposable
|
||||
});
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
invoker.invokeLaterIfNeeded(() -> {
|
||||
if (roots != null) {
|
||||
for (Root root : roots) {
|
||||
root.tree.invalidate();
|
||||
}
|
||||
}
|
||||
treeStructureChanged(state.path, null, null);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@@ -57,6 +57,11 @@ public final class MapBasedTree<K, N> {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
if (root != null) root.invalidate();
|
||||
map.values().forEach(entry -> entry.invalidate());
|
||||
}
|
||||
|
||||
public void onRemove(@NotNull Consumer<N> consumer) {
|
||||
Consumer<N> old = nodeRemoved;
|
||||
nodeRemoved = old == null ? consumer : old.andThen(consumer);
|
||||
@@ -146,6 +151,7 @@ public final class MapBasedTree<K, N> {
|
||||
}
|
||||
parent.leaf = children == null;
|
||||
parent.children = guard(newChildren);
|
||||
parent.valid = true;
|
||||
|
||||
List<Entry<N>> removed = oldChildren;
|
||||
List<Entry<N>> inserted = newChildren;
|
||||
@@ -218,6 +224,7 @@ public final class MapBasedTree<K, N> {
|
||||
private volatile boolean leaf;
|
||||
private volatile List<Entry<N>> children;
|
||||
private volatile N loading;
|
||||
private volatile boolean valid;
|
||||
|
||||
private Entry(TreePath path, N parent, N node, Boolean leaf) {
|
||||
super(path, node);
|
||||
@@ -225,6 +232,11 @@ public final class MapBasedTree<K, N> {
|
||||
this.parent = parent;
|
||||
this.leaf = Boolean.TRUE.equals(leaf);
|
||||
if (this.leaf) children = emptyList();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
valid = leaf;
|
||||
}
|
||||
|
||||
public N getNode() {
|
||||
@@ -240,7 +252,7 @@ public final class MapBasedTree<K, N> {
|
||||
}
|
||||
|
||||
public boolean isLoadingRequired() {
|
||||
return children == null;
|
||||
return !valid || children == null;
|
||||
}
|
||||
|
||||
public int getChildCount() {
|
||||
@@ -272,6 +284,7 @@ public final class MapBasedTree<K, N> {
|
||||
if (children != null) LOG.warn("MapBasedTree: rewrite loaded nodes");
|
||||
this.loading = loading;
|
||||
children = loading == null ? emptyList() : singletonList(new Entry<>(this, node, loading, true));
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user