gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.remove / src / main / java / org / gvsig / vectorediting / lib / prov / remove / RemoveEditingProvider.java @ 401
History | View | Annotate | Download (10.4 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright ? 2007-2014 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 2
|
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 |
|
25 |
package org.gvsig.vectorediting.lib.prov.remove; |
26 |
|
27 |
import java.awt.geom.AffineTransform; |
28 |
import java.util.ArrayList; |
29 |
import java.util.HashMap; |
30 |
import java.util.List; |
31 |
import java.util.Map; |
32 |
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
34 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
35 |
import org.gvsig.fmap.dal.feature.Feature; |
36 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
38 |
import org.gvsig.fmap.geom.Geometry; |
39 |
import org.gvsig.fmap.geom.GeometryLocator; |
40 |
import org.gvsig.fmap.geom.GeometryManager; |
41 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
42 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
43 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
44 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
45 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
46 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
47 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
48 |
import org.gvsig.fmap.geom.primitive.Curve; |
49 |
import org.gvsig.fmap.geom.primitive.Line; |
50 |
import org.gvsig.fmap.geom.primitive.Point; |
51 |
import org.gvsig.fmap.geom.primitive.Surface; |
52 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
53 |
import org.gvsig.tools.dispose.DisposableIterator; |
54 |
import org.gvsig.tools.dynobject.DynObject; |
55 |
import org.gvsig.tools.exception.BaseException; |
56 |
import org.gvsig.tools.service.spi.ProviderServices; |
57 |
import org.gvsig.tools.visitor.VisitCanceledException; |
58 |
import org.gvsig.tools.visitor.Visitor; |
59 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
60 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
61 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
62 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
63 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
64 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
65 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
66 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
67 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
68 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
69 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
70 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
71 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
72 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
73 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
74 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
75 |
|
76 |
/**
|
77 |
* @author fdiaz
|
78 |
*
|
79 |
*/
|
80 |
public class RemoveEditingProvider extends AbstractEditingProvider implements |
81 |
EditingProvider { |
82 |
|
83 |
private EditingServiceParameter selection;
|
84 |
|
85 |
private FeatureStore featureStore;
|
86 |
|
87 |
private Map<EditingServiceParameter, Object> values; |
88 |
|
89 |
/**
|
90 |
* Default constructor.
|
91 |
*
|
92 |
* @param providerServices
|
93 |
* available services for this provider
|
94 |
* @param parameters
|
95 |
* of this provider
|
96 |
*/
|
97 |
public RemoveEditingProvider(ProviderServices providerServices,
|
98 |
DynObject parameters) { |
99 |
super(providerServices);
|
100 |
|
101 |
this.featureStore =
|
102 |
(FeatureStore) parameters |
103 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
104 |
|
105 |
this.selection =
|
106 |
new DefaultEditingServiceParameter("selection", "selection", |
107 |
TYPE.SELECTION); |
108 |
|
109 |
} |
110 |
|
111 |
public EditingServiceParameter next() {
|
112 |
if (values.get(selection) == null) { |
113 |
return selection;
|
114 |
} |
115 |
return null; |
116 |
} |
117 |
|
118 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
119 |
throws DrawServiceException {
|
120 |
// GeometryManager geometryManager =
|
121 |
// GeometryLocator.getGeometryManager();
|
122 |
// EditingProviderManager editingProviderManager =
|
123 |
// EditingProviderLocator.getProviderManager();
|
124 |
// EditingProviderServices editingProviderServices =
|
125 |
// (EditingProviderServices) getProviderServices();
|
126 |
// int subtype;
|
127 |
// try {
|
128 |
// subtype = editingProviderServices.getSubType(featureStore);
|
129 |
// } catch (DataException e2) {
|
130 |
// throw new DrawServiceException(e2);
|
131 |
// }
|
132 |
// ISymbol lineSymbolEditing =
|
133 |
// editingProviderManager.getSymbol("line-symbol-editing");
|
134 |
// ISymbol auxiliarylineSymbolEditing =
|
135 |
// editingProviderManager.getSymbol("auxiliary-line-symbol-editing");
|
136 |
// ISymbol polygonSymbolEditing =
|
137 |
// editingProviderManager.getSymbol("polygon-symbol-editing");
|
138 |
// ISymbol auxiliaryPointSymbolEditing =
|
139 |
// editingProviderManager.getSymbol("auxiliary-point-symbol-editing");
|
140 |
//
|
141 |
// DefaultDrawingStatus drawingStatus = new DefaultDrawingStatus();
|
142 |
//
|
143 |
// if (values != null) {
|
144 |
//
|
145 |
// FeatureSelection featureSelection =
|
146 |
// (FeatureSelection) values.get(selection);
|
147 |
// Point firstPointValue = (Point) values.get(firstPoint);
|
148 |
//
|
149 |
// if (featureSelection != null && firstPointValue != null) {
|
150 |
// drawingStatus.addStatus(firstPointValue, auxiliaryPointSymbolEditing,
|
151 |
// "");
|
152 |
// Line auxLine;
|
153 |
// try {
|
154 |
// auxLine = geometryManager.createLine(subtype);
|
155 |
// } catch (CreateGeometryException e1) {
|
156 |
// throw new DrawServiceException(e1);
|
157 |
// }
|
158 |
// auxLine.setPoints(firstPointValue, mousePosition);
|
159 |
// drawingStatus.addStatus(auxLine, auxiliarylineSymbolEditing, "");
|
160 |
//
|
161 |
// DisposableIterator it = null;
|
162 |
// try {
|
163 |
// it = featureSelection.fastIterator();
|
164 |
// while (it.hasNext()) {
|
165 |
// Feature feature = (Feature) it.next();
|
166 |
//
|
167 |
// Geometry geometry =
|
168 |
// feature.getDefaultGeometry().cloneGeometry();
|
169 |
//
|
170 |
// AffineTransform at =
|
171 |
// getMoveAffineTransform(firstPointValue,
|
172 |
// mousePosition);
|
173 |
// geometry.transform(at);
|
174 |
// ISymbol symbol=null;
|
175 |
// if(geometry instanceof Curve || geometry instanceof MultiCurve){
|
176 |
// symbol = lineSymbolEditing;
|
177 |
// } else if(geometry instanceof Surface || geometry instanceof
|
178 |
// MultiSurface){
|
179 |
// symbol = polygonSymbolEditing;
|
180 |
// } else if(geometry instanceof Point || geometry instanceof
|
181 |
// MultiPoint){
|
182 |
// symbol = auxiliaryPointSymbolEditing;
|
183 |
// }
|
184 |
// if(geometry instanceof Aggregate){
|
185 |
// int primitivesNumber = ((Aggregate)geometry).getPrimitivesNumber();
|
186 |
// for (int i = 0; i < primitivesNumber; i++) {
|
187 |
// drawingStatus.addStatus(((Aggregate)geometry).getPrimitiveAt(i),
|
188 |
// symbol, "");
|
189 |
// }
|
190 |
// } else {
|
191 |
// drawingStatus.addStatus(geometry, symbol, "");
|
192 |
// }
|
193 |
//
|
194 |
// }
|
195 |
// } catch (BaseException e) {
|
196 |
// throw new DrawServiceException(e);
|
197 |
// } finally {
|
198 |
// it.dispose();
|
199 |
// }
|
200 |
// }
|
201 |
// }
|
202 |
// return drawingStatus;
|
203 |
return null; |
204 |
} |
205 |
|
206 |
public void stop() throws StopServiceException { |
207 |
if (values != null) { |
208 |
values.clear(); |
209 |
} |
210 |
} |
211 |
|
212 |
public List<EditingServiceParameter> getParameters() { |
213 |
List<EditingServiceParameter> parameters =
|
214 |
new ArrayList<EditingServiceParameter>(); |
215 |
parameters.add(selection); |
216 |
return parameters;
|
217 |
} |
218 |
|
219 |
public void setValue(Object value) throws InvalidEntryException { |
220 |
EditingServiceParameter parameter = next(); |
221 |
validateAndInsertValue(parameter, value); |
222 |
} |
223 |
|
224 |
private void validateAndInsertValue(EditingServiceParameter parameter, |
225 |
Object value) {
|
226 |
|
227 |
if (parameter == selection) {
|
228 |
if (value instanceof FeatureSelection) { |
229 |
if (((FeatureSelection) value).getSelectedCount() > 0) { |
230 |
values.put(selection, value); |
231 |
} |
232 |
} |
233 |
} |
234 |
} |
235 |
|
236 |
public Geometry finish() throws FinishServiceException { |
237 |
return null; |
238 |
} |
239 |
|
240 |
public void finishAndStore() throws FinishServiceException { |
241 |
|
242 |
if (values != null) { |
243 |
|
244 |
FeatureSelection featureSelection = |
245 |
(FeatureSelection) values.get(selection); |
246 |
|
247 |
try {
|
248 |
featureSelection.accept(new Visitor() {
|
249 |
|
250 |
public void visit(Object obj) |
251 |
throws VisitCanceledException, BaseException {
|
252 |
Feature feature = (Feature) obj; |
253 |
|
254 |
((EditingProviderServices) getProviderServices()) |
255 |
.deleteFeatureFromFeatureStore(feature, |
256 |
featureStore); |
257 |
} |
258 |
}); |
259 |
|
260 |
featureStore.getFeatureSelection().deselectAll(); |
261 |
featureSelection.dispose(); |
262 |
} catch (BaseException e) {
|
263 |
throw new FinishServiceException(e); |
264 |
} |
265 |
} |
266 |
} |
267 |
|
268 |
public void start() throws StartServiceException, InvalidEntryException { |
269 |
values = new HashMap<EditingServiceParameter, Object>(); |
270 |
FeatureSelection selected = null;
|
271 |
if (featureStore != null) { |
272 |
try {
|
273 |
selected = featureStore.getFeatureSelection(); |
274 |
} catch (DataException e) {
|
275 |
throw new StartServiceException(e); |
276 |
} |
277 |
try {
|
278 |
setValue(selected); |
279 |
} catch (InvalidEntryException e) {
|
280 |
throw new InvalidEntryException(e); |
281 |
} |
282 |
} |
283 |
} |
284 |
|
285 |
public String getName() { |
286 |
return RemoveEditingProviderFactory.PROVIDER_NAME;
|
287 |
} |
288 |
|
289 |
} |