Revision 42775 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/DefaultFeatureAttributeDescriptor.java

View differences:

DefaultFeatureAttributeDescriptor.java
45 45
import org.gvsig.tools.dynobject.DynField;
46 46
import org.gvsig.tools.dynobject.DynField_LabelAttribute;
47 47
import org.gvsig.tools.dynobject.DynField_v2;
48
import org.gvsig.tools.dynobject.DynMethod;
48 49
import org.gvsig.tools.dynobject.DynObject;
49 50
import org.gvsig.tools.dynobject.DynObjectValueItem;
50 51
import org.gvsig.tools.dynobject.DynStruct;
51 52
import org.gvsig.tools.dynobject.Tags;
52 53
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException;
53 54
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
55
import org.gvsig.tools.dynobject.exception.DynMethodException;
54 56
import org.gvsig.tools.dynobject.impl.DefaultTags;
55 57
import org.gvsig.tools.evaluator.AbstractEvaluator;
56 58
import org.gvsig.tools.evaluator.Evaluator;
......
99 101
    protected boolean hidden;
100 102
    protected String groupName;
101 103
    protected Tags tags = new DefaultTags();
102
    private AvailableValuesProvider availableValuesProvider;
104
    private DynMethod availableValuesMethod;
105
    private DynMethod calculateMethod;
103 106

  
104 107
    protected DefaultFeatureAttributeDescriptor() {
105 108
        this.allowNull = true;
......
125 128

  
126 129
    protected DefaultFeatureAttributeDescriptor(
127 130
            DefaultFeatureAttributeDescriptor other) {
131
        copyFrom(other);
132
    }
133
    
134
    @Override
135
    public void copyFrom(DynField other1) {
136
        if( !(other1 instanceof DefaultFeatureAttributeDescriptor) ) {
137
            throw new IllegalArgumentException("Can't copy from a non DefaultFeatureAttributeDescriptor");
138
        }
139
        DefaultFeatureAttributeDescriptor other = (DefaultFeatureAttributeDescriptor) other1;
128 140
        this.allowNull = other.allowNull;
129 141
        this.dataType = other.dataType;
130 142
        this.dateFormat = other.dateFormat;
......
161 173
        this.isIndexAscending = other.isIndexAscending;
162 174
        this.allowIndexDuplicateds = other.allowIndexDuplicateds;
163 175
    }
164

  
176
    
165 177
    @Override
166 178
    public String getDataTypeName() {
167 179
        if (this.getDataType() == null) {
......
176 188
    }
177 189

  
178 190
    @Override
191
    public Object clone() throws CloneNotSupportedException {
192
        return new DefaultFeatureAttributeDescriptor(this);
193
    }
194
    
195
    @Override
179 196
    public boolean allowNull() {
180 197
        return allowNull;
181 198
    }
......
851 868
    }
852 869

  
853 870
    @Override
854
    public void setAvailableValuesProvider(AvailableValuesProvider provider) {
855
        this.availableValuesProvider = provider;
871
    public DynField setAvailableValues(DynMethod availableValuesMethod) {
872
        this.availableValuesMethod = availableValuesMethod;
873
        return this;
856 874
    }
857 875

  
858 876
    @Override
859
    public DynObjectValueItem[] getAvailableValues(DynObject dynObject) {
860
        if( this.availableValuesProvider != null ) {
861
            DynObjectValueItem[] values = this.availableValuesProvider.getValues(this, dynObject);
877
    public DynObjectValueItem[] getAvailableValues(DynObject self) {
878
        if( this.availableValuesMethod != null ) {
879
            DynObjectValueItem[] values;
880
            try {
881
                values = (DynObjectValueItem[]) this.availableValuesMethod.invoke(self,new Object[] {this});
882
            } catch (DynMethodException ex) {
883
                return this.availableValues;
884
            }
862 885
            if( values != null ) {
863 886
                return values;
864 887
            }
......
866 889
        return this.availableValues;
867 890
    }
868 891

  
892
    @Override
893
    public DynMethod getAvailableValuesMethod() {
894
        return this.availableValuesMethod;
895
    }
896

  
897
    @Override
898
    public boolean isAvailableValuesCalculated() {
899
        return this.availableValuesMethod!=null;
900
    }
901

  
902
    @Override
903
    public DynMethod getCalculateMethod() {
904
        return this.calculateMethod;
905
    }
906

  
907
    @Override
908
    public DynField setCalculateMethod(DynMethod method) {
909
        this.calculateMethod = method;
910
        return this;
911
    }
912
    
913
    @Override
914
    public boolean isCalculated() {
915
        return this.calculateMethod != null;
916
    }
917
    
918
    @Override
919
    public Object getCalculatedValue(DynObject self) {
920
        try {
921
            return this.calculateMethod.invoke(self, new Object[] { this });
922
        } catch (DynMethodException ex) {
923
            throw new RuntimeException(ex);
924
        }
925
    }
926

  
927
    @Override
928
    public DynField setValidateElements(boolean validate) {
929
        return this;
930
    }
931

  
932
    @Override
933
    public boolean getValidateElements() {
934
        return false;
935
    }
936

  
869 937
    private class ConstantValueEvaluator extends AbstractEvaluator {
870 938

  
871 939
        @Override

Also available in: Unified diff