gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.spi / src / main / java / org / gvsig / vectorediting / lib / spi / AbstractEditingProvider.java @ 2870
History | View | Annotate | Download (5.67 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.spi; |
26 |
|
27 |
import java.util.List; |
28 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
29 |
import org.gvsig.fmap.dal.feature.Feature; |
30 |
import org.gvsig.fmap.geom.Geometry; |
31 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
32 |
import org.gvsig.tools.service.spi.AbstractProvider; |
33 |
import org.gvsig.tools.service.spi.ProviderServices; |
34 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
35 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
36 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
37 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
38 |
import org.slf4j.Logger; |
39 |
import org.slf4j.LoggerFactory; |
40 |
|
41 |
public abstract class AbstractEditingProvider extends AbstractProvider |
42 |
implements EditingProvider, Geometry.TYPES, Geometry.SUBTYPES {
|
43 |
|
44 |
protected static final Logger LOGGER = LoggerFactory |
45 |
.getLogger(AbstractEditingProvider.class); |
46 |
|
47 |
private boolean showPreviewSymbol; |
48 |
|
49 |
public AbstractEditingProvider(ProviderServices providerServices) {
|
50 |
super(providerServices);
|
51 |
showPreviewSymbol = true;
|
52 |
} |
53 |
|
54 |
@Override
|
55 |
public boolean isEnabled(EditingServiceParameter parameter) { |
56 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
57 |
} |
58 |
|
59 |
// @Override
|
60 |
// public void setValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException {
|
61 |
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
62 |
// }
|
63 |
|
64 |
@Override
|
65 |
public abstract void setValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException; |
66 |
|
67 |
@Override
|
68 |
public void activate() { |
69 |
|
70 |
} |
71 |
|
72 |
@Override
|
73 |
public Object getValue(EditingServiceParameter parameter) { |
74 |
// To implement in subclasses
|
75 |
LOGGER.warn("'"+this.getClass().getName() + "' dooes not implement the method 'getValue'."); |
76 |
return null; |
77 |
} |
78 |
|
79 |
public Object getValue(EditingServiceParameter parameter, EditingServiceParameter.TYPE type) { |
80 |
return this.getValue(parameter); |
81 |
} |
82 |
|
83 |
@Override
|
84 |
protected EditingProviderServices getProviderServices() {
|
85 |
return (EditingProviderServices)super.getProviderServices(); |
86 |
} |
87 |
|
88 |
@Override
|
89 |
public void setDefaultFeatureValues(EditableFeature feature) { |
90 |
((EditingProviderServices)(this.getProviderServices())).setDefaultFeatureValues(feature);
|
91 |
} |
92 |
|
93 |
@Override
|
94 |
public EditableFeature getDefaultFeatureValues() {
|
95 |
return ((EditingProviderServices)(this.getProviderServices())).getDefaultFeatureValues(); |
96 |
} |
97 |
|
98 |
public ISymbol getPreviewSymbol() {
|
99 |
if(!showPreviewSymbol){
|
100 |
return null; |
101 |
} |
102 |
return this.getProviderServices().getPreviewSymbol(); |
103 |
} |
104 |
|
105 |
public ISymbol getPreviewSymbol(Feature feature) {
|
106 |
if(!showPreviewSymbol){
|
107 |
return null; |
108 |
} |
109 |
return this.getProviderServices().getPreviewSymbol(feature); |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public void setShowPreviewSymbol(boolean showPreviewSymbol) { |
114 |
this.showPreviewSymbol = showPreviewSymbol;
|
115 |
} |
116 |
|
117 |
@Override
|
118 |
public boolean isShowPreviewSymbol() { |
119 |
return this.showPreviewSymbol; |
120 |
} |
121 |
|
122 |
// protected Object validateAndInsertTypeOptionParameterValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException {
|
123 |
// EditingServiceParameterOptions opt = parameter.getOptions2();
|
124 |
// Object defaultValue = parameter.getDefaultValue();
|
125 |
// if (value instanceof String) {
|
126 |
// Object v = opt.getValue((String)value, defaultValue);
|
127 |
// if(v != null){
|
128 |
// return v;
|
129 |
// } else if(defaultValue != null) {
|
130 |
// return defaultValue;
|
131 |
// } else {
|
132 |
// throw new InvalidEntryException(null);
|
133 |
// }
|
134 |
// } else if(opt.isValidValue(value)){
|
135 |
// return value;
|
136 |
// } else {
|
137 |
// throw new InvalidEntryException(null);
|
138 |
// }
|
139 |
// }
|
140 |
|
141 |
@Override
|
142 |
public void restart() throws StartServiceException, InvalidEntryException ,StopServiceException { |
143 |
this.stop();
|
144 |
this.start();
|
145 |
} |
146 |
|
147 |
@Override
|
148 |
public void initDefaultValues() { |
149 |
List<EditingServiceParameter> parameters = this.getParameters(); |
150 |
for (EditingServiceParameter parameter : parameters) {
|
151 |
if(parameter.isOptional()){
|
152 |
try {
|
153 |
setValue(parameter, parameter.getDefaultValue()); |
154 |
} catch (InvalidEntryException ex) {
|
155 |
LOGGER.debug("Can't init default value of "+parameter.getName(), ex);
|
156 |
} |
157 |
} |
158 |
} |
159 |
} |
160 |
|
161 |
|
162 |
|
163 |
} |