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 / FeatureAttributeElement.java @ 43983
History | View | Annotate | Download (4.26 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.expressionevaluator; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Iterator; |
5 |
import java.util.List; |
6 |
import org.apache.commons.lang.mutable.MutableInt; |
7 |
import org.gvsig.expressionevaluator.Function; |
8 |
import org.gvsig.expressionevaluator.swing.Element; |
9 |
import org.gvsig.expressionevaluator.swing.Element.GroupElement; |
10 |
import org.gvsig.expressionevaluator.swing.Element.SimpleElement; |
11 |
import org.gvsig.expressionevaluator.swing.Element.VariableElement; |
12 |
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
13 |
import org.gvsig.expressionevaluator.swing.spi.AbstractElement; |
14 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
15 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
16 |
import org.gvsig.fmap.dal.feature.Feature; |
17 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
18 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
19 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
20 |
import org.gvsig.tools.exception.BaseException; |
21 |
import org.gvsig.tools.visitor.VisitCanceledException; |
22 |
import org.gvsig.tools.visitor.Visitor; |
23 |
|
24 |
/**
|
25 |
*
|
26 |
* @author jjdelcerro
|
27 |
*/
|
28 |
public class FeatureAttributeElement |
29 |
extends AbstractElement
|
30 |
implements
|
31 |
GroupElement, |
32 |
SimpleElement, |
33 |
VariableElement |
34 |
{ |
35 |
|
36 |
final FeatureStore store;
|
37 |
final FeatureAttributeDescriptor attrdesc;
|
38 |
List<Element> elements; |
39 |
final ExpressionBuilderConfig configPanel;
|
40 |
boolean hasMoreElements;
|
41 |
|
42 |
FeatureAttributeElement(ExpressionBuilderConfig configPanel, FeatureStore store, FeatureAttributeDescriptor attrdesc) { |
43 |
super(attrdesc.getName(), attrdesc.getDescription(), "expressionbuilder-element-table-field"); |
44 |
this.configPanel = configPanel;
|
45 |
this.store = store;
|
46 |
this.attrdesc = attrdesc;
|
47 |
this.elements = null; |
48 |
this.hasMoreElements = false; |
49 |
} |
50 |
|
51 |
@Override
|
52 |
public String getTypeName() { |
53 |
return this.attrdesc.getDataTypeName(); |
54 |
} |
55 |
|
56 |
@Override
|
57 |
public Element get(int index) { |
58 |
return this.getElements().get(index); |
59 |
} |
60 |
|
61 |
@Override
|
62 |
public int size() { |
63 |
return this.getElements().size(); |
64 |
} |
65 |
|
66 |
@Override
|
67 |
public Iterator<Element> iterator() { |
68 |
return this.getElements().iterator(); |
69 |
} |
70 |
|
71 |
@Override
|
72 |
public void addElement(Element element) { |
73 |
|
74 |
} |
75 |
|
76 |
@Override
|
77 |
public void addElement(Function function) { |
78 |
|
79 |
} |
80 |
|
81 |
@Override
|
82 |
public List<Element> getElements() { |
83 |
if( this.elements==null ) { |
84 |
hasMoreElements = false;
|
85 |
final int limit = this.configPanel==null? 1000 : this.configPanel.getSimpleElementsLimit(); |
86 |
ExpressionEvaluatorSwingManager manager = ExpressionEvaluatorSwingLocator.getManager(); |
87 |
final List<Object> values = new ArrayList<>(); |
88 |
try {
|
89 |
FeatureSet set = this.store.getFeatureSet();
|
90 |
final MutableInt count = new MutableInt(0); |
91 |
set.accept(new Visitor() {
|
92 |
@Override
|
93 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
94 |
Object value = ((Feature)o).get(attrdesc.getName());
|
95 |
if( !values.contains(value ) ) {
|
96 |
values.add(value); |
97 |
} |
98 |
count.increment(); |
99 |
if( count.intValue()>= limit ) {
|
100 |
hasMoreElements = true;
|
101 |
throw new VisitCanceledException(); |
102 |
} |
103 |
} |
104 |
}); |
105 |
} catch(VisitCanceledException ex) {
|
106 |
|
107 |
} catch (Exception ex) { |
108 |
// FIXME
|
109 |
} |
110 |
this.elements = new ArrayList<>(); |
111 |
for (Object value : values) { |
112 |
this.elements.add(manager.createConstantElement(value));
|
113 |
} |
114 |
} |
115 |
return this.elements; |
116 |
} |
117 |
|
118 |
@Override
|
119 |
public boolean hasSubgroups() { |
120 |
return false; |
121 |
} |
122 |
|
123 |
@Override
|
124 |
public String getSource() { |
125 |
return this.store.getName(); |
126 |
} |
127 |
|
128 |
@Override
|
129 |
public String getLabel() { |
130 |
return "Field"; |
131 |
} |
132 |
|
133 |
@Override
|
134 |
public boolean hasMoreElements() { |
135 |
return this.hasMoreElements; |
136 |
} |
137 |
|
138 |
} |