Revision 55 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
DefaultEditingProviderServices.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved. |
3 |
*
|
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.impl
|
|
3 |
* |
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.impl |
|
5 | 5 |
* SVN Id : $Id$ |
6 | 6 |
*/ |
7 | 7 |
package org.gvsig.vectorediting.lib.impl; |
8 | 8 |
|
9 |
import java.awt.geom.Point2D; |
|
10 |
|
|
9 | 11 |
import org.gvsig.andami.messages.NotificationManager; |
10 | 12 |
import org.gvsig.editing.EditingNotification; |
11 | 13 |
import org.gvsig.editing.EditingNotificationManager; |
14 |
import org.gvsig.fmap.dal.exception.DataException; |
|
12 | 15 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
13 | 16 |
import org.gvsig.fmap.dal.feature.Feature; |
14 | 17 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
15 | 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; |
|
16 | 29 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
17 | 30 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
18 | 31 |
import org.gvsig.tools.service.spi.AbstractProviderServices; |
19 | 32 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
20 | 33 |
|
21 | 34 |
public class DefaultEditingProviderServices extends AbstractProviderServices |
22 |
implements EditingProviderServices {
|
|
35 |
implements EditingProviderServices {
|
|
23 | 36 |
|
24 |
public void insertFeatureIntoFeatureStore(Feature feature, FeatureStore featureStore) { |
|
25 |
// TODO Auto-generated method stub |
|
37 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
26 | 38 |
|
27 |
} |
|
39 |
public void insertFeatureIntoFeatureStore(Feature feature, |
|
40 |
FeatureStore featureStore) { |
|
41 |
// TODO Auto-generated method stub |
|
28 | 42 |
|
29 |
public void insertGeometryIntoFeatureStore(Geometry geometry, FeatureStore featureStore) { |
|
30 |
try { |
|
31 |
EditableFeature eFeature = featureStore.createNewFeature(true); |
|
43 |
} |
|
32 | 44 |
|
33 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
|
34 |
.getDefaultGeometryAttributeName(), geometry); |
|
45 |
public void insertGeometryIntoFeatureStore(Geometry geometry, |
|
46 |
FeatureStore featureStore) { |
|
47 |
try { |
|
48 |
EditableFeature eFeature = featureStore.createNewFeature(true); |
|
35 | 49 |
|
36 |
EditingNotificationManager editingNotificationManager = MapControlLocator
|
|
37 |
.getEditingNotificationManager();
|
|
50 |
eFeature.setGeometry(featureStore.getDefaultFeatureType()
|
|
51 |
.getDefaultGeometryAttributeName(), geometry);
|
|
38 | 52 |
|
39 |
EditingNotification notification = editingNotificationManager.notifyObservers( |
|
40 |
this, //source |
|
41 |
EditingNotification.BEFORE_INSERT_FEATURE, //type |
|
42 |
null,//document |
|
43 |
null,//layer |
|
44 |
featureStore,//store |
|
45 |
eFeature//feature |
|
46 |
); |
|
47 |
if (notification.isCanceled()) { |
|
48 |
throw new CancelationException(""); |
|
49 |
} |
|
50 |
if (!notification.shouldValidateTheFeature()) { |
|
51 |
if (!editingNotificationManager.validateFeature(eFeature)) { |
|
52 |
throw new Exception(""); |
|
53 |
} |
|
54 |
} |
|
53 |
EditingNotificationManager editingNotificationManager = MapControlLocator |
|
54 |
.getEditingNotificationManager(); |
|
55 | 55 |
|
56 |
featureStore.insert(eFeature); |
|
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 |
} |
|
57 | 72 |
|
58 |
editingNotificationManager.notifyObservers(this, |
|
59 |
EditingNotification.AFTER_INSERT_FEATURE, null, null, featureStore, |
|
60 |
eFeature); |
|
73 |
featureStore.insert(eFeature); |
|
61 | 74 |
|
62 |
} |
|
63 |
catch (Exception e) { |
|
64 |
NotificationManager.addError(e.getMessage(), e); |
|
65 |
} |
|
66 |
} |
|
75 |
editingNotificationManager.notifyObservers(this, |
|
76 |
EditingNotification.AFTER_INSERT_FEATURE, null, null, |
|
77 |
featureStore, eFeature); |
|
67 | 78 |
|
68 |
public void deleteFeatureFromFeatureStore(Feature feature, FeatureStore featureStore) { |
|
69 |
// TODO Auto-generated method stub |
|
79 |
} catch (Exception e) { |
|
80 |
NotificationManager.addError(e.getMessage(), e); |
|
81 |
} |
|
82 |
} |
|
70 | 83 |
|
71 |
} |
|
84 |
public void deleteFeatureFromFeatureStore(Feature feature, |
|
85 |
FeatureStore featureStore) { |
|
86 |
// TODO Auto-generated method stub |
|
72 | 87 |
|
73 |
public void deleteGeometryFromFeatureStore(Geometry geometry, FeatureStore featureStore) { |
|
74 |
// TODO Auto-generated method stub |
|
88 |
} |
|
75 | 89 |
|
76 |
} |
|
90 |
public void deleteGeometryFromFeatureStore(Geometry geometry, |
|
91 |
FeatureStore featureStore) { |
|
92 |
// TODO Auto-generated method stub |
|
77 | 93 |
|
78 |
public void updateFeatureInFeatureStore(Feature feature, FeatureStore featureStore) { |
|
79 |
// TODO Auto-generated method stub |
|
94 |
} |
|
80 | 95 |
|
81 |
} |
|
96 |
public void updateFeatureInFeatureStore(Feature feature, |
|
97 |
FeatureStore featureStore) { |
|
98 |
// TODO Auto-generated method stub |
|
82 | 99 |
|
83 |
public void updateGeometryInFeatureStore(Geometry geometry, FeatureStore featureStore) { |
|
84 |
// TODO Auto-generated method stub |
|
100 |
} |
|
85 | 101 |
|
86 |
} |
|
102 |
public void updateGeometryInFeatureStore(Geometry geometry, |
|
103 |
FeatureStore featureStore) { |
|
104 |
// TODO Auto-generated method stub |
|
87 | 105 |
|
106 |
} |
|
88 | 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 |
|
|
89 | 185 |
} |
Also available in: Unified diff