Statistics
| Revision:

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 159 llmarques
/**
2
 * gvSIG. Desktop Geographic Information System.
3 52 fdiaz
 *
4 159 llmarques
 * 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 4 llmarques
 */
24 159 llmarques
25 4 llmarques
package org.gvsig.vectorediting.lib.spi;
26
27 2723 fdiaz
import org.gvsig.vectorediting.lib.api.EditingServiceParameterOptions;
28 191 llmarques
import java.util.Arrays;
29 156 llmarques
import java.util.HashSet;
30 191 llmarques
import java.util.Map;
31 2870 fdiaz
import java.util.Objects;
32 156 llmarques
import java.util.Set;
33 157 llmarques
import org.gvsig.fmap.geom.Geometry;
34 2870 fdiaz
import org.gvsig.fmap.geom.primitive.Point;
35 2723 fdiaz
import org.gvsig.timesupport.DataTypes;
36 4 llmarques
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
37
38 10 llmarques
public class DefaultEditingServiceParameter implements EditingServiceParameter {
39 4 llmarques
40 157 llmarques
    private String name;
41 10 llmarques
42 157 llmarques
    private String description;
43 10 llmarques
44 157 llmarques
    private Set<TYPE> types;
45 52 fdiaz
46 157 llmarques
    private int geometryType;
47
48 191 llmarques
    private Map<String, String> options;
49 227 llmarques
50 2723 fdiaz
    private EditingServiceParameterOptions options2;
51
52 365 llmarques
    private Object defaultValue;
53
54 2125 fdiaz
    private boolean optional;
55 2723 fdiaz
56
    private int dataType;
57 2125 fdiaz
58 157 llmarques
    public DefaultEditingServiceParameter(String theName,
59
        String theDescription, TYPE... theTypes) {
60 227 llmarques
61 2723 fdiaz
        this(theName, theDescription, Geometry.TYPES.NULL, null, null , null, false, theTypes);
62 157 llmarques
63 156 llmarques
    }
64 4 llmarques
65 157 llmarques
    public DefaultEditingServiceParameter(String theName,
66 2125 fdiaz
        String theDescription, boolean optional, TYPE... theTypes) {
67
68 2723 fdiaz
        this(theName, theDescription, Geometry.TYPES.NULL, null, null, null, optional, theTypes);
69 2125 fdiaz
    }
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 2723 fdiaz
        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 365 llmarques
        Object theDefaultValue, String theDescription, TYPE... theTypes) {
85
86 2723 fdiaz
        this(theName, theDescription, Geometry.TYPES.NULL, null, null, theDefaultValue, false, theTypes);
87 2125 fdiaz
88 365 llmarques
    }
89
90
    public DefaultEditingServiceParameter(String theName,
91 157 llmarques
        String theDescription, int theGeometryType, TYPE... theTypes) {
92 191 llmarques
93 2723 fdiaz
        this(theName, theDescription, theGeometryType, null, null, null, false, theTypes);
94 4 llmarques
95 157 llmarques
    }
96 4 llmarques
97 191 llmarques
    public DefaultEditingServiceParameter(String theName,
98 365 llmarques
        String theDescription, Object theDefaultValue, int theGeometryType,
99
        TYPE... theTypes) {
100
101 2723 fdiaz
        this(theName, theDescription, theGeometryType, null, null, theDefaultValue, false, theTypes);
102 2125 fdiaz
103 365 llmarques
    }
104
105
    public DefaultEditingServiceParameter(String theName,
106 191 llmarques
        String theDescription, Map<String, String> theOptions, TYPE... theTypes) {
107
108 2125 fdiaz
        this(theName, theDescription, Geometry.TYPES.NULL, theOptions, null, false, theTypes);
109 191 llmarques
    }
110 377 fdiaz
111 365 llmarques
    public DefaultEditingServiceParameter(String theName,
112
        String theDescription, Map<String, String> theOptions, Object theDefaultValue, TYPE... theTypes) {
113 191 llmarques
114 2125 fdiaz
        this(theName, theDescription, Geometry.TYPES.NULL, theOptions, theDefaultValue, false, theTypes);
115 365 llmarques
    }
116
117 191 llmarques
    public DefaultEditingServiceParameter(String theName,
118 2723 fdiaz
        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 191 llmarques
        String theDescription, int theGeometryType,
125
        Map<String, String> theOptions, TYPE... theTypes) {
126
127 2125 fdiaz
        this(theName, theDescription, theGeometryType, theOptions, null, false, theTypes);
128 191 llmarques
129 2125 fdiaz
    }
130 191 llmarques
131 2125 fdiaz
    public DefaultEditingServiceParameter(String theName,
132
        String theDescription, int theGeometryType,
133
        Map<String, String> theOptions, Object theDefaultValue, TYPE... theTypes) {
134 191 llmarques
135 2125 fdiaz
        this(theName, theDescription, theGeometryType, theOptions, theDefaultValue, false, theTypes);
136 191 llmarques
    }
137 377 fdiaz
138 365 llmarques
    public DefaultEditingServiceParameter(String theName,
139
        String theDescription, int theGeometryType,
140 2125 fdiaz
        Map<String, String> theOptions, Object theDefaultValue,
141
        boolean optional, TYPE... theTypes) {
142 2723 fdiaz
143
        this(theName, theDescription, theGeometryType, theOptions, null, theDefaultValue, optional, theTypes);
144 191 llmarques
145 2723 fdiaz
    }
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 365 llmarques
        this.name = theName;
162
        this.description = theDescription;
163
        this.geometryType = theGeometryType;
164
165 2616 fdiaz
        this.types = new HashSet<>();
166 365 llmarques
        this.types.addAll(Arrays.asList(theTypes));
167
168
        this.options = theOptions;
169 2723 fdiaz
        this.options2 = theOptions2;
170 365 llmarques
        this.defaultValue = theDefaultValue;
171 2125 fdiaz
        this.optional = optional;
172 2723 fdiaz
        this.dataType = DataTypes.STRING;
173 365 llmarques
    }
174
175 2616 fdiaz
    @Override
176 157 llmarques
    public Set<TYPE> getTypes() {
177
        return types;
178
    }
179 4 llmarques
180 2616 fdiaz
    @Override
181 157 llmarques
    public String getName() {
182
        return name;
183
    }
184 57 llmarques
185 2616 fdiaz
    @Override
186 157 llmarques
    public String getDescription() {
187
        return description;
188
    }
189
190
    public void setDescription(String newDescription) {
191
        this.description = newDescription;
192
    }
193
194 2616 fdiaz
    @Override
195 157 llmarques
    public int getGeometryType() {
196
        return this.geometryType;
197
    }
198
199 2616 fdiaz
    @Override
200 227 llmarques
    public Map<String, String> getOptions() {
201 191 llmarques
        return this.options;
202
    }
203
204 2616 fdiaz
    @Override
205 2723 fdiaz
    public EditingServiceParameterOptions getOptions2() {
206
        return this.options2;
207
    }
208
209
    @Override
210 365 llmarques
    public Object getDefaultValue() {
211
        return this.defaultValue;
212
    }
213
214 2616 fdiaz
    @Override
215 377 fdiaz
    public void setDefaultValue(Object value) {
216
        this.defaultValue = value;
217
    }
218 2870 fdiaz
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 377 fdiaz
235 2870 fdiaz
        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 2125 fdiaz
    @Override
246
    public boolean isOptional() {
247
        return optional;
248
    }
249
250
    public void setOptional(boolean optional) {
251
        this.optional = optional;
252
    }
253 2723 fdiaz
254
    public DefaultEditingServiceParameter setDataType(int dataType) {
255
        this.dataType = dataType;
256
        return this;
257
    }
258 2125 fdiaz
259 2723 fdiaz
    @Override
260
    public int getDataType() {
261
        return this.dataType;
262
    }
263
264
265
266 4 llmarques
}