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 |
package org.gvsig.fmap.dal.swing.impl.expressionevaluator; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement; |
4 |
import java.util.ArrayList; |
5 |
import java.util.Collection; |
6 |
import java.util.Collections; |
7 |
import java.util.Comparator; |
8 |
import java.util.Iterator; |
9 |
import java.util.List; |
10 |
import org.apache.commons.lang3.StringUtils; |
11 |
import org.gvsig.expressionevaluator.Function; |
12 |
import org.gvsig.expressionevaluator.swing.Element; |
13 |
import org.gvsig.expressionevaluator.swing.Element.SimpleElement; |
14 |
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 |
import org.gvsig.fmap.dal.swing.impl.searchpanel.SearchUtils; |
21 |
|
22 |
/**
|
23 |
*
|
24 |
* @author jjdelcerro
|
25 |
*/
|
26 |
@SuppressWarnings("UseSpecificCatch") |
27 |
public class DefaultFeatureStoreElement |
28 |
extends AbstractElement
|
29 |
implements FeatureStoreElement, SimpleElement {
|
30 |
|
31 |
private FeatureStore store;
|
32 |
private FeatureType type;
|
33 |
private List<Element> elements; |
34 |
private String myName; |
35 |
|
36 |
public DefaultFeatureStoreElement(FeatureStore store) {
|
37 |
super("store", "store", "expressionbuilder-element-table"); |
38 |
this.setFeatureStore(store);
|
39 |
} |
40 |
|
41 |
@Override
|
42 |
public Element get(int index) { |
43 |
return this.elements.get(index); |
44 |
} |
45 |
|
46 |
@Override
|
47 |
public void setName(String name) { |
48 |
this.myName = name;
|
49 |
} |
50 |
|
51 |
@Override
|
52 |
public String getName() { |
53 |
if (!StringUtils.isBlank(this.myName)) { |
54 |
return this.myName; |
55 |
} |
56 |
if (this.store == null) { |
57 |
return super.getName(); |
58 |
} |
59 |
return this.store.getName(); |
60 |
} |
61 |
|
62 |
@Override
|
63 |
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 |
if (this.elements == null) { |
83 |
return Collections.EMPTY_LIST; |
84 |
} |
85 |
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 |
|
98 |
@Override
|
99 |
public void setFeatureStore(FeatureStore store) { |
100 |
if (store == null) { |
101 |
this.elements = Collections.EMPTY_LIST; |
102 |
return;
|
103 |
} |
104 |
this.store = store;
|
105 |
this.buildElements();
|
106 |
} |
107 |
|
108 |
@Override
|
109 |
public FeatureStore getFeatureStore() {
|
110 |
return this.store; |
111 |
} |
112 |
|
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 |
} |
143 |
} |