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 / DefaultEditingServiceParameter.java @ 2870
History | View | Annotate | Download (8.26 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 org.gvsig.vectorediting.lib.api.EditingServiceParameterOptions; |
28 |
import java.util.Arrays; |
29 |
import java.util.HashSet; |
30 |
import java.util.Map; |
31 |
import java.util.Objects; |
32 |
import java.util.Set; |
33 |
import org.gvsig.fmap.geom.Geometry; |
34 |
import org.gvsig.fmap.geom.primitive.Point; |
35 |
import org.gvsig.timesupport.DataTypes; |
36 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
37 |
|
38 |
public class DefaultEditingServiceParameter implements EditingServiceParameter { |
39 |
|
40 |
private String name; |
41 |
|
42 |
private String description; |
43 |
|
44 |
private Set<TYPE> types; |
45 |
|
46 |
private int geometryType; |
47 |
|
48 |
private Map<String, String> options; |
49 |
|
50 |
private EditingServiceParameterOptions options2;
|
51 |
|
52 |
private Object defaultValue; |
53 |
|
54 |
private boolean optional; |
55 |
|
56 |
private int dataType; |
57 |
|
58 |
public DefaultEditingServiceParameter(String theName, |
59 |
String theDescription, TYPE... theTypes) {
|
60 |
|
61 |
this(theName, theDescription, Geometry.TYPES.NULL, null, null , null, false, theTypes); |
62 |
|
63 |
} |
64 |
|
65 |
public DefaultEditingServiceParameter(String theName, |
66 |
String theDescription, boolean optional, TYPE... theTypes) { |
67 |
|
68 |
this(theName, theDescription, Geometry.TYPES.NULL, null, null, null, optional, theTypes); |
69 |
} |
70 |
|
71 |
public DefaultEditingServiceParameter(String theName, |
72 |
String theDescription, Map<String, String> options, Object defaultValue, boolean optional, TYPE... theTypes) { |
73 |
|
74 |
this(theName, theDescription, Geometry.TYPES.NULL, options, defaultValue, optional, theTypes);
|
75 |
} |
76 |
|
77 |
public DefaultEditingServiceParameter(String theName, |
78 |
String theDescription, EditingServiceParameterOptions options, Object defaultValue, boolean optional, TYPE... theTypes) { |
79 |
|
80 |
this(theName, theDescription, Geometry.TYPES.NULL, options, defaultValue, optional, theTypes);
|
81 |
} |
82 |
|
83 |
public DefaultEditingServiceParameter(String theName, |
84 |
Object theDefaultValue, String theDescription, TYPE... theTypes) { |
85 |
|
86 |
this(theName, theDescription, Geometry.TYPES.NULL, null, null, theDefaultValue, false, theTypes); |
87 |
|
88 |
} |
89 |
|
90 |
public DefaultEditingServiceParameter(String theName, |
91 |
String theDescription, int theGeometryType, TYPE... theTypes) { |
92 |
|
93 |
this(theName, theDescription, theGeometryType, null, null, null, false, theTypes); |
94 |
|
95 |
} |
96 |
|
97 |
public DefaultEditingServiceParameter(String theName, |
98 |
String theDescription, Object theDefaultValue, int theGeometryType, |
99 |
TYPE... theTypes) { |
100 |
|
101 |
this(theName, theDescription, theGeometryType, null, null, theDefaultValue, false, theTypes); |
102 |
|
103 |
} |
104 |
|
105 |
public DefaultEditingServiceParameter(String theName, |
106 |
String theDescription, Map<String, String> theOptions, TYPE... theTypes) { |
107 |
|
108 |
this(theName, theDescription, Geometry.TYPES.NULL, theOptions, null, false, theTypes); |
109 |
} |
110 |
|
111 |
public DefaultEditingServiceParameter(String theName, |
112 |
String theDescription, Map<String, String> theOptions, Object theDefaultValue, TYPE... theTypes) { |
113 |
|
114 |
this(theName, theDescription, Geometry.TYPES.NULL, theOptions, theDefaultValue, false, theTypes); |
115 |
} |
116 |
|
117 |
public DefaultEditingServiceParameter(String theName, |
118 |
String theDescription, EditingServiceParameterOptions theOptions, Object theDefaultValue, TYPE... theTypes) { |
119 |
|
120 |
this(theName, theDescription, Geometry.TYPES.NULL, null, theOptions, theDefaultValue, false, theTypes); |
121 |
} |
122 |
|
123 |
public DefaultEditingServiceParameter(String theName, |
124 |
String theDescription, int theGeometryType, |
125 |
Map<String, String> theOptions, TYPE... theTypes) { |
126 |
|
127 |
this(theName, theDescription, theGeometryType, theOptions, null, false, theTypes); |
128 |
|
129 |
} |
130 |
|
131 |
public DefaultEditingServiceParameter(String theName, |
132 |
String theDescription, int theGeometryType, |
133 |
Map<String, String> theOptions, Object theDefaultValue, TYPE... theTypes) { |
134 |
|
135 |
this(theName, theDescription, theGeometryType, theOptions, theDefaultValue, false, theTypes); |
136 |
} |
137 |
|
138 |
public DefaultEditingServiceParameter(String theName, |
139 |
String theDescription, int theGeometryType, |
140 |
Map<String, String> theOptions, Object theDefaultValue, |
141 |
boolean optional, TYPE... theTypes) {
|
142 |
|
143 |
this(theName, theDescription, theGeometryType, theOptions, null, theDefaultValue, optional, theTypes); |
144 |
|
145 |
} |
146 |
|
147 |
public DefaultEditingServiceParameter(String theName, |
148 |
String theDescription, int theGeometryType, |
149 |
EditingServiceParameterOptions theOptions, Object theDefaultValue,
|
150 |
boolean optional, TYPE... theTypes) {
|
151 |
|
152 |
this(theName, theDescription, theGeometryType, null, theOptions, theDefaultValue, optional, theTypes); |
153 |
|
154 |
} |
155 |
|
156 |
public DefaultEditingServiceParameter(String theName, |
157 |
String theDescription, int theGeometryType, |
158 |
Map<String, String> theOptions, EditingServiceParameterOptions theOptions2, Object theDefaultValue, |
159 |
boolean optional, TYPE... theTypes) {
|
160 |
|
161 |
this.name = theName;
|
162 |
this.description = theDescription;
|
163 |
this.geometryType = theGeometryType;
|
164 |
|
165 |
this.types = new HashSet<>(); |
166 |
this.types.addAll(Arrays.asList(theTypes)); |
167 |
|
168 |
this.options = theOptions;
|
169 |
this.options2 = theOptions2;
|
170 |
this.defaultValue = theDefaultValue;
|
171 |
this.optional = optional;
|
172 |
this.dataType = DataTypes.STRING;
|
173 |
} |
174 |
|
175 |
@Override
|
176 |
public Set<TYPE> getTypes() { |
177 |
return types;
|
178 |
} |
179 |
|
180 |
@Override
|
181 |
public String getName() { |
182 |
return name;
|
183 |
} |
184 |
|
185 |
@Override
|
186 |
public String getDescription() { |
187 |
return description;
|
188 |
} |
189 |
|
190 |
public void setDescription(String newDescription) { |
191 |
this.description = newDescription;
|
192 |
} |
193 |
|
194 |
@Override
|
195 |
public int getGeometryType() { |
196 |
return this.geometryType; |
197 |
} |
198 |
|
199 |
@Override
|
200 |
public Map<String, String> getOptions() { |
201 |
return this.options; |
202 |
} |
203 |
|
204 |
@Override
|
205 |
public EditingServiceParameterOptions getOptions2() {
|
206 |
return this.options2; |
207 |
} |
208 |
|
209 |
@Override
|
210 |
public Object getDefaultValue() { |
211 |
return this.defaultValue; |
212 |
} |
213 |
|
214 |
@Override
|
215 |
public void setDefaultValue(Object value) { |
216 |
this.defaultValue = value;
|
217 |
} |
218 |
|
219 |
public String getConsoleDefaultValue() { |
220 |
if(this.defaultValue == null) { |
221 |
return ""; |
222 |
} |
223 |
if (defaultValue instanceof Point) { |
224 |
Point point = (Point) defaultValue; |
225 |
StringBuilder builder = new StringBuilder(); |
226 |
for (int i = 0; i < point.getDimension(); i++) { |
227 |
builder.append(point.getCoordinateAt(i)); |
228 |
if (i < point.getDimension() - 1) { |
229 |
builder.append(" , ");
|
230 |
} |
231 |
} |
232 |
return builder.toString();
|
233 |
} |
234 |
|
235 |
if (this.options2 != null) { |
236 |
return this.options2.getConsoleValue(this.defaultValue); |
237 |
} |
238 |
if (this.options != null) { |
239 |
//FIXME: ????
|
240 |
return this.options.getOrDefault(defaultValue, ""); |
241 |
} |
242 |
return Objects.toString(defaultValue, ""); |
243 |
} |
244 |
|
245 |
@Override
|
246 |
public boolean isOptional() { |
247 |
return optional;
|
248 |
} |
249 |
|
250 |
public void setOptional(boolean optional) { |
251 |
this.optional = optional;
|
252 |
} |
253 |
|
254 |
public DefaultEditingServiceParameter setDataType(int dataType) { |
255 |
this.dataType = dataType;
|
256 |
return this; |
257 |
} |
258 |
|
259 |
@Override
|
260 |
public int getDataType() { |
261 |
return this.dataType; |
262 |
} |
263 |
|
264 |
|
265 |
|
266 |
} |