Revision 45521 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/editing/memory/FeatureManager.java
FeatureManager.java | ||
---|---|---|
47 | 47 |
private final Map<FeatureReference, Integer> added; |
48 | 48 |
private final Map<FeatureReference, Integer> addedAndDeleted; |
49 | 49 |
private final Map<FeatureReference, Integer> modifiedFromOriginal; |
50 |
private final Map<FeatureReference, Integer> original; |
|
50 | 51 |
|
51 | 52 |
public FeatureManager() { |
52 | 53 |
deltaSize = 0; |
... | ... | |
55 | 56 |
added = new LinkedHashMap<>(); |
56 | 57 |
addedAndDeleted = new LinkedHashMap<>(); |
57 | 58 |
modifiedFromOriginal = new HashMap<>(); |
59 |
original = new HashMap<>(); |
|
58 | 60 |
} |
59 | 61 |
|
60 | 62 |
/** |
... | ... | |
64 | 66 |
* @return The deleted feature or null if the feature had not been edited or |
65 | 67 |
* previously added in the editing session |
66 | 68 |
*/ |
67 |
public Feature delete(FeatureReference id) { |
|
69 |
public Feature delete(Feature feature) { |
|
70 |
FeatureReference id = feature.getReference(); |
|
71 |
if(!original.containsKey(id)){ |
|
72 |
int n = expansionAdapter.addObject(feature); |
|
73 |
original.put(id, n); |
|
74 |
} |
|
68 | 75 |
deleted.add(id); |
69 | 76 |
Integer num = added.remove(id); |
70 |
Feature feature = null;
|
|
77 |
Feature previousFeature = null;
|
|
71 | 78 |
if (num == null || num == -1) { |
72 | 79 |
num = modifiedFromOriginal.remove(id); |
73 | 80 |
if (num != null) { |
74 |
feature = (Feature) expansionAdapter.getObject(num);
|
|
81 |
previousFeature = (Feature) expansionAdapter.getObject(num);
|
|
75 | 82 |
} |
76 | 83 |
// if num is null here, method returns null |
77 | 84 |
} else { |
78 |
feature = (Feature) expansionAdapter.getObject(num);
|
|
85 |
previousFeature = (Feature) expansionAdapter.getObject(num);
|
|
79 | 86 |
addedAndDeleted.put(id, num); |
80 | 87 |
} |
81 | 88 |
deltaSize--; |
82 |
return feature;
|
|
89 |
return previousFeature;
|
|
83 | 90 |
} |
84 | 91 |
|
85 | 92 |
public void add(Feature feature) { |
93 |
FeatureReference id = feature.getReference(); |
|
94 |
if(!original.containsKey(id)){ |
|
95 |
original.put(id, null); |
|
96 |
} |
|
97 |
|
|
86 | 98 |
int pos = expansionAdapter.addObject(feature); |
87 | 99 |
added.put(feature.getReference(), pos); |
88 | 100 |
deleted.remove(feature.getReference()); |
... | ... | |
128 | 140 |
// Si no existe feature con ese id... ? retorna null ? |
129 | 141 |
// en EditedDefaultIterator se hace uso de ese comportamiento. |
130 | 142 |
// |
143 |
boolean isNewFeature = false; |
|
131 | 144 |
Integer intNum = (added.get(id)); |
132 | 145 |
if (intNum == null) { |
133 | 146 |
intNum = (modifiedFromOriginal.get(id)); |
... | ... | |
138 | 151 |
return null; |
139 | 152 |
} |
140 | 153 |
} |
154 |
} else { |
|
155 |
isNewFeature = true; |
|
141 | 156 |
} |
142 | 157 |
int num = intNum; |
143 | 158 |
if (num == -1) { |
... | ... | |
147 | 162 |
if (featureType == null) { |
148 | 163 |
featureType = store.getDefaultFeatureType(); |
149 | 164 |
} |
150 |
return new DefaultFeature(featureType, feature); |
|
165 |
DefaultFeature feat = new DefaultFeature(featureType, feature); |
|
166 |
feat.getData().setNew(isNewFeature); |
|
167 |
return feat; |
|
151 | 168 |
} |
152 | 169 |
|
153 | 170 |
public int update(Feature feature, Feature oldFeature) { |
171 |
FeatureReference id = feature.getReference(); |
|
172 |
if(!original.containsKey(id)){ |
|
173 |
int n = expansionAdapter.addObject(oldFeature); |
|
174 |
original.put(id, n); |
|
175 |
} |
|
154 | 176 |
int oldNum = -1; |
155 | 177 |
int num = expansionAdapter.addObject(feature); |
156 |
FeatureReference id = feature.getReference(); |
|
157 | 178 |
if (added.containsKey(id)) { |
158 | 179 |
oldNum = (added.get(id)); |
159 | 180 |
added.put(id, num); |
... | ... | |
364 | 385 |
while (iter.hasNext()) { |
365 | 386 |
pos++; |
366 | 387 |
feature = (Feature) iter.next(); |
367 |
if ( !deleted.contains(feature.getReference()) && |
|
388 |
if ( feature != null && |
|
389 |
!deleted.contains(feature.getReference()) && |
|
368 | 390 |
modifiedFromOriginal.containsValue(pos)) { |
369 | 391 |
hasnext = true; |
370 | 392 |
break; |
... | ... | |
406 | 428 |
//Only deleted features can change order, as added features are added at the end. |
407 | 429 |
return deleted.size() > 0; |
408 | 430 |
} |
431 |
|
|
432 |
public Feature getOriginal(FeatureReference id){ |
|
433 |
Integer n = original.get(id); |
|
434 |
if(n == null){ |
|
435 |
return null; |
|
436 |
} |
|
437 |
return (Feature) this.expansionAdapter.getObject(n); |
|
438 |
} |
|
439 |
|
|
440 |
public boolean isFeatureModified(FeatureReference id) { |
|
441 |
return original.containsKey(id); |
|
442 |
} |
|
443 |
|
|
409 | 444 |
} |
Also available in: Unified diff