gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.impl / src / main / java / org / gvsig / vectorediting / lib / impl / DefaultEditingProviderServices.java @ 68
History | View | Annotate | Download (9.63 KB)
1 |
/*
|
---|---|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved.
|
3 |
*
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.impl
|
5 |
* SVN Id : $Id$
|
6 |
*/
|
7 |
package org.gvsig.vectorediting.lib.impl; |
8 |
|
9 |
import java.awt.geom.Point2D; |
10 |
import java.util.Iterator; |
11 |
|
12 |
import org.gvsig.andami.messages.NotificationManager; |
13 |
import org.gvsig.editing.EditingNotification; |
14 |
import org.gvsig.editing.EditingNotificationManager; |
15 |
import org.gvsig.fmap.dal.exception.DataException; |
16 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
17 |
import org.gvsig.fmap.dal.feature.Feature; |
18 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
19 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
20 |
import org.gvsig.fmap.dal.feature.FeatureType; |
21 |
import org.gvsig.fmap.geom.Geometry; |
22 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
23 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
24 |
import org.gvsig.fmap.geom.GeometryLocator; |
25 |
import org.gvsig.fmap.geom.GeometryManager; |
26 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
27 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
28 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
29 |
import org.gvsig.fmap.geom.primitive.Arc; |
30 |
import org.gvsig.fmap.geom.primitive.Circle; |
31 |
import org.gvsig.fmap.geom.primitive.Curve; |
32 |
import org.gvsig.fmap.geom.primitive.Point; |
33 |
import org.gvsig.fmap.geom.type.GeometryType; |
34 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
35 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
36 |
import org.gvsig.tools.service.spi.AbstractProviderServices; |
37 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
38 |
|
39 |
public class DefaultEditingProviderServices extends AbstractProviderServices |
40 |
implements EditingProviderServices {
|
41 |
|
42 |
protected GeometryManager geomManager = GeometryLocator
|
43 |
.getGeometryManager(); |
44 |
|
45 |
public void insertFeatureIntoFeatureStore(Feature feature, |
46 |
FeatureStore featureStore) { |
47 |
try {
|
48 |
EditableFeature eFeature; |
49 |
|
50 |
if (feature instanceof EditableFeature){ |
51 |
eFeature = (EditableFeature)feature; |
52 |
} else {
|
53 |
eFeature = feature.getEditable(); |
54 |
} |
55 |
|
56 |
EditingNotificationManager editingNotificationManager = MapControlLocator |
57 |
.getEditingNotificationManager(); |
58 |
|
59 |
EditingNotification notification = editingNotificationManager |
60 |
.notifyObservers(this, // source |
61 |
EditingNotification.BEFORE_INSERT_FEATURE, // type
|
62 |
null,// document |
63 |
null,// layer |
64 |
featureStore,// store
|
65 |
eFeature// feature
|
66 |
); |
67 |
if (notification.isCanceled()) {
|
68 |
throw new CancelationException(""); |
69 |
} |
70 |
|
71 |
//FIXME: Este m?todo est? hecho al rev?s. Cuando est? corregido en EditingNotification, deber?a quitarse el !
|
72 |
if (!notification.shouldValidateTheFeature()) {
|
73 |
if (!editingNotificationManager.validateFeature(eFeature)) {
|
74 |
throw new Exception(""); |
75 |
} |
76 |
} |
77 |
|
78 |
featureStore.insert(eFeature); |
79 |
editingNotificationManager.notifyObservers(this,
|
80 |
EditingNotification.AFTER_INSERT_FEATURE, null, null, |
81 |
featureStore, eFeature); |
82 |
} catch (Exception e) { |
83 |
NotificationManager.addError(e.getMessage(), e); |
84 |
} |
85 |
} |
86 |
|
87 |
public void insertGeometryIntoFeatureStore(Geometry geometry, |
88 |
FeatureStore featureStore) { |
89 |
try {
|
90 |
EditableFeature eFeature = featureStore.createNewFeature(true);
|
91 |
|
92 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
93 |
.getDefaultGeometryAttributeName(), geometry); |
94 |
|
95 |
EditingNotificationManager editingNotificationManager = MapControlLocator |
96 |
.getEditingNotificationManager(); |
97 |
|
98 |
EditingNotification notification = editingNotificationManager |
99 |
.notifyObservers(this, // source |
100 |
EditingNotification.BEFORE_INSERT_FEATURE, // type
|
101 |
null,// document |
102 |
null,// layer |
103 |
featureStore,// store
|
104 |
eFeature// feature
|
105 |
); |
106 |
if (notification.isCanceled()) {
|
107 |
throw new CancelationException(""); |
108 |
} |
109 |
//FIXME: Este m?todo est? hecho al rev?s. Cuando est? corregido en EditingNotification, deber?a quitarse el !
|
110 |
if (!notification.shouldValidateTheFeature()) {
|
111 |
if (!editingNotificationManager.validateFeature(eFeature)) {
|
112 |
throw new Exception(""); |
113 |
} |
114 |
} |
115 |
|
116 |
featureStore.insert(eFeature); |
117 |
|
118 |
editingNotificationManager.notifyObservers(this,
|
119 |
EditingNotification.AFTER_INSERT_FEATURE, null, null, featureStore, |
120 |
eFeature); |
121 |
|
122 |
} |
123 |
catch (Exception e) { |
124 |
NotificationManager.addError(e.getMessage(), e); |
125 |
} |
126 |
} |
127 |
|
128 |
public void deleteFeatureFromFeatureStore(Feature feature, |
129 |
FeatureStore featureStore) { |
130 |
// TODO Auto-generated method stub
|
131 |
|
132 |
} |
133 |
|
134 |
public void deleteGeometryFromFeatureStore(Geometry geometry, |
135 |
FeatureStore featureStore) { |
136 |
// TODO Auto-generated method stub
|
137 |
|
138 |
} |
139 |
|
140 |
public void updateFeatureInFeatureStore(Feature feature, |
141 |
FeatureStore featureStore) { |
142 |
try {
|
143 |
EditableFeature eFeature; |
144 |
|
145 |
if (feature instanceof EditableFeature){ |
146 |
eFeature = (EditableFeature)feature; |
147 |
} else {
|
148 |
eFeature = feature.getEditable(); |
149 |
} |
150 |
|
151 |
EditingNotificationManager editingNotificationManager = MapControlLocator |
152 |
.getEditingNotificationManager(); |
153 |
|
154 |
EditingNotification notification = editingNotificationManager |
155 |
.notifyObservers(this, // source |
156 |
EditingNotification.BEFORE_UPDATE_FEATURE, // type
|
157 |
null,// document |
158 |
null,// layer |
159 |
featureStore,// store
|
160 |
eFeature// feature
|
161 |
); |
162 |
if (notification.isCanceled()) {
|
163 |
throw new CancelationException(""); |
164 |
} |
165 |
//FIXME: Este m?todo est? hecho al rev?s. Cuando est? corregido en EditingNotification, deber?a quitarse el !
|
166 |
if (!notification.shouldValidateTheFeature()) {
|
167 |
if (!editingNotificationManager.validateFeature(eFeature)) {
|
168 |
throw new Exception(""); |
169 |
} |
170 |
} |
171 |
|
172 |
featureStore.update(eFeature); |
173 |
editingNotificationManager.notifyObservers(this,
|
174 |
EditingNotification.AFTER_UPDATE_FEATURE, null, null, |
175 |
featureStore, eFeature); |
176 |
} catch (Exception e) { |
177 |
NotificationManager.addError(e.getMessage(), e); |
178 |
} |
179 |
} |
180 |
|
181 |
public void updateGeometryInFeatureStore(Geometry geometry, |
182 |
FeatureStore featureStore) { |
183 |
// TODO Auto-generated method stub
|
184 |
|
185 |
} |
186 |
|
187 |
public Circle createCircle(Point2D p1, Point2D p2, FeatureStore featureStore) |
188 |
throws CreateGeometryException, DataException {
|
189 |
Point centro = createPoint(p1.getX(), p1.getY(), featureStore);
|
190 |
Point radio = createPoint(p2.getX(), p2.getY(), featureStore);
|
191 |
return createCircle(centro, radio, featureStore);
|
192 |
} |
193 |
|
194 |
public Circle createCircle(Point p1, Point p2, FeatureStore featureStore) |
195 |
throws CreateGeometryException, DataException {
|
196 |
Circle circle = null;
|
197 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
198 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, |
199 |
featStoreGeomType.getSubType()); |
200 |
circle.setPoints(p1, p2); |
201 |
|
202 |
return circle;
|
203 |
} |
204 |
|
205 |
public Circle createCircle(Point center, double radius, |
206 |
FeatureStore featureStore) |
207 |
throws CreateGeometryException, DataException {
|
208 |
Circle circle = null;
|
209 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
210 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, |
211 |
featStoreGeomType.getSubType()); |
212 |
circle.setPoints(center, radius); |
213 |
|
214 |
return circle;
|
215 |
} |
216 |
|
217 |
public Arc createArc(Point center, double radius, double startAngle, |
218 |
double angleExt, FeatureStore featureStore)
|
219 |
throws CreateGeometryException, DataException {
|
220 |
Arc arc = null;
|
221 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
222 |
arc = (Arc) geomManager.create(TYPES.ARC, featStoreGeomType.getSubType()); |
223 |
arc.setPoints(center, radius, startAngle, angleExt); |
224 |
return arc;
|
225 |
} |
226 |
|
227 |
public Arc createArc(Point p1, Point midPoint, Point p2, |
228 |
FeatureStore featureStore) |
229 |
throws CreateGeometryException, DataException,
|
230 |
GeometryOperationNotSupportedException, GeometryOperationException { |
231 |
Arc arc = null;
|
232 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
233 |
arc = (Arc) geomManager.create(TYPES.ARC, featStoreGeomType.getSubType()); |
234 |
arc.setPoints(p1, midPoint, p2); |
235 |
return arc;
|
236 |
} |
237 |
|
238 |
public Point createPoint(double x, double y, FeatureStore featureStore) |
239 |
throws CreateGeometryException, DataException {
|
240 |
Point point = null; |
241 |
point = (Point) geomManager.create(TYPES.POINT, getSubType(featureStore));
|
242 |
point.setX(x); |
243 |
point.setY(y); |
244 |
return point;
|
245 |
} |
246 |
|
247 |
public Curve createLine(double x1, double y1, double x2, double y2, |
248 |
FeatureStore featureStore) |
249 |
throws CreateGeometryException, DataException {
|
250 |
Curve line = null;
|
251 |
line = (Curve) geomManager.create(TYPES.CURVE, getSubType(featureStore)); |
252 |
line.addVertex(x1, y1); |
253 |
line.addVertex(x2, y2); |
254 |
return line;
|
255 |
} |
256 |
|
257 |
public int getSubType(FeatureStore featureStore) throws DataException { |
258 |
|
259 |
GeometryType geomType = getGeomType(featureStore); |
260 |
if (geomType != null) { |
261 |
return geomType.getSubType();
|
262 |
} |
263 |
return SUBTYPES.GEOM3D; // ??????? |
264 |
} |
265 |
|
266 |
public GeometryType getGeomType(FeatureStore featureStore)
|
267 |
throws DataException {
|
268 |
return featureStore.getDefaultFeatureType().getDefaultGeometryAttribute()
|
269 |
.getGeomType(); |
270 |
} |
271 |
|
272 |
public EditableFeature getFeatureCopyWithoutPK(FeatureStore featureStore, Feature feature)
|
273 |
throws DataException {
|
274 |
EditableFeature editableFeature = featureStore.createNewFeature( |
275 |
feature.getType(), true);
|
276 |
|
277 |
FeatureType type_src = feature.getType(); |
278 |
@SuppressWarnings("rawtypes") |
279 |
Iterator iterator = type_src.iterator();
|
280 |
FeatureType type_dest = editableFeature.getType(); |
281 |
|
282 |
while (iterator.hasNext()) {
|
283 |
FeatureAttributeDescriptor attribute_src = (FeatureAttributeDescriptor) iterator |
284 |
.next(); |
285 |
|
286 |
FeatureAttributeDescriptor attribute_dest = type_dest |
287 |
.getAttributeDescriptor(attribute_src.getName()); |
288 |
if (attribute_dest != null) { |
289 |
if (!attribute_dest.isPrimaryKey()) {
|
290 |
editableFeature.set(attribute_dest.getIndex(), |
291 |
feature.get(attribute_src.getIndex())); |
292 |
} |
293 |
} |
294 |
} |
295 |
return editableFeature;
|
296 |
} |
297 |
|
298 |
|
299 |
} |