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 @ 74
History | View | Annotate | Download (8.53 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(Point center, double radius, |
188 |
FeatureStore featureStore) |
189 |
throws CreateGeometryException, DataException {
|
190 |
Circle circle = null;
|
191 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
192 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, |
193 |
featStoreGeomType.getSubType()); |
194 |
circle.setPoints(center, radius); |
195 |
|
196 |
return circle;
|
197 |
} |
198 |
|
199 |
public Arc createArc(Point center, double radius, double startAngle, |
200 |
double angleExt, FeatureStore featureStore)
|
201 |
throws CreateGeometryException, DataException {
|
202 |
Arc arc = null;
|
203 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
204 |
arc = (Arc) geomManager.create(TYPES.ARC, featStoreGeomType.getSubType()); |
205 |
arc.setPoints(center, radius, startAngle, angleExt); |
206 |
return arc;
|
207 |
} |
208 |
|
209 |
public Point createPoint(double x, double y, FeatureStore featureStore) |
210 |
throws CreateGeometryException, DataException {
|
211 |
Point point = null; |
212 |
point = (Point) geomManager.create(TYPES.POINT, getSubType(featureStore));
|
213 |
point.setX(x); |
214 |
point.setY(y); |
215 |
return point;
|
216 |
} |
217 |
|
218 |
public Curve createLine(double x1, double y1, double x2, double y2, |
219 |
FeatureStore featureStore) |
220 |
throws CreateGeometryException, DataException {
|
221 |
Curve line = null;
|
222 |
line = (Curve) geomManager.create(TYPES.CURVE, getSubType(featureStore)); |
223 |
line.addVertex(x1, y1); |
224 |
line.addVertex(x2, y2); |
225 |
return line;
|
226 |
} |
227 |
|
228 |
public int getSubType(FeatureStore featureStore) throws DataException { |
229 |
|
230 |
GeometryType geomType = getGeomType(featureStore); |
231 |
if (geomType != null) { |
232 |
return geomType.getSubType();
|
233 |
} |
234 |
return SUBTYPES.GEOM3D; // ??????? |
235 |
} |
236 |
|
237 |
public GeometryType getGeomType(FeatureStore featureStore)
|
238 |
throws DataException {
|
239 |
return featureStore.getDefaultFeatureType().getDefaultGeometryAttribute()
|
240 |
.getGeomType(); |
241 |
} |
242 |
|
243 |
public EditableFeature getFeatureCopyWithoutPK(FeatureStore featureStore, Feature feature)
|
244 |
throws DataException {
|
245 |
EditableFeature editableFeature = featureStore.createNewFeature( |
246 |
feature.getType(), true);
|
247 |
|
248 |
FeatureType type_src = feature.getType(); |
249 |
@SuppressWarnings("rawtypes") |
250 |
Iterator iterator = type_src.iterator();
|
251 |
FeatureType type_dest = editableFeature.getType(); |
252 |
|
253 |
while (iterator.hasNext()) {
|
254 |
FeatureAttributeDescriptor attribute_src = (FeatureAttributeDescriptor) iterator |
255 |
.next(); |
256 |
|
257 |
FeatureAttributeDescriptor attribute_dest = type_dest |
258 |
.getAttributeDescriptor(attribute_src.getName()); |
259 |
if (attribute_dest != null) { |
260 |
if (!attribute_dest.isPrimaryKey()) {
|
261 |
editableFeature.set(attribute_dest.getIndex(), |
262 |
feature.get(attribute_src.getIndex())); |
263 |
} |
264 |
} |
265 |
} |
266 |
return editableFeature;
|
267 |
} |
268 |
|
269 |
|
270 |
} |