⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 backgroundcontentprovider.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		        	        		        		break;		        	}	        	}	        		        	continue;        	}        		        int totalElements = collection.size();            if (limit != -1) {                if (totalElements > limit) {                    totalElements = limit;                }            }                        if (totalElements != prevSize) {            	prevSize = totalElements;	            // Send the total items to the updator ASAP -- the user may want	            // to scroll to a different section of the table, which would	            // cause our sort range to change and cause this job to get cancelled.		        updator.setTotalItems(totalElements);		        dirty = true;            }                        // Terminate loop            if (!dirty) {            	break;            }        	            try {            	ConcurrentTableUpdator.Range updateRange = updator.getVisibleRange();            	sortMon = new FastProgressReporter();            	range = updateRange;            	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);		        		        Object[] objectsOfInterest = new Object[sortLength];		     		        collection.getRange(objectsOfInterest, sortStart, true, sortMon);		        		        // Send the new elements to the table		        for (int i = 0; i < sortLength; i++) {					Object object = objectsOfInterest[i];					updator.replace(object, sortStart + i);				}		        			    objectsOfInterest = new Object[collection.size()];			        			    collection.getFirst(objectsOfInterest, true, sortMon);		        		        // Send the new elements to the table		        for (int i = 0; i < totalElements; i++) {					Object object = objectsOfInterest[i];					updator.replace(object, i);				}            } catch (InterruptedException e) {            	continue;            }                        dirty = false;	    }                mon.done();    }	/**	 * @param collection	 * @param toAdd	 */	private static void filteredAdd(LazySortedCollection collection, Object[] toAdd, IFilter filter) {		if (filter != AcceptAllFilter.getInstance()) { 			for (int i = 0; i < toAdd.length; i++) {				Object object = toAdd[i];								if (filter.select(object)) {					collection.add(object);				}			}		} else {			collection.addAll(toAdd);		}	}        /**     * Sets the sort order for this content provider     *      * @param sorter sort order     */    public void setSortOrder(Comparator sorter) {    	Assert.isNotNull(sorter);        this.sortOrder = sorter;    	sortMon.cancel();        refresh();    }        /**     * Sets the filter for this content provider     *      * @param toSet filter to set     */    public void setFilter(IFilter toSet) {    	Assert.isNotNull(toSet);    	this.filter = toSet;    	sortMon.cancel();    	refresh();    }        /**     * Sets the maximum table size. Based on the current sort order,     * the table will be truncated if it grows beyond this size.     * Using a limit improves memory usage and performance, and is     * strongly recommended for large tables.      *      * @param limit maximum rows to show in the table or -1 if unbounded     */    public void setLimit(int limit) {        this.limit = limit;        refresh();    }        /**     * Returns the maximum table size or -1 if unbounded     *      * @return the maximum number of rows in the table or -1 if unbounded     */    public int getLimit() {        return limit;    }        /**     * Checks if currently visible range has changed, and triggers and update     * and resort if necessary. Must be called in the UI thread, typically     * within a SWT.SetData callback.     * @param includeIndex the index that should be included in the visible range.     */    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();		}    }        /**     * This lock protects the two boolean variables sortThreadStarted and resortScheduled.     */    private Object lock = new Object();    /**     * true if the sort thread is running     */    private boolean sortThreadStarted = false;    /**     * true if we need to sort     */    private boolean sortScheduled = false;    	private final class SortThread extends Thread {		private SortThread(String name) {			super(name);		}		public void run() {			loop: while (true) {				synchronized (lock) {					sortScheduled = false;				}				try {					// this is the main work					doSort(sortingProgressMonitor);				} catch (Exception ex) {					// ignore				}				synchronized (lock) {					if (sortScheduled) {						continue loop;					}					sortThreadStarted = false;					break loop;				}			}		}	}        /**     * Must be called whenever the model changes. Dirties this object and triggers a sort     * if necessary.      */    private void makeDirty() {		synchronized (lock) {			sortMon.cancel();			// request sorting			sortScheduled = true;			if (!sortThreadStarted) {				sortThreadStarted = true;				sortThread = new SortThread(SORTING);				sortThread.setDaemon(true);				sortThread.setPriority(Thread.NORM_PRIORITY - 1);				sortThread.start();			}		}	}        /**	 * Cancels any sort in progress. Note that we try to use the	 * FastProgresReporter if possible since this is more responsive than	 * cancelling the sort job. However, it is not a problem to cancel in both	 * ways.	 */    private void cancelSortJob() {        sortMon.cancel();        sortingProgressMonitor.setCanceled(true);    }        /**	 * Called when new elements are added to the model.	 * 	 * @param toAdd	 *            newly added elements	 */    private void add(Object[] toAdd) {    	changeQueue.enqueue(ChangeQueue.ADD, toAdd);    	makeDirty();    }        /**     * Called with the complete contents of the model     *      * @param contents new contents of the model     */    private void setContents(Object[] contents) {    	changeQueue.enqueue(ChangeQueue.SET, contents);    	makeDirty();    }    /**     * Called when elements are removed from the model     *      * @param toRemove elements removed from the model     */    private void remove(Object[] toRemove) {        changeQueue.enqueue(ChangeQueue.REMOVE, toRemove);        makeDirty();        refresh();    }    /**     * Notifies the updator that the given elements have changed      *      * @param toFlush changed elements     * @param collection collection of currently-known elements     */    private void flush(Object[] toFlush, LazySortedCollection collection) {        for (int i = 0; i < toFlush.length; i++) {            Object item = toFlush[i];                        if (collection.contains(item)) {                updator.clear(item);            }        }    }    /**     * Called when elements in the model change     *      * @param items changed items     */    private void update(Object[] items) {        changeQueue.enqueue(ChangeQueue.UPDATE, items);        makeDirty();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -