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 / expressionevaluator / DefaultFeatureStoreElement.java @ 44259
History | View | Annotate | Download (3.83 KB)
1 | 43983 | jjdelcerro | package org.gvsig.fmap.dal.swing.impl.expressionevaluator; |
---|---|---|---|
2 | |||
3 | 44000 | omartinez | import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement; |
4 | 43983 | jjdelcerro | import java.util.ArrayList; |
5 | 44259 | jjdelcerro | import java.util.Collection; |
6 | 43983 | jjdelcerro | import java.util.Collections; |
7 | import java.util.Comparator; |
||
8 | import java.util.Iterator; |
||
9 | import java.util.List; |
||
10 | 44190 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
11 | 43983 | jjdelcerro | import org.gvsig.expressionevaluator.Function; |
12 | import org.gvsig.expressionevaluator.swing.Element; |
||
13 | 44190 | jjdelcerro | import org.gvsig.expressionevaluator.swing.Element.SimpleElement; |
14 | 43983 | jjdelcerro | import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
15 | import org.gvsig.expressionevaluator.swing.spi.AbstractElement; |
||
16 | import org.gvsig.fmap.dal.exception.DataException; |
||
17 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
18 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
19 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
20 | 44259 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.searchpanel.SearchUtils; |
21 | 43983 | jjdelcerro | |
22 | /**
|
||
23 | *
|
||
24 | * @author jjdelcerro
|
||
25 | */
|
||
26 | 44259 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
27 | public class DefaultFeatureStoreElement |
||
28 | 43983 | jjdelcerro | extends AbstractElement
|
29 | 44259 | jjdelcerro | implements FeatureStoreElement, SimpleElement {
|
30 | 43983 | jjdelcerro | |
31 | 44000 | omartinez | private FeatureStore store;
|
32 | private FeatureType type;
|
||
33 | private List<Element> elements; |
||
34 | 44190 | jjdelcerro | private String myName; |
35 | 43983 | jjdelcerro | |
36 | 44259 | jjdelcerro | public DefaultFeatureStoreElement(FeatureStore store) {
|
37 | super("store", "store", "expressionbuilder-element-table"); |
||
38 | this.setFeatureStore(store);
|
||
39 | 43983 | jjdelcerro | } |
40 | 44259 | jjdelcerro | |
41 | 43983 | jjdelcerro | @Override
|
42 | public Element get(int index) { |
||
43 | return this.elements.get(index); |
||
44 | } |
||
45 | |||
46 | @Override
|
||
47 | 44190 | jjdelcerro | public void setName(String name) { |
48 | this.myName = name;
|
||
49 | } |
||
50 | 44259 | jjdelcerro | |
51 | 44190 | jjdelcerro | @Override
|
52 | 44000 | omartinez | public String getName() { |
53 | 44259 | jjdelcerro | if (!StringUtils.isBlank(this.myName)) { |
54 | 44190 | jjdelcerro | return this.myName; |
55 | } |
||
56 | 44000 | omartinez | if (this.store == null) { |
57 | return super.getName(); |
||
58 | } |
||
59 | return this.store.getName(); |
||
60 | } |
||
61 | |||
62 | @Override
|
||
63 | 43983 | jjdelcerro | public int size() { |
64 | return this.type.size(); |
||
65 | } |
||
66 | |||
67 | @Override
|
||
68 | public Iterator<Element> iterator() { |
||
69 | return this.elements.iterator(); |
||
70 | } |
||
71 | |||
72 | @Override
|
||
73 | public void addElement(Element element) { |
||
74 | } |
||
75 | |||
76 | @Override
|
||
77 | public void addElement(Function function) { |
||
78 | } |
||
79 | |||
80 | @Override
|
||
81 | public List<Element> getElements() { |
||
82 | 44259 | jjdelcerro | if (this.elements == null) { |
83 | 44215 | jjdelcerro | return Collections.EMPTY_LIST; |
84 | } |
||
85 | 43983 | jjdelcerro | return Collections.unmodifiableList(this.elements); |
86 | } |
||
87 | |||
88 | @Override
|
||
89 | public boolean hasSubgroups() { |
||
90 | return true; |
||
91 | } |
||
92 | |||
93 | @Override
|
||
94 | public boolean hasMoreElements() { |
||
95 | return false; |
||
96 | } |
||
97 | 44128 | jjdelcerro | |
98 | 44000 | omartinez | @Override
|
99 | public void setFeatureStore(FeatureStore store) { |
||
100 | 44259 | jjdelcerro | if (store == null) { |
101 | this.elements = Collections.EMPTY_LIST; |
||
102 | return;
|
||
103 | 44000 | omartinez | } |
104 | 44259 | jjdelcerro | this.store = store;
|
105 | this.buildElements();
|
||
106 | 44000 | omartinez | } |
107 | 43983 | jjdelcerro | |
108 | 44128 | jjdelcerro | @Override
|
109 | public FeatureStore getFeatureStore() {
|
||
110 | return this.store; |
||
111 | } |
||
112 | |||
113 | 44259 | jjdelcerro | @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 | } |
||
143 | 43983 | jjdelcerro | } |