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 | 159 | llmarques | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 46 | fdiaz | *
|
4 | 2611 | jjdelcerro | * Copyright � 2007-2014 gvSIG Association
|
5 | 159 | llmarques | *
|
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 | 19 | llmarques | */
|
24 | 159 | llmarques | |
25 | 19 | llmarques | package org.gvsig.vectorediting.lib.spi; |
26 | |||
27 | 2870 | fdiaz | import java.util.List; |
28 | 2611 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeature; |
29 | 2616 | fdiaz | import org.gvsig.fmap.dal.feature.Feature; |
30 | 19 | llmarques | import org.gvsig.fmap.geom.Geometry; |
31 | 2616 | fdiaz | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
32 | 19 | llmarques | import org.gvsig.tools.service.spi.AbstractProvider; |
33 | import org.gvsig.tools.service.spi.ProviderServices; |
||
34 | 2125 | fdiaz | import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
35 | import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
||
36 | 2870 | fdiaz | import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
37 | import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
||
38 | 2444 | fdiaz | import org.slf4j.Logger; |
39 | import org.slf4j.LoggerFactory; |
||
40 | 19 | llmarques | |
41 | public abstract class AbstractEditingProvider extends AbstractProvider |
||
42 | 227 | llmarques | implements EditingProvider, Geometry.TYPES, Geometry.SUBTYPES {
|
43 | 2444 | fdiaz | |
44 | 2870 | fdiaz | protected static final Logger LOGGER = LoggerFactory |
45 | 2444 | fdiaz | .getLogger(AbstractEditingProvider.class); |
46 | 2616 | fdiaz | |
47 | private boolean showPreviewSymbol; |
||
48 | 19 | llmarques | |
49 | 159 | llmarques | public AbstractEditingProvider(ProviderServices providerServices) {
|
50 | super(providerServices);
|
||
51 | 2616 | fdiaz | showPreviewSymbol = true;
|
52 | 159 | llmarques | } |
53 | 19 | llmarques | |
54 | 2125 | fdiaz | @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 | 2204 | fdiaz | // @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 | 2125 | fdiaz | @Override
|
65 | 2204 | fdiaz | public abstract void setValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException; |
66 | 2125 | fdiaz | |
67 | 2444 | fdiaz | @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 | 2608 | fdiaz | |
79 | 2748 | fdiaz | public Object getValue(EditingServiceParameter parameter, EditingServiceParameter.TYPE type) { |
80 | return this.getValue(parameter); |
||
81 | } |
||
82 | |||
83 | 2608 | fdiaz | @Override
|
84 | protected EditingProviderServices getProviderServices() {
|
||
85 | return (EditingProviderServices)super.getProviderServices(); |
||
86 | } |
||
87 | 2444 | fdiaz | |
88 | 2616 | fdiaz | @Override
|
89 | 2611 | jjdelcerro | 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 | 2616 | fdiaz | |
98 | public ISymbol getPreviewSymbol() {
|
||
99 | if(!showPreviewSymbol){
|
||
100 | return null; |
||
101 | } |
||
102 | return this.getProviderServices().getPreviewSymbol(); |
||
103 | } |
||
104 | 2611 | jjdelcerro | |
105 | 2616 | fdiaz | 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 | 2723 | fdiaz | |
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 | 2616 | fdiaz | |
141 | 2870 | fdiaz | @Override
|
142 | public void restart() throws StartServiceException, InvalidEntryException ,StopServiceException { |
||
143 | this.stop();
|
||
144 | this.start();
|
||
145 | } |
||
146 | 2723 | fdiaz | |
147 | 2870 | fdiaz | @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 | 2723 | fdiaz | |
161 | 2870 | fdiaz | |
162 | |||
163 | 19 | llmarques | } |