Revision 42821 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureSelection.java
DefaultFeatureSelection.java | ||
---|---|---|
34 | 34 |
|
35 | 35 |
import org.gvsig.fmap.dal.DataStoreNotification; |
36 | 36 |
import org.gvsig.fmap.dal.exception.DataException; |
37 |
import org.gvsig.fmap.dal.exception.DataRuntimeException; |
|
37 | 38 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
38 | 39 |
import org.gvsig.fmap.dal.feature.Feature; |
39 | 40 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
... | ... | |
57 | 58 |
/** |
58 | 59 |
* Default implementation of the FeatureSelection interface. Internally, only |
59 | 60 |
* FeatureReference values are stored. |
60 |
*
|
|
61 |
* |
|
61 | 62 |
* This implementation performs better if used with the selection related |
62 | 63 |
* methods: select, deselect and isSelected ones. |
63 |
*
|
|
64 |
* |
|
64 | 65 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
65 | 66 |
*/ |
66 | 67 |
public class DefaultFeatureSelection extends DefaultFeatureReferenceSelection |
... | ... | |
73 | 74 |
|
74 | 75 |
/** |
75 | 76 |
* Creates a DefaultFeatureSelection, with a FeatureStore. |
76 |
*
|
|
77 |
* |
|
77 | 78 |
* @param featureStore |
78 | 79 |
* the FeatureStore to load Features from |
79 | 80 |
* @throws DataException |
... | ... | |
89 | 90 |
/** |
90 | 91 |
* Creates a new Selection with the total size of Features from which the |
91 | 92 |
* selection will be performed. |
92 |
*
|
|
93 |
* |
|
93 | 94 |
* @param featureStore |
94 | 95 |
* the FeatureStore of the selected FeatureReferences |
95 | 96 |
* @param helper |
... | ... | |
153 | 154 |
boolean inComplex = false; |
154 | 155 |
if (undoable && getFeatureStore().isEditing() |
155 | 156 |
&& !getCommands().inComplex()) { |
156 |
|
|
157 |
|
|
157 | 158 |
getCommands().startComplex("_selectionSelectFeatureSet"); |
158 | 159 |
inComplex = getCommands().inComplex(); |
159 | 160 |
} |
... | ... | |
299 | 300 |
/** |
300 | 301 |
* Returns the list of selected values, or the deselected ones if the |
301 | 302 |
* selection has been reversed. |
302 |
*
|
|
303 |
* |
|
303 | 304 |
* WARN: not very good performance implementation. |
304 | 305 |
*/ |
305 | 306 |
public DisposableIterator iterator(long index) { |
... | ... | |
309 | 310 |
/** |
310 | 311 |
* Returns the list of selected values, or the deselected ones if the |
311 | 312 |
* selection has been reversed. |
312 |
*
|
|
313 |
* |
|
313 | 314 |
* WARN: not really a fast implementation. |
314 | 315 |
*/ |
315 | 316 |
public DisposableIterator fastIterator() { |
... | ... | |
319 | 320 |
/** |
320 | 321 |
* Returns the list of selected values, or the deselected ones if the |
321 | 322 |
* selection has been reversed. |
322 |
*
|
|
323 |
* |
|
323 | 324 |
* WARN: not really a fast implementation. |
324 | 325 |
*/ |
325 | 326 |
public DisposableIterator fastIterator(long index) { |
... | ... | |
379 | 380 |
|
380 | 381 |
/** |
381 | 382 |
* Facade over a Iterator of FeatureReferences, to return Features instead. |
382 |
*
|
|
383 |
* |
|
383 | 384 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
384 | 385 |
*/ |
385 | 386 |
private class FeatureIteratorFacade implements DisposableIterator { |
... | ... | |
415 | 416 |
|
416 | 417 |
/** |
417 | 418 |
* Returns the next FeatureReference. |
418 |
*
|
|
419 |
* |
|
419 | 420 |
* @return the next FeatureReference |
420 | 421 |
*/ |
421 | 422 |
public FeatureReference nextFeatureReference() { |
... | ... | |
438 | 439 |
/** |
439 | 440 |
* Facade over a Iterator of FeatureReferences, to return Features instead, |
440 | 441 |
* when the Selection is reversed |
441 |
*
|
|
442 |
* |
|
442 | 443 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
443 | 444 |
*/ |
444 | 445 |
private class ReversedFeatureIteratorFacade implements DisposableIterator { |
... | ... | |
447 | 448 |
|
448 | 449 |
private DisposableIterator iterator; |
449 | 450 |
|
450 |
private Feature nextFeature = null; |
|
451 |
private Feature nextFeature = null; |
|
452 |
private Feature currentFeature = null; |
|
451 | 453 |
|
452 | 454 |
private FeatureSet featureSet; |
453 | 455 |
|
... | ... | |
477 | 479 |
} |
478 | 480 |
|
479 | 481 |
public Object next() { |
480 |
Feature tmp = nextFeature.getCopy();
|
|
482 |
currentFeature = nextFeature.getCopy();
|
|
481 | 483 |
positionInNextElement(); |
482 |
return tmp;
|
|
484 |
return currentFeature ;
|
|
483 | 485 |
} |
484 | 486 |
|
485 | 487 |
public void remove() { |
486 |
iterator.remove(); |
|
488 |
try { |
|
489 |
featureSet.delete(currentFeature); |
|
490 |
} catch (DataException e) { |
|
491 |
throw new RemoveFromFeatureSelectionException(e); |
|
492 |
|
|
493 |
} |
|
487 | 494 |
} |
488 | 495 |
|
496 |
public class RemoveFromFeatureSelectionException extends DataRuntimeException { |
|
497 |
|
|
498 |
/** |
|
499 |
* |
|
500 |
*/ |
|
501 |
private static final long serialVersionUID = 2636692469445838928L; |
|
502 |
private final static String MESSAGE_FORMAT = "Can't remove feature from reversed selection."; |
|
503 |
private final static String MESSAGE_KEY = "_RemoveFromFeatureSelectionException"; |
|
504 |
|
|
505 |
public RemoveFromFeatureSelectionException(Throwable cause) { |
|
506 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID); |
|
507 |
//setValue("store", store); |
|
508 |
} |
|
509 |
} |
|
510 |
|
|
511 |
|
|
489 | 512 |
private void positionInNextElement() { |
490 | 513 |
nextFeature = null; |
491 | 514 |
while (iterator.hasNext()) { |
... | ... | |
520 | 543 |
|
521 | 544 |
/* |
522 | 545 |
* (non-Javadoc) |
523 |
*
|
|
546 |
* |
|
524 | 547 |
* @seeorg.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection# |
525 | 548 |
* loadFromState(org.gvsig.tools.persistence.PersistentState) |
526 | 549 |
*/ |
Also available in: Unified diff