Revision 45068 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
251 251
    this.dataProfile = other.dataProfile;
252 252

  
253 253
    this.availableValues = other.availableValues;
254
    this.availableValuesExpression = other.availableValuesExpression;
254 255
    this.description = other.description;
255 256
    this.minValue = other.minValue;
256 257
    this.maxValue = other.maxValue;
......
978 979
                String theLabel;
979 980
                Object theValue;
980 981
                if (labelname == null) {
982
                    theLabel = v.toString();
983
                } else {
981 984
                    theLabel = v.getString(labelname);
982
                } else {
983
                    theLabel = v.toString();
984 985
                }
985 986
                if (valuename == null) {
986 987
                    theValue = v.getString(valuename);
......
989 990
                }
990 991
                r[i] = new DynObjectValueItem(theValue, theLabel);
991 992
            }
993
        } else if (firstelement instanceof Map) {
994
            Map<String,Object> v = (Map<String,Object>) firstelement;
995
            String labelname = null;
996
            for (String theName : new String[]{
997
                "name", "label", "key", "description"
998
            }) {
999
                if (v.containsKey(theName)) {
1000
                    labelname = theName;
1001
                    break;
1002
                }
1003
                if (v.containsKey(theName.toUpperCase())) {
1004
                    labelname = theName.toLowerCase();
1005
                    break;
1006
                }
1007
            }
1008
            String valuename = null;
1009
            if (v.containsKey("value")) {
1010
                valuename = "value";
1011
            }
1012
            r = new DynObjectValueItem[values.size()];
1013
            for (int i = 0; i < values.size(); i++) {
1014
                v = (Map<String,Object>) values.get(i);
1015
                String theLabel;
1016
                Object theValue;
1017
                if (labelname == null) {
1018
                    theLabel = v.toString();
1019
                } else {
1020
                    theLabel = (String) v.get(labelname);
1021
                }
1022
                if (valuename == null) {
1023
                    theValue = v;
1024
                } else {
1025
                    theValue = v.get(valuename);
1026
                }
1027
                r[i] = new DynObjectValueItem(theValue, theLabel);
1028
            }
992 1029
        } else if (firstelement instanceof Feature) {
993 1030
            Feature v = (Feature) firstelement;
994 1031
            FeatureType featureType = v.getType();
......
1012 1049
                String theLabel;
1013 1050
                Object theValue;
1014 1051
                if (labelname == null) {
1052
                    theLabel = v.toString();
1053
                } else {
1015 1054
                    theLabel = v.getString(labelname);
1016
                } else {
1017
                    theLabel = v.toString();
1018 1055
                }
1019 1056
                if( valuename == null ) {
1057
                    theValue = v.getReference().getCode();
1058
                } else {
1020 1059
                    theValue = v.get(valuename);
1021
                } else {
1022
                    theValue = v.getReference().getCode();
1023 1060
                }
1024 1061
                r[i] = new DynObjectValueItem(theValue, theLabel);
1025 1062
            }
......
1032 1069
      if( this.availableValuesExpression == null || this.availableValuesExpression.isEmpty() ) {
1033 1070
          return null;
1034 1071
      }
1035
      Object value = this.availableValuesExpression.execute(null);
1036
      if( value instanceof DynObjectValueItem[] ) {
1037
          return (DynObjectValueItem[]) value;
1038
      }
1039
      if( value instanceof List ) {
1040
          return this.getAvailableValuesFrom(new GetItemWithSize() {
1041
              @Override
1042
              public Object get(int i) {
1043
                  return ((List)value).get(i);
1044
              }
1072
      try {
1073
        Object value = this.availableValuesExpression.execute(null);
1074
        if( value instanceof DynObjectValueItem[] ) {
1075
            return (DynObjectValueItem[]) value;
1076
        }
1077
        if( value instanceof List ) {
1078
            return this.getAvailableValuesFrom(new GetItemWithSize() {
1079
                @Override
1080
                public Object get(int i) {
1081
                    return ((List)value).get(i);
1082
                }
1045 1083

  
1046
              @Override
1047
              public int size() {
1048
                  return ((List)value).size();
1049
              }
1050
          });
1084
                @Override
1085
                public int size() {
1086
                    return ((List)value).size();
1087
                }
1088
            });
1089
        }
1090
      } catch(Throwable th) {
1091
          LOGGER.warn("Can't get available values from expression", th);
1051 1092
      }
1052 1093
      return null;
1053 1094
  }

Also available in: Unified diff