gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.insertpoint / src / main / java / org / gvsig / vectorediting / lib / prov / insertpoint / InsertPointEditingProvider.java @ 97
History | View | Annotate | Download (4.16 KB)
1 |
/*
|
---|---|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved.
|
3 |
*
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.prov
|
5 |
* SVN Id : $Id$
|
6 |
*/
|
7 |
package org.gvsig.vectorediting.lib.prov.insertpoint; |
8 |
|
9 |
import java.util.ArrayList; |
10 |
import java.util.List; |
11 |
|
12 |
import org.apache.log4j.Logger; |
13 |
import org.gvsig.fmap.dal.exception.DataException; |
14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
15 |
import org.gvsig.fmap.geom.Geometry; |
16 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
17 |
import org.gvsig.fmap.geom.primitive.Point; |
18 |
import org.gvsig.tools.ToolsLocator; |
19 |
import org.gvsig.tools.dynobject.DynObject; |
20 |
import org.gvsig.tools.i18n.I18nManager; |
21 |
import org.gvsig.tools.service.spi.ProviderServices; |
22 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
23 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
24 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
25 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
26 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
27 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
28 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
29 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
30 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
31 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
32 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
33 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
34 |
|
35 |
public class InsertPointEditingProvider extends AbstractEditingProvider |
36 |
implements EditingProvider {
|
37 |
|
38 |
private EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices();
|
39 |
|
40 |
private I18nManager i18nManager = ToolsLocator.getI18nManager();
|
41 |
|
42 |
private EditingServiceParameter point = new DefaultEditingServiceParameter( |
43 |
"Insert point", i18nManager.getTranslation("indicate_new_point"), |
44 |
TYPE.POSITION); |
45 |
|
46 |
private Point valuePoint; |
47 |
|
48 |
private FeatureStore featureStore;
|
49 |
|
50 |
public InsertPointEditingProvider(ProviderServices services,
|
51 |
DynObject parameters) { |
52 |
super(services);
|
53 |
this.featureStore = (FeatureStore) parameters
|
54 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
55 |
} |
56 |
|
57 |
public void setProviderServices(ProviderServices services) { |
58 |
// TODO Auto-generated method stub
|
59 |
|
60 |
} |
61 |
|
62 |
public DefaultDrawingStatus getDrawingStatus(Point mousePosition) |
63 |
throws DrawServiceException {
|
64 |
return null; |
65 |
} |
66 |
|
67 |
public void stop() { |
68 |
|
69 |
} |
70 |
|
71 |
private boolean isValidValue(EditingServiceParameter param, Object value) { |
72 |
return (value instanceof Point) ? true : false; |
73 |
} |
74 |
|
75 |
public EditingServiceParameter next() {
|
76 |
if (valuePoint == null) { |
77 |
return this.point; |
78 |
} |
79 |
return null; |
80 |
} |
81 |
|
82 |
public List<EditingServiceParameter> getParameters() { |
83 |
List<EditingServiceParameter> list = new ArrayList<EditingServiceParameter>(); |
84 |
list.add(point); |
85 |
return list;
|
86 |
} |
87 |
|
88 |
public void setValue(Object value) throws InvalidEntryException { |
89 |
EditingServiceParameter param = next(); |
90 |
if (isValidValue(param, value)) {
|
91 |
this.valuePoint = (Point) value; |
92 |
} |
93 |
else {
|
94 |
throw new InvalidEntryException(null); |
95 |
} |
96 |
} |
97 |
|
98 |
public void finishAndStore() throws FinishServiceException { |
99 |
Geometry geometry = null;
|
100 |
try {
|
101 |
geometry = finish(); |
102 |
editingProviderServices.insertGeometryIntoFeatureStore(geometry, |
103 |
featureStore); |
104 |
} |
105 |
catch (Exception e) { |
106 |
throw new FinishServiceException("Can't finalize " + this.getName() |
107 |
+ "with X=" + valuePoint.getX() + " Y= " + valuePoint.getY(), e); |
108 |
} |
109 |
} |
110 |
|
111 |
public void start() throws StartServiceException { |
112 |
this.valuePoint = null; |
113 |
} |
114 |
|
115 |
public String getName() { |
116 |
return InsertPointEditingProviderFactory.PROVIDER_NAME;
|
117 |
} |
118 |
|
119 |
public Geometry finish() throws FinishServiceException { |
120 |
Point geometry = null; |
121 |
try {
|
122 |
geometry = editingProviderServices.createPoint(valuePoint.getX(), |
123 |
valuePoint.getY(), featureStore); |
124 |
} |
125 |
catch (Exception e) { |
126 |
throw new FinishServiceException("Can't finalize " + this.getName() |
127 |
+ "with X=" + valuePoint.getX() + " Y= " + valuePoint.getY(), e); |
128 |
} |
129 |
return geometry;
|
130 |
} |
131 |
} |