svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / DefaultEditableFeatureType.java @ 47784
History | View | Annotate | Download (17.8 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 42290 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40559 | jjdelcerro | *
|
11 | 42290 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40559 | jjdelcerro | *
|
16 | 42290 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40559 | jjdelcerro | *
|
20 | 42290 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40559 | jjdelcerro | */
|
23 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.feature.impl; |
24 | |||
25 | import java.text.MessageFormat; |
||
26 | import java.util.Iterator; |
||
27 | 45154 | jjdelcerro | import javax.json.JsonObject; |
28 | 45784 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
29 | import org.gvsig.fmap.dal.DataTypeUtils; |
||
30 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.exception.DataListException; |
31 | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
||
32 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
33 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
34 | 41335 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
35 | 43739 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
36 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
37 | import org.gvsig.fmap.dal.feature.exception.FeatureTypeIntegrityException; |
||
38 | 47436 | fdiaz | import static org.gvsig.fmap.dal.feature.impl.DefaultFeatureAttributeDescriptor.NOTIFICATION_FIXED_CHANGED; |
39 | 46012 | jjdelcerro | import org.gvsig.fmap.dal.impl.DefaultDataManager; |
40 | 47176 | jjdelcerro | import org.gvsig.json.Json; |
41 | import org.gvsig.json.JsonManager; |
||
42 | import org.gvsig.json.JsonObjectBuilder; |
||
43 | import org.gvsig.json.SupportToJson; |
||
44 | 42293 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
45 | 40435 | jjdelcerro | import org.gvsig.tools.evaluator.Evaluator; |
46 | 47436 | fdiaz | import org.gvsig.tools.observer.Notification; |
47 | import org.gvsig.tools.observer.Observable; |
||
48 | import org.gvsig.tools.observer.Observer; |
||
49 | 40435 | jjdelcerro | |
50 | 45158 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
51 | 40435 | jjdelcerro | public class DefaultEditableFeatureType extends DefaultFeatureType implements |
52 | 47436 | fdiaz | EditableFeatureType, Observer {
|
53 | 40435 | jjdelcerro | |
54 | 42290 | jjdelcerro | /**
|
55 | *
|
||
56 | */
|
||
57 | private static final long serialVersionUID = -713976880396024389L; |
||
58 | 40435 | jjdelcerro | |
59 | 42290 | jjdelcerro | private boolean hasStrongChanges; |
60 | private DefaultFeatureType source;
|
||
61 | 40435 | jjdelcerro | |
62 | 43739 | jjdelcerro | public DefaultEditableFeatureType(FeatureStore store) {
|
63 | super(store);
|
||
64 | 42290 | jjdelcerro | this.hasStrongChanges = false; |
65 | this.source = null; |
||
66 | } |
||
67 | 40435 | jjdelcerro | |
68 | 43739 | jjdelcerro | public DefaultEditableFeatureType(FeatureStore store, String id) { |
69 | super(store, id);
|
||
70 | 42290 | jjdelcerro | this.hasStrongChanges = false; |
71 | this.source = null; |
||
72 | } |
||
73 | 40435 | jjdelcerro | |
74 | 42290 | jjdelcerro | protected DefaultEditableFeatureType(DefaultEditableFeatureType other) {
|
75 | super(other);
|
||
76 | 44582 | omartinez | this.hasStrongChanges = other.hasStrongChanges;
|
77 | 42290 | jjdelcerro | this.source = (DefaultFeatureType) other.getSource();
|
78 | } |
||
79 | 40435 | jjdelcerro | |
80 | 42290 | jjdelcerro | protected DefaultEditableFeatureType(DefaultFeatureType other) {
|
81 | super(other);
|
||
82 | this.source = other;
|
||
83 | 44582 | omartinez | this.fixAll();
|
84 | 42290 | jjdelcerro | } |
85 | 40435 | jjdelcerro | |
86 | 43739 | jjdelcerro | @Override
|
87 | 44318 | jjdelcerro | protected DefaultFeatureAttributeDescriptor getCopyAttributeDescriptor(DefaultFeatureAttributeDescriptor src) {
|
88 | DefaultFeatureAttributeDescriptor copy = new DefaultEditableFeatureAttributeDescriptor(src);
|
||
89 | copy.setFeatureType(this);
|
||
90 | return copy;
|
||
91 | 42290 | jjdelcerro | } |
92 | 46723 | fdiaz | |
93 | 47176 | jjdelcerro | @Override
|
94 | 46723 | fdiaz | public void forceStrongChanges() { |
95 | this.hasStrongChanges = true; |
||
96 | } |
||
97 | 40435 | jjdelcerro | |
98 | 42290 | jjdelcerro | public boolean hasStrongChanges() { |
99 | if (hasStrongChanges) {
|
||
100 | return true; |
||
101 | } |
||
102 | Iterator iter = this.iterator(); |
||
103 | DefaultEditableFeatureAttributeDescriptor attr; |
||
104 | while (iter.hasNext()) {
|
||
105 | attr = (DefaultEditableFeatureAttributeDescriptor) iter.next(); |
||
106 | 43981 | omartinez | if (attr.isComputed()) {
|
107 | continue;
|
||
108 | } |
||
109 | 42290 | jjdelcerro | if (attr.hasStrongChanges()) {
|
110 | return true; |
||
111 | } |
||
112 | } |
||
113 | return false; |
||
114 | } |
||
115 | 40435 | jjdelcerro | |
116 | 45152 | fdiaz | @Override
|
117 | 42290 | jjdelcerro | public FeatureType getCopy() {
|
118 | 45152 | fdiaz | DefaultEditableFeatureType copy = new DefaultEditableFeatureType(this); |
119 | copy.fixAll(); |
||
120 | return copy;
|
||
121 | 42290 | jjdelcerro | } |
122 | 40435 | jjdelcerro | |
123 | 45152 | fdiaz | @Override
|
124 | 42290 | jjdelcerro | public EditableFeatureType getEditable() {
|
125 | 44669 | jjdelcerro | return (EditableFeatureType) this.getCopy(); |
126 | 42290 | jjdelcerro | } |
127 | 40435 | jjdelcerro | |
128 | 42290 | jjdelcerro | public boolean addAll(DefaultFeatureType other) { |
129 | Iterator iter = other.iterator();
|
||
130 | DefaultFeatureAttributeDescriptor attr; |
||
131 | DefaultEditableFeatureAttributeDescriptor editableAttr; |
||
132 | while (iter.hasNext()) {
|
||
133 | attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
||
134 | if (attr instanceof DefaultEditableFeatureAttributeDescriptor) { |
||
135 | editableAttr = new DefaultEditableFeatureAttributeDescriptor(
|
||
136 | attr); |
||
137 | } else {
|
||
138 | editableAttr = new DefaultEditableFeatureAttributeDescriptor(
|
||
139 | attr); |
||
140 | } |
||
141 | 47436 | fdiaz | editableAttr.addObserver(this);
|
142 | 42290 | jjdelcerro | super.add(editableAttr);
|
143 | } |
||
144 | this.pk = null; |
||
145 | this.fixAll();
|
||
146 | return true; |
||
147 | } |
||
148 | 40435 | jjdelcerro | |
149 | 45158 | jjdelcerro | @Override
|
150 | 42290 | jjdelcerro | public EditableFeatureAttributeDescriptor addLike(
|
151 | FeatureAttributeDescriptor other) { |
||
152 | DefaultEditableFeatureAttributeDescriptor editableAttr; |
||
153 | 44801 | omartinez | editableAttr = new DefaultEditableFeatureAttributeDescriptor(
|
154 | 45159 | jjdelcerro | (DefaultFeatureAttributeDescriptor) other); |
155 | 42290 | jjdelcerro | super.add(editableAttr);
|
156 | 45159 | jjdelcerro | if (!editableAttr.isComputed()) {
|
157 | 44669 | jjdelcerro | this.hasStrongChanges = true; |
158 | 45159 | jjdelcerro | } |
159 | 47436 | fdiaz | editableAttr.addObserver(this);
|
160 | 42290 | jjdelcerro | this.fixAll();
|
161 | return editableAttr;
|
||
162 | } |
||
163 | 40435 | jjdelcerro | |
164 | 45158 | jjdelcerro | @Override
|
165 | 42290 | jjdelcerro | public FeatureType getSource() {
|
166 | return source;
|
||
167 | } |
||
168 | 40435 | jjdelcerro | |
169 | 45158 | jjdelcerro | @Override
|
170 | 42290 | jjdelcerro | public FeatureType getNotEditableCopy() {
|
171 | this.fixAll();
|
||
172 | DefaultFeatureType copy = new DefaultFeatureType(this, false); |
||
173 | Iterator iter = this.iterator(); |
||
174 | DefaultFeatureAttributeDescriptor attr; |
||
175 | while (iter.hasNext()) {
|
||
176 | attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
||
177 | 44259 | jjdelcerro | DefaultFeatureAttributeDescriptor newattr = new DefaultFeatureAttributeDescriptor(attr);
|
178 | newattr.setFeatureType(copy); |
||
179 | copy.add(newattr); |
||
180 | 42027 | jjdelcerro | } |
181 | 47525 | jjdelcerro | copy.fixAll(); |
182 | 42290 | jjdelcerro | return copy;
|
183 | } |
||
184 | 42027 | jjdelcerro | |
185 | 45158 | jjdelcerro | @Override
|
186 | 42290 | jjdelcerro | public EditableFeatureAttributeDescriptor add(String name, int type) { |
187 | return this.add(name, type, true); |
||
188 | } |
||
189 | 40435 | jjdelcerro | |
190 | 44505 | jjdelcerro | @Override
|
191 | public void removeAll() { |
||
192 | 45159 | jjdelcerro | while (!super.isEmpty()) { |
193 | 47436 | fdiaz | FeatureAttributeDescriptor attr = this.get(0); |
194 | if(attr instanceof Observable){ |
||
195 | ((Observable) attr).deleteObserver(this); |
||
196 | } |
||
197 | 44505 | jjdelcerro | super.remove(0); |
198 | } |
||
199 | this.fixAll();
|
||
200 | } |
||
201 | |||
202 | @Override
|
||
203 | public void addAll(FeatureType attributes) { |
||
204 | super.addAll(attributes);
|
||
205 | this.fixAll();
|
||
206 | } |
||
207 | 45159 | jjdelcerro | |
208 | 44190 | jjdelcerro | private EditableFeatureAttributeDescriptor add(String name, int type, boolean strongChanges) { |
209 | 42290 | jjdelcerro | Iterator iter = this.iterator(); |
210 | while (iter.hasNext()) {
|
||
211 | EditableFeatureAttributeDescriptor descriptor = (EditableFeatureAttributeDescriptor) iter.next(); |
||
212 | if (descriptor.getName().equalsIgnoreCase(name)) {
|
||
213 | 47349 | fdiaz | throw new IllegalArgumentException( |
214 | MessageFormat.format("Duplicated name descriptor {0}.", name) |
||
215 | 42290 | jjdelcerro | ); |
216 | } |
||
217 | 40435 | jjdelcerro | |
218 | 42290 | jjdelcerro | } |
219 | 46104 | omartinez | DefaultEditableFeatureAttributeDescriptor attr = DefaultDataManager.createEditableFeatureAttributeDescriptor(this, name, type, strongChanges);
|
220 | 42290 | jjdelcerro | attr.setIndex(this.size());
|
221 | 45159 | jjdelcerro | |
222 | 44669 | jjdelcerro | this.hasStrongChanges = this.hasStrongChanges || strongChanges; |
223 | 42290 | jjdelcerro | super.add(attr);
|
224 | this.pk = null; |
||
225 | 47436 | fdiaz | attr.addObserver(this);
|
226 | this.fixed = false; |
||
227 | 42290 | jjdelcerro | return attr;
|
228 | } |
||
229 | 40435 | jjdelcerro | |
230 | 45158 | jjdelcerro | @Override
|
231 | public EditableFeatureAttributeDescriptor add(String name, int type, int size) { |
||
232 | 42290 | jjdelcerro | return this.add(name, type, true).setSize(size); |
233 | } |
||
234 | 40435 | jjdelcerro | |
235 | 45158 | jjdelcerro | @Override
|
236 | 42290 | jjdelcerro | public EditableFeatureAttributeDescriptor add(String name, int type, |
237 | Evaluator evaluator) { |
||
238 | if (evaluator == null) { |
||
239 | throw new IllegalArgumentException(); |
||
240 | } |
||
241 | return this.add(name, type, false).setEvaluator(evaluator); |
||
242 | } |
||
243 | 41335 | jjdelcerro | |
244 | 45158 | jjdelcerro | @Override
|
245 | 42290 | jjdelcerro | public EditableFeatureAttributeDescriptor add(String name, int type, |
246 | FeatureAttributeEmulator emulator) { |
||
247 | if (emulator == null) { |
||
248 | throw new IllegalArgumentException(); |
||
249 | } |
||
250 | return this.add(name, type, false).setFeatureAttributeEmulator(emulator); |
||
251 | } |
||
252 | 45159 | jjdelcerro | |
253 | 45158 | jjdelcerro | @Override
|
254 | 42293 | jjdelcerro | public EditableFeatureAttributeDescriptor add(String name, String type) { |
255 | 45159 | jjdelcerro | return this.add(name, ToolsLocator.getDataTypesManager().getType(type)); |
256 | 42293 | jjdelcerro | } |
257 | 40435 | jjdelcerro | |
258 | 45158 | jjdelcerro | @Override
|
259 | 42293 | jjdelcerro | public EditableFeatureAttributeDescriptor add(String name, String type, int size) { |
260 | 45159 | jjdelcerro | return this.add(name, ToolsLocator.getDataTypesManager().getType(type), size); |
261 | 42293 | jjdelcerro | } |
262 | 43966 | jjdelcerro | |
263 | public Object removeAttributeDescriptor(String name) { |
||
264 | // Hemos metido los metodos removeAttributeDescriptor ya que existe
|
||
265 | // un problema desde python al llamar a los metodos remove. En lugar de llamar
|
||
266 | // a estos metodos remove, llama a los de la superclase ArrayList.
|
||
267 | return this.remove(name); |
||
268 | } |
||
269 | 45159 | jjdelcerro | |
270 | 43966 | jjdelcerro | public boolean removeAttributeDescriptor(EditableFeatureAttributeDescriptor attribute) { |
271 | return this.remove(attribute); |
||
272 | } |
||
273 | 44669 | jjdelcerro | |
274 | 43966 | jjdelcerro | @Override
|
275 | 44669 | jjdelcerro | public FeatureAttributeDescriptor remove(int index) { |
276 | FeatureAttributeDescriptor attr = (FeatureAttributeDescriptor) this.get(index);
|
||
277 | 45159 | jjdelcerro | if (!attr.isComputed()) {
|
278 | 42290 | jjdelcerro | hasStrongChanges = true;
|
279 | } |
||
280 | 45159 | jjdelcerro | if (index == this.getDefaultGeometryAttributeIndex()) { |
281 | this.defaultGeometryAttributeIndex = -1; |
||
282 | 44669 | jjdelcerro | this.defaultGeometryAttributeName = null; |
283 | 45159 | jjdelcerro | } else if (index == this.getDefaultTimeAttributeIndex()) { |
284 | 44669 | jjdelcerro | this.defaultTimeAttributeIndex = -1; |
285 | this.defaultTimeAttributeName = null; |
||
286 | } |
||
287 | 42290 | jjdelcerro | super.remove(attr);
|
288 | 47498 | fdiaz | this.fixed = false; |
289 | 42290 | jjdelcerro | this.pk = null; |
290 | 47436 | fdiaz | if(attr instanceof Observable){ |
291 | ((Observable) attr).deleteObserver(this); |
||
292 | } |
||
293 | 42290 | jjdelcerro | this.fixAll();
|
294 | return attr;
|
||
295 | } |
||
296 | 45159 | jjdelcerro | |
297 | 44669 | jjdelcerro | @Override
|
298 | public Object remove(String name) { |
||
299 | FeatureAttributeDescriptor attr = (FeatureAttributeDescriptor) this.get(name);
|
||
300 | if (attr == null) { |
||
301 | return null; |
||
302 | } |
||
303 | this.remove(attr.getIndex());
|
||
304 | return attr;
|
||
305 | } |
||
306 | 40435 | jjdelcerro | |
307 | 43610 | jjdelcerro | @Override
|
308 | 43966 | jjdelcerro | public boolean remove(EditableFeatureAttributeDescriptor attribute) { |
309 | 44669 | jjdelcerro | this.remove(attribute.getIndex());
|
310 | 43966 | jjdelcerro | return true; |
311 | } |
||
312 | |||
313 | @Override
|
||
314 | 42290 | jjdelcerro | protected void fixAll() { |
315 | 47436 | fdiaz | if(this.fixed){ |
316 | return;
|
||
317 | } |
||
318 | 43610 | jjdelcerro | super.fixAll();
|
319 | 44582 | omartinez | for (FeatureAttributeDescriptor attr : this) { |
320 | if (attr instanceof DefaultEditableFeatureAttributeDescriptor) { |
||
321 | DefaultEditableFeatureAttributeDescriptor attr2 = (DefaultEditableFeatureAttributeDescriptor) attr; |
||
322 | if (attr2.hasStrongChanges()) {
|
||
323 | this.hasStrongChanges = true; |
||
324 | break;
|
||
325 | } |
||
326 | } |
||
327 | } |
||
328 | 47436 | fdiaz | this.fixed = true; |
329 | 42290 | jjdelcerro | } |
330 | 40435 | jjdelcerro | |
331 | 42290 | jjdelcerro | public void checkIntegrity() throws DataListException { |
332 | Iterator iter = super.iterator(); |
||
333 | FeatureTypeIntegrityException ex = null;
|
||
334 | 40435 | jjdelcerro | |
335 | 42290 | jjdelcerro | while (iter.hasNext()) {
|
336 | DefaultEditableFeatureAttributeDescriptor attr = (DefaultEditableFeatureAttributeDescriptor) iter |
||
337 | .next(); |
||
338 | try {
|
||
339 | attr.checkIntegrity(); |
||
340 | } catch (Exception e) { |
||
341 | if (ex == null) { |
||
342 | ex = new FeatureTypeIntegrityException(this.getId()); |
||
343 | } |
||
344 | ex.add(e); |
||
345 | } |
||
346 | } |
||
347 | if (ex != null) { |
||
348 | throw ex;
|
||
349 | } |
||
350 | } |
||
351 | 40435 | jjdelcerro | |
352 | 43074 | jjdelcerro | @Override
|
353 | public void setDefaultGeometryType(int type, int subType) { |
||
354 | 45158 | jjdelcerro | EditableFeatureAttributeDescriptor descr = (EditableFeatureAttributeDescriptor) this.getDefaultGeometryAttribute();
|
355 | 45159 | jjdelcerro | if (descr == null) { |
356 | 43074 | jjdelcerro | throw new IllegalStateException("Default geometry attribute not set."); |
357 | } |
||
358 | 45158 | jjdelcerro | descr.setGeometryType(type, subType); |
359 | 47436 | fdiaz | this.fixed = false; |
360 | 43074 | jjdelcerro | } |
361 | |||
362 | 45158 | jjdelcerro | @Override
|
363 | 42290 | jjdelcerro | public void setDefaultGeometryAttributeName(String name) { |
364 | if (name == null || name.length() == 0) { |
||
365 | this.defaultGeometryAttributeName = null; |
||
366 | this.defaultGeometryAttributeIndex = -1; |
||
367 | 47452 | jjdelcerro | this.fixed = false; |
368 | 42290 | jjdelcerro | return;
|
369 | } |
||
370 | 45158 | jjdelcerro | FeatureAttributeDescriptor attr = this.getAttributeDescriptor(name);
|
371 | 42290 | jjdelcerro | if (attr == null) { |
372 | 45159 | jjdelcerro | throw new IllegalArgumentException("Attribute '" + name + "' not found."); |
373 | 42290 | jjdelcerro | } |
374 | this.defaultGeometryAttributeName = name;
|
||
375 | this.defaultGeometryAttributeIndex = attr.getIndex();
|
||
376 | 47436 | fdiaz | this.fixed = false; |
377 | 42290 | jjdelcerro | } |
378 | 40435 | jjdelcerro | |
379 | 44948 | jjdelcerro | @Override
|
380 | public int getDefaultGeometryAttributeIndex() { |
||
381 | this.fixAll();
|
||
382 | return this.defaultGeometryAttributeIndex; |
||
383 | } |
||
384 | |||
385 | @Override
|
||
386 | public String getDefaultGeometryAttributeName() { |
||
387 | this.fixAll();
|
||
388 | return this.defaultGeometryAttributeName; |
||
389 | } |
||
390 | |||
391 | @Override
|
||
392 | 45564 | jjdelcerro | public FeatureAttributeDescriptor getDefaultGeometryAttribute() {
|
393 | this.fixAll();
|
||
394 | return super.getDefaultGeometryAttribute(); |
||
395 | } |
||
396 | |||
397 | @Override
|
||
398 | 44948 | jjdelcerro | public int getDefaultTimeAttributeIndex() { |
399 | this.fixAll();
|
||
400 | return this.defaultTimeAttributeIndex; |
||
401 | } |
||
402 | |||
403 | @Override
|
||
404 | public String getDefaultTimeAttributeName() { |
||
405 | this.fixAll();
|
||
406 | return this.defaultTimeAttributeName; |
||
407 | } |
||
408 | |||
409 | 45158 | jjdelcerro | @Override
|
410 | 42290 | jjdelcerro | public void setHasOID(boolean hasOID) { |
411 | this.hasOID = hasOID;
|
||
412 | 47436 | fdiaz | this.fixed = false; |
413 | 42290 | jjdelcerro | } |
414 | 40435 | jjdelcerro | |
415 | 45158 | jjdelcerro | @Override
|
416 | 42290 | jjdelcerro | protected Iterator getIterator(Iterator iter) { |
417 | return new EditableDelegatedIterator(iter, this); |
||
418 | } |
||
419 | |||
420 | 45158 | jjdelcerro | @Override
|
421 | 41272 | jjdelcerro | public EditableFeatureAttributeDescriptor getEditableAttributeDescriptor(String name) { |
422 | return (EditableFeatureAttributeDescriptor) this.getAttributeDescriptor(name); |
||
423 | } |
||
424 | |||
425 | 45158 | jjdelcerro | @Override
|
426 | 41272 | jjdelcerro | public EditableFeatureAttributeDescriptor getEditableAttributeDescriptor(int index) { |
427 | 42290 | jjdelcerro | return (EditableFeatureAttributeDescriptor) this.getAttributeDescriptor(index); |
428 | 41272 | jjdelcerro | } |
429 | |||
430 | 45739 | jjdelcerro | @Override
|
431 | public void setCheckFeaturesAtFinishEditing(boolean check) { |
||
432 | this.checkFeaturesAtFinishEditing = check;
|
||
433 | 47436 | fdiaz | this.fixed = false; |
434 | 45739 | jjdelcerro | } |
435 | |||
436 | @Override
|
||
437 | public void setCheckFeaturesAtInsert(boolean check) { |
||
438 | this.checkFeaturesAtInsert = check;
|
||
439 | 47436 | fdiaz | this.fixed = false; |
440 | 45739 | jjdelcerro | } |
441 | |||
442 | 42290 | jjdelcerro | protected class EditableDelegatedIterator extends DelegatedIterator { |
443 | 40435 | jjdelcerro | |
444 | 45158 | jjdelcerro | private final DefaultEditableFeatureType fType; |
445 | 40435 | jjdelcerro | |
446 | 45158 | jjdelcerro | public EditableDelegatedIterator(Iterator iter, DefaultEditableFeatureType fType) { |
447 | 42290 | jjdelcerro | super(iter);
|
448 | this.fType = fType;
|
||
449 | } |
||
450 | 40435 | jjdelcerro | |
451 | 45158 | jjdelcerro | @Override
|
452 | 42290 | jjdelcerro | public void remove() { |
453 | this.iterator.remove();
|
||
454 | this.fType.fixAll();
|
||
455 | } |
||
456 | 40435 | jjdelcerro | |
457 | 42290 | jjdelcerro | } |
458 | 40435 | jjdelcerro | |
459 | 42290 | jjdelcerro | protected void setAllowAutomaticValues(boolean value) { |
460 | this.allowAtomaticValues = value;
|
||
461 | 47436 | fdiaz | this.fixed = false; |
462 | 42290 | jjdelcerro | } |
463 | 45159 | jjdelcerro | |
464 | 44582 | omartinez | @Override
|
465 | public void copyFrom(FeatureType other) { |
||
466 | super.copyFrom(other);
|
||
467 | if (other instanceof EditableFeatureType) { |
||
468 | DefaultEditableFeatureType other2 = (DefaultEditableFeatureType) other; |
||
469 | 44587 | omartinez | this.hasStrongChanges = other2.hasStrongChanges();
|
470 | 44582 | omartinez | this.source = (DefaultFeatureType) other2.getSource();
|
471 | } else {
|
||
472 | this.hasStrongChanges = false; |
||
473 | this.source = (DefaultFeatureType) other;
|
||
474 | } |
||
475 | 47436 | fdiaz | this.fixed = false; |
476 | 44582 | omartinez | } |
477 | 45159 | jjdelcerro | |
478 | 45154 | jjdelcerro | public void copyFrom(JsonObject json) { |
479 | 45784 | jjdelcerro | // TODO: falta por implementar copyFrom(json)
|
480 | 47436 | fdiaz | this.fixed = false; |
481 | 45154 | jjdelcerro | } |
482 | 45784 | jjdelcerro | |
483 | @Override
|
||
484 | public void set(String name, String value) { |
||
485 | if (StringUtils.isBlank(name)) {
|
||
486 | throw new IllegalArgumentException("Name can't be empty"); |
||
487 | } |
||
488 | switch (name.trim().toLowerCase()) {
|
||
489 | case "checkfeaturesatfinishediting": |
||
490 | this.setCheckFeaturesAtFinishEditing(DataTypeUtils.toBoolean(value, false)); |
||
491 | break;
|
||
492 | case "checkfeaturesatinsert": |
||
493 | this.setCheckFeaturesAtInsert(DataTypeUtils.toBoolean(value, false)); |
||
494 | break;
|
||
495 | case "defaultgeometryattributename": |
||
496 | case "defaultgeometryname": |
||
497 | case "defaultgeometry": |
||
498 | this.setDefaultGeometryAttributeName(DataTypeUtils.toString(value, null)); |
||
499 | break;
|
||
500 | default:
|
||
501 | throw new IllegalArgumentException("Name attribute '" + name + "' not valid."); |
||
502 | } |
||
503 | 47436 | fdiaz | this.fixed = false; |
504 | 45784 | jjdelcerro | } |
505 | |||
506 | 47176 | jjdelcerro | private static class TheJsonSerializer implements JsonManager.JsonSerializer { |
507 | |||
508 | public TheJsonSerializer() {
|
||
509 | } |
||
510 | |||
511 | @Override
|
||
512 | public Class getObjectClass() { |
||
513 | return DefaultEditableFeatureType.class;
|
||
514 | } |
||
515 | |||
516 | @Override
|
||
517 | public Object toObject(JsonObject json) { |
||
518 | EditableFeatureType o = new DefaultFeatureType().getEditable();
|
||
519 | o.fromJson(json); |
||
520 | return o;
|
||
521 | } |
||
522 | |||
523 | @Override
|
||
524 | public JsonObjectBuilder toJsonBuilder(Object value) { |
||
525 | return ((SupportToJson)value).toJsonBuilder();
|
||
526 | } |
||
527 | |||
528 | } |
||
529 | |||
530 | public static void selfRegister() { |
||
531 | Json.registerSerializer(new TheJsonSerializer());
|
||
532 | } |
||
533 | 47436 | fdiaz | |
534 | @Override
|
||
535 | public void update(Observable observable, Object notification) { |
||
536 | if (notification instanceof Notification && observable instanceof DefaultFeatureAttributeDescriptor){ |
||
537 | DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) observable; |
||
538 | Notification n = (Notification) notification; |
||
539 | if(n.isOfType(NOTIFICATION_FIXED_CHANGED)){
|
||
540 | if(!attr.isFixed()) {
|
||
541 | this.fixed = false; |
||
542 | } |
||
543 | } |
||
544 | } |
||
545 | } |
||
546 | |||
547 | |||
548 | 40435 | jjdelcerro | } |