Revision 31272 branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/DefaultFeatureSelection.java
DefaultFeatureSelection.java | ||
---|---|---|
63 | 63 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
64 | 64 |
*/ |
65 | 65 |
public class DefaultFeatureSelection extends DefaultFeatureReferenceSelection |
66 |
implements FeatureSelection {
|
|
66 |
implements FeatureSelection { |
|
67 | 67 |
|
68 |
private static final Logger LOGGER = LoggerFactory
|
|
69 |
.getLogger(DefaultFeatureSelection.class);
|
|
68 |
private static final Logger LOGGER = LoggerFactory
|
|
69 |
.getLogger(DefaultFeatureSelection.class);
|
|
70 | 70 |
|
71 |
private Map featureTypeCounts = new HashMap(1);
|
|
71 |
private Map featureTypeCounts = new HashMap(1);
|
|
72 | 72 |
|
73 |
/**
|
|
74 |
* Creates a DefaultFeatureSelection, with a FeatureStore.
|
|
75 |
*
|
|
76 |
* @param featureStore
|
|
77 |
* the FeatureStore to load Features from
|
|
78 |
* @throws DataException
|
|
79 |
* if there is an error while getting the total number of
|
|
80 |
* Features of the Store.
|
|
81 |
* @see AbstractSetBasedDataSelection#DefaultSelection(int)
|
|
82 |
*/
|
|
83 |
public DefaultFeatureSelection(DefaultFeatureStore featureStore)
|
|
84 |
throws DataException {
|
|
85 |
super(featureStore);
|
|
86 |
}
|
|
73 |
/**
|
|
74 |
* Creates a DefaultFeatureSelection, with a FeatureStore.
|
|
75 |
*
|
|
76 |
* @param featureStore
|
|
77 |
* the FeatureStore to load Features from
|
|
78 |
* @throws DataException
|
|
79 |
* if there is an error while getting the total number of
|
|
80 |
* Features of the Store.
|
|
81 |
* @see AbstractSetBasedDataSelection#DefaultSelection(int)
|
|
82 |
*/
|
|
83 |
public DefaultFeatureSelection(DefaultFeatureStore featureStore)
|
|
84 |
throws DataException {
|
|
85 |
super(featureStore);
|
|
86 |
}
|
|
87 | 87 |
|
88 |
/** |
|
89 |
* Creates a new Selection with the total size of Features from which the |
|
90 |
* selection will be performed. |
|
91 |
* |
|
92 |
* @param featureStore |
|
93 |
* the FeatureStore of the selected FeatureReferences |
|
94 |
* @param helper |
|
95 |
* to get some information of the Store |
|
96 |
* @throws DataException |
|
97 |
* if there is an error while getting the total number of |
|
98 |
* Features of the Store. |
|
88 |
/** |
|
89 |
* Creates a new Selection with the total size of Features from which the |
|
90 |
* selection will be performed. |
|
91 |
* |
|
92 |
* @param featureStore |
|
93 |
* the FeatureStore of the selected FeatureReferences |
|
94 |
* @param helper |
|
95 |
* to get some information of the Store |
|
96 |
* @throws DataException |
|
97 |
* if there is an error while getting the total number of |
|
98 |
* Features of the Store. |
|
99 |
*/ |
|
100 |
public DefaultFeatureSelection(FeatureStore featureStore, |
|
101 |
FeatureSelectionHelper helper) throws DataException { |
|
102 |
super(featureStore, helper); |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Constructor used by the persistence manager. Don't use directly. |
|
107 |
* After to invoke this method, the persistence manager calls |
|
108 |
* the the method {@link #loadFromState(PersistentState)} to set |
|
109 |
* the values of the internal attributes that this class needs to work. |
|
99 | 110 |
*/ |
100 |
public DefaultFeatureSelection(FeatureStore featureStore, |
|
101 |
FeatureSelectionHelper helper) throws DataException { |
|
102 |
super(featureStore, helper); |
|
103 |
} |
|
111 |
public DefaultFeatureSelection() { |
|
112 |
super(); |
|
113 |
} |
|
104 | 114 |
|
105 |
public boolean select(Feature feature) {
|
|
106 |
return select(feature, true);
|
|
107 |
}
|
|
115 |
public boolean select(Feature feature) {
|
|
116 |
return select(feature, true);
|
|
117 |
}
|
|
108 | 118 |
|
109 |
/**
|
|
110 |
* @see #select(Feature)
|
|
111 |
* @param undoable
|
|
112 |
* if the action must be undoable
|
|
113 |
*/
|
|
114 |
public boolean select(Feature feature, boolean undoable) {
|
|
115 |
// TODO: should we check if the feature is from the same FeatureStore??
|
|
116 |
if (feature == null) {
|
|
117 |
return false;
|
|
118 |
}
|
|
119 |
/**
|
|
120 |
* @see #select(Feature)
|
|
121 |
* @param undoable
|
|
122 |
* if the action must be undoable
|
|
123 |
*/
|
|
124 |
public boolean select(Feature feature, boolean undoable) {
|
|
125 |
// TODO: should we check if the feature is from the same FeatureStore??
|
|
126 |
if (feature == null) {
|
|
127 |
return false;
|
|
128 |
}
|
|
119 | 129 |
|
120 |
// LOGGER.debug("Selected feature: {}", feature); |
|
130 |
// LOGGER.debug("Selected feature: {}", feature);
|
|
121 | 131 |
|
122 |
if (isReversed()) {
|
|
123 |
removeFeatureTypeCount(feature.getType());
|
|
124 |
} else {
|
|
125 |
addFeatureTypeCount(feature.getType());
|
|
126 |
}
|
|
127 |
return select(feature.getReference(), undoable);
|
|
128 |
}
|
|
132 |
if (isReversed()) {
|
|
133 |
removeFeatureTypeCount(feature.getType());
|
|
134 |
} else {
|
|
135 |
addFeatureTypeCount(feature.getType());
|
|
136 |
}
|
|
137 |
return select(feature.getReference(), undoable);
|
|
138 |
}
|
|
129 | 139 |
|
130 |
public boolean select(FeatureSet features) throws DataException {
|
|
131 |
return select(features, true);
|
|
132 |
}
|
|
140 |
public boolean select(FeatureSet features) throws DataException {
|
|
141 |
return select(features, true);
|
|
142 |
}
|
|
133 | 143 |
|
134 |
/**
|
|
135 |
* @see #select(FeatureSet)
|
|
136 |
* @param undoable
|
|
137 |
* if the action must be undoable
|
|
138 |
*/
|
|
139 |
public boolean select(FeatureSet features, boolean undoable)
|
|
140 |
throws DataException {
|
|
141 |
boolean change = false;
|
|
142 |
boolean inComplex = false;
|
|
143 |
if (undoable && getFeatureStore().isEditing()
|
|
144 |
/**
|
|
145 |
* @see #select(FeatureSet)
|
|
146 |
* @param undoable
|
|
147 |
* if the action must be undoable
|
|
148 |
*/
|
|
149 |
public boolean select(FeatureSet features, boolean undoable)
|
|
150 |
throws DataException {
|
|
151 |
boolean change = false;
|
|
152 |
boolean inComplex = false;
|
|
153 |
if (undoable && getFeatureStore().isEditing()
|
|
144 | 154 |
&& !getCommands().inComplex()) { |
145 | 155 |
inComplex = getCommands().inComplex(); |
146 | 156 |
getCommands().startComplex("_selectionSelectFeatureSet"); |
147 |
}
|
|
157 |
}
|
|
148 | 158 |
|
149 |
disableNotifications();
|
|
150 |
for (DisposableIterator iter = features.fastIterator(); iter.hasNext();) {
|
|
151 |
change |= select((Feature) iter.next(), undoable);
|
|
152 |
}
|
|
153 |
enableNotifications();
|
|
154 |
if (undoable && getFeatureStore().isEditing() && !inComplex) {
|
|
155 |
getCommands().endComplex();
|
|
156 |
}
|
|
157 |
if (change) {
|
|
158 |
notifyObservers(DataStoreNotification.SELECTION_CHANGE);
|
|
159 |
}
|
|
160 |
return change;
|
|
161 |
}
|
|
159 |
disableNotifications();
|
|
160 |
for (DisposableIterator iter = features.fastIterator(); iter.hasNext();) {
|
|
161 |
change |= select((Feature) iter.next(), undoable);
|
|
162 |
}
|
|
163 |
enableNotifications();
|
|
164 |
if (undoable && getFeatureStore().isEditing() && !inComplex) {
|
|
165 |
getCommands().endComplex();
|
|
166 |
}
|
|
167 |
if (change) {
|
|
168 |
notifyObservers(DataStoreNotification.SELECTION_CHANGE);
|
|
169 |
}
|
|
170 |
return change;
|
|
171 |
}
|
|
162 | 172 |
|
163 |
public boolean deselect(Feature feature) {
|
|
164 |
return deselect(feature, true);
|
|
165 |
}
|
|
173 |
public boolean deselect(Feature feature) {
|
|
174 |
return deselect(feature, true);
|
|
175 |
}
|
|
166 | 176 |
|
167 |
/**
|
|
168 |
* @see #deselect(Feature)
|
|
169 |
* @param undoable
|
|
170 |
* if the action must be undoable
|
|
171 |
*/
|
|
172 |
public boolean deselect(Feature feature, boolean undoable) {
|
|
173 |
if (feature == null) {
|
|
174 |
return false;
|
|
175 |
}
|
|
177 |
/**
|
|
178 |
* @see #deselect(Feature)
|
|
179 |
* @param undoable
|
|
180 |
* if the action must be undoable
|
|
181 |
*/
|
|
182 |
public boolean deselect(Feature feature, boolean undoable) {
|
|
183 |
if (feature == null) {
|
|
184 |
return false;
|
|
185 |
}
|
|
176 | 186 |
|
177 |
LOGGER.debug("Deselected feature: {}", feature);
|
|
187 |
LOGGER.debug("Deselected feature: {}", feature);
|
|
178 | 188 |
|
179 |
if (isReversed()) {
|
|
180 |
addFeatureTypeCount(feature.getType());
|
|
181 |
} else {
|
|
182 |
removeFeatureTypeCount(feature.getType());
|
|
183 |
}
|
|
184 |
return deselect(feature.getReference(), undoable);
|
|
185 |
}
|
|
189 |
if (isReversed()) {
|
|
190 |
addFeatureTypeCount(feature.getType());
|
|
191 |
} else {
|
|
192 |
removeFeatureTypeCount(feature.getType());
|
|
193 |
}
|
|
194 |
return deselect(feature.getReference(), undoable);
|
|
195 |
}
|
|
186 | 196 |
|
187 |
public boolean deselect(FeatureSet features) throws DataException {
|
|
188 |
return deselect(features, true);
|
|
189 |
}
|
|
197 |
public boolean deselect(FeatureSet features) throws DataException {
|
|
198 |
return deselect(features, true);
|
|
199 |
}
|
|
190 | 200 |
|
191 |
/**
|
|
192 |
* @see #deselect(FeatureSet)
|
|
193 |
* @param undoable
|
|
194 |
* if the action must be undoable
|
|
195 |
*/
|
|
196 |
public boolean deselect(FeatureSet features, boolean undoable)
|
|
197 |
throws DataException {
|
|
198 |
boolean change = false;
|
|
199 |
if (undoable && getFeatureStore().isEditing()) {
|
|
200 |
getCommands().startComplex("_selectionDeselectFeatureSet");
|
|
201 |
}
|
|
202 |
disableNotifications();
|
|
203 |
for (DisposableIterator iter = features.fastIterator(); iter.hasNext();) {
|
|
204 |
change |= deselect((Feature) iter.next(), undoable);
|
|
205 |
}
|
|
206 |
enableNotifications();
|
|
207 |
if (undoable && getFeatureStore().isEditing()) {
|
|
208 |
getCommands().endComplex();
|
|
209 |
}
|
|
210 |
if (change) {
|
|
211 |
notifyObservers(DataStoreNotification.SELECTION_CHANGE);
|
|
212 |
}
|
|
213 |
return change;
|
|
214 |
}
|
|
201 |
/**
|
|
202 |
* @see #deselect(FeatureSet)
|
|
203 |
* @param undoable
|
|
204 |
* if the action must be undoable
|
|
205 |
*/
|
|
206 |
public boolean deselect(FeatureSet features, boolean undoable)
|
|
207 |
throws DataException {
|
|
208 |
boolean change = false;
|
|
209 |
if (undoable && getFeatureStore().isEditing()) {
|
|
210 |
getCommands().startComplex("_selectionDeselectFeatureSet");
|
|
211 |
}
|
|
212 |
disableNotifications();
|
|
213 |
for (DisposableIterator iter = features.fastIterator(); iter.hasNext();) {
|
|
214 |
change |= deselect((Feature) iter.next(), undoable);
|
|
215 |
}
|
|
216 |
enableNotifications();
|
|
217 |
if (undoable && getFeatureStore().isEditing()) {
|
|
218 |
getCommands().endComplex();
|
|
219 |
}
|
|
220 |
if (change) {
|
|
221 |
notifyObservers(DataStoreNotification.SELECTION_CHANGE);
|
|
222 |
}
|
|
223 |
return change;
|
|
224 |
}
|
|
215 | 225 |
|
216 |
public boolean isSelected(Feature feature) {
|
|
217 |
if (feature == null) {
|
|
218 |
return false;
|
|
219 |
}
|
|
220 |
return isSelected(feature.getReference());
|
|
221 |
}
|
|
226 |
public boolean isSelected(Feature feature) {
|
|
227 |
if (feature == null) {
|
|
228 |
return false;
|
|
229 |
}
|
|
230 |
return isSelected(feature.getReference());
|
|
231 |
}
|
|
222 | 232 |
|
223 |
public FeatureType getDefaultFeatureType() {
|
|
224 |
try {
|
|
225 |
return getFeatureStore().getDefaultFeatureType();
|
|
226 |
} catch (DataException ex) {
|
|
227 |
LOGGER.error("Error getting the default feature type "
|
|
228 |
+ "of the FeatureStore: " + getFeatureStore(), ex);
|
|
229 |
}
|
|
230 |
return null;
|
|
231 |
}
|
|
233 |
public FeatureType getDefaultFeatureType() {
|
|
234 |
try {
|
|
235 |
return getFeatureStore().getDefaultFeatureType();
|
|
236 |
} catch (DataException ex) {
|
|
237 |
LOGGER.error("Error getting the default feature type "
|
|
238 |
+ "of the FeatureStore: " + getFeatureStore(), ex);
|
|
239 |
}
|
|
240 |
return null;
|
|
241 |
}
|
|
232 | 242 |
|
233 |
public List getFeatureTypes() {
|
|
234 |
// Go through the map of FeatureTypes, and return only the ones that
|
|
235 |
// have at least a Feature.
|
|
236 |
List types = new ArrayList();
|
|
237 |
for (java.util.Iterator iterator = featureTypeCounts.entrySet()
|
|
243 |
public List getFeatureTypes() {
|
|
244 |
// Go through the map of FeatureTypes, and return only the ones that
|
|
245 |
// have at least a Feature.
|
|
246 |
List types = new ArrayList();
|
|
247 |
for (java.util.Iterator iterator = featureTypeCounts.entrySet()
|
|
238 | 248 |
.iterator(); iterator |
239 |
.hasNext();) {
|
|
240 |
Map.Entry entry = (Entry) iterator.next();
|
|
241 |
FeatureType type = (FeatureType) entry.getKey();
|
|
242 |
Long count = (Long) entry.getValue();
|
|
249 |
.hasNext();) {
|
|
250 |
Map.Entry entry = (Entry) iterator.next();
|
|
251 |
FeatureType type = (FeatureType) entry.getKey();
|
|
252 |
Long count = (Long) entry.getValue();
|
|
243 | 253 |
|
244 |
if (count.longValue() > 0) {
|
|
245 |
types.add(type);
|
|
246 |
}
|
|
247 |
}
|
|
254 |
if (count.longValue() > 0) {
|
|
255 |
types.add(type);
|
|
256 |
}
|
|
257 |
}
|
|
248 | 258 |
|
249 |
return types;
|
|
250 |
}
|
|
259 |
return types;
|
|
260 |
}
|
|
251 | 261 |
|
252 |
public long getSize() throws DataException {
|
|
253 |
return getSelectedCount();
|
|
254 |
}
|
|
262 |
public long getSize() throws DataException {
|
|
263 |
return getSelectedCount();
|
|
264 |
}
|
|
255 | 265 |
|
256 |
public boolean isEmpty() throws DataException {
|
|
257 |
return getSelectedCount() == 0;
|
|
258 |
}
|
|
266 |
public boolean isEmpty() throws DataException {
|
|
267 |
return getSelectedCount() == 0;
|
|
268 |
}
|
|
259 | 269 |
|
260 |
/**
|
|
261 |
* Returns the list of selected values, or the deselected ones if the
|
|
262 |
* selection has been reversed.
|
|
263 |
*/
|
|
264 |
public DisposableIterator iterator() {
|
|
265 |
return iterator(0);
|
|
266 |
}
|
|
270 |
/**
|
|
271 |
* Returns the list of selected values, or the deselected ones if the
|
|
272 |
* selection has been reversed.
|
|
273 |
*/
|
|
274 |
public DisposableIterator iterator() {
|
|
275 |
return iterator(0);
|
|
276 |
}
|
|
267 | 277 |
|
268 |
/**
|
|
269 |
* Returns the list of selected values, or the deselected ones if the
|
|
270 |
* selection has been reversed.
|
|
271 |
*
|
|
272 |
* WARN: not very good performance implementation.
|
|
273 |
*/
|
|
274 |
public DisposableIterator iterator(long index) {
|
|
275 |
return iterator(index, false);
|
|
276 |
}
|
|
278 |
/**
|
|
279 |
* Returns the list of selected values, or the deselected ones if the
|
|
280 |
* selection has been reversed.
|
|
281 |
*
|
|
282 |
* WARN: not very good performance implementation.
|
|
283 |
*/
|
|
284 |
public DisposableIterator iterator(long index) {
|
|
285 |
return iterator(index, false);
|
|
286 |
}
|
|
277 | 287 |
|
278 |
/**
|
|
279 |
* Returns the list of selected values, or the deselected ones if the
|
|
280 |
* selection has been reversed.
|
|
281 |
*
|
|
282 |
* WARN: not really a fast implementation.
|
|
283 |
*/
|
|
284 |
public DisposableIterator fastIterator() {
|
|
285 |
return fastIterator(0);
|
|
286 |
}
|
|
288 |
/**
|
|
289 |
* Returns the list of selected values, or the deselected ones if the
|
|
290 |
* selection has been reversed.
|
|
291 |
*
|
|
292 |
* WARN: not really a fast implementation.
|
|
293 |
*/
|
|
294 |
public DisposableIterator fastIterator() {
|
|
295 |
return fastIterator(0);
|
|
296 |
}
|
|
287 | 297 |
|
288 |
/**
|
|
289 |
* Returns the list of selected values, or the deselected ones if the
|
|
290 |
* selection has been reversed.
|
|
291 |
*
|
|
292 |
* WARN: not really a fast implementation.
|
|
293 |
*/
|
|
294 |
public DisposableIterator fastIterator(long index) {
|
|
295 |
return iterator(index, true);
|
|
296 |
}
|
|
298 |
/**
|
|
299 |
* Returns the list of selected values, or the deselected ones if the
|
|
300 |
* selection has been reversed.
|
|
301 |
*
|
|
302 |
* WARN: not really a fast implementation.
|
|
303 |
*/
|
|
304 |
public DisposableIterator fastIterator(long index) {
|
|
305 |
return iterator(index, true);
|
|
306 |
}
|
|
297 | 307 |
|
298 | 308 |
|
299 |
protected void clearFeatureReferences() {
|
|
300 |
super.clearFeatureReferences();
|
|
301 |
featureTypeCounts.clear();
|
|
302 |
}
|
|
309 |
protected void clearFeatureReferences() {
|
|
310 |
super.clearFeatureReferences();
|
|
311 |
featureTypeCounts.clear();
|
|
312 |
}
|
|
303 | 313 |
|
304 |
/**
|
|
305 |
* Creates an iterator for the Selection.
|
|
306 |
*/
|
|
307 |
private DisposableIterator iterator(long index, boolean fastIterator) {
|
|
308 |
if (isReversed()) {
|
|
309 |
DisposableIterator iter = new ReversedFeatureIteratorFacade(getData(),
|
|
310 |
getFeatureStore(), fastIterator);
|
|
311 |
for (long l = 0; l < index && iter.hasNext(); l++) {
|
|
312 |
iter.next();
|
|
313 |
}
|
|
314 |
return iter;
|
|
314 |
/**
|
|
315 |
* Creates an iterator for the Selection.
|
|
316 |
*/
|
|
317 |
private DisposableIterator iterator(long index, boolean fastIterator) {
|
|
318 |
if (isReversed()) {
|
|
319 |
DisposableIterator iter = new ReversedFeatureIteratorFacade(getData(),
|
|
320 |
getFeatureStore(), fastIterator);
|
|
321 |
for (long l = 0; l < index && iter.hasNext(); l++) {
|
|
322 |
iter.next();
|
|
323 |
}
|
|
324 |
return iter;
|
|
315 | 325 |
|
316 |
} else {
|
|
317 |
// TODO: maybe we could add a new referenceIterator(int index)
|
|
318 |
// method that could be implemented in a more performant way
|
|
326 |
} else {
|
|
327 |
// TODO: maybe we could add a new referenceIterator(int index)
|
|
328 |
// method that could be implemented in a more performant way
|
|
319 | 329 |
|
320 |
java.util.Iterator iter = referenceIterator();
|
|
321 |
for (long l = 0; l < index && iter.hasNext(); l++) {
|
|
322 |
iter.next();
|
|
323 |
}
|
|
324 |
return new FeatureIteratorFacade(iter, getFeatureStore());
|
|
325 |
}
|
|
326 |
}
|
|
330 |
java.util.Iterator iter = referenceIterator();
|
|
331 |
for (long l = 0; l < index && iter.hasNext(); l++) {
|
|
332 |
iter.next();
|
|
333 |
}
|
|
334 |
return new FeatureIteratorFacade(iter, getFeatureStore());
|
|
335 |
}
|
|
336 |
}
|
|
327 | 337 |
|
328 |
private Long removeFeatureTypeCount(FeatureType featureType) {
|
|
338 |
private Long removeFeatureTypeCount(FeatureType featureType) {
|
|
329 | 339 |
Long count = (Long) featureTypeCounts.get(featureType); |
330 | 340 |
if (count == null) { |
331 | 341 |
count = new Long(-1); |
... | ... | |
345 | 355 |
} |
346 | 356 |
featureTypeCounts.put(featureType, count); |
347 | 357 |
return count; |
348 |
}
|
|
358 |
}
|
|
349 | 359 |
|
350 |
/**
|
|
351 |
* Facade over a Iterator of FeatureReferences, to return Features instead.
|
|
352 |
*
|
|
353 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
|
354 |
*/
|
|
355 |
private class FeatureIteratorFacade implements DisposableIterator {
|
|
360 |
/**
|
|
361 |
* Facade over a Iterator of FeatureReferences, to return Features instead.
|
|
362 |
*
|
|
363 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
|
364 |
*/
|
|
365 |
private class FeatureIteratorFacade implements DisposableIterator {
|
|
356 | 366 |
|
357 |
final Logger logger = LoggerFactory
|
|
358 |
.getLogger(FeatureIteratorFacade.class);
|
|
367 |
final Logger logger = LoggerFactory
|
|
368 |
.getLogger(FeatureIteratorFacade.class);
|
|
359 | 369 |
|
360 |
private java.util.Iterator refIterator;
|
|
370 |
private java.util.Iterator refIterator;
|
|
361 | 371 |
|
362 |
private FeatureStore featureStore;
|
|
372 |
private FeatureStore featureStore;
|
|
363 | 373 |
|
364 |
public FeatureIteratorFacade(java.util.Iterator iter,
|
|
365 |
FeatureStore featureStore) {
|
|
366 |
this.refIterator = iter;
|
|
367 |
this.featureStore = featureStore;
|
|
368 |
}
|
|
374 |
public FeatureIteratorFacade(java.util.Iterator iter,
|
|
375 |
FeatureStore featureStore) {
|
|
376 |
this.refIterator = iter;
|
|
377 |
this.featureStore = featureStore;
|
|
378 |
}
|
|
369 | 379 |
|
370 |
public boolean hasNext() {
|
|
371 |
return refIterator.hasNext();
|
|
372 |
}
|
|
380 |
public boolean hasNext() {
|
|
381 |
return refIterator.hasNext();
|
|
382 |
}
|
|
373 | 383 |
|
374 |
public Object next() {
|
|
375 |
FeatureReference ref = nextFeatureReference();
|
|
376 |
try {
|
|
377 |
return featureStore.getFeatureByReference(ref);
|
|
378 |
} catch (DataException ex) {
|
|
379 |
logger.error(
|
|
380 |
"Error loading the Feature with FeatureReference: "
|
|
381 |
+ ref, ex);
|
|
382 |
return null;
|
|
383 |
}
|
|
384 |
}
|
|
384 |
public Object next() {
|
|
385 |
FeatureReference ref = nextFeatureReference();
|
|
386 |
try {
|
|
387 |
return featureStore.getFeatureByReference(ref);
|
|
388 |
} catch (DataException ex) {
|
|
389 |
logger.error(
|
|
390 |
"Error loading the Feature with FeatureReference: "
|
|
391 |
+ ref, ex);
|
|
392 |
return null;
|
|
393 |
}
|
|
394 |
}
|
|
385 | 395 |
|
386 |
/**
|
|
387 |
* Returns the next FeatureReference.
|
|
388 |
*
|
|
389 |
* @return the next FeatureReference
|
|
390 |
*/
|
|
391 |
public FeatureReference nextFeatureReference() {
|
|
392 |
return (FeatureReference) refIterator.next();
|
|
393 |
}
|
|
396 |
/**
|
|
397 |
* Returns the next FeatureReference.
|
|
398 |
*
|
|
399 |
* @return the next FeatureReference
|
|
400 |
*/
|
|
401 |
public FeatureReference nextFeatureReference() {
|
|
402 |
return (FeatureReference) refIterator.next();
|
|
403 |
}
|
|
394 | 404 |
|
395 |
public void remove() {
|
|
396 |
refIterator.remove();
|
|
397 |
}
|
|
405 |
public void remove() {
|
|
406 |
refIterator.remove();
|
|
407 |
}
|
|
398 | 408 |
|
399 |
public void dispose() {
|
|
409 |
public void dispose() {
|
|
400 | 410 |
if (refIterator instanceof DisposableIterator) { |
401 | 411 |
((DisposableIterator) refIterator).dispose(); |
402 | 412 |
} |
403 | 413 |
refIterator = null; |
404 | 414 |
featureStore = null; |
405 | 415 |
} |
406 |
}
|
|
416 |
}
|
|
407 | 417 |
|
408 |
/**
|
|
409 |
* Facade over a Iterator of FeatureReferences, to return Features instead,
|
|
410 |
* when the Selection is reversed
|
|
411 |
*
|
|
412 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
|
413 |
*/
|
|
414 |
private class ReversedFeatureIteratorFacade implements DisposableIterator {
|
|
418 |
/**
|
|
419 |
* Facade over a Iterator of FeatureReferences, to return Features instead,
|
|
420 |
* when the Selection is reversed
|
|
421 |
*
|
|
422 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
|
423 |
*/
|
|
424 |
private class ReversedFeatureIteratorFacade implements DisposableIterator {
|
|
415 | 425 |
|
416 |
private SelectionData selectionData;
|
|
426 |
private SelectionData selectionData;
|
|
417 | 427 |
|
418 |
private DisposableIterator iterator;
|
|
428 |
private DisposableIterator iterator;
|
|
419 | 429 |
|
420 |
private Feature nextFeature = null;
|
|
430 |
private Feature nextFeature = null;
|
|
421 | 431 |
|
422 | 432 |
private FeatureSet featureSet; |
423 | 433 |
|
424 |
public ReversedFeatureIteratorFacade(SelectionData selectionData,
|
|
425 |
FeatureStore featureStore, boolean fastIterator) {
|
|
426 |
this.selectionData = selectionData;
|
|
434 |
public ReversedFeatureIteratorFacade(SelectionData selectionData,
|
|
435 |
FeatureStore featureStore, boolean fastIterator) {
|
|
436 |
this.selectionData = selectionData;
|
|
427 | 437 |
|
428 |
// Load a Set with all the store features
|
|
429 |
try {
|
|
430 |
featureSet = featureStore.getFeatureSet();
|
|
431 |
if (fastIterator) {
|
|
432 |
iterator = featureSet.fastIterator();
|
|
433 |
} else {
|
|
434 |
iterator = featureSet.iterator();
|
|
435 |
}
|
|
436 |
} catch (DataException ex) {
|
|
437 |
throw new ReversedSelectionIteratorException(ex);
|
|
438 |
}
|
|
438 |
// Load a Set with all the store features
|
|
439 |
try {
|
|
440 |
featureSet = featureStore.getFeatureSet();
|
|
441 |
if (fastIterator) {
|
|
442 |
iterator = featureSet.fastIterator();
|
|
443 |
} else {
|
|
444 |
iterator = featureSet.iterator();
|
|
445 |
}
|
|
446 |
} catch (DataException ex) {
|
|
447 |
throw new ReversedSelectionIteratorException(ex);
|
|
448 |
}
|
|
439 | 449 |
|
440 |
// Filter the features not selected and position in the next
|
|
441 |
// selected feature
|
|
442 |
positionInNextElement();
|
|
443 |
}
|
|
450 |
// Filter the features not selected and position in the next
|
|
451 |
// selected feature
|
|
452 |
positionInNextElement();
|
|
453 |
}
|
|
444 | 454 |
|
445 |
public boolean hasNext() {
|
|
446 |
return nextFeature != null;
|
|
447 |
}
|
|
455 |
public boolean hasNext() {
|
|
456 |
return nextFeature != null;
|
|
457 |
}
|
|
448 | 458 |
|
449 |
public Object next() {
|
|
450 |
Feature tmp = nextFeature;
|
|
451 |
positionInNextElement();
|
|
452 |
return tmp;
|
|
453 |
}
|
|
459 |
public Object next() {
|
|
460 |
Feature tmp = nextFeature;
|
|
461 |
positionInNextElement();
|
|
462 |
return tmp;
|
|
463 |
}
|
|
454 | 464 |
|
455 |
public void remove() {
|
|
456 |
iterator.remove();
|
|
457 |
}
|
|
465 |
public void remove() {
|
|
466 |
iterator.remove();
|
|
467 |
}
|
|
458 | 468 |
|
459 |
private void positionInNextElement() {
|
|
460 |
nextFeature = null;
|
|
461 |
while (iterator.hasNext()) {
|
|
462 |
nextFeature = (Feature) iterator.next();
|
|
463 |
if (selectionData.contains(nextFeature.getReference())) {
|
|
464 |
nextFeature = null;
|
|
465 |
} else {
|
|
466 |
break;
|
|
467 |
}
|
|
468 |
}
|
|
469 |
}
|
|
469 |
private void positionInNextElement() {
|
|
470 |
nextFeature = null;
|
|
471 |
while (iterator.hasNext()) {
|
|
472 |
nextFeature = (Feature) iterator.next();
|
|
473 |
if (selectionData.contains(nextFeature.getReference())) {
|
|
474 |
nextFeature = null;
|
|
475 |
} else {
|
|
476 |
break;
|
|
477 |
}
|
|
478 |
}
|
|
479 |
}
|
|
470 | 480 |
|
471 | 481 |
public void dispose() { |
472 | 482 |
this.featureSet.dispose(); |
... | ... | |
474 | 484 |
this.selectionData = null; |
475 | 485 |
this.nextFeature = null; |
476 | 486 |
} |
477 |
}
|
|
487 |
}
|
|
478 | 488 |
|
479 |
public void delete(Feature feature) throws DataException {
|
|
480 |
throw new UnsupportedOperationException();
|
|
481 |
}
|
|
489 |
public void delete(Feature feature) throws DataException {
|
|
490 |
throw new UnsupportedOperationException();
|
|
491 |
}
|
|
482 | 492 |
|
483 |
public void insert(EditableFeature feature) throws DataException {
|
|
484 |
throw new UnsupportedOperationException();
|
|
485 |
}
|
|
493 |
public void insert(EditableFeature feature) throws DataException {
|
|
494 |
throw new UnsupportedOperationException();
|
|
495 |
}
|
|
486 | 496 |
|
487 |
public void update(EditableFeature feature) throws DataException {
|
|
488 |
throw new UnsupportedOperationException();
|
|
489 |
}
|
|
497 |
public void update(EditableFeature feature) throws DataException {
|
|
498 |
throw new UnsupportedOperationException();
|
|
499 |
}
|
|
490 | 500 |
|
491 | 501 |
/* |
492 | 502 |
* (non-Javadoc) |
... | ... | |
495 | 505 |
* loadFromState(org.gvsig.tools.persistence.PersistentState) |
496 | 506 |
*/ |
497 | 507 |
public void loadFromState(PersistentState state) |
498 |
throws PersistenceException {
|
|
508 |
throws PersistenceException { |
|
499 | 509 |
super.loadFromState(state); |
500 | 510 |
|
501 | 511 |
|
... | ... | |
506 | 516 |
} |
507 | 517 |
|
508 | 518 |
public void accept(Visitor visitor, long firstValueIndex) |
509 |
throws BaseException {
|
|
519 |
throws BaseException { |
|
510 | 520 |
DisposableIterator iterator = fastIterator(firstValueIndex); |
511 | 521 |
|
512 | 522 |
if (iterator != null) { |
... | ... | |
525 | 535 |
DynObjectManager dynMan = ToolsLocator.getDynObjectManager(); |
526 | 536 |
DynClass dynClass = dynMan.add( |
527 | 537 |
"DefaultFeatureSelection_Persistent", |
528 |
"DefaultFeatureSelection Persistent definition");
|
|
538 |
"DefaultFeatureSelection Persistent definition"); |
|
529 | 539 |
|
530 | 540 |
dynClass |
531 |
.extend(DefaultFeatureReferenceSelection.DYNCLASS_PERSISTENT_NAME);
|
|
541 |
.extend(DefaultFeatureReferenceSelection.DYNCLASS_PERSISTENT_NAME); |
|
532 | 542 |
dynClass.addDynFieldMap("featureTypeCounts").setMandatory(true); |
533 | 543 |
ToolsLocator.getPersistenceManager().registerClass( |
534 | 544 |
DefaultFeatureSelection.class, dynClass); |
Also available in: Unified diff