mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup after cleanup review
This commit is contained in:
@@ -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<N> {
|
||||
|
||||
private final AtomicReference<State> state = new AtomicReference<>();
|
||||
private final AsyncPromise<TreePath> promise = new AsyncPromise<>();
|
||||
private final Deque<ArrayDeque<N>> stack = new ArrayDeque<>();
|
||||
private final ArrayDeque<ArrayDeque<N>> stack = new ArrayDeque<>();
|
||||
private final Function<? super N, Object> converter;
|
||||
private final TreeVisitor visitor;
|
||||
private volatile TreePath current;
|
||||
|
||||
@@ -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<? super NodeDescriptor> comparator) {
|
||||
/**
|
||||
* @param comparator a comparator to sort tree nodes or {@code null} to disable sorting
|
||||
*/
|
||||
public final void setComparator(@Nullable Comparator<? super NodeDescriptor> 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();
|
||||
|
||||
@@ -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<? extends VirtualFile> updatedFiles);
|
||||
|
||||
@@ -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<TreeModelListener> myDeque = new ArrayDeque<TreeModelListener>();
|
||||
private final ArrayDeque<TreeModelListener> myDeque = new ArrayDeque<TreeModelListener>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user