Revision 44262 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;
6 5
import java.util.Collections;
7
import java.util.Comparator;
8 6
import java.util.Iterator;
9 7
import java.util.List;
10 8
import org.apache.commons.lang3.StringUtils;
......
13 11
import org.gvsig.expressionevaluator.swing.Element.SimpleElement;
14 12
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig;
15 13
import org.gvsig.expressionevaluator.swing.spi.AbstractElement;
16
import org.gvsig.fmap.dal.exception.DataException;
14
import org.gvsig.fmap.dal.complements.Search;
17 15
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
18 16
import org.gvsig.fmap.dal.feature.FeatureStore;
19 17
import org.gvsig.fmap.dal.feature.FeatureType;
20
import org.gvsig.fmap.dal.swing.impl.searchpanel.SearchUtils;
18
import org.gvsig.tools.ToolsLocator;
21 19

  
22 20
/**
23 21
 *
......
29 27
        implements FeatureStoreElement, SimpleElement {
30 28

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

  
36 33
    public DefaultFeatureStoreElement(FeatureStore store) {
37
        super("store", "store", "expressionbuilder-element-table");
34
        super("store", "store", "featurestore-table");
38 35
        this.setFeatureStore(store);
39 36
    }
40 37

  
41 38
    @Override
42 39
    public Element get(int index) {
43
        return this.elements.get(index);
40
        return this.buildElements().get(index);
44 41
    }
45 42

  
46 43
    @Override
44
    public String getLabel() {
45
        return this.getName();
46
    }
47

  
48
    @Override
47 49
    public void setName(String name) {
48 50
        this.myName = name;
49 51
    }
......
61 63

  
62 64
    @Override
63 65
    public int size() {
64
        return this.type.size();
66
        return this.buildElements().size();
65 67
    }
66 68

  
67 69
    @Override
68 70
    public Iterator<Element> iterator() {
69
        return this.elements.iterator();
71
        return this.buildElements().iterator();
70 72
    }
71 73

  
72 74
    @Override
......
79 81

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

  
88 87
    @Override
......
97 96

  
98 97
    @Override
99 98
    public void setFeatureStore(FeatureStore store) {
100
        if (store == null) {
101
            this.elements = Collections.EMPTY_LIST;
102
            return;
99
        this.store = store;
100
        if( store == null ) {
101
            this.elements = null;
103 102
        }
104
        this.store = store;
105 103
        this.buildElements();
106 104
    }
107 105

  
......
117 115
        return this;
118 116
    }
119 117

  
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);
118
    private List<Element> buildElements() {
119
        if (this.elements == null) {
120
            if (this.store == null || this.getConfig() == null) {
121
                return Collections.EMPTY_LIST;
138 122
            }
139
        } catch (Exception ex) {
140
            throw new RuntimeException(ex);
123
            try {
124
                FeatureType type = this.store.getDefaultFeatureType();
125

  
126
                this.elements = new ArrayList<>();
127
                Search search = (Search) ToolsLocator.getComplementsManager().get(
128
                        Search.COMPLEMENT_MANE,
129
                        type
130
                );
131
                List<FeatureAttributeDescriptor> attributes = search.getOrderedAttributes(
132
                        FeatureType.ALL_FILTER,
133
                        Search.LABEL_ORDER,
134
                        -1
135
                );
136
                for (FeatureAttributeDescriptor attrdesc : attributes) {
137
                    Element element = new FeatureAttributeElement(this.store, attrdesc);
138
                    element.setConfig(this.getConfig());
139
                    this.elements.add(element);
140
                }
141
            } catch (Exception ex) {
142
                throw new RuntimeException(ex);
143
            }
141 144
        }
145
        return this.elements;
142 146
    }
143 147
}

Also available in: Unified diff