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 / DefaultEditingService.java @ 2870
History | View | Annotate | Download (7.97 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.impl; |
26 |
|
27 |
import java.util.List; |
28 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
29 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
30 |
import org.gvsig.fmap.geom.Geometry; |
31 |
import org.gvsig.fmap.geom.primitive.Point; |
32 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
33 |
import org.gvsig.tools.dynobject.DynClass; |
34 |
import org.gvsig.tools.dynobject.DynObject; |
35 |
import org.gvsig.tools.observer.BaseNotification; |
36 |
import org.gvsig.tools.observer.Notification; |
37 |
import org.gvsig.tools.observer.ObservableHelper; |
38 |
import org.gvsig.tools.observer.Observer; |
39 |
import org.gvsig.tools.service.AbstractService; |
40 |
import org.gvsig.tools.service.Manager; |
41 |
import org.gvsig.tools.service.ServiceException; |
42 |
import org.gvsig.tools.service.spi.AbstractProviderServices; |
43 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
44 |
import org.gvsig.vectorediting.lib.api.EditingLocator; |
45 |
import org.gvsig.vectorediting.lib.api.EditingService; |
46 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
47 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
48 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
49 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
50 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
51 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
52 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
53 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
54 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
55 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
56 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
57 |
|
58 |
public class DefaultEditingService extends AbstractService implements EditingService { |
59 |
|
60 |
private final ObservableHelper observableHelper; |
61 |
// private final DynObject parameters;
|
62 |
|
63 |
// public DefaultEditingService(EditingProvider provider, DynObject parameters) {
|
64 |
// this.parameters = parameters;
|
65 |
// this.provider = provider;
|
66 |
// this.observableHelper = new ObservableHelper();
|
67 |
// }
|
68 |
|
69 |
DefaultEditingService(DynObject arg0, EditingProviderServices editingProviderServices) throws ServiceException {
|
70 |
this.init(arg0, editingProviderServices);
|
71 |
((AbstractProviderServices)editingProviderServices).setService(this);
|
72 |
this.observableHelper = new ObservableHelper(); |
73 |
} |
74 |
|
75 |
@Override
|
76 |
protected EditingProvider getProvider() {
|
77 |
return (EditingProvider) super.getProvider(); |
78 |
} |
79 |
|
80 |
@Override
|
81 |
public Manager getManager() {
|
82 |
return null; |
83 |
} |
84 |
|
85 |
@Override
|
86 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
87 |
throws DrawServiceException {
|
88 |
return getProvider().getDrawingStatus(mousePosition);
|
89 |
} |
90 |
|
91 |
@Override
|
92 |
public List<EditingServiceParameter> getParameters() { |
93 |
return getProvider().getParameters();
|
94 |
} |
95 |
|
96 |
@Override
|
97 |
public EditingServiceParameter next() {
|
98 |
EditingServiceParameter x = getProvider().next(); |
99 |
this.updateObservers(NEXT_NOTIFICATION, x, null); |
100 |
return x;
|
101 |
} |
102 |
|
103 |
@Override
|
104 |
public void setValue(Object value) throws InvalidEntryException { |
105 |
getProvider().setValue(value); |
106 |
this.updateObservers(PARAMETER_CHANGED1_NOTIFICATION, value, null); |
107 |
} |
108 |
|
109 |
@Override
|
110 |
public void stop() throws StopServiceException { |
111 |
getProvider().stop(); |
112 |
this.updateObservers(STOP_NOTIFICATION, null, null); |
113 |
} |
114 |
|
115 |
@Override
|
116 |
public void finishAndStore() throws FinishServiceException { |
117 |
getProvider().finishAndStore(); |
118 |
this.updateObservers(FINISH_AND_STORE_NOTIFICATION, null, null); |
119 |
} |
120 |
|
121 |
@Override
|
122 |
public Geometry finish() throws FinishServiceException { |
123 |
Geometry x = getProvider().finish(); |
124 |
this.updateObservers(FINISH_NOTIFICATION, x, null); |
125 |
return x;
|
126 |
} |
127 |
|
128 |
@Override
|
129 |
public void start() throws StartServiceException, InvalidEntryException { |
130 |
this.getProvider().start();
|
131 |
this.getProvider().initDefaultValues();
|
132 |
this.updateObservers(START_NOTIFICATION, null, null); |
133 |
} |
134 |
|
135 |
@Override
|
136 |
public String getName() { |
137 |
return getProvider().getName();
|
138 |
} |
139 |
|
140 |
@Override
|
141 |
public void setValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException { |
142 |
getProvider().setValue(parameter, value); |
143 |
this.updateObservers(PARAMETER_CHANGED2_NOTIFICATION, parameter, value);
|
144 |
} |
145 |
|
146 |
@Override
|
147 |
public boolean isEnabled(EditingServiceParameter parameter) { |
148 |
return getProvider().isEnabled(parameter);
|
149 |
} |
150 |
|
151 |
@Override
|
152 |
public void activate() { |
153 |
getProvider().activate(); |
154 |
this.updateObservers(ACTIVATE_NOTIFICATION, null, null); |
155 |
} |
156 |
|
157 |
@Override
|
158 |
public Object getValue(EditingServiceParameter parameter) { |
159 |
return getProvider().getValue(parameter);
|
160 |
} |
161 |
|
162 |
@Override
|
163 |
public Object getValue(EditingServiceParameter parameter, EditingServiceParameter.TYPE type) { |
164 |
return getProvider().getValue(parameter, type);
|
165 |
} |
166 |
|
167 |
@Override
|
168 |
public void addObserver(Observer o) { |
169 |
this.observableHelper.addObserver(o);
|
170 |
} |
171 |
@Override
|
172 |
public void deleteObserver(Observer o) { |
173 |
this.observableHelper.deleteObserver(o);
|
174 |
} |
175 |
|
176 |
@Override
|
177 |
public void deleteObservers() { |
178 |
this.observableHelper.deleteObservers();
|
179 |
} |
180 |
|
181 |
private void updateObservers(String type, Object v1, Object v2) { |
182 |
Notification notification =
|
183 |
new BaseNotification(type,new Object[] {v1,v2}); |
184 |
this.observableHelper.notifyObservers(this, notification); |
185 |
} |
186 |
|
187 |
@Override
|
188 |
public void setDefaultFeatureValues(EditableFeature feature) { |
189 |
this.getProvider().setDefaultFeatureValues(feature);
|
190 |
} |
191 |
|
192 |
@Override
|
193 |
public EditableFeature getDefaultFeatureValues() {
|
194 |
return this.getProvider().getDefaultFeatureValues(); |
195 |
} |
196 |
|
197 |
@Override
|
198 |
public FeatureStore getStore() {
|
199 |
return (FeatureStore) this.getServiceParameters().getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
200 |
} |
201 |
|
202 |
@Override
|
203 |
public IVectorLegend getLegend() {
|
204 |
return (IVectorLegend) this.getServiceParameters().getDynValue(EditingProviderFactory.LEGEND_FIELD); |
205 |
} |
206 |
|
207 |
@Override
|
208 |
public String getDescription() { |
209 |
String name = this.getProvider().getName(); |
210 |
try {
|
211 |
DynObject params = EditingLocator.getManager().createServiceParameters(name); |
212 |
DynClass dynclass = params.getDynClass(); |
213 |
return dynclass.getDescription();
|
214 |
} catch (ServiceException ex) {
|
215 |
return name;
|
216 |
} |
217 |
} |
218 |
|
219 |
@Override
|
220 |
protected EditingProviderManager getProviderManager() {
|
221 |
return EditingProviderLocator.getProviderManager();
|
222 |
} |
223 |
|
224 |
@Override
|
225 |
public void setShowPreviewSymbol(boolean showPreviewSymbol) { |
226 |
getProvider().setShowPreviewSymbol(showPreviewSymbol); |
227 |
} |
228 |
|
229 |
@Override
|
230 |
public void restart() throws StartServiceException, InvalidEntryException ,StopServiceException { |
231 |
this.getProvider().restart();
|
232 |
this.updateObservers(RESTART_NOTIFICATION, null, null); |
233 |
} |
234 |
|
235 |
} |