diff --git a/platform/platform-impl/src/com/intellij/ui/tree/AbstractTreeWalker.java b/platform/platform-impl/src/com/intellij/ui/tree/AbstractTreeWalker.java index ffccdae9f12c..b128d1a2c151 100644 --- a/platform/platform-impl/src/com/intellij/ui/tree/AbstractTreeWalker.java +++ b/platform/platform-impl/src/com/intellij/ui/tree/AbstractTreeWalker.java @@ -8,7 +8,6 @@ import org.jetbrains.concurrency.Promise; import javax.swing.tree.TreePath; import java.util.ArrayDeque; import java.util.Collection; -import java.util.Deque; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; @@ -17,7 +16,7 @@ public abstract class AbstractTreeWalker { private final AtomicReference state = new AtomicReference<>(); private final AsyncPromise promise = new AsyncPromise<>(); - private final Deque> stack = new ArrayDeque<>(); + private final ArrayDeque> stack = new ArrayDeque<>(); private final Function converter; private final TreeVisitor visitor; private volatile TreePath current; diff --git a/platform/platform-impl/src/com/intellij/ui/tree/StructureTreeModel.java b/platform/platform-impl/src/com/intellij/ui/tree/StructureTreeModel.java index 646d130314ed..d5a31749a4eb 100644 --- a/platform/platform-impl/src/com/intellij/ui/tree/StructureTreeModel.java +++ b/platform/platform-impl/src/com/intellij/ui/tree/StructureTreeModel.java @@ -20,7 +20,9 @@ import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.util.*; -import static java.util.Collections.*; +import static java.util.Collections.emptyList; +import static java.util.Collections.enumeration; +import static java.util.Collections.unmodifiableList; /** * @author Sergey.Malenkov @@ -38,13 +40,25 @@ public class StructureTreeModel extends AbstractTreeModel implements Disposable, : new Invoker.EDT(this); } - public final void setComparator(@NotNull Comparator comparator) { + /** + * @param comparator a comparator to sort tree nodes or {@code null} to disable sorting + */ + public final void setComparator(@Nullable Comparator comparator) { if (disposed) return; - this.comparator = (node1, node2) -> comparator.compare(node1.getDescriptor(), node2.getDescriptor()); - invalidate(); + if (comparator != null) { + this.comparator = (node1, node2) -> comparator.compare(node1.getDescriptor(), node2.getDescriptor()); + invalidate(); + } + else if (this.comparator != null) { + this.comparator = null; + invalidate(); + } } - public void setStructure(@NotNull AbstractTreeStructure structure) { + /** + * @param structure a structure to build tree model or {@code null} to clear its content + */ + public void setStructure(@Nullable AbstractTreeStructure structure) { if (disposed) return; this.structure = structure; invalidate(); diff --git a/platform/platform-impl/src/com/intellij/ui/tree/project/ProjectFileNodeUpdater.java b/platform/platform-impl/src/com/intellij/ui/tree/project/ProjectFileNodeUpdater.java index cc72baa6d399..5f17dcf9dcc3 100644 --- a/platform/platform-impl/src/com/intellij/ui/tree/project/ProjectFileNodeUpdater.java +++ b/platform/platform-impl/src/com/intellij/ui/tree/project/ProjectFileNodeUpdater.java @@ -109,7 +109,7 @@ public abstract class ProjectFileNodeUpdater { /** * Notifies that project roots are changed. - * The {@link #update} method will be executed with a small delay + * The {@link #onInvokerThread} method will be executed with a small delay * after calling of this method. * * @see #getUpdatingDelay @@ -120,7 +120,7 @@ public abstract class ProjectFileNodeUpdater { /** * Notifies that the specified file (or folder) is changed. - * The {@link #update} method will be executed with a small delay + * The {@link #onInvokerThread} method will be executed with a small delay * after last calling of this method, * i.e. a bunch of modified files will be reported together. * @@ -152,7 +152,7 @@ public abstract class ProjectFileNodeUpdater { } /** - * @return a delay between an event and the {@link #update} method calling, + * @return a delay between an event and the {@link #onInvokerThread} method calling, * that is used to collect a bunch of changes */ protected int getUpdatingDelay() { @@ -220,7 +220,8 @@ public abstract class ProjectFileNodeUpdater { /** * This method is called on invoker's thread to report changes in virtual files. - * @param fromRoot {@code true} if roots are changed + * + * @param fromRoot {@code true} if roots are changed * @param updatedFiles a set of modified files */ protected abstract void updateStructure(boolean fromRoot, @NotNull Set updatedFiles); diff --git a/platform/util/src/com/intellij/util/ui/tree/TreeModelListenerList.java b/platform/util/src/com/intellij/util/ui/tree/TreeModelListenerList.java index 7a2a7182f95b..4aed1b082143 100644 --- a/platform/util/src/com/intellij/util/ui/tree/TreeModelListenerList.java +++ b/platform/util/src/com/intellij/util/ui/tree/TreeModelListenerList.java @@ -20,14 +20,13 @@ import org.jetbrains.annotations.NotNull; import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelListener; import java.util.ArrayDeque; -import java.util.Deque; /** * @author Sergey.Malenkov */ public final class TreeModelListenerList implements TreeModelListener { private static final TreeModelListener[] EMPTY_ARRAY = new TreeModelListener[0]; - private final Deque myDeque = new ArrayDeque(); + private final ArrayDeque myDeque = new ArrayDeque(); private volatile boolean myDequeEmpty = true; /** @@ -50,9 +49,11 @@ public final class TreeModelListenerList implements TreeModelListener { * @param listener a listener to remove */ public void remove(@NotNull TreeModelListener listener) { - synchronized (myDeque) { - myDeque.remove(listener); - myDequeEmpty = myDeque.isEmpty(); + if (!myDequeEmpty) { + synchronized (myDeque) { + myDeque.remove(listener); + myDequeEmpty = myDeque.isEmpty(); + } } } @@ -61,9 +62,11 @@ public final class TreeModelListenerList implements TreeModelListener { * This method is safe for use by multiple concurrent threads. */ public void clear() { - synchronized (myDeque) { - myDeque.clear(); - myDequeEmpty = true; + if (!myDequeEmpty) { + synchronized (myDeque) { + myDeque.clear(); + myDequeEmpty = true; + } } }