Revision 42639
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/dal/feature/swing/FeatureSelectionModel.java | ||
---|---|---|
50 | 50 |
* @author 2010- C?sar Ordi?ana - gvSIG team |
51 | 51 |
*/ |
52 | 52 |
public class FeatureSelectionModel implements ListSelectionModel, Observer { |
53 |
private static Logger LOG =
|
|
53 |
private static Logger LOG = |
|
54 | 54 |
LoggerFactory.getLogger(FeatureSelectionModel.class); |
55 |
|
|
55 |
|
|
56 | 56 |
protected EventListenerList listenerList = new EventListenerList(); |
57 | 57 |
|
58 | 58 |
private final FeatureTableModel featureTableModel; |
... | ... | |
64 | 64 |
private int anchor = -1; |
65 | 65 |
|
66 | 66 |
private int lead = -1; |
67 |
|
|
67 |
|
|
68 | 68 |
private int currentFirst = -1; |
69 | 69 |
private int currentLast = -1; |
70 | 70 |
|
... | ... | |
72 | 72 |
* Creates a new {@link FeatureSelectionModel} with a |
73 | 73 |
* {@link FeatureTableModel} used to get the {@link Feature}s by position in |
74 | 74 |
* the table. |
75 |
*
|
|
75 |
* |
|
76 | 76 |
* @param featureTableModel |
77 | 77 |
* to get Features from |
78 | 78 |
* @throws DataException |
... | ... | |
93 | 93 |
} |
94 | 94 |
|
95 | 95 |
public int getMaxSelectionIndex() { |
96 |
|
|
96 |
|
|
97 | 97 |
int resp = this.getSelectionIndex(true); |
98 | 98 |
return resp; |
99 | 99 |
/* |
100 |
*
|
|
100 |
* |
|
101 | 101 |
* The call to "featureTableModel.getFeatureAt(i)" |
102 | 102 |
* causes a lot of reloadPage all over |
103 |
*
|
|
103 |
* |
|
104 | 104 |
FeatureSelection selection = getFeatureSelection(); |
105 | 105 |
try { |
106 | 106 |
if (!selection.isEmpty()) { |
... | ... | |
121 | 121 |
|
122 | 122 |
int resp = this.getSelectionIndex(false); |
123 | 123 |
return resp; |
124 |
|
|
124 |
|
|
125 | 125 |
/* |
126 |
*
|
|
126 |
* |
|
127 | 127 |
* The call to "featureTableModel.getFeatureAt(i)" |
128 | 128 |
* causes a lot of reloadPage all over |
129 |
*
|
|
129 |
* |
|
130 | 130 |
try { |
131 | 131 |
|
132 | 132 |
int ii = 0; |
... | ... | |
141 | 141 |
throw new SelectionChangeException(e); |
142 | 142 |
} |
143 | 143 |
*/ |
144 |
|
|
144 |
|
|
145 | 145 |
} |
146 | 146 |
|
147 | 147 |
public void insertIndexInterval(int index, int length, boolean before) { |
... | ... | |
161 | 161 |
} |
162 | 162 |
|
163 | 163 |
public void addSelectionInterval(int index0, int index1) { |
164 |
doWithSelection(new FeatureSelectionOperation() { |
|
164 |
if (!featureTableModel.isSelectionLocked()){ |
|
165 |
doWithSelection(new FeatureSelectionOperation() { |
|
165 | 166 |
|
166 |
public void doWithSelection(FeatureSelection selection, int first,
|
|
167 |
int last) throws DataException {
|
|
168 |
for (int i = first; i <= last; i++) {
|
|
169 |
Feature feature = getFeature(i);
|
|
170 |
if (!selection.isSelected(feature)) {
|
|
171 |
selection.select(feature);
|
|
172 |
}
|
|
173 |
}
|
|
174 |
}
|
|
167 |
public void doWithSelection(FeatureSelection selection, int first,
|
|
168 |
int last) throws DataException {
|
|
169 |
for (int i = first; i <= last; i++) {
|
|
170 |
Feature feature = getFeature(i);
|
|
171 |
if (!selection.isSelected(feature)) {
|
|
172 |
selection.select(feature);
|
|
173 |
}
|
|
174 |
}
|
|
175 |
}
|
|
175 | 176 |
|
176 |
}, index0, index1, true); |
|
177 |
}, index0, index1, true); |
|
178 |
} |
|
177 | 179 |
} |
178 | 180 |
|
179 | 181 |
public void setSelectionInterval(int index0, int index1) { |
180 |
doWithSelection(new FeatureSelectionOperation() { |
|
182 |
if (!featureTableModel.isSelectionLocked()){ |
|
183 |
doWithSelection(new FeatureSelectionOperation() { |
|
181 | 184 |
|
182 |
public void doWithSelection(FeatureSelection selection, int first,
|
|
183 |
int last) throws DataException {
|
|
184 |
selection.deselectAll();
|
|
185 |
for (int i = first; i <= last; i++) {
|
|
186 |
Feature feature = getFeature(i);
|
|
187 |
selection.select(feature);
|
|
188 |
}
|
|
189 |
}
|
|
185 |
public void doWithSelection(FeatureSelection selection, int first,
|
|
186 |
int last) throws DataException {
|
|
187 |
selection.deselectAll();
|
|
188 |
for (int i = first; i <= last; i++) {
|
|
189 |
Feature feature = getFeature(i);
|
|
190 |
selection.select(feature);
|
|
191 |
}
|
|
192 |
}
|
|
190 | 193 |
|
191 |
}, index0, index1, true); |
|
194 |
}, index0, index1, true); |
|
195 |
} |
|
192 | 196 |
} |
193 | 197 |
|
194 | 198 |
public void removeSelectionInterval(int index0, int index1) { |
195 |
doWithSelection(new FeatureSelectionOperation() { |
|
199 |
if (!featureTableModel.isSelectionLocked()){ |
|
200 |
doWithSelection(new FeatureSelectionOperation() { |
|
196 | 201 |
|
197 |
public void doWithSelection(FeatureSelection selection, int first,
|
|
198 |
int last) throws DataException {
|
|
199 |
for (int i = first; i <= last; i++) {
|
|
200 |
Feature feature = getFeature(i);
|
|
201 |
if (selection.isSelected(feature)) {
|
|
202 |
selection.deselect(feature);
|
|
203 |
}
|
|
204 |
}
|
|
205 |
}
|
|
202 |
public void doWithSelection(FeatureSelection selection, int first,
|
|
203 |
int last) throws DataException {
|
|
204 |
for (int i = first; i <= last; i++) {
|
|
205 |
Feature feature = getFeature(i);
|
|
206 |
if (selection.isSelected(feature)) {
|
|
207 |
selection.deselect(feature);
|
|
208 |
}
|
|
209 |
}
|
|
210 |
}
|
|
206 | 211 |
|
207 |
}, index0, index1, false); |
|
212 |
}, index0, index1, false); |
|
213 |
} |
|
208 | 214 |
} |
209 | 215 |
|
210 | 216 |
public void clearSelection() { |
211 |
try { |
|
212 |
getFeatureSelection().deselectAll(); |
|
213 |
} catch (DataException e) { |
|
214 |
throw new SelectionChangeException(e); |
|
215 |
} |
|
217 |
if (!featureTableModel.isSelectionLocked()){ |
|
218 |
try { |
|
219 |
getFeatureSelection().deselectAll(); |
|
220 |
} catch (DataException e) { |
|
221 |
throw new SelectionChangeException(e); |
|
222 |
} |
|
223 |
} |
|
216 | 224 |
} |
217 | 225 |
|
218 | 226 |
public boolean isSelectedIndex(int index) { |
... | ... | |
302 | 310 |
// values |
303 | 311 |
int first = (index0 <= index1) ? index0 : index1; |
304 | 312 |
int last = (index0 <= index1) ? index1 : index0; |
305 |
|
|
313 |
|
|
306 | 314 |
//If the new selection is not updated don't continue |
307 | 315 |
if ((currentFirst == first) && (currentLast == last)){ |
308 | 316 |
return; |
... | ... | |
378 | 386 |
void doWithSelection(FeatureSelection selection, int first, int last) |
379 | 387 |
throws DataException; |
380 | 388 |
} |
381 |
|
|
389 |
|
|
382 | 390 |
/** |
383 |
*
|
|
384 |
* Return the index of the the first (last) selected feature
|
|
385 |
*
|
|
386 |
* @param last whether to return the index of the last selected feature
|
|
391 |
* |
|
392 |
* Return the index of the the first (last) selected feature |
|
393 |
* |
|
394 |
* @param last whether to return the index of the last selected feature |
|
387 | 395 |
* @return |
388 | 396 |
*/ |
389 | 397 |
private int getSelectionIndex(boolean last) { |
390 |
|
|
398 |
|
|
391 | 399 |
int ind = -1; |
392 | 400 |
int resp = -1; |
393 | 401 |
|
... | ... | |
397 | 405 |
try { |
398 | 406 |
FeatureSelection selection = getFeatureSelection(); |
399 | 407 |
if (!selection.isEmpty()) { |
400 |
|
|
408 |
|
|
401 | 409 |
fs = getFeatureStore().getFeatureSet(); |
402 | 410 |
diter = fs.fastIterator(); |
403 | 411 |
Feature feat = null; |
... | ... | |
411 | 419 |
} |
412 | 420 |
} |
413 | 421 |
} |
414 |
|
|
422 |
|
|
415 | 423 |
} |
416 | 424 |
} catch (DataException e) { |
417 | 425 |
throw new SelectionChangeException(e); |
... | ... | |
424 | 432 |
fs.dispose(); |
425 | 433 |
} |
426 | 434 |
} |
427 |
return resp;
|
|
435 |
return resp; |
|
428 | 436 |
} |
429 |
|
|
430 |
|
|
437 |
|
|
431 | 438 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/dal/feature/swing/table/FeatureTableModel.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import java.awt.event.ActionEvent; |
31 | 31 |
import java.awt.event.ActionListener; |
32 |
|
|
32 | 33 |
import javax.swing.SwingUtilities; |
33 | 34 |
import javax.swing.Timer; |
34 | 35 |
import javax.swing.event.TableModelEvent; |
35 | 36 |
import javax.swing.table.AbstractTableModel; |
37 |
|
|
36 | 38 |
import org.gvsig.editing.EditingNotification; |
37 | 39 |
import org.gvsig.editing.EditingNotificationManager; |
38 |
|
|
39 | 40 |
import org.gvsig.fmap.dal.DALLocator; |
40 | 41 |
import org.gvsig.fmap.dal.exception.DataException; |
41 | 42 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
... | ... | |
77 | 78 |
/** Used to know if a modification in the FeatureStore is created by us. */ |
78 | 79 |
private EditableFeature editableFeature; |
79 | 80 |
|
81 |
private boolean selectionLocked=false; |
|
82 |
|
|
80 | 83 |
/** |
81 | 84 |
* Constructs a TableModel from the features of a FeatureStore, with the |
82 | 85 |
* default page size. |
... | ... | |
279 | 282 |
public void setFeatureType(FeatureType featureType) { |
280 | 283 |
getFeatureQuery().setFeatureType(featureType); |
281 | 284 |
reloadFeatures(); |
282 |
fireTableStructureChanged(); |
|
285 |
//Selection must be locked to avoid losing it when the table is refreshed |
|
286 |
selectionLocked=true; |
|
287 |
//The table is refreshed |
|
288 |
try { |
|
289 |
fireTableStructureChanged(); |
|
290 |
} catch (Exception e) { |
|
291 |
logger.warn("Couldn't reload changed table"); |
|
292 |
}finally{ |
|
293 |
//The locked selection is unlocked. |
|
294 |
selectionLocked=false; |
|
295 |
} |
|
283 | 296 |
} |
284 | 297 |
|
285 | 298 |
/** |
... | ... | |
632 | 645 |
// changed through us. |
633 | 646 |
if (editableFeature == null || !editableFeature.equals(feature)) { |
634 | 647 |
reloadFeatures(); |
635 |
fireTableDataChanged(); |
|
648 |
//Selection must be locked to avoid losing it when the table is refreshed |
|
649 |
selectionLocked=true; |
|
650 |
//The table is refreshed |
|
651 |
try { |
|
652 |
fireTableDataChanged(); |
|
653 |
} catch (Exception e) { |
|
654 |
logger.warn("Couldn't reload changed table"); |
|
655 |
}finally{ |
|
656 |
//The locked selection is unlocked. |
|
657 |
selectionLocked=false; |
|
658 |
} |
|
636 | 659 |
} |
637 | 660 |
} |
638 | 661 |
|
... | ... | |
682 | 705 |
throw new FeaturesDataReloadException(ex); |
683 | 706 |
} |
684 | 707 |
} |
708 |
|
|
709 |
/** |
|
710 |
* Returns true if selection must not be changed. |
|
711 |
* @return |
|
712 |
*/ |
|
713 |
public boolean isSelectionLocked() { |
|
714 |
return selectionLocked; |
|
715 |
} |
|
716 |
|
|
685 | 717 |
} |
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/FeatureManager.java | ||
---|---|---|
53 | 53 |
private Map added = new LinkedHashMap(); |
54 | 54 |
private Map addedAndDeleted = new LinkedHashMap(); |
55 | 55 |
private HashMap modifiedFromOriginal=new HashMap(); |
56 |
|
|
56 |
|
|
57 | 57 |
public FeatureManager(ExpansionAdapter expansionAdapter){ |
58 | 58 |
this.expansionAdapter=expansionAdapter; |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
/** |
62 |
* Deletes feature from this manager.
|
|
63 |
* @param id
|
|
62 |
* Deletes feature from this manager. |
|
63 |
* @param id |
|
64 | 64 |
* @return The deleted feature or null if the |
65 |
* feature had not been edited or previously added in the editing session
|
|
65 |
* feature had not been edited or previously added in the editing session |
|
66 | 66 |
*/ |
67 | 67 |
public Feature delete(FeatureReference id) { |
68 | 68 |
deleted.add(id); |
... | ... | |
147 | 147 |
Integer intNum = ((Integer) added.get(id)); |
148 | 148 |
if (intNum == null){ |
149 | 149 |
intNum =((Integer) modifiedFromOriginal.get(id)); |
150 |
if (intNum == null){
|
|
150 |
if (intNum == null){ |
|
151 | 151 |
//If the feature has been added and deleted |
152 | 152 |
intNum = (Integer)addedAndDeleted.get(id); |
153 | 153 |
if (intNum == null){ |
... | ... | |
398 | 398 |
public long getDeltaSize() { |
399 | 399 |
return deltaSize; |
400 | 400 |
} |
401 |
|
|
402 |
/** |
|
403 |
* Indicates if any operation has comprimised the selected features. |
|
404 |
* @return |
|
405 |
*/ |
|
406 |
public boolean isSelectionCompromised() { |
|
407 |
//Only deleted features can change order, as added features are added at the end. |
|
408 |
return deleted.size()>0; |
|
409 |
} |
|
401 | 410 |
} |
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/DefaultFeatureStore.java | ||
---|---|---|
1204 | 1204 |
* to prevent conflicts with selection remaining from |
1205 | 1205 |
* editing mode. |
1206 | 1206 |
*/ |
1207 |
((FeatureSelection) this.getSelection()).deselectAll(); |
|
1207 |
// ((FeatureSelection) this.getSelection()).deselectAll();
|
|
1208 | 1208 |
|
1209 | 1209 |
switch (mode) { |
1210 | 1210 |
case MODE_QUERY: |
1211 | 1211 |
throw new NeedEditingModeException(this.getName()); |
1212 | 1212 |
|
1213 | 1213 |
case MODE_APPEND: |
1214 |
((FeatureSelection) this.getSelection()).deselectAll(); |
|
1214 | 1215 |
notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING); |
1215 | 1216 |
provider.endAppend(); |
1216 | 1217 |
exitEditingMode(); |
... | ... | |
1222 | 1223 |
if (hasStrongChanges && !this.allowWrite()) { |
1223 | 1224 |
throw new WriteNotAllowedException(getName()); |
1224 | 1225 |
} |
1226 |
|
|
1227 |
if(featureManager.isSelectionCompromised()) { |
|
1228 |
((FeatureSelection) this.getSelection()).deselectAll(); |
|
1229 |
}; |
|
1230 |
|
|
1225 | 1231 |
notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING); |
1226 | 1232 |
if (hasStrongChanges) { |
1227 | 1233 |
validateFeatures(Feature.FINISH_EDITING); |
Also available in: Unified diff