Revision 43888
branches/org.gvsig.desktop-2018a/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 | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.feature.impl; |
|
25 |
|
|
26 |
import java.util.Collection; |
|
27 |
import java.util.HashMap; |
|
28 |
import java.util.Iterator; |
|
29 |
import java.util.LinkedHashMap; |
|
30 |
import java.util.LinkedHashSet; |
|
31 |
import java.util.Map; |
|
32 |
import java.util.NoSuchElementException; |
|
33 |
|
|
34 |
import org.gvsig.fmap.dal.exception.DataException; |
|
35 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
36 |
import org.gvsig.fmap.dal.feature.Feature; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
40 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
41 |
import org.gvsig.fmap.dal.feature.impl.expansionadapter.ExpansionAdapter; |
|
42 |
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
|
43 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
44 |
|
|
45 |
|
|
46 |
/** |
|
47 |
* DOCUMENT ME! |
|
48 |
* |
|
49 |
* @author Vicente Caballero Navarro |
|
50 |
*/ |
|
51 |
public class FeatureManager { |
|
52 |
private ExpansionAdapter expansionAdapter; |
|
53 |
private Collection deleted = new LinkedHashSet();//<FeatureID> |
|
54 |
private int deltaSize=0; |
|
55 |
private Map added = new LinkedHashMap(); |
|
56 |
private Map addedAndDeleted = new LinkedHashMap(); |
|
57 |
private HashMap modifiedFromOriginal=new HashMap(); |
|
58 |
|
|
59 |
public FeatureManager(ExpansionAdapter expansionAdapter){ |
|
60 |
this.expansionAdapter=expansionAdapter; |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Deletes feature from this manager. |
|
65 |
* @param id |
|
66 |
* @return The deleted feature or null if the |
|
67 |
* feature had not been edited or previously added in the editing session |
|
68 |
*/ |
|
69 |
public Feature delete(FeatureReference id) { |
|
70 |
deleted.add(id); |
|
71 |
Integer num = (Integer) added.remove(id); |
|
72 |
Feature feature=null; |
|
73 |
if (num == null || num.intValue() == -1) { |
|
74 |
num = (Integer) modifiedFromOriginal.remove(id); |
|
75 |
if (num != null) { |
|
76 |
feature = (Feature) expansionAdapter.getObject(num.intValue()); |
|
77 |
} |
|
78 |
// if num is null here, method returns null |
|
79 |
}else{ |
|
80 |
feature = (Feature) expansionAdapter.getObject(num.intValue()); |
|
81 |
addedAndDeleted.put(id, num); |
|
82 |
} |
|
83 |
deltaSize--; |
|
84 |
return feature; |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* DOCUMENT ME! |
|
89 |
* |
|
90 |
* @param feature DOCUMENT ME! |
|
91 |
*/ |
|
92 |
public void add(Feature feature) { |
|
93 |
int pos = expansionAdapter.addObject(feature); |
|
94 |
added.put(feature.getReference(),new Integer(pos)); |
|
95 |
deleted.remove(feature.getReference()); |
|
96 |
deltaSize++; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* DOCUMENT ME! |
|
101 |
* @param id DOCUMENT ME! |
|
102 |
*/ |
|
103 |
public Feature deleteLastFeature() { |
|
104 |
expansionAdapter.deleteLastObject(); |
|
105 |
Feature feature=(Feature)expansionAdapter.getObject(expansionAdapter.getSize()-1); |
|
106 |
added.remove(feature.getReference()); |
|
107 |
modifiedFromOriginal.remove(feature.getReference()); |
|
108 |
deltaSize--; |
|
109 |
return feature; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Returns a Feature of the default type. |
|
114 |
* |
|
115 |
* @param id |
|
116 |
* the feature reference |
|
117 |
* @param store |
|
118 |
* the store to get the feature from |
|
119 |
* @return a Feature with the given reference |
|
120 |
* @throws DataException |
|
121 |
* if there is an error getting the Feature |
|
122 |
*/ |
|
123 |
public Feature get(FeatureReference id, FeatureStore store) |
|
124 |
throws DataException { |
|
125 |
return get(id, store, null); |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Returns a Feature of the given type. |
|
130 |
* |
|
131 |
* @param id |
|
132 |
* the feature reference |
|
133 |
* @param store |
|
134 |
* the store to get the feature from |
|
135 |
* @param featureType |
|
136 |
* the type of the feature to return |
|
137 |
* @return a Feature with the given reference |
|
138 |
* @throws DataException |
|
139 |
* if there is an error getting the Feature |
|
140 |
*/ |
|
141 |
public Feature get(FeatureReference id, FeatureStore store, |
|
142 |
FeatureType featureType) throws DataException { |
|
143 |
// FIXME: y si el featuretype que paso esta modificado. |
|
144 |
// Deberia buscarlo en el featuretypemanager ? |
|
145 |
// |
|
146 |
// Si no existe feature con ese id... ? retorna null ? |
|
147 |
// en EditedDefaultIterator se hace uso de ese comportamiento. |
|
148 |
// |
|
149 |
Integer intNum = ((Integer) added.get(id)); |
|
150 |
if (intNum == null){ |
|
151 |
intNum =((Integer) modifiedFromOriginal.get(id)); |
|
152 |
if (intNum == null){ |
|
153 |
//If the feature has been added and deleted |
|
154 |
intNum = (Integer)addedAndDeleted.get(id); |
|
155 |
if (intNum == null){ |
|
156 |
return null; |
|
157 |
} |
|
158 |
} |
|
159 |
} |
|
160 |
int num = intNum.intValue(); |
|
161 |
if (num==-1) { |
|
162 |
return null; |
|
163 |
} |
|
164 |
Feature feature=(Feature)expansionAdapter.getObject(num); |
|
165 |
if (featureType== null){ |
|
166 |
featureType = store.getDefaultFeatureType(); |
|
167 |
} |
|
168 |
return new DefaultFeature(featureType, feature); |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* DOCUMENT ME! |
|
173 |
* |
|
174 |
* @param feature DOCUMENT ME! |
|
175 |
* @param oldFeature DOCUMENT ME! |
|
176 |
*/ |
|
177 |
public int update(Feature feature, Feature oldFeature) { |
|
178 |
int oldNum=-1; |
|
179 |
int num = expansionAdapter.addObject(feature); |
|
180 |
FeatureReference id=feature.getReference(); |
|
181 |
if (added.containsKey(id)){ |
|
182 |
oldNum=((Integer)added.get(id)).intValue(); |
|
183 |
added.put(id,new Integer(num)); |
|
184 |
}else{ |
|
185 |
if (modifiedFromOriginal.get(id)!=null) { |
|
186 |
oldNum=((Integer)modifiedFromOriginal.get(id)).intValue(); |
|
187 |
} |
|
188 |
modifiedFromOriginal.put(id,new Integer(num)); |
|
189 |
} |
|
190 |
return oldNum; |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* DOCUMENT ME! |
|
195 |
* |
|
196 |
* @param id DOCUMENT ME! |
|
197 |
*/ |
|
198 |
public void restore(FeatureReference id) { |
|
199 |
deleted.remove(id); |
|
200 |
deltaSize++; |
|
201 |
} |
|
202 |
public void restore(FeatureReference id,int num){ |
|
203 |
if (added.containsKey(id)){ |
|
204 |
added.put(id,new Integer(num)); |
|
205 |
}else{ |
|
206 |
modifiedFromOriginal.put(id,new Integer(num)); |
|
207 |
} |
|
208 |
} |
|
209 |
|
|
210 |
|
|
211 |
public boolean isDeleted(Feature feature){ |
|
212 |
return deleted.contains(feature.getReference()); |
|
213 |
} |
|
214 |
|
|
215 |
public boolean isDeleted(FeatureReference featureID) { |
|
216 |
return deleted.contains(featureID); |
|
217 |
} |
|
218 |
|
|
219 |
public void clear() { |
|
220 |
added.clear(); |
|
221 |
modifiedFromOriginal.clear(); |
|
222 |
expansionAdapter.close(); |
|
223 |
deleted.clear();//<FeatureID> |
|
224 |
addedAndDeleted.clear(); |
|
225 |
deltaSize=0; |
|
226 |
} |
|
227 |
|
|
228 |
|
|
229 |
public boolean hasChanges() { |
|
230 |
return added.size()>0 || modifiedFromOriginal.size() > 0 || deleted.size() > 0; |
|
231 |
} |
|
232 |
|
|
233 |
public Iterator getDeleted() { |
|
234 |
return new DeletedIterator(); |
|
235 |
|
|
236 |
} |
|
237 |
|
|
238 |
class DeletedIterator implements Iterator { |
|
239 |
private Boolean hasnext = null; |
|
240 |
private Iterator iter; |
|
241 |
private DefaultFeatureReference obj; |
|
242 |
|
|
243 |
public DeletedIterator(){ |
|
244 |
iter = deleted.iterator(); |
|
245 |
} |
|
246 |
|
|
247 |
public boolean hasNext() { |
|
248 |
if (hasnext != null) { |
|
249 |
return hasnext.booleanValue(); |
|
250 |
} |
|
251 |
hasnext = Boolean.FALSE; |
|
252 |
while (iter.hasNext()) { |
|
253 |
obj = (DefaultFeatureReference) iter.next(); |
|
254 |
if (obj.isNewFeature()) { |
|
255 |
continue; |
|
256 |
} |
|
257 |
hasnext = Boolean.TRUE; |
|
258 |
break; |
|
259 |
} |
|
260 |
return hasnext.booleanValue(); |
|
261 |
} |
|
262 |
|
|
263 |
public Object next() { |
|
264 |
if (!hasNext()) { |
|
265 |
throw new NoSuchElementException(); |
|
266 |
} |
|
267 |
|
|
268 |
hasnext = null; |
|
269 |
return obj; |
|
270 |
} |
|
271 |
|
|
272 |
public void remove() { |
|
273 |
throw new UnsupportedOperationException(); |
|
274 |
|
|
275 |
} |
|
276 |
|
|
277 |
} |
|
278 |
|
|
279 |
public Iterator getInserted() { |
|
280 |
return new InsertedIterator(); |
|
281 |
} |
|
282 |
|
|
283 |
class InsertedIterator implements Iterator { |
|
284 |
|
|
285 |
private Iterator addedIter; |
|
286 |
private DefaultFeature obj; |
|
287 |
private Boolean hasnext = null; |
|
288 |
|
|
289 |
public InsertedIterator(){ |
|
290 |
addedIter = added.values().iterator(); |
|
291 |
} |
|
292 |
|
|
293 |
public boolean hasNext() { |
|
294 |
if (hasnext != null) { |
|
295 |
return hasnext.booleanValue(); |
|
296 |
} |
|
297 |
hasnext = Boolean.FALSE; |
|
298 |
int pos; |
|
299 |
while (addedIter.hasNext()) { |
|
300 |
pos = ((Integer) addedIter.next()).intValue(); |
|
301 |
obj = (DefaultFeature) expansionAdapter.getObject(pos); |
|
302 |
if (!deleted.contains(obj.getReference())) { |
|
303 |
hasnext = Boolean.TRUE; |
|
304 |
break; |
|
305 |
} |
|
306 |
} |
|
307 |
return hasnext.booleanValue(); |
|
308 |
} |
|
309 |
|
|
310 |
public Object next() { |
|
311 |
if (!hasNext()) { |
|
312 |
throw new NoSuchElementException(); |
|
313 |
} |
|
314 |
hasnext = null; |
|
315 |
return obj.getData(); |
|
316 |
} |
|
317 |
|
|
318 |
public void remove() { |
|
319 |
addedIter.remove(); |
|
320 |
} |
|
321 |
|
|
322 |
} |
|
323 |
public Iterator getUpdated() { |
|
324 |
return new UpdatedIterator(); |
|
325 |
} |
|
326 |
class UpdatedIterator implements Iterator{ |
|
327 |
private Boolean hasnext = null; |
|
328 |
private Iterator iter; |
|
329 |
private DefaultFeature obj; |
|
330 |
private int pos; |
|
331 |
|
|
332 |
public UpdatedIterator() { |
|
333 |
iter = expansionAdapter.iterator(); |
|
334 |
pos = -1; |
|
335 |
} |
|
336 |
|
|
337 |
public boolean hasNext() { |
|
338 |
if (hasnext != null) { |
|
339 |
return hasnext.booleanValue(); |
|
340 |
} |
|
341 |
hasnext = Boolean.FALSE; |
|
342 |
while (iter.hasNext()) { |
|
343 |
pos++; |
|
344 |
obj = (DefaultFeature) iter.next(); |
|
345 |
if (deleted.contains(obj.getReference())){ |
|
346 |
continue; |
|
347 |
}else if (!modifiedFromOriginal.containsValue(new Integer(pos))){ |
|
348 |
continue; |
|
349 |
}else { |
|
350 |
hasnext = Boolean.TRUE; |
|
351 |
break; |
|
352 |
} |
|
353 |
} |
|
354 |
return hasnext.booleanValue(); |
|
355 |
} |
|
356 |
|
|
357 |
public Object next() { |
|
358 |
if (!hasNext()) { |
|
359 |
throw new NoSuchElementException(); |
|
360 |
} |
|
361 |
hasnext = null; |
|
362 |
return obj.getData(); |
|
363 |
} |
|
364 |
|
|
365 |
public void remove() { |
|
366 |
throw new UnsupportedOperationException(); |
|
367 |
|
|
368 |
} |
|
369 |
} |
|
370 |
|
|
371 |
public boolean hasNews() { |
|
372 |
return !added.isEmpty(); |
|
373 |
} |
|
374 |
|
|
375 |
public long getDeltaSize() { |
|
376 |
return deltaSize; |
|
377 |
} |
|
378 |
|
|
379 |
/** |
|
380 |
* Indicates if any operation has comprimised the selected features. |
|
381 |
* @return |
|
382 |
*/ |
|
383 |
public boolean isSelectionCompromised() { |
|
384 |
//Only deleted features can change order, as added features are added at the end. |
|
385 |
return deleted.size()>0; |
|
386 |
} |
|
387 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/SpatialManager.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.feature.impl; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.ConcurrentModificationException; |
|
28 |
import java.util.Iterator; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.exception.DataException; |
|
31 |
import org.gvsig.fmap.dal.feature.Feature; |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureIndex; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureIndexes; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
39 |
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException; |
|
40 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
41 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
42 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
43 |
import org.slf4j.Logger; |
|
44 |
import org.slf4j.LoggerFactory; |
|
45 |
|
|
46 |
/** |
|
47 |
* DOCUMENT ME! |
|
48 |
* |
|
49 |
* @author Vicente Caballero Navarro |
|
50 |
*/ |
|
51 |
public class SpatialManager { |
|
52 |
private static final Logger LOG = LoggerFactory.getLogger(SpatialManager.class); |
|
53 |
|
|
54 |
protected boolean isFullExtentDirty = true; |
|
55 |
private FeatureStore featureStore; |
|
56 |
private FeatureIndex featureIndex = null; |
|
57 |
private Envelope originalEnvelope = null; |
|
58 |
private Envelope fullEnvelope = null; |
|
59 |
private ArrayList feaOperation=new ArrayList(); |
|
60 |
private boolean noSpatialData = false; |
|
61 |
|
|
62 |
public SpatialManager(FeatureStore featureStore, Envelope originalEnvelope) |
|
63 |
throws DataException { |
|
64 |
this.featureStore=featureStore; |
|
65 |
FeatureIndexes findexes=featureStore.getIndexes(); |
|
66 |
// Comprobamos si hay algun campo espacial a manejar |
|
67 |
|
|
68 |
FeatureType fType = this.featureStore.getDefaultFeatureType(); |
|
69 |
// TODO Multy FType !! |
|
70 |
if (fType.getDefaultGeometryAttributeIndex() < 0) { |
|
71 |
noSpatialData = true; |
|
72 |
return; |
|
73 |
} |
|
74 |
FeatureAttributeDescriptor attr = fType.getAttributeDescriptor(fType |
|
75 |
.getDefaultGeometryAttributeIndex()); |
|
76 |
this.originalEnvelope = originalEnvelope; |
|
77 |
if ((originalEnvelope != null) && (!originalEnvelope.isEmpty())) { |
|
78 |
this.fullEnvelope = originalEnvelope.getGeometry().getEnvelope(); |
|
79 |
} else { |
|
80 |
FeatureAttributeDescriptor geoAttr = fType.getAttributeDescriptor(fType.getDefaultGeometryAttributeIndex()); |
|
81 |
try { |
|
82 |
this.fullEnvelope = GeometryLocator.getGeometryManager() |
|
83 |
.createEnvelope(geoAttr.getGeometrySubType()); |
|
84 |
} catch (Exception e) { |
|
85 |
// FIXME Excpetion |
|
86 |
throw new RuntimeException(e); |
|
87 |
} |
|
88 |
} |
|
89 |
if (!fType.hasOID()) { |
|
90 |
return; |
|
91 |
} |
|
92 |
|
|
93 |
Iterator iterator = findexes.iterator(); |
|
94 |
FeatureIndex index; |
|
95 |
while (iterator.hasNext()) { |
|
96 |
index = (FeatureIndex) iterator.next(); |
|
97 |
if (index.getAttributeNames().size() == 1 |
|
98 |
&& index.getAttributeNames().contains(attr.getName())) { |
|
99 |
featureIndex = index; |
|
100 |
break; |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
if (featureIndex instanceof DefaultFeatureIndex) { |
|
105 |
((DefaultFeatureIndex) featureIndex).setValid(true); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
/** |
|
112 |
* DOCUMENT ME! |
|
113 |
* |
|
114 |
* @param feature DOCUMENT ME! |
|
115 |
* @param oldFeature DOCUMENT ME! |
|
116 |
*/ |
|
117 |
public void updateFeature(Feature feature, Feature oldFeature) { |
|
118 |
if (noSpatialData) { |
|
119 |
return; |
|
120 |
} |
|
121 |
try { |
|
122 |
if (featureIndex != null) { |
|
123 |
featureIndex.delete(oldFeature); |
|
124 |
} |
|
125 |
feaOperation.add(new FeatureOperation(((DefaultFeature) oldFeature) |
|
126 |
.getReference(), FeatureOperation.DELETE)); |
|
127 |
if (featureIndex != null) { |
|
128 |
featureIndex.insert(feature); |
|
129 |
} |
|
130 |
feaOperation.add(new FeatureOperation(((DefaultFeature) feature) |
|
131 |
.getReference(), FeatureOperation.INSERT)); |
|
132 |
} catch (DataException e) { |
|
133 |
throw new RuntimeException("Exception updating feature: " |
|
134 |
+ feature, e); |
|
135 |
} |
|
136 |
// } else { |
|
137 |
// fullEnvelope.add(feature.getDefaultEnvelope()); |
|
138 |
isFullExtentDirty = true; |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* DOCUMENT ME! |
|
143 |
* |
|
144 |
* @param feature DOCUMENT ME! |
|
145 |
*/ |
|
146 |
public void insertFeature(Feature feature) { |
|
147 |
if (noSpatialData) { |
|
148 |
return; |
|
149 |
} |
|
150 |
try { |
|
151 |
if (featureIndex != null) { |
|
152 |
featureIndex.insert(feature); |
|
153 |
} |
|
154 |
feaOperation.add(new FeatureOperation( |
|
155 |
((DefaultFeature) feature).getReference(), |
|
156 |
FeatureOperation.INSERT)); |
|
157 |
} catch (DataException e) { |
|
158 |
throw new RuntimeException("Exception inserting feature: " |
|
159 |
+ feature, e); |
|
160 |
} |
|
161 |
isFullExtentDirty = true; |
|
162 |
// } else if (!isFullExtentDirty) { |
|
163 |
// fullEnvelope.add(feature.getDefaultEnvelope()); |
|
164 |
// } |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* DOCUMENT ME! |
|
169 |
* |
|
170 |
* @param feature DOCUMENT ME! |
|
171 |
*/ |
|
172 |
public void deleteFeature(Feature feature) { |
|
173 |
if (noSpatialData) { |
|
174 |
return; |
|
175 |
} |
|
176 |
try { |
|
177 |
if (featureIndex != null) { |
|
178 |
featureIndex.delete(feature); |
|
179 |
} |
|
180 |
feaOperation.add(new FeatureOperation(((DefaultFeature) feature) |
|
181 |
.getReference(), FeatureOperation.DELETE)); |
|
182 |
} catch (DataException e) { |
|
183 |
throw new RuntimeException("Exception deleting feature: " |
|
184 |
+ feature, e); |
|
185 |
} |
|
186 |
isFullExtentDirty = true; |
|
187 |
} |
|
188 |
|
|
189 |
public void clear() { |
|
190 |
} |
|
191 |
|
|
192 |
public Envelope getEnvelope() throws DataException { |
|
193 |
if (noSpatialData) { |
|
194 |
return null; |
|
195 |
} |
|
196 |
if (!isFullExtentDirty){ |
|
197 |
return this.fullEnvelope; |
|
198 |
} |
|
199 |
|
|
200 |
// FIXME in every changes when anyone ask for envelope it was regenerated. |
|
201 |
// if we assume that the envelope may not be the minimum in edit mode |
|
202 |
// this call must be very much faster |
|
203 |
|
|
204 |
|
|
205 |
FeatureAttributeDescriptor attr = featureStore.getDefaultFeatureType() |
|
206 |
.getAttributeDescriptor( |
|
207 |
featureStore.getDefaultFeatureType() |
|
208 |
.getDefaultGeometryAttributeIndex()); |
|
209 |
Envelope fullEnvelope = null; |
|
210 |
|
|
211 |
FeatureSet set = null; |
|
212 |
DisposableIterator iterator = null; |
|
213 |
try { |
|
214 |
set = featureStore.getFeatureSet(); |
|
215 |
iterator = set.fastIterator(); |
|
216 |
//First while to initialize the feature envelope |
|
217 |
while (iterator.hasNext()) { |
|
218 |
Feature feature = (Feature) iterator.next(); |
|
219 |
Envelope envelope = feature.getDefaultEnvelope(); |
|
220 |
if (envelope != null){ |
|
221 |
fullEnvelope = (Envelope)envelope.clone(); |
|
222 |
break; |
|
223 |
} |
|
224 |
} |
|
225 |
//Second while to add new evelopes tho the full envelope |
|
226 |
while (iterator.hasNext()) { |
|
227 |
Feature feature = (Feature) iterator.next(); |
|
228 |
Envelope envelope = feature.getDefaultEnvelope(); |
|
229 |
if(envelope!=null){ |
|
230 |
fullEnvelope.add(envelope); |
|
231 |
} |
|
232 |
} |
|
233 |
//Creating an empty envelope by default |
|
234 |
if (fullEnvelope == null){ |
|
235 |
fullEnvelope = GeometryLocator.getGeometryManager().createEnvelope( |
|
236 |
attr.getGeometrySubType()); |
|
237 |
} |
|
238 |
} catch (ConcurrentModificationException e) { |
|
239 |
throw e; |
|
240 |
} catch (ConcurrentDataModificationException e) { |
|
241 |
throw e; |
|
242 |
} catch (Exception e) { |
|
243 |
throw new RuntimeException(e); |
|
244 |
} finally { |
|
245 |
if (iterator != null) { |
|
246 |
iterator.dispose(); |
|
247 |
} |
|
248 |
if (set != null) { |
|
249 |
set.dispose(); |
|
250 |
} |
|
251 |
} |
|
252 |
this.fullEnvelope = fullEnvelope; |
|
253 |
this.isFullExtentDirty = false; |
|
254 |
return fullEnvelope; |
|
255 |
} |
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
public void cancelModifies() { |
|
260 |
if (noSpatialData) { |
|
261 |
return; |
|
262 |
} |
|
263 |
if (featureIndex != null){ |
|
264 |
for (int i = feaOperation.size()-1 ; i>=0 ; i--){ |
|
265 |
try { |
|
266 |
FeatureOperation fo = (FeatureOperation) feaOperation.get(i); |
|
267 |
if (fo.getOperation() == FeatureOperation.INSERT){ |
|
268 |
featureIndex.delete(fo.getFeatureReference().getFeature()); |
|
269 |
}else if (fo.getOperation() == FeatureOperation.DELETE){ |
|
270 |
featureIndex.insert(fo.getFeatureReference().getFeature()); |
|
271 |
} |
|
272 |
} catch (DataException e) { |
|
273 |
LOG.error("Error canceling the edition", e); |
|
274 |
} |
|
275 |
} |
|
276 |
} |
|
277 |
if (originalEnvelope!=null){ |
|
278 |
try { |
|
279 |
fullEnvelope = (Envelope) originalEnvelope.clone(); |
|
280 |
} catch (CloneNotSupportedException e) { |
|
281 |
// Should never happen |
|
282 |
LOG.error("While cloning envelope", e); |
|
283 |
} |
|
284 |
} else { |
|
285 |
fullEnvelope = null; |
|
286 |
} |
|
287 |
isFullExtentDirty = false; |
|
288 |
} |
|
289 |
|
|
290 |
private class FeatureOperation{ |
|
291 |
final static int INSERT=0; |
|
292 |
final static int DELETE=1; |
|
293 |
private FeatureReference ref; |
|
294 |
private int operation; |
|
295 |
public FeatureOperation(FeatureReference fe,int op){ |
|
296 |
ref=fe; |
|
297 |
operation=op; |
|
298 |
} |
|
299 |
public FeatureReference getFeatureReference() { |
|
300 |
return ref; |
|
301 |
} |
|
302 |
public void setFeatureReference(FeatureReference ref) { |
|
303 |
this.ref = ref; |
|
304 |
} |
|
305 |
public int getOperation() { |
|
306 |
return operation; |
|
307 |
} |
|
308 |
public void setOperation(int operation) { |
|
309 |
this.operation = operation; |
|
310 |
} |
|
311 |
} |
|
312 |
|
|
313 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/FeatureTypeManager.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify it under |
|
7 |
* the terms of the GNU General Public License as published by the Free Software |
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later |
|
9 |
* version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
14 |
* details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us at info AT |
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.fmap.dal.feature.impl; |
|
24 |
|
|
25 |
import java.lang.ref.WeakReference; |
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Arrays; |
|
28 |
import java.util.HashMap; |
|
29 |
import java.util.Iterator; |
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import org.gvsig.fmap.dal.exception.DataException; |
|
33 |
import org.gvsig.fmap.dal.feature.AbstractFeatureStoreTransform; |
|
34 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
35 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
36 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
37 |
import org.gvsig.fmap.dal.feature.Feature; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
40 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransform; |
|
41 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
42 |
import org.gvsig.fmap.dal.feature.impl.expansionadapter.ExpansionAdapter; |
|
43 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider.FeatureTypeChanged; |
|
44 |
import org.gvsig.tools.persistence.PersistentState; |
|
45 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
46 |
|
|
47 |
public class FeatureTypeManager { |
|
48 |
|
|
49 |
private ExpansionAdapter expansionAdapter; |
|
50 |
private ArrayList deleted = new ArrayList();// <FeatureID> |
|
51 |
private int deltaSize = 0; |
|
52 |
private HashMap added = new HashMap(); |
|
53 |
private HashMap modifiedFromOriginal = new HashMap(); |
|
54 |
private FeatureType originalType = null; |
|
55 |
private boolean first = true; |
|
56 |
private FeatureTypeManagerFeatureStoreTransforms transforms; |
|
57 |
private FeatureStore store; |
|
58 |
|
|
59 |
public FeatureTypeManager(FeatureStore store, |
|
60 |
ExpansionAdapter expansionAdapter) { |
|
61 |
this.expansionAdapter = expansionAdapter; |
|
62 |
this.store = store; |
|
63 |
this.transforms = new FeatureTypeManagerFeatureStoreTransforms(); |
|
64 |
this.transforms.setFeatureStore(store); |
|
65 |
} |
|
66 |
|
|
67 |
public void dispose() { |
|
68 |
this.expansionAdapter.close(); |
|
69 |
this.expansionAdapter = null; |
|
70 |
this.deleted.clear(); |
|
71 |
this.deleted = null; |
|
72 |
this.transforms.clear(); |
|
73 |
} |
|
74 |
|
|
75 |
public FeatureType getType(String id) throws DataException { |
|
76 |
Integer intNum = ((Integer) added.get(id)); |
|
77 |
if (intNum == null) { |
|
78 |
intNum = ((Integer) modifiedFromOriginal.get(id)); |
|
79 |
if (intNum == null) { |
|
80 |
return null; |
|
81 |
} |
|
82 |
} |
|
83 |
int num = intNum.intValue(); |
|
84 |
|
|
85 |
if (num == -1) { |
|
86 |
/* |
|
87 |
* This happens for example when we are going back to the |
|
88 |
* original feature type which is not managed by |
|
89 |
* expansionAdapter |
|
90 |
*/ |
|
91 |
return null; |
|
92 |
} |
|
93 |
|
|
94 |
FeatureType type = (FeatureType) expansionAdapter.getObject(num); |
|
95 |
return type; |
|
96 |
} |
|
97 |
|
|
98 |
public int update(FeatureType type, FeatureType oldType) { |
|
99 |
// deleted.add(oldType.getId()); |
|
100 |
if (first) { |
|
101 |
originalType = oldType; |
|
102 |
first = false; |
|
103 |
} |
|
104 |
int oldNum = -1; |
|
105 |
int num = expansionAdapter.addObject(type); |
|
106 |
String id = type.getId(); |
|
107 |
|
|
108 |
if (added.containsKey(id)) { |
|
109 |
oldNum = ((Integer) added.get(id)).intValue(); |
|
110 |
added.put(id, new Integer(num)); |
|
111 |
} else { |
|
112 |
if (modifiedFromOriginal.get(id) != null) { |
|
113 |
oldNum = ((Integer) modifiedFromOriginal.get(id)).intValue(); |
|
114 |
} |
|
115 |
modifiedFromOriginal.put(id, new Integer(num)); |
|
116 |
} |
|
117 |
|
|
118 |
try { |
|
119 |
this.transforms.add(new UpdateFeatureTypeTransform(this.store, |
|
120 |
oldType, type)); |
|
121 |
} catch (DataException e) { |
|
122 |
throw new RuntimeException(); // FIXME (pero esto no deberia de |
|
123 |
// pasar nunca) |
|
124 |
} |
|
125 |
return oldNum; |
|
126 |
} |
|
127 |
|
|
128 |
private class UpdateFeatureTypeTransform extends AbstractFeatureStoreTransform { |
|
129 |
|
|
130 |
private FeatureType ftSource; |
|
131 |
|
|
132 |
private EditableFeatureType ftTarget_editable; |
|
133 |
private FeatureType ftTarget_non_editable; |
|
134 |
|
|
135 |
private WeakReference wkRefStore; |
|
136 |
private List ftypes = null; |
|
137 |
private List attrInSourceToUse; |
|
138 |
|
|
139 |
UpdateFeatureTypeTransform(FeatureStore featureStore, |
|
140 |
FeatureType ftSource, FeatureType ftTarget) { |
|
141 |
this.ftSource = ftSource; |
|
142 |
|
|
143 |
if (ftTarget instanceof EditableFeatureType) { |
|
144 |
|
|
145 |
ftTarget_editable = (EditableFeatureType) ftTarget; |
|
146 |
ftTarget_non_editable = ftTarget_editable.getNotEditableCopy(); |
|
147 |
} else { |
|
148 |
ftTarget_non_editable = ftTarget; |
|
149 |
} |
|
150 |
|
|
151 |
this.wkRefStore = new WeakReference(featureStore); |
|
152 |
this.initializeAttributesToUse(); |
|
153 |
} |
|
154 |
|
|
155 |
private void initializeAttributesToUse() { |
|
156 |
attrInSourceToUse = new ArrayList(); |
|
157 |
|
|
158 |
Iterator iter = null; |
|
159 |
if (ftTarget_editable != null) { |
|
160 |
iter = ftTarget_editable.iterator(); |
|
161 |
} else { |
|
162 |
iter = ftTarget_non_editable.iterator(); |
|
163 |
} |
|
164 |
|
|
165 |
FeatureAttributeDescriptor tAttr, sAttr; |
|
166 |
EditableFeatureAttributeDescriptor ead = null; |
|
167 |
while (iter.hasNext()) { |
|
168 |
tAttr = (FeatureAttributeDescriptor) iter.next(); |
|
169 |
sAttr = this.ftSource.getAttributeDescriptor(tAttr.getName()); |
|
170 |
if (sAttr == null) { |
|
171 |
if (tAttr instanceof EditableFeatureAttributeDescriptor) { |
|
172 |
ead = (EditableFeatureAttributeDescriptor) tAttr; |
|
173 |
if (ead.getOriginalName() != null) { |
|
174 |
sAttr = this.ftSource.getAttributeDescriptor(ead.getOriginalName()); |
|
175 |
if (sAttr == null) { |
|
176 |
continue; |
|
177 |
} |
|
178 |
} else { |
|
179 |
continue; |
|
180 |
} |
|
181 |
} else { |
|
182 |
continue; |
|
183 |
} |
|
184 |
} |
|
185 |
if (tAttr.getType() != sAttr.getType()) { |
|
186 |
/* |
|
187 |
* Ignore if type is not the same (user removed field |
|
188 |
* and added another with same name but different type) |
|
189 |
*/ |
|
190 |
continue; |
|
191 |
} |
|
192 |
attrInSourceToUse.add(sAttr.getName()); |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
@Override |
|
197 |
public void setUp() throws Exception { |
|
198 |
|
|
199 |
} |
|
200 |
|
|
201 |
public void applyTransform(Feature source, EditableFeature target) |
|
202 |
throws DataException { |
|
203 |
|
|
204 |
Iterator iter = target.getType().iterator(); |
|
205 |
FeatureAttributeDescriptor tAttr; |
|
206 |
FeatureAttributeDescriptor tAttr_edi; |
|
207 |
FeatureAttributeDescriptor srcAtt; |
|
208 |
|
|
209 |
/* |
|
210 |
* field name in source feature |
|
211 |
*/ |
|
212 |
String s_name; |
|
213 |
|
|
214 |
/* |
|
215 |
* field name in target feature (the same as in source |
|
216 |
* except if renamed) |
|
217 |
*/ |
|
218 |
String t_name; |
|
219 |
|
|
220 |
EditableFeatureAttributeDescriptor eatd = null; |
|
221 |
while (iter.hasNext()) { |
|
222 |
tAttr = (FeatureAttributeDescriptor) iter.next(); |
|
223 |
|
|
224 |
if (ftTarget_editable != null) { |
|
225 |
/* |
|
226 |
* If target FT is editable, try to get original name |
|
227 |
*/ |
|
228 |
t_name = tAttr.getName(); |
|
229 |
s_name = t_name; |
|
230 |
tAttr_edi = ftTarget_editable.getAttributeDescriptor(t_name); |
|
231 |
if (tAttr_edi instanceof EditableFeatureAttributeDescriptor) { |
|
232 |
eatd = (EditableFeatureAttributeDescriptor) tAttr_edi; |
|
233 |
s_name = eatd.getOriginalName(); |
|
234 |
} |
|
235 |
|
|
236 |
/* |
|
237 |
* If not found, use normal name |
|
238 |
*/ |
|
239 |
if (s_name == null) { |
|
240 |
s_name = tAttr.getName(); |
|
241 |
} |
|
242 |
} else { |
|
243 |
/* |
|
244 |
* If target FT is not editable, use normal name |
|
245 |
*/ |
|
246 |
t_name = tAttr.getName(); |
|
247 |
s_name = t_name; |
|
248 |
} |
|
249 |
|
|
250 |
srcAtt = source.getType().getAttributeDescriptor(s_name); |
|
251 |
|
|
252 |
if (srcAtt != null |
|
253 |
&& /* |
|
254 |
* This prevents the case when user has removed field and |
|
255 |
* added new field with same name and different type. |
|
256 |
* In that case, value will be the default value (else below) |
|
257 |
*/ srcAtt.getType() == tAttr.getType()) { |
|
258 |
|
|
259 |
target.set(t_name, source.get(s_name)); |
|
260 |
|
|
261 |
} else { |
|
262 |
target.set(t_name, tAttr.getDefaultValue()); |
|
263 |
} |
|
264 |
} |
|
265 |
} |
|
266 |
|
|
267 |
public FeatureType getDefaultFeatureType() throws DataException { |
|
268 |
return this.ftTarget_non_editable; |
|
269 |
} |
|
270 |
|
|
271 |
public FeatureStore getFeatureStore() { |
|
272 |
return (FeatureStore) this.wkRefStore.get(); |
|
273 |
} |
|
274 |
|
|
275 |
public List getFeatureTypes() throws DataException { |
|
276 |
if (this.ftypes == null) { |
|
277 |
this.ftypes = Arrays |
|
278 |
.asList(new FeatureType[]{this.ftTarget_non_editable}); |
|
279 |
} |
|
280 |
return this.ftypes; |
|
281 |
} |
|
282 |
|
|
283 |
public FeatureType getSourceFeatureTypeFrom( |
|
284 |
FeatureType targetFeatureType) { |
|
285 |
EditableFeatureType orgType = ftSource.getEditable(); |
|
286 |
Iterator iter = orgType.iterator(); |
|
287 |
FeatureAttributeDescriptor attr; |
|
288 |
EditableFeatureAttributeDescriptor efad = null; |
|
289 |
|
|
290 |
while (iter.hasNext()) { |
|
291 |
attr = (FeatureAttributeDescriptor) iter.next(); |
|
292 |
if (!attrInSourceToUse.contains(attr.getName())) { |
|
293 |
if (attr instanceof EditableFeatureAttributeDescriptor) { |
|
294 |
efad = (EditableFeatureAttributeDescriptor) attr; |
|
295 |
if (efad.getOriginalName() != null |
|
296 |
&& !attrInSourceToUse.contains(efad.getOriginalName())) { |
|
297 |
iter.remove(); |
|
298 |
} |
|
299 |
} else { |
|
300 |
iter.remove(); |
|
301 |
} |
|
302 |
} |
|
303 |
} |
|
304 |
return orgType.getNotEditableCopy(); |
|
305 |
} |
|
306 |
|
|
307 |
public void setFeatureStore(FeatureStore featureStore) { |
|
308 |
this.wkRefStore = new WeakReference(featureStore); |
|
309 |
} |
|
310 |
|
|
311 |
public boolean isTransformsOriginalValues() { |
|
312 |
return false; |
|
313 |
} |
|
314 |
|
|
315 |
} |
|
316 |
|
|
317 |
public void restore(String id) { |
|
318 |
deleted.remove(id); |
|
319 |
deltaSize++; |
|
320 |
} |
|
321 |
|
|
322 |
public void restore(String id, int num) { |
|
323 |
if (added.containsKey(id)) { |
|
324 |
added.put(id, new Integer(num)); |
|
325 |
} else { |
|
326 |
modifiedFromOriginal.put(id, new Integer(num)); |
|
327 |
} |
|
328 |
} |
|
329 |
|
|
330 |
public boolean isDeleted(FeatureType type) { |
|
331 |
return deleted.contains(type.getId()); |
|
332 |
} |
|
333 |
|
|
334 |
public boolean isDeleted(String id) { |
|
335 |
return deleted.contains(id); |
|
336 |
} |
|
337 |
|
|
338 |
public void clear() { |
|
339 |
added.clear(); |
|
340 |
modifiedFromOriginal.clear(); |
|
341 |
expansionAdapter.close(); |
|
342 |
deleted.clear();// <FeatureID> |
|
343 |
deltaSize = 0; |
|
344 |
} |
|
345 |
|
|
346 |
public boolean hasChanges() { |
|
347 |
return added.size() > 0 || modifiedFromOriginal.size() > 0 |
|
348 |
|| deleted.size() > 0; |
|
349 |
} |
|
350 |
|
|
351 |
public Iterator newsIterator() { |
|
352 |
return added.values().iterator(); |
|
353 |
} |
|
354 |
|
|
355 |
public boolean hasNews() { |
|
356 |
return !added.isEmpty(); |
|
357 |
} |
|
358 |
|
|
359 |
public long getDeltaSize() { |
|
360 |
return deltaSize; |
|
361 |
} |
|
362 |
|
|
363 |
public FeatureType getOriginalFeatureType() { |
|
364 |
return originalType; |
|
365 |
} |
|
366 |
|
|
367 |
public DefaultFeatureStoreTransforms getTransforms() { |
|
368 |
return this.transforms; |
|
369 |
} |
|
370 |
|
|
371 |
public class FeatureTypeManagerFeatureStoreTransforms extends |
|
372 |
DefaultFeatureStoreTransforms { |
|
373 |
|
|
374 |
private FeatureTypeManagerFeatureStoreTransforms() { |
|
375 |
|
|
376 |
} |
|
377 |
|
|
378 |
protected void checkEditingMode() { |
|
379 |
} |
|
380 |
|
|
381 |
protected void notifyChangeToStore() { |
|
382 |
} |
|
383 |
|
|
384 |
public PersistentState getState() throws PersistenceException { |
|
385 |
// FIXME |
|
386 |
throw new UnsupportedOperationException(); |
|
387 |
} |
|
388 |
|
|
389 |
public void loadState(PersistentState state) |
|
390 |
throws PersistenceException { |
|
391 |
// FIXME |
|
392 |
throw new UnsupportedOperationException(); |
|
393 |
} |
|
394 |
|
|
395 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
396 |
// FIXME |
|
397 |
throw new UnsupportedOperationException(); |
|
398 |
} |
|
399 |
|
|
400 |
public FeatureStoreTransform add(FeatureStoreTransform transform) |
|
401 |
throws DataException { |
|
402 |
if (!(transform instanceof UpdateFeatureTypeTransform)) { |
|
403 |
// FIXME |
|
404 |
throw new IllegalArgumentException(); |
|
405 |
} |
|
406 |
return super.add(transform); |
|
407 |
} |
|
408 |
|
|
409 |
} |
|
410 |
|
|
411 |
public class FeatureTypesChangedItem implements FeatureTypeChanged { |
|
412 |
|
|
413 |
private FeatureType source; |
|
414 |
private FeatureType target; |
|
415 |
|
|
416 |
public FeatureTypesChangedItem(FeatureType source, FeatureType target) { |
|
417 |
this.source = source; |
|
418 |
this.target = target; |
|
419 |
} |
|
420 |
|
|
421 |
public FeatureType getSource() { |
|
422 |
return source; |
|
423 |
} |
|
424 |
|
|
425 |
public FeatureType getTarget() { |
|
426 |
return target; |
|
427 |
} |
|
428 |
|
|
429 |
} |
|
430 |
|
|
431 |
public Iterator getFeatureTypesChanged() throws DataException { |
|
432 |
// FIXME this don't work for Store.fType.size() > 1 |
|
433 |
List list = new ArrayList(); |
|
434 |
if (modifiedFromOriginal.size() > 0) { |
|
435 |
FeatureType src = this.getOriginalFeatureType(); |
|
436 |
list.add(new FeatureTypesChangedItem(src, this.store |
|
437 |
.getFeatureType(src.getId()))); |
|
438 |
} |
|
439 |
return list.iterator(); |
|
440 |
} |
|
441 |
|
|
442 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/featureset/EditedIterator.java | ||
---|---|---|
31 | 31 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
32 | 32 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReference; |
33 | 33 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
34 |
import org.gvsig.fmap.dal.feature.impl.FeatureManager; |
|
34 |
import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureManager;
|
|
35 | 35 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
36 | 36 |
import org.gvsig.tools.dispose.DisposableIterator; |
37 | 37 |
import org.gvsig.tools.exception.BaseException; |
branches/org.gvsig.desktop-2018a/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 | ||
---|---|---|
24 | 24 |
|
25 | 25 |
package org.gvsig.fmap.dal.feature.impl; |
26 | 26 |
|
27 |
import org.gvsig.fmap.dal.feature.impl.editing.memory.SpatialManager; |
|
28 |
import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureTypeManager; |
|
29 |
import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureManager; |
|
27 | 30 |
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase; |
28 | 31 |
|
29 | 32 |
import java.util.ArrayList; |
... | ... | |
108 | 111 |
import org.gvsig.fmap.dal.feature.exception.StoreUpdateFeatureTypeException; |
109 | 112 |
import org.gvsig.fmap.dal.feature.exception.ValidateFeaturesException; |
110 | 113 |
import org.gvsig.fmap.dal.feature.exception.WriteNotAllowedException; |
111 |
import org.gvsig.fmap.dal.feature.impl.expansionadapter.MemoryExpansionAdapter; |
|
112 | 114 |
import org.gvsig.fmap.dal.feature.impl.featureset.DefaultFeatureSet; |
113 | 115 |
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DynObjectFeatureFacade; |
114 | 116 |
import org.gvsig.fmap.dal.feature.impl.undo.DefaultFeatureCommandsStack; |
... | ... | |
180 | 182 |
new DelegateWeakReferencingObservable(this); |
181 | 183 |
|
182 | 184 |
private FeatureCommandsStack commands; |
185 |
|
|
186 |
/* |
|
187 |
TODO: Sustituir estos tres manager por un EditingManager |
|
188 |
*/ |
|
183 | 189 |
private FeatureTypeManager featureTypeManager; |
184 | 190 |
private FeatureManager featureManager; |
185 | 191 |
private SpatialManager spatialManager; |
... | ... | |
222 | 228 |
private boolean broken; |
223 | 229 |
private Throwable breakingsCause; |
224 | 230 |
|
231 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
225 | 232 |
public StateInformation() { |
226 | 233 |
this.clear(); |
227 | 234 |
} |
... | ... | |
477 | 484 |
} |
478 | 485 |
|
479 | 486 |
/** |
487 |
* @throws org.gvsig.fmap.dal.exception.DataException |
|
480 | 488 |
* @deprecated use getDefaultFeatureType().getDefaultSRS() |
481 | 489 |
*/ |
482 | 490 |
@Override |
... | ... | |
1075 | 1083 |
} |
1076 | 1084 |
notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING); |
1077 | 1085 |
invalidateIndexes(); |
1078 |
featureManager = |
|
1079 |
new FeatureManager(new MemoryExpansionAdapter()); |
|
1080 |
featureTypeManager = |
|
1081 |
new FeatureTypeManager(this, new MemoryExpansionAdapter()); |
|
1082 |
spatialManager = |
|
1083 |
new SpatialManager(this, provider.getEnvelope()); |
|
1086 |
featureManager = new FeatureManager(); |
|
1087 |
featureTypeManager = new FeatureTypeManager(this); |
|
1088 |
spatialManager = new SpatialManager(this, provider.getEnvelope()); |
|
1084 | 1089 |
|
1085 |
commands = |
|
1086 |
new DefaultFeatureCommandsStack(this, featureManager,
|
|
1090 |
commands = new DefaultFeatureCommandsStack(
|
|
1091 |
this, featureManager,
|
|
1087 | 1092 |
spatialManager, featureTypeManager); |
1088 | 1093 |
this.mode = MODE_FULLEDIT; |
1089 | 1094 |
hasStrongChanges = false; |
... | ... | |
1515 | 1520 |
featureTypeManager.getFeatureTypesChanged()); |
1516 | 1521 |
} |
1517 | 1522 |
invalidateIndexes(); |
1518 |
featureManager = |
|
1519 |
new FeatureManager(new MemoryExpansionAdapter()); |
|
1520 |
featureTypeManager = |
|
1521 |
new FeatureTypeManager(this, new MemoryExpansionAdapter()); |
|
1522 |
spatialManager = |
|
1523 |
new SpatialManager(this, provider.getEnvelope()); |
|
1523 |
featureManager = new FeatureManager(); |
|
1524 |
featureTypeManager = new FeatureTypeManager(this); |
|
1525 |
spatialManager = new SpatialManager(this, provider.getEnvelope()); |
|
1524 | 1526 |
|
1525 | 1527 |
commands = |
1526 | 1528 |
new DefaultFeatureCommandsStack(this, featureManager, |
... | ... | |
1606 | 1608 |
FeatureType targetType = target.getDefaultFeatureType(); |
1607 | 1609 |
|
1608 | 1610 |
target.edit(MODE_APPEND); |
1609 |
FeatureAttributeDescriptor[] pk = type.getPrimaryKey(); |
|
1611 |
FeatureAttributeDescriptor[] pkattrs = type.getPrimaryKey();
|
|
1610 | 1612 |
if (featureSelection.getSize() > 0) { |
1611 | 1613 |
features = this.getFeatureSelection(); |
1612 | 1614 |
} else { |
1613 |
if ((pk != null) && (pk.length > 0)) {
|
|
1615 |
if ((pkattrs != null) && (pkattrs.length > 0)) {
|
|
1614 | 1616 |
FeatureQuery query = createFeatureQuery(); |
1615 |
for (int i = 0; i < pk.length; i++) {
|
|
1616 |
query.getOrder().add(pk[i].getName(), true);
|
|
1617 |
for (FeatureAttributeDescriptor pkattr : pkattrs) {
|
|
1618 |
query.getOrder().add(pkattr.getName(), true);
|
|
1617 | 1619 |
} |
1618 | 1620 |
features = this.getFeatureSet(query); |
1619 | 1621 |
} else { |
... | ... | |
2438 | 2440 |
try{ |
2439 | 2441 |
throw new IllegalStateException(); |
2440 | 2442 |
} catch(IllegalStateException e) { |
2441 |
LOG.info("Call DefaultFeatureStore.getFeatureCount editing in mode APPEND"); |
|
2442 |
e.printStackTrace(); |
|
2443 |
LOG.info("Call DefaultFeatureStore.getFeatureCount editing in mode APPEND",e); |
|
2443 | 2444 |
} |
2444 | 2445 |
return -1; |
2445 | 2446 |
} else { |
... | ... | |
2620 | 2621 |
} |
2621 | 2622 |
|
2622 | 2623 |
@Override |
2624 |
@SuppressWarnings("CloneDoesntCallSuperClone") |
|
2623 | 2625 |
public Object clone() throws CloneNotSupportedException { |
2624 | 2626 |
|
2625 | 2627 |
DataStoreParameters dsp = getParameters(); |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/EditingManager.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.fmap.dal.feature.impl; |
|
3 |
|
|
4 |
import java.util.Iterator; |
|
5 |
import org.gvsig.fmap.dal.exception.DataException; |
|
6 |
import org.gvsig.fmap.dal.feature.Feature; |
|
7 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
8 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
9 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
10 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
11 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider.FeatureTypeChanged; |
|
12 |
|
|
13 |
|
|
14 |
public interface EditingManager { |
|
15 |
/* |
|
16 |
Este interface, con el tiempo deberia ir al SPI. |
|
17 |
|
|
18 |
Tendria que sustituir a: |
|
19 |
- FeatureManager |
|
20 |
- FeatureTypeManager |
|
21 |
- SpatialManager |
|
22 |
como mecanismos para guardar los datos mientras se esta en edicion. |
|
23 |
|
|
24 |
Habria que eliminar estos managers del DefaultFeatureStore y sustituirlos |
|
25 |
por este. |
|
26 |
|
|
27 |
En una primera implementacion, se mantendrian estos managers como parte interna |
|
28 |
de la implementacion del MemoryEditingManager. |
|
29 |
|
|
30 |
*/ |
|
31 |
|
|
32 |
public void dispose(); |
|
33 |
|
|
34 |
public void delete(Feature feature); |
|
35 |
|
|
36 |
public void delete(FeatureReference featureReference); |
|
37 |
|
|
38 |
public void add(Feature newFeature); |
|
39 |
|
|
40 |
public int update(Feature newFeature, Feature oldFeature); |
|
41 |
|
|
42 |
public int update(FeatureType type, FeatureType oldType); |
|
43 |
|
|
44 |
public void restore(FeatureReference featureReference); |
|
45 |
|
|
46 |
public void restore(FeatureReference featureReference, int code); |
|
47 |
|
|
48 |
public void restore(String featureTypeId); |
|
49 |
|
|
50 |
public void restore(String featureTypeId, int code); |
|
51 |
|
|
52 |
public boolean isDeleted(Feature feature); |
|
53 |
|
|
54 |
public boolean isDeleted(FeatureReference featureReference); |
|
55 |
|
|
56 |
public boolean isDeleted(FeatureType type); |
|
57 |
|
|
58 |
public boolean isDeleted(String featureTypeId); |
|
59 |
|
|
60 |
public boolean isSelectionCompromised(); |
|
61 |
|
|
62 |
public Iterator<FeatureProvider> getDeletedFeatures(); |
|
63 |
public Iterator<FeatureProvider> getInsertedFeatures(); |
|
64 |
public Iterator<FeatureProvider> getUpdatedFeatures(); |
|
65 |
|
|
66 |
public Iterator<FeatureTypeChanged> getFeatureTypesChanged() throws DataException; |
|
67 |
|
|
68 |
public FeatureType getFeatureType(String id) throws DataException ; |
|
69 |
|
|
70 |
public Feature getFeature(FeatureReference reference, FeatureStore store, FeatureType type) throws DataException; |
|
71 |
|
|
72 |
|
|
73 |
/* |
|
74 |
it = featureTypeManager.newsIterator(); |
|
75 |
|
|
76 |
position = expansionManager.update(type, oldType); |
|
77 |
|
|
78 |
expansionManager.restore(oldType.getId(),position); |
|
79 |
|
|
80 |
spatialManager.cancelModifies(); |
|
81 |
*/ |
|
82 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/undo/command/FTypeUpdateCommand.java | ||
---|---|---|
24 | 24 |
package org.gvsig.fmap.dal.feature.impl.undo.command; |
25 | 25 |
|
26 | 26 |
import org.gvsig.fmap.dal.feature.FeatureType; |
27 |
import org.gvsig.fmap.dal.feature.impl.FeatureTypeManager; |
|
27 |
import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureTypeManager;
|
|
28 | 28 |
import org.gvsig.tools.undo.RedoException; |
29 | 29 |
import org.gvsig.tools.undo.UndoException; |
30 | 30 |
|
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/undo/command/AbstractFTypeCommand.java | ||
---|---|---|
25 | 25 |
package org.gvsig.fmap.dal.feature.impl.undo.command; |
26 | 26 |
|
27 | 27 |
import org.gvsig.fmap.dal.feature.FeatureType; |
28 |
import org.gvsig.fmap.dal.feature.impl.FeatureTypeManager; |
|
28 |
import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureTypeManager;
|
|
29 | 29 |
import org.gvsig.tools.undo.command.impl.AbstractCommand; |
30 | 30 |
|
31 | 31 |
/** |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/undo/DefaultFeatureCommandsStack.java | ||
---|---|---|
30 | 30 |
import org.gvsig.fmap.dal.feature.FeatureType; |
31 | 31 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection; |
32 | 32 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
33 |
import org.gvsig.fmap.dal.feature.impl.FeatureManager; |
|
34 |
import org.gvsig.fmap.dal.feature.impl.FeatureTypeManager; |
|
35 |
import org.gvsig.fmap.dal.feature.impl.SpatialManager; |
|
33 |
import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureManager;
|
|
34 |
import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureTypeManager;
|
|
35 |
import org.gvsig.fmap.dal.feature.impl.editing.memory.SpatialManager;
|
|
36 | 36 |
import org.gvsig.fmap.dal.feature.impl.undo.command.FTypeUpdateCommand; |
37 | 37 |
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureDeleteCommand; |
38 | 38 |
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureInsertCommand; |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/FLayers.java | ||
---|---|---|
946 | 946 |
public void accept(Visitor visitor) throws BaseException { |
947 | 947 |
for (int i = 0; i < this.getLayersCount(); i++) { |
948 | 948 |
FLayer layer = this.getLayer(i); |
949 |
try { |
|
949 |
// try {
|
|
950 | 950 |
if (layer instanceof LayersVisitable) { |
951 | 951 |
((LayersVisitable) layer).accept(visitor); |
952 | 952 |
} else { |
953 | 953 |
visitor.visit(layer); |
954 | 954 |
} |
955 |
} catch (VisitCanceledException ex) { |
|
956 |
break; |
|
957 |
} |
|
955 |
// } catch (VisitCanceledException ex) {
|
|
956 |
// break;
|
|
957 |
// }
|
|
958 | 958 |
} |
959 | 959 |
} |
960 | 960 |
|
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.framework/org.gvsig.andami/src/main/resources-application/LEEME.txt | ||
---|---|---|
1 |
gvSIG Desktop v2.2.0.
|
|
1 |
gvSIG Desktop v2.4.1.
|
|
2 | 2 |
|
3 | 3 |
- (c) Asociaci?n gvSIG |
4 | 4 |
- Software con licencia GNU/GPL (http://www.fsf.org/licensing/licenses/gpl.html) |
... | ... | |
9 | 9 |
|
10 | 10 |
Sistema |
11 | 11 |
- M?nimos: Intel/AMD - 512 MB RAM. |
12 |
- Sistemas operativos: plataformas Windows y Linux. Probado en Windows XP, Linux Ubuntu/Debian.
|
|
12 |
- Sistemas operativos: plataformas Windows, Linux y Mac. Probado en Windows 10, Linux Ubuntu/Debian.
|
|
13 | 13 |
|
14 | 14 |
Software instalado (disponible en http://www.oracle.com) |
15 |
- M?quina Virtual Java 1.6.0 ? superior (En Windows 8 m?nimo Java 1.7.0).
|
|
15 |
- M?quina Virtual Java 1.8.0.
|
|
16 | 16 |
|
17 | 17 |
|
18 | 18 |
M?s informaci?n y soporte en: |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.framework/org.gvsig.andami/src/main/resources-application/README.txt | ||
---|---|---|
1 |
gvSIG Desktop v2.2.0.
|
|
1 |
gvSIG Desktop v2.4.1.
|
|
2 | 2 |
|
3 | 3 |
- (c) gvSIG Association |
4 | 4 |
- Software under GNU/GPL license (http://www.fsf.org/licensing/licenses/gpl.html) |
... | ... | |
9 | 9 |
|
10 | 10 |
System |
11 | 11 |
- At least: Intel/AMD - 512 MB RAM. |
12 |
- Operative Systems: platforms Windows and Linux. Tested in Windows XP, Linux Ubuntu/Debian.
|
|
12 |
- Operative Systems: platforms Windows, Linux and Mac. Tested in Windows 10, Linux Ubuntu/Debian.
|
|
13 | 13 |
|
14 | 14 |
Installed software (available at http://www.oracle.com) |
15 |
- Java VM 1.6.0 or higher (Java 1.7.0 in Windows 8).
|
|
15 |
- Java VM 1.8.0.
|
|
16 | 16 |
|
17 | 17 |
Further information and support: |
18 | 18 |
|
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/ui/mdiFrame/MDIFrame.java | ||
---|---|---|
69 | 69 |
import javax.swing.Timer; |
70 | 70 |
import javax.swing.WindowConstants; |
71 | 71 |
import javax.swing.filechooser.FileFilter; |
Also available in: Unified diff