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 @ 55
History | View | Annotate | Download (5.68 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 |
|
11 |
import org.gvsig.andami.messages.NotificationManager; |
12 |
import org.gvsig.editing.EditingNotification; |
13 |
import org.gvsig.editing.EditingNotificationManager; |
14 |
import org.gvsig.fmap.dal.exception.DataException; |
15 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
16 |
import org.gvsig.fmap.dal.feature.Feature; |
17 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
18 |
import org.gvsig.fmap.geom.Geometry; |
19 |
import org.gvsig.fmap.geom.GeometryLocator; |
20 |
import org.gvsig.fmap.geom.GeometryManager; |
21 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
22 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
23 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
24 |
import org.gvsig.fmap.geom.primitive.Arc; |
25 |
import org.gvsig.fmap.geom.primitive.Circle; |
26 |
import org.gvsig.fmap.geom.primitive.Curve; |
27 |
import org.gvsig.fmap.geom.primitive.Point; |
28 |
import org.gvsig.fmap.geom.type.GeometryType; |
29 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
30 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
31 |
import org.gvsig.tools.service.spi.AbstractProviderServices; |
32 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
33 |
|
34 |
public class DefaultEditingProviderServices extends AbstractProviderServices |
35 |
implements EditingProviderServices {
|
36 |
|
37 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
38 |
|
39 |
public void insertFeatureIntoFeatureStore(Feature feature, |
40 |
FeatureStore featureStore) { |
41 |
// TODO Auto-generated method stub
|
42 |
|
43 |
} |
44 |
|
45 |
public void insertGeometryIntoFeatureStore(Geometry geometry, |
46 |
FeatureStore featureStore) { |
47 |
try {
|
48 |
EditableFeature eFeature = featureStore.createNewFeature(true);
|
49 |
|
50 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
51 |
.getDefaultGeometryAttributeName(), geometry); |
52 |
|
53 |
EditingNotificationManager editingNotificationManager = MapControlLocator |
54 |
.getEditingNotificationManager(); |
55 |
|
56 |
EditingNotification notification = editingNotificationManager |
57 |
.notifyObservers(this, // source |
58 |
EditingNotification.BEFORE_INSERT_FEATURE, // type
|
59 |
null,// document |
60 |
null,// layer |
61 |
featureStore,// store
|
62 |
eFeature// feature
|
63 |
); |
64 |
if (notification.isCanceled()) {
|
65 |
throw new CancelationException(""); |
66 |
} |
67 |
if (!notification.shouldValidateTheFeature()) {
|
68 |
if (!editingNotificationManager.validateFeature(eFeature)) {
|
69 |
throw new Exception(""); |
70 |
} |
71 |
} |
72 |
|
73 |
featureStore.insert(eFeature); |
74 |
|
75 |
editingNotificationManager.notifyObservers(this,
|
76 |
EditingNotification.AFTER_INSERT_FEATURE, null, null, |
77 |
featureStore, eFeature); |
78 |
|
79 |
} catch (Exception e) { |
80 |
NotificationManager.addError(e.getMessage(), e); |
81 |
} |
82 |
} |
83 |
|
84 |
public void deleteFeatureFromFeatureStore(Feature feature, |
85 |
FeatureStore featureStore) { |
86 |
// TODO Auto-generated method stub
|
87 |
|
88 |
} |
89 |
|
90 |
public void deleteGeometryFromFeatureStore(Geometry geometry, |
91 |
FeatureStore featureStore) { |
92 |
// TODO Auto-generated method stub
|
93 |
|
94 |
} |
95 |
|
96 |
public void updateFeatureInFeatureStore(Feature feature, |
97 |
FeatureStore featureStore) { |
98 |
// TODO Auto-generated method stub
|
99 |
|
100 |
} |
101 |
|
102 |
public void updateGeometryInFeatureStore(Geometry geometry, |
103 |
FeatureStore featureStore) { |
104 |
// TODO Auto-generated method stub
|
105 |
|
106 |
} |
107 |
|
108 |
public Circle createCircle(Point2D p1, Point2D p2, FeatureStore featureStore) |
109 |
throws CreateGeometryException, DataException {
|
110 |
Point centro = createPoint(p1.getX(), p1.getY(), featureStore);
|
111 |
Point radio = createPoint(p2.getX(), p2.getY(), featureStore);
|
112 |
return createCircle(centro, radio, featureStore);
|
113 |
} |
114 |
|
115 |
public Circle createCircle(Point p1, Point p2, FeatureStore featureStore) |
116 |
throws CreateGeometryException, DataException {
|
117 |
Circle circle = null;
|
118 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
119 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, |
120 |
featStoreGeomType.getSubType()); |
121 |
circle.setPoints(p1, p2); |
122 |
|
123 |
return circle;
|
124 |
} |
125 |
|
126 |
public Circle createCircle(Point center, double radius, |
127 |
FeatureStore featureStore) throws CreateGeometryException,
|
128 |
DataException { |
129 |
Circle circle = null;
|
130 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
131 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, |
132 |
featStoreGeomType.getSubType()); |
133 |
circle.setPoints(center, radius); |
134 |
|
135 |
return circle;
|
136 |
} |
137 |
|
138 |
public Arc createArc(Point center, double radius, double startAngle, |
139 |
double angleExt, FeatureStore featureStore)
|
140 |
throws CreateGeometryException, DataException {
|
141 |
Arc arc = null;
|
142 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
143 |
arc = (Arc) geomManager.create(TYPES.ARC, |
144 |
featStoreGeomType.getSubType()); |
145 |
arc.setPoints(center, radius, startAngle, angleExt); |
146 |
return arc;
|
147 |
} |
148 |
|
149 |
public Point createPoint(double x, double y, FeatureStore featureStore) |
150 |
throws CreateGeometryException, DataException {
|
151 |
Point point = null; |
152 |
point = (Point) geomManager.create(TYPES.POINT,
|
153 |
getSubType(featureStore)); |
154 |
point.setX(x); |
155 |
point.setY(y); |
156 |
return point;
|
157 |
} |
158 |
|
159 |
public Curve createLine(double x1, double y1, double x2, double y2, |
160 |
FeatureStore featureStore) throws CreateGeometryException,
|
161 |
DataException { |
162 |
Curve line = null;
|
163 |
line = (Curve) geomManager |
164 |
.create(TYPES.CURVE, getSubType(featureStore)); |
165 |
line.addVertex(x1, y1); |
166 |
line.addVertex(x2, y2); |
167 |
return line;
|
168 |
} |
169 |
|
170 |
public int getSubType(FeatureStore featureStore) throws DataException { |
171 |
|
172 |
GeometryType geomType = getGeomType(featureStore); |
173 |
if (geomType != null) { |
174 |
return geomType.getSubType();
|
175 |
} |
176 |
return SUBTYPES.GEOM3D; // ??????? |
177 |
} |
178 |
|
179 |
public GeometryType getGeomType(FeatureStore featureStore)
|
180 |
throws DataException {
|
181 |
return featureStore.getDefaultFeatureType()
|
182 |
.getDefaultGeometryAttribute().getGeomType(); |
183 |
} |
184 |
|
185 |
} |