Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / featuretable / table / DynFieldFacadeOfAFeatureAttributeDescriptor.java @ 45739

History | View | Annotate | Download (20.8 KB)

1

    
2
package org.gvsig.fmap.dal.swing.impl.featuretable.table;
3

    
4
import java.math.BigDecimal;
5
import java.math.MathContext;
6
import java.text.DateFormat;
7
import java.util.List;
8
import java.util.Locale;
9
import java.util.Objects;
10
import java.util.function.Supplier;
11
import javax.json.JsonObject;
12
import org.gvsig.json.JsonObjectBuilder;
13
import org.apache.commons.lang3.ArrayUtils;
14
import org.apache.commons.lang3.StringUtils;
15
import org.cresques.cts.IProjection;
16
import org.gvsig.expressionevaluator.Expression;
17
import org.gvsig.fmap.dal.feature.DataProfile;
18
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
19
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
20
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter;
21
import org.gvsig.fmap.dal.feature.FeatureStore;
22
import org.gvsig.fmap.dal.feature.FeatureType;
23
import org.gvsig.fmap.dal.feature.ForeingKey;
24
import org.gvsig.fmap.geom.Geometry;
25
import org.gvsig.fmap.geom.type.GeometryType;
26
import org.gvsig.timesupport.Interval;
27
import org.gvsig.tools.dataTypes.Coercion;
28
import org.gvsig.tools.dataTypes.CoercionException;
29
import org.gvsig.tools.dataTypes.DataType;
30
import org.gvsig.tools.dataTypes.DataTypeUtils;
31
import org.gvsig.tools.dynobject.DynField;
32
import org.gvsig.tools.dynobject.DynField_v2;
33
import org.gvsig.tools.dynobject.DynMethod;
34
import org.gvsig.tools.dynobject.DynObject;
35
import org.gvsig.tools.dynobject.DynObjectValueItem;
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.dynobject.Tags;
38
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException;
39
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
40
import org.gvsig.tools.evaluator.Evaluator;
41
import org.gvsig.tools.dataTypes.CoercionContext;
42
import org.gvsig.tools.persistence.PersistentState;
43
import org.gvsig.tools.persistence.exception.PersistenceException;
44

    
45

    
46
public class DynFieldFacadeOfAFeatureAttributeDescriptor implements FeatureAttributeDescriptor {
47

    
48
    private DynField field;
49
    private CoercionContext coerceContext;
50
  
51
    public DynFieldFacadeOfAFeatureAttributeDescriptor(DynField field) {
52
        this.field = field;
53
    }
54
    
55
    @Override
56
    public FeatureAttributeDescriptor getCopy() {
57
        try {
58
            return (FeatureAttributeDescriptor) field.clone();
59
        } catch (CloneNotSupportedException ex) {
60
            throw new RuntimeException(ex);
61
        }
62
    }
63

    
64
    @Override
65
    public MathContext getMathContext() {
66
      return MathContext.UNLIMITED;
67
    }
68

    
69
    @Override
70
    public String getDataTypeName() {
71
        return field.getDataType().getName();
72
    }
73

    
74
    @Override
75
    public int getSize() {
76
        return 1;
77
    }
78

    
79
    @Override
80
    public int getPrecision() {
81
        return 0;
82
    }
83

    
84
    @Override
85
    public int getScale() {
86
        return 0;
87
    }
88

    
89
    @Override
90
    public Coercion getCoercion() {
91
      return this.field.getDataType().getCoercion();
92
    }
93

    
94
    @Override
95
    public CoercionContext getCoercionContext() {
96
      if( this.coerceContext==null ) {
97
        if( this.getDataType().isNumeric() ) {
98
          if( this.getSize()==0 ) {
99
            this.coerceContext = DataTypeUtils.coerceContextDefaultDecimal();
100
          } else {
101
            this.coerceContext = DataTypeUtils.coerceContextDecimal(
102
                    null, 
103
                    this.getSize(), 
104
                    this.getPrecision(),
105
                    BigDecimal.ROUND_HALF_UP
106
            );
107
          }
108
        } else {
109
            this.coerceContext = DataTypeUtils.coerceContextDefaultLocale();
110
        }
111
      }
112
      return this.coerceContext;
113
    }
114

    
115
    @Override
116
    public Class getObjectClass() {
117
        return this.getDataType().getDefaultClass();
118
    }
119

    
120
    @Override
121
    public int getMinimumOccurrences() {
122
        return 0;
123
    }
124

    
125
    @Override
126
    public int getMaximumOccurrences() {
127
        return 0;
128
    }
129

    
130
    @Override
131
    public boolean isPrimaryKey() {
132
        return false;
133
    }
134

    
135
    @Override
136
    public boolean allowNull() {
137
        return true;
138
    }
139

    
140
    @Override
141
    public Evaluator getEvaluator() {
142
        return null;
143
    }
144

    
145
    @Override
146
    public IProjection getSRS() {
147
        return null;
148
    }
149

    
150
    @Override
151
    public int getGeometryType() {
152
        return Geometry.TYPES.GEOMETRY;
153
    }
154

    
155
    @Override
156
    public int getGeometrySubType() {
157
        return Geometry.SUBTYPES.UNKNOWN;
158
    }
159

    
160
    @Override
161
    public GeometryType getGeomType() {
162
        return null;
163
    }
164

    
165
    @Override
166
    public DateFormat getDateFormat() {
167
        return null;
168
    }
169

    
170
    @Override
171
    public int getIndex() {
172
        return -1;
173
    }
174

    
175
    @Override
176
    public String getAdditionalInfo(String infoName) {
177
        return null;
178
    }
179

    
180
    @Override
181
    public boolean isAutomatic() {
182
        return false;
183
    }
184

    
185
    @Override
186
    public boolean isTime() {
187
        return false;
188
    }
189

    
190
    @Override
191
    public boolean isIndexed() {
192
        return false;
193
    }
194

    
195
    @Override
196
    public boolean allowIndexDuplicateds() {
197
        return false;
198
    }
199

    
200
    @Override
201
    public boolean isIndexAscending() {
202
        return false;
203
    }
204

    
205
    @Override
206
    public FeatureAttributeGetter getFeatureAttributeGetter() {
207
        return null;
208
    }
209

    
210
    @Override
211
    public void setFeatureAttributeGetter(FeatureAttributeGetter featureAttributeGetter) {
212
    }
213

    
214
    @Override
215
    public FeatureAttributeEmulator getFeatureAttributeEmulator() {
216
        return null;
217
    }
218

    
219
    @Override
220
    public String getName() {
221
        return this.field.getName();
222
    }
223

    
224
    @Override
225
    public int getType() {
226
        return this.field.getDataType().getType();
227
    }
228

    
229
    @Override
230
    public DataType getDataType() {
231
        return this.field.getDataType();
232
    }
233

    
234
    @Override
235
    public Object getDefaultValueCoerced() {
236
        try {
237
            return this.getDataType().coerce(this.getDefaultValue());
238
        } catch (CoercionException ex) {
239
            return null;
240
        }
241
    }
242
    
243
    @Override
244
    public String getSubtype() {
245
        return null;
246
    }
247

    
248
    @Override
249
    public String getDescription() {
250
        return this.field.getDescription();
251
    }
252

    
253
    @Override
254
    public Object getDefaultValue() {
255
        return this.field.getDefaultValue();
256
    }
257

    
258
    @Override
259
    public String getGroup() {
260
        return this.field.getGroup();
261
    }
262

    
263
    @Override
264
    public int getOder() {
265
        return this.field.getOder();
266
    }
267

    
268
    @Override
269
    public boolean isMandatory() {
270
        return this.field.isMandatory();
271
    }
272

    
273
    @Override
274
    public boolean isPersistent() {
275
        return this.field.isPersistent();
276
    }
277

    
278
    @Override
279
    public boolean isHidden() {
280
        return this.field.isHidden();
281
    }
282

    
283
    @Override
284
    public boolean isReadOnly() {
285
        return this.field.isReadOnly();
286
    }
287

    
288
    @Override
289
    public boolean isContainer() {
290
        return this.field.isContainer();
291
    }
292

    
293
    @Override
294
    public DynObjectValueItem[] getAvailableValues() {
295
        return this.field.getAvailableValues();
296
    }
297

    
298
    @Override
299
    public boolean hasConstantAvailableValues() {
300
        DynObjectValueItem[] values = this.field.getAvailableValues();
301
        return ! ArrayUtils.isEmpty(values);
302
    }
303

    
304
    @Override
305
    public Object getMinValue() {
306
        return this.field.getMinValue();
307
    }
308

    
309
    @Override
310
    public Object getMaxValue() {
311
        return this.field.getMaxValue();
312
    }
313

    
314
    @Override
315
    public Class getClassOfValue() {
316
        return this.field.getClassOfValue();
317
    }
318

    
319
    @Override
320
    public Class getClassOfItems() {
321
        return this.field.getClassOfItems();
322
    }
323

    
324
    @Override
325
    public DynField setDescription(String description) {
326
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
327
    }
328

    
329
    @Override
330
    public DynField setType(int type) {
331
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
332
    }
333

    
334
    @Override
335
    public DynField setType(DataType type) {
336
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
337
    }
338

    
339
    @Override
340
    public DynField setSubtype(String subtype) {
341
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
342
    }
343

    
344
    @Override
345
    public DynField setDefaultFieldValue(Object defaultValue) {
346
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
347
    }
348

    
349
    @Override
350
    public DynField setGroup(String groupName) {
351
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
352
    }
353

    
354
    @Override
355
    public DynField setOrder(int order) {
356
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
357
    }
358

    
359
    @Override
360
    public DynField setMandatory(boolean mandatory) {
361
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
362
    }
363

    
364
    @Override
365
    public DynField setHidden(boolean hidden) {
366
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
367
    }
368

    
369
    @Override
370
    public DynField setPersistent(boolean persistent) {
371
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
372
    }
373

    
374
    @Override
375
    public DynField setAvailableValues(DynObjectValueItem[] values) {
376
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
377
    }
378

    
379
    @Override
380
    public DynField setAvailableValues(List values) {
381
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
382
    }
383

    
384
    @Override
385
    public DynField setMinValue(Object minValue) {
386
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
387
    }
388

    
389
    @Override
390
    public DynField setMaxValue(Object maxValue) {
391
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
392
    }
393

    
394
    @Override
395
    public DynField setClassOfValue(Class theClass) throws DynFieldIsNotAContainerException {
396
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
397
    }
398

    
399
    @Override
400
    public DynField setClassOfItems(Class theClass) throws DynFieldIsNotAContainerException {
401
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
402
    }
403

    
404
    @Override
405
    public DynField setReadOnly(boolean isReadOnly) {
406
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
407
    }
408

    
409
    @Override
410
    public DynField getElementsType() {
411
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
412
    }
413

    
414
    @Override
415
    public DynField setElementsType(int type) throws DynFieldIsNotAContainerException {
416
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
417
    }
418

    
419
    @Override
420
    public DynField setElementsType(DynStruct type) throws DynFieldIsNotAContainerException {
421
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
422
    }
423

    
424
    @Override
425
    public void validate(Object value) throws DynFieldValidateException {
426
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
427
    }
428

    
429
    @Override
430
    public Object coerce(Object value) throws CoercionException {
431
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
432
    }
433

    
434
    @Override
435
    public int getTheTypeOfAvailableValues() {
436
        return this.field.getTheTypeOfAvailableValues();
437
    }
438

    
439
    @Override
440
    public DynField setDefaultDynValue(Object defaultValue) {
441
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
442
    }
443

    
444
    @Override
445
    public DynField setTheTypeOfAvailableValues(int type) {
446
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
447
    }
448

    
449
    @Override
450
    public Object clone() throws CloneNotSupportedException {
451
        DynFieldFacadeOfAFeatureAttributeDescriptor other = (DynFieldFacadeOfAFeatureAttributeDescriptor) super.clone(); 
452
        other.field = (DynField) other.field.clone();
453
        return other;
454
    }
455

    
456
    @Override
457
    public boolean isComputed() {
458
        if( field instanceof DynField_v2 ) {
459
            return ((DynField_v2)field).isCalculated();
460
        }
461
        return false;
462
    }
463

    
464
    @Override
465
    public FeatureStore getStore() {
466
        return null;
467
    }
468

    
469
    @Override
470
    public FeatureType getFeatureType() {
471
        return null;
472
    }
473

    
474
    @Override
475
    public Interval getInterval() {
476
        return null;
477
    }
478

    
479
    @Override
480
    public String getDataProfileName() {
481
        return null;
482
    }
483

    
484
    @Override
485
    public String[] getRequiredFieldNames() {
486
        return null;
487
    }
488

    
489
    @Override
490
    public DynField setClassOfValue(DynStruct dynStrct) {
491
        ((DynField_v2)this.field).setClassOfValue(dynStrct);
492
        return this;
493
    }
494

    
495
    @Override
496
    public DynField setClassOfValue(String theClassNameOfValue) {
497
        ((DynField_v2)this.field).setClassOfValue(theClassNameOfValue);
498
        return this;
499
    }
500

    
501
    @Override
502
    public String getClassNameOfValue() {
503
        return ((DynField_v2)this.field).getClassNameOfValue();
504
    }
505

    
506
    @Override
507
    public DynStruct getDynClassOfValue() {
508
        return ((DynField_v2)this.field).getDynClassOfValue();
509
    }
510

    
511
    @Override
512
    public DynField setTypeOfItems(int type) {
513
        ((DynField_v2)this.field).setTypeOfItems(type);
514
        return this;
515
    }
516

    
517
    @Override
518
    public int getTypeOfItems() {
519
        return ((DynField_v2)this.field).getTypeOfItems();
520
    }
521

    
522
    @Override
523
    public DynField setClassOfItems(DynStruct dynStrct) {
524
        ((DynField_v2)this.field).setClassOfItems(dynStrct);
525
        return this;
526
    }
527

    
528
    @Override
529
    public DynField setClassOfItems(String theClassNameOfValue) {
530
        ((DynField_v2)this.field).setClassOfItems(theClassNameOfValue);
531
        return this;
532
    }
533

    
534
    @Override
535
    public String getClassNameOfItems() {
536
        return ((DynField_v2)this.field).getClassNameOfItems();
537
    }
538

    
539
    @Override
540
    public DynStruct getDynClassOfItems() {
541
        return ((DynField_v2)this.field).getDynClassOfItems();
542
    }
543

    
544
    @Override
545
    public Tags getTags() {
546
        return ((DynField_v2)this.field).getTags();
547
    }
548

    
549
    @Override
550
    public DynField setRelationType(int relationType) {
551
        ((DynField_v2)this.field).setRelationType(relationType);
552
        return this;
553
    }
554

    
555
    @Override
556
    public int getRelationType() {
557
        return ((DynField_v2)this.field).getRelationType();
558
    }
559

    
560
    @Override
561
    public DynField setAvailableValues(DynMethod computeAvailableValues) {
562
        ((DynField_v2)this.field).setAvailableValues(computeAvailableValues);
563
        return this;
564
    }
565

    
566
    @Override
567
    public DynMethod getAvailableValuesMethod() {
568
        return ((DynField_v2)this.field).getAvailableValuesMethod();
569
    }
570

    
571
    @Override
572
    public DynObjectValueItem[] getAvailableValues(DynObject self) {
573
        return ((DynField_v2)this.field).getAvailableValues(self);
574
    }
575

    
576
    @Override
577
    public boolean isAvailableValuesCalculated() {
578
        return ((DynField_v2)this.field).isAvailableValuesCalculated();
579
    }
580

    
581
    @Override
582
    public DynField setCalculateMethod(DynMethod computeValue) {
583
        ((DynField_v2)this.field).setCalculateMethod(computeValue);
584
        return this;
585
    }
586

    
587
    @Override
588
    public DynMethod getCalculateMethod() {
589
        return ((DynField_v2)this.field).getCalculateMethod();
590
    }
591

    
592
    @Override
593
    public boolean isCalculated() {
594
        return ((DynField_v2)this.field).isCalculated();
595
    }
596

    
597
    @Override
598
    public Object getCalculatedValue(DynObject self) {
599
        return ((DynField_v2)this.field).getCalculatedValue(self);
600
    }
601

    
602
    @Override
603
    public void copyFrom(DynField other) {
604
        ((DynField_v2)this.field).copyFrom(other);
605
    }
606

    
607
    @Override
608
    public DynField setValidateElements(boolean validate) {
609
        ((DynField_v2)this.field).setValidateElements(validate);
610
        return this;
611
    }
612

    
613
    @Override
614
    public boolean getValidateElements() {
615
        return ((DynField_v2)this.field).getValidateElements();
616
    }
617

    
618
    @Override
619
    public String getLabel() {
620
        return ((DynField_v2)this.field).getLabel();
621
    }
622

    
623
    @Override
624
    public DynField setLabel(String label) {
625
        ((DynField_v2)this.field).setLabel(label);
626
        return this;
627
    }
628

    
629
    @Override
630
    public void recentUsed() {
631
    }
632

    
633
    @Override
634
    public boolean isForeingKey() {
635
        return false;
636
    }
637

    
638
    @Override
639
    public ForeingKey getForeingKey() {
640
        return null;
641
    }
642

    
643
    @Override
644
    public String getShortLabel() {
645
        return ((DynField_v2)field).getShortLabel();
646
    }
647

    
648
    @Override
649
    public DynField setShortLabel(String shortLabel) {
650
        ((DynField_v2)field).setShortLabel(shortLabel);
651
        return this;
652
    }
653

    
654
    @Override
655
    public String getLocalizedShortLabel() {
656
        return ((DynField_v2)field).getLocalizedShortLabel();
657
    }
658

    
659
    @Override
660
    public String getLocalizedLabel() {
661
        return ((DynField_v2)field).getLocalizedLabel();
662
    }
663

    
664
    @Override
665
    public String getLabelOfValue(Object value) {
666
        return Objects.toString(value, "");
667
    }
668

    
669
    @Override
670
    public DataProfile getDataProfile() {
671
        return null;
672
    }
673

    
674
    @Override
675
    public boolean hasOnlyMetadataChanges(FeatureAttributeDescriptor other) {
676
        return false;
677
    }
678

    
679
    @Override
680
    public boolean hasLabel() {
681
        return StringUtils.isNotBlank(((DynField_v2) this.field).getLabel());
682
    }
683

    
684
    @Override
685
    public boolean hasShortLabel() {
686
        return StringUtils.isNotBlank(((DynField_v2) this.field).getShortLabel());
687
    }
688

    
689
    @Override
690
    public boolean hasDescription() {
691
        return StringUtils.isNotBlank(this.field.getDescription());
692
    }
693

    
694
    @Override
695
    public FeatureAttributeDescriptor getValue() {
696
        return this;
697
    }
698

    
699
  @Override
700
  public int getRoundMode() {
701
    return BigDecimal.ROUND_HALF_UP;
702
  }
703

    
704
  @Override
705
  public Locale getLocale() {
706
    return Locale.ENGLISH;
707
  }
708

    
709
  @Override
710
  public Object get(String name) {
711
    return null;
712
  }
713

    
714
    @Override
715
    public void saveToState(PersistentState state) throws PersistenceException {
716
        
717
    }
718

    
719
    @Override
720
    public void loadFromState(PersistentState state) throws PersistenceException {
721
        
722
    }
723

    
724
  @Override
725
  public int getDisplaySize() {
726
    return 0;
727
  }
728

    
729
    @Override
730
    public Expression getAvailableValuesExpression() {
731
        return null;
732
    }
733

    
734
    @Override
735
    public FeatureAttributeDescriptor setAvailableValuesExpression(String expression) {
736
        return this;
737
    }
738

    
739
    @Override
740
    public FeatureAttributeDescriptor setAvailableValuesExpression(Expression expression) {
741
        return this;
742
    }
743

    
744
    @Override
745
    public boolean isAvoidCachingAvailableValues() {
746
        return false;
747
    }
748

    
749
    @Override
750
    public JsonObject toJson() {
751
        return null;
752
    }
753

    
754
    @Override
755
    public JsonObjectBuilder toJsonBuilder() {
756
        return null;
757
    }
758

    
759
    @Override
760
    public boolean isInAvailableValues(Object valueToCheck) {
761
        if (hasConstantAvailableValues() && this.field.getAvailableValues().length > 0) {
762
            for (DynObjectValueItem availableValue : this.field.getAvailableValues()) {
763
                if (Objects.equals(valueToCheck, availableValue.getValue())) {
764
                    return true;
765
                }
766
            }
767
        }
768
        return false;
769
    }
770

    
771
    @Override
772
    public boolean hasAvailableValues() {
773
        return this.field.getAvailableValues()!=null;
774
    }
775

    
776
    @Override
777
    public Supplier getDefaultValueSupplier() {
778
        return ((DynField_v2)this.field).getDefaultValueSupplier();
779
    }
780

    
781
    @Override
782
    public DynField setDefaultValueSupplier(Supplier supplier) {
783
        ((DynField_v2)this.field).setDefaultValueSupplier(supplier);
784
        return this;
785
    }
786

    
787
    @Override
788
    public Expression getAvailableValuesFilter() {
789
        return null;
790
    }
791

    
792
    @Override
793
    public Object getCoercedDefaultValue() {
794
        return ((DynField_v2)this.field).getCoercedDefaultValue();
795
    }
796
}