diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/BackgroundContentProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/BackgroundContentProvider.java
index 9977b752beb..78096369bf0 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/BackgroundContentProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/BackgroundContentProvider.java
@@ -15,13 +15,12 @@
import java.util.Comparator;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.AcceptAllFilter;
import org.eclipse.jface.viewers.IFilter;
-import org.eclipse.jface.viewers.deferred.ConcurrentTableUpdator.Range;
/**
* Contains the algorithm for performing background sorting and filtering in a virtual
@@ -124,10 +123,6 @@ public void update(Object[] changed) {
private IProgressMonitor sortingProgressMonitor = new NullProgressMonitor();
private Thread sortThread = null;
- private volatile FastProgressReporter sortMon = new FastProgressReporter();
-
- private volatile Range range = new Range(0,0);
-
/**
* Creates a new background content provider
*
@@ -307,42 +302,35 @@ private void doSort(IProgressMonitor mon) {
break;
}
- try {
- ConcurrentTableUpdator.Range updateRange = updator.getVisibleRange();
- sortMon = new FastProgressReporter();
- range = updateRange;
- int sortStart = updateRange.start;
- int sortLength = updateRange.length;
+ ConcurrentTableUpdator.Range updateRange = updator.getVisibleRange();
+ int sortStart = updateRange.start;
+ int sortLength = updateRange.length;
- if (limit != -1) {
- collection.retainFirst(limit, sortMon);
- }
-
- sortLength = Math.min(sortLength, totalElements - sortStart);
- sortLength = Math.max(sortLength, 0);
+ if (limit != -1) {
+ collection.retainFirst(limit);
+ }
- Object[] objectsOfInterest = new Object[sortLength];
+ sortLength = Math.min(sortLength, totalElements - sortStart);
+ sortLength = Math.max(sortLength, 0);
- collection.getRange(objectsOfInterest, sortStart, true, sortMon);
+ Object[] objectsOfInterest = new Object[sortLength];
- // Send the new elements to the table
- for (int i = 0; i < sortLength; i++) {
- Object object = objectsOfInterest[i];
- updator.replace(object, sortStart + i);
- }
+ collection.getRange(objectsOfInterest, sortStart, true);
- objectsOfInterest = new Object[collection.size()];
+ // Send the new elements to the table
+ for (int i = 0; i < sortLength; i++) {
+ Object object = objectsOfInterest[i];
+ updator.replace(object, sortStart + i);
+ }
- collection.getFirst(objectsOfInterest, true, sortMon);
+ objectsOfInterest = new Object[collection.size()];
- // Send the new elements to the table
- for (int i = 0; i < totalElements; i++) {
- Object object = objectsOfInterest[i];
- updator.replace(object, i);
- }
+ collection.getFirst(objectsOfInterest, true);
- } catch (InterruptedException e) {
- continue;
+ // Send the new elements to the table
+ for (int i = 0; i < totalElements; i++) {
+ Object object = objectsOfInterest[i];
+ updator.replace(object, i);
}
dirty = false;
@@ -371,7 +359,6 @@ private static void filteredAdd(LazySortedCollection collection, Object[] toAdd,
public void setSortOrder(Comparator sorter) {
Assert.isNotNull(sorter);
this.sortOrder = sorter;
- sortMon.cancel();
refresh();
}
@@ -383,7 +370,6 @@ public void setSortOrder(Comparator sorter) {
public void setFilter(IFilter toSet) {
Assert.isNotNull(toSet);
this.filter = toSet;
- sortMon.cancel();
refresh();
}
@@ -417,13 +403,6 @@ public int getLimit() {
*/
public void checkVisibleRange(int includeIndex) {
updator.checkVisibleRange(includeIndex);
- ConcurrentTableUpdator.Range newRange = updator.getVisibleRange();
- ConcurrentTableUpdator.Range oldRange = range;
-
- // If we're in the middle of processing an invalid range, cancel the sort
- if (newRange.start != oldRange.start || newRange.length != oldRange.length) {
- sortMon.cancel();
- }
}
/**
@@ -475,7 +454,6 @@ public void run() {
*/
private void makeDirty() {
synchronized (lock) {
- sortMon.cancel();
// request sorting
sortScheduled = true;
if (!sortThreadStarted) {
@@ -495,7 +473,6 @@ private void makeDirty() {
* ways.
*/
private void cancelSortJob() {
- sortMon.cancel();
sortingProgressMonitor.setCanceled(true);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/FastProgressReporter.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/FastProgressReporter.java
deleted file mode 100644
index 6c95fe50f4c..00000000000
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/FastProgressReporter.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2015 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.viewers.deferred;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-/**
- * A more efficient alternative to an IProgressMonitor. In particular, the
- * implementation is designed to make isCanceled() run as efficiently as
- * possible. Currently package-visible because the implementation is incomplete.
- *
- * @since 3.1
- *
- * @deprecated use SubMonitor instead
- *
- * TODO mark for deletion
- */
-@Deprecated
-final class FastProgressReporter {
- private IProgressMonitor monitor;
- private volatile boolean canceled = false;
- private int cancelCheck = 0;
-
- private static int CANCEL_CHECK_PERIOD = 40;
-
- /**
- * Constructs a null FastProgressReporter
- */
- public FastProgressReporter() {
- }
-
- /**
- * Constructs a FastProgressReporter that wraps the given progress monitor
- *
- * @param monitor the monitor to wrap
- * @param totalProgress the total progress to be reported
- */
- public FastProgressReporter(IProgressMonitor monitor, int totalProgress) {
- this.monitor = monitor;
- canceled = monitor.isCanceled();
- }
- /**
- * Return whether the progress monitor has been canceled.
- *
- * @return true if the monitor has been cancelled, false otherwise.
- */
- public boolean isCanceled() {
- if (monitor == null) {
- return canceled;
- }
-
- cancelCheck++;
- if (cancelCheck > CANCEL_CHECK_PERIOD) {
- canceled = monitor.isCanceled();
- cancelCheck = 0;
- }
- return canceled;
- }
-
- /**
- * Cancel the progress monitor.
- */
- public void cancel() {
- canceled = true;
-
- if (monitor == null) {
- return;
- }
- monitor.setCanceled(true);
- }
-}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/LazySortedCollection.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/LazySortedCollection.java
index 019d2dc9368..b4b4a267746 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/LazySortedCollection.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/LazySortedCollection.java
@@ -364,7 +364,7 @@ private final int partition(int subTree, int toMove) {
* was replaced during the removal)
* @since 3.1
*/
- private final int partition(int subTree, FastProgressReporter mon) throws InterruptedException {
+ private final int partition(int subTree) {
if (subTree == -1) {
return -1;
}
@@ -382,10 +382,6 @@ private final int partition(int subTree, FastProgressReporter mon) throws Interr
if (idx != -1) {
parentTree[idx] = subTree;
}
-
- if (mon.isCanceled()) {
- throw new InterruptedException();
- }
}
// At this point, there are no remaining unsorted nodes in this subtree
@@ -834,42 +830,20 @@ public final void removeAll(Object[] toRemove) {
}
/**
- * Retains the n smallest items in the collection, removing the rest. When
- * this method returns, the size of the collection will be n. Note that
- * this is a no-op if n > the current size of the collection.
- *
- * Temporarily package visibility until the implementation of FastProgressReporter - * is finished. - *
+ * Retains the n smallest items in the collection, removing the rest. When this + * method returns, the size of the collection will be n. Note that this is a + * no-op if n > the current size of the collection. * * @param n number of items to retain - * @param mon progress monitor - * @throws InterruptedException if the progress monitor is cancelled in another thread */ - /* package */ final void retainFirst(int n, FastProgressReporter mon) throws InterruptedException { + public final void retainFirst(int n) { int sz = size(); if (n >= sz) { return; } - removeRange(n, sz - n, mon); - - testInvariants(); - } - - /** - * Retains the n smallest items in the collection, removing the rest. When this - * method returns, the size of the collection will be n. Note that this is a - * no-op if n > the current size of the collection. - * - * @param n number of items to retain - */ - public final void retainFirst(int n) { - try { - retainFirst(n, new FastProgressReporter()); - } catch (InterruptedException e) { - } + removeRange(n, sz - n); testInvariants(); } @@ -883,36 +857,14 @@ public final void retainFirst(int n) { * @param length number of items to remove */ public final void removeRange(int first, int length) { - try { - removeRange(first, length, new FastProgressReporter()); - } catch (InterruptedException e) { - } - - testInvariants(); - } - - /** - * Removes all elements in the given range from this collection. - * For example, removeRange(10, 3) would remove the 11th through 13th - * smallest items from the collection. - * - * Temporarily package visiblity until the implementation of FastProgressReporter is - * finished. - * - * @param first 0-based index of the smallest item to remove - * @param length number of items to remove - * @param mon progress monitor - * @throws InterruptedException if the progress monitor is cancelled in another thread - */ - /* package */ final void removeRange(int first, int length, FastProgressReporter mon) throws InterruptedException { - removeRange(root, first, length, mon); + removeRange(root, first, length); pack(); testInvariants(); } - private final void removeRange(int node, int rangeStart, int rangeLength, FastProgressReporter mon) throws InterruptedException { + private final void removeRange(int node, int rangeStart, int rangeLength) { if (rangeLength == 0) { return; } @@ -930,7 +882,7 @@ private final void removeRange(int node, int rangeStart, int rangeLength, FastPr } try { // Partition any unsorted nodes - node = partition(node, mon); + node = partition(node); int left = leftSubTree[node]; int leftSize = getSubtreeSize(left); @@ -939,14 +891,14 @@ private final void removeRange(int node, int rangeStart, int rangeLength, FastPr // If we're removing anything from the left node if (toRemoveFromLeft >= 0) { - removeRange(leftSubTree[node], rangeStart, toRemoveFromLeft, mon); + removeRange(leftSubTree[node], rangeStart, toRemoveFromLeft); // Check if we're removing from both sides int toRemoveFromRight = rangeStart + rangeLength - leftSize - 1; if (toRemoveFromRight >= 0) { // Remove from right subtree - removeRange(rightSubTree[node], 0, toRemoveFromRight, mon); + removeRange(rightSubTree[node], 0, toRemoveFromRight); // ... removing from both sides means we need to remove the node itself too removeNode(node); @@ -954,7 +906,7 @@ private final void removeRange(int node, int rangeStart, int rangeLength, FastPr } } else { // If removing from the right side only - removeRange(rightSubTree[node], rangeStart - leftSize - 1, rangeLength, mon); + removeRange(rightSubTree[node], rangeStart - leftSize - 1, rangeLength); } } finally { recomputeTreeSize(node); @@ -1046,11 +998,7 @@ private final int removeNode(int subTree) { result = left; } - try { - result = partition(result, new FastProgressReporter()); - } catch (InterruptedException e) { - - } + result = partition(result); if (result == -1) { result = nextUnsorted[subTree]; } else { @@ -1183,29 +1131,6 @@ public Comparator getComparator() { return comparator; } - /** - * Fills in an array of size n with the n smallest elements from the collection. - * Can compute the result in sorted or unsorted order. - * - * Currently package visible until the implementation of FastProgressReporter is finished. - * - * @param result array to be filled - * @param sorted if true, the result array will be sorted. If false, the result array - * may be unsorted. This does not affect which elements appear in the result, only their - * order. - * @param mon monitor used to report progress and check for cancellation - * @return the number of items inserted into the result array. This will be equal to the minimum - * of result.length and container.size() - * @throws InterruptedException if the progress monitor is cancelled - */ - /* package */ final int getFirst(Object[] result, boolean sorted, FastProgressReporter mon) throws InterruptedException { - int returnValue = getRange(result, 0, sorted, mon); - - testInvariants(); - - return returnValue; - } - /** * Fills in an array of size n with the n smallest elements from the collection. * Can compute the result in sorted or unsorted order. @@ -1218,39 +1143,13 @@ public Comparator getComparator() { * of result.length and container.size() */ public final int getFirst(Object[] result, boolean sorted) { - int returnValue = 0; - - try { - returnValue = getFirst(result, sorted, new FastProgressReporter()); - } catch (InterruptedException e) { - } + int returnValue = getRange(result, 0, sorted); testInvariants(); return returnValue; } - /** - * Given a position defined by k and an array of size n, this fills in the array with - * the kth smallest element through to the (k+n)th smallest element. For example, - * getRange(myArray, 10, false) would fill in myArray starting with the 10th smallest item - * in the collection. The result can be computed in sorted or unsorted order. Computing the - * result in unsorted order is more efficient. - *- * Temporarily set to package visibility until the implementation of FastProgressReporter - * is finished. - *
- * - * @param result array to be filled in - * @param rangeStart index of the smallest element to appear in the result - * @param sorted true iff the result array should be sorted - * @param mon progress monitor used to cancel the operation - * @throws InterruptedException if the progress monitor was cancelled in another thread - */ - /* package */ final int getRange(Object[] result, int rangeStart, boolean sorted, FastProgressReporter mon) throws InterruptedException { - return getRange(result, 0, rangeStart, root, sorted, mon); - } - /** * Computes the n through n+k items in this collection. * Computing the result in unsorted order is more efficient. Sorting the result will @@ -1265,12 +1164,7 @@ public final int getFirst(Object[] result, boolean sorted) { * of result.length and this.size()) */ public final int getRange(Object[] result, int rangeStart, boolean sorted) { - int returnValue = 0; - - try { - returnValue = getRange(result, rangeStart, sorted, new FastProgressReporter()); - } catch (InterruptedException e) { - } + int returnValue = getRange(result, 0, rangeStart, root, sorted); testInvariants(); @@ -1285,11 +1179,7 @@ public final int getRange(Object[] result, int rangeStart, boolean sorted) { */ public final Object getItem(int index) { Object[] result = new Object[1]; - try { - getRange(result, index, false, new FastProgressReporter()); - } catch (InterruptedException e) { - // shouldn't happen - } + getRange(result, index, false); Object returnValue = result[0]; testInvariants(); @@ -1313,7 +1203,7 @@ public final Object[] getItems(boolean sorted) { return result; } - private final int getRange(Object[] result, int resultIdx, int rangeStart, int node, boolean sorted, FastProgressReporter mon) throws InterruptedException { + private final int getRange(Object[] result, int resultIdx, int rangeStart, int node, boolean sorted) { if (node == -1) { return 0; } @@ -1323,11 +1213,11 @@ private final int getRange(Object[] result, int resultIdx, int rangeStart, int n // If we're asking for all children of the current node, simply call getChildren if (rangeStart == 0) { if (treeSize[node] <= availableSpace) { - return getChildren(result, resultIdx, node, sorted, mon); + return getChildren(result, resultIdx, node, sorted); } } - node = partition(node, mon); + node = partition(node); if (node == -1) { return 0; } @@ -1338,7 +1228,7 @@ private final int getRange(Object[] result, int resultIdx, int rangeStart, int n if (rangeStart < numberLessThanNode) { if (inserted < availableSpace) { - inserted += getRange(result, resultIdx, rangeStart, leftSubTree[node], sorted, mon); + inserted += getRange(result, resultIdx, rangeStart, leftSubTree[node], sorted); } } @@ -1351,7 +1241,7 @@ private final int getRange(Object[] result, int resultIdx, int rangeStart, int n if (inserted < availableSpace) { inserted += getRange(result, resultIdx + inserted, - Math.max(rangeStart - numberLessThanNode - 1, 0), rightSubTree[node], sorted, mon); + Math.max(rangeStart - numberLessThanNode - 1, 0), rightSubTree[node], sorted); } return inserted; @@ -1364,7 +1254,7 @@ private final int getRange(Object[] result, int resultIdx, int rangeStart, int n * @return the number of children added to the array * @since 3.1 */ - private final int getChildren(Object[] result, int resultIdx, int node, boolean sorted, FastProgressReporter mon) throws InterruptedException { + private final int getChildren(Object[] result, int resultIdx, int node, boolean sorted) { if (node == -1) { return 0; } @@ -1372,7 +1262,7 @@ private final int getChildren(Object[] result, int resultIdx, int node, boolean int tempIdx = resultIdx; if (sorted) { - node = partition(node, mon); + node = partition(node); if (node == -1) { return 0; } @@ -1380,7 +1270,7 @@ private final int getChildren(Object[] result, int resultIdx, int node, boolean // Add child nodes smaller than this one if (tempIdx < result.length) { - tempIdx += getChildren(result, tempIdx, leftSubTree[node], sorted, mon); + tempIdx += getChildren(result, tempIdx, leftSubTree[node], sorted); } // Add the pivot @@ -1393,7 +1283,7 @@ private final int getChildren(Object[] result, int resultIdx, int node, boolean // Add child nodes larger than this one if (tempIdx < result.length) { - tempIdx += getChildren(result, tempIdx, rightSubTree[node], sorted, mon); + tempIdx += getChildren(result, tempIdx, rightSubTree[node], sorted); } // Add unsorted children (should be empty if the sorted flag was true)