Revision 44259 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/expressionevaluator/DefaultFeatureStoreElement.java

View differences:

DefaultFeatureStoreElement.java
2 2

  
3 3
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement;
4 4
import java.util.ArrayList;
5
import java.util.Collection;
5 6
import java.util.Collections;
6 7
import java.util.Comparator;
7 8
import java.util.Iterator;
......
16 17
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
17 18
import org.gvsig.fmap.dal.feature.FeatureStore;
18 19
import org.gvsig.fmap.dal.feature.FeatureType;
20
import org.gvsig.fmap.dal.swing.impl.searchpanel.SearchUtils;
19 21

  
20 22
/**
21 23
 *
22 24
 * @author jjdelcerro
23 25
 */
24
public class DefaultFeatureStoreElement 
26
@SuppressWarnings("UseSpecificCatch")
27
public class DefaultFeatureStoreElement
25 28
        extends AbstractElement
26
        implements FeatureStoreElement , SimpleElement
27
{
29
        implements FeatureStoreElement, SimpleElement {
28 30

  
29 31
    private FeatureStore store;
30 32
    private FeatureType type;
31 33
    private List<Element> elements;
32
    private final ExpressionBuilderConfig config;
33 34
    private String myName;
34 35

  
35
    @SuppressWarnings("OverridableMethodCallInConstructor")
36
    public DefaultFeatureStoreElement(ExpressionBuilderConfig config, FeatureStore store) {
37
        super("store", "expressionbuilder-element-table");
38
        this.config = config;
39
        if( store!=null ) {
40
            this.setFeatureStore(store);
41
        }
36
    public DefaultFeatureStoreElement(FeatureStore store) {
37
        super("store", "store", "expressionbuilder-element-table");
38
        this.setFeatureStore(store);
42 39
    }
43
    
40

  
44 41
    @Override
45 42
    public Element get(int index) {
46 43
        return this.elements.get(index);
......
50 47
    public void setName(String name) {
51 48
        this.myName = name;
52 49
    }
53
    
50

  
54 51
    @Override
55 52
    public String getName() {
56
        if( !StringUtils.isBlank(this.myName) ) {
53
        if (!StringUtils.isBlank(this.myName)) {
57 54
            return this.myName;
58 55
        }
59 56
        if (this.store == null) {
......
82 79

  
83 80
    @Override
84 81
    public List<Element> getElements() {
85
        if( this.elements == null ) {
82
        if (this.elements == null) {
86 83
            return Collections.EMPTY_LIST;
87 84
        }
88 85
        return Collections.unmodifiableList(this.elements);
......
100 97

  
101 98
    @Override
102 99
    public void setFeatureStore(FeatureStore store) {
103
          if (store==null) {
104
              this.elements = Collections.EMPTY_LIST;
105
              return;
106
          }
107
          try {
108
            
109
            this.store = store;
110
            this.type = this.store.getDefaultFeatureType();
111
            this.elements = new ArrayList<>();
112
            for (FeatureAttributeDescriptor attrdesc : type) {
113
                this.elements.add(new FeatureAttributeElement(
114
                                this.config,
115
                                this.store,
116
                                attrdesc
117
                        )
118
                );
119
            }
120
            Collections.sort(elements, new Comparator<Element>() {
121
                @Override
122
                public int compare(Element o1, Element o2) {
123
                    return o1.getName().compareTo(o2.getName());
124
                }
125
            });
126
        } catch (DataException ex) {
127
            throw new RuntimeException(ex);
100
        if (store == null) {
101
            this.elements = Collections.EMPTY_LIST;
102
            return;
128 103
        }
104
        this.store = store;
105
        this.buildElements();
129 106
    }
130 107

  
131 108
    @Override
......
133 110
        return this.store;
134 111
    }
135 112

  
136
    
113
    @Override
114
    public Element setConfig(ExpressionBuilderConfig config) {
115
        super.setConfig(config);
116
        this.buildElements();
117
        return this;
118
    }
119

  
120
    private void buildElements() {
121
        if( this.store == null || this.getConfig()==null ) {
122
            return;
123
        }
124
        try {
125
            this.type = this.store.getDefaultFeatureType();
126
            
127
            this.elements = new ArrayList<>();
128
            Collection<FeatureAttributeDescriptor> attributes = SearchUtils.getOrderedAttributes(
129
                    type, 
130
                    SearchUtils.ALL_FILTER, 
131
                    SearchUtils.LABEL_ORDER, 
132
                    -1
133
            );
134
            for (FeatureAttributeDescriptor attrdesc : attributes) {
135
                Element element = new FeatureAttributeElement(this.store,attrdesc);
136
                element.setConfig(this.getConfig());
137
                this.elements.add(element);
138
            }
139
        } catch (Exception ex) {
140
            throw new RuntimeException(ex);
141
        }
142
    }
137 143
}

Also available in: Unified diff