01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.ui;
16:
17: import java.util.Iterator;
18:
19: import org.eclipse.core.runtime.IProgressMonitor;
20: import org.geotools.feature.FeatureCollection;
21: import org.geotools.feature.collection.AbstractFeatureCollection;
22:
23: /**
24: * This is a single use collection because the monitor is used by the iterators and
25: * since iterator doesn't take one then it can only be used once.
26: *
27: * @author Jesse
28: * @since 1.1.0
29: */
30: public class ProgressFeatureCollection extends
31: AbstractFeatureCollection implements FeatureCollection {
32:
33: protected FeatureCollection delegate;
34: protected IProgressMonitor monitor;
35:
36: public ProgressFeatureCollection(FeatureCollection delegate,
37: IProgressMonitor monitor) {
38: super (delegate.getSchema());
39: this .delegate = delegate;
40: this .monitor = monitor;
41: }
42:
43: @Override
44: protected void closeIterator(Iterator close) {
45: delegate.close(close);
46: }
47:
48: @Override
49: protected Iterator openIterator() {
50: final Iterator iterator = delegate.iterator();
51: return new Iterator() {
52:
53: public boolean hasNext() {
54: return iterator.hasNext();
55: }
56:
57: public Object next() {
58: monitor.worked(1);
59: return iterator.next();
60: }
61:
62: public void remove() {
63: iterator.next();
64: }
65:
66: };
67: }
68:
69: @Override
70: public int size() {
71: return delegate.size();
72: }
73:
74: }
|