svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.swing / org.gvsig.expressionevaluator.swing.impl / src / main / java / org / gvsig / expressionevaluator / swing / impl / DefaultExpressionBuilderConfig.java @ 44259
History | View | Annotate | Download (5.62 KB)
1 |
package org.gvsig.expressionevaluator.swing.impl; |
---|---|
2 |
|
3 |
import java.util.Collection; |
4 |
import java.util.Collections; |
5 |
import java.util.HashMap; |
6 |
import java.util.List; |
7 |
import java.util.Map; |
8 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
9 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
10 |
import org.gvsig.expressionevaluator.SymbolTable; |
11 |
import org.gvsig.expressionevaluator.SymbolTableFactory; |
12 |
import org.gvsig.expressionevaluator.swing.Element; |
13 |
import org.gvsig.expressionevaluator.swing.ElementFactory; |
14 |
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
15 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
16 |
import org.gvsig.tools.util.PropertiesSupportHelper; |
17 |
|
18 |
/**
|
19 |
*
|
20 |
* @author jjdelcerro
|
21 |
*/
|
22 |
public class DefaultExpressionBuilderConfig |
23 |
implements ExpressionBuilderConfig, ExpressionBuilderConfig.Preferences {
|
24 |
|
25 |
private List<Element> elements; |
26 |
private int limit; |
27 |
private HashMap<String, SymbolTable> symbolTables; |
28 |
private final ExpressionEvaluatorSwingManager manager; |
29 |
private boolean scriptsEnabled = true; |
30 |
private SymbolTable previewSymbolTable;
|
31 |
private boolean SQLCompatible; |
32 |
private final PropertiesSupportHelper propertiesSupportHelper; |
33 |
private boolean showLabelsOfAttributes; |
34 |
|
35 |
public DefaultExpressionBuilderConfig(ExpressionEvaluatorSwingManager manager) {
|
36 |
this.manager = manager;
|
37 |
this.limit = 6; |
38 |
this.SQLCompatible = false; |
39 |
this.propertiesSupportHelper = new PropertiesSupportHelper(); |
40 |
this.showLabelsOfAttributes = true; |
41 |
initSymbolTables(); |
42 |
} |
43 |
|
44 |
@Override
|
45 |
public Preferences getPreferences() { |
46 |
return this; |
47 |
} |
48 |
|
49 |
private void initSymbolTables() { |
50 |
ExpressionEvaluatorManager theManager = ExpressionEvaluatorLocator.getManager(); |
51 |
for (SymbolTableFactory factory : theManager.getSymbolTableFactories()) {
|
52 |
if (factory.isAutoload()) {
|
53 |
this.addSymbolTable(factory.createSymbolTable());
|
54 |
} |
55 |
} |
56 |
} |
57 |
|
58 |
@Override
|
59 |
public List<Element> getElements() { |
60 |
if (this.elements == null) { |
61 |
this.elements = manager.createElements(this.getSymbolTables()); |
62 |
for (ElementFactory factory : manager.getElementFactories()) {
|
63 |
if (factory.isAutoload()) {
|
64 |
Element e = factory.createElement();
|
65 |
this.elements.add(e);
|
66 |
e.setConfig(this);
|
67 |
} |
68 |
} |
69 |
} |
70 |
return Collections.unmodifiableList(elements); |
71 |
} |
72 |
|
73 |
@Override
|
74 |
public void addElement(Element element) { |
75 |
if( element==null ) { |
76 |
return;
|
77 |
} |
78 |
this.getElements(); // Forzamos a crear la lista de elementos |
79 |
for (Element theElement : this.elements) { |
80 |
if (theElement.getName().equalsIgnoreCase(element.getName())) {
|
81 |
return;
|
82 |
} |
83 |
} |
84 |
this.elements.add(element);
|
85 |
element.setConfig(this);
|
86 |
} |
87 |
|
88 |
@Override
|
89 |
public Collection<SymbolTable> getSymbolTables() { |
90 |
return Collections.unmodifiableCollection(this.symbolTables.values()); |
91 |
} |
92 |
|
93 |
@Override
|
94 |
public void addSymbolTable(String name) { |
95 |
ExpressionEvaluatorManager theManager = ExpressionEvaluatorLocator.getManager(); |
96 |
SymbolTable symbolTable = theManager.getSymbolTable(name); |
97 |
if (symbolTable == null) { |
98 |
throw new IllegalArgumentException("Can't locate symbol table '" + name + "'."); |
99 |
} |
100 |
addSymbolTable(symbolTable); |
101 |
} |
102 |
|
103 |
@Override
|
104 |
public void addSymbolTable(SymbolTable symbolTable) { |
105 |
if (symbolTable == null) { |
106 |
return;
|
107 |
} |
108 |
if (this.elements != null) { |
109 |
throw new IllegalStateException("Can not add symbol tables once the elements are built."); |
110 |
} |
111 |
if (this.symbolTables == null) { |
112 |
this.symbolTables = new HashMap<>(); |
113 |
} |
114 |
this.symbolTables.put(symbolTable.getName(), symbolTable);
|
115 |
} |
116 |
|
117 |
@Override
|
118 |
public void removeAllSymbolTables() { |
119 |
this.symbolTables.clear();
|
120 |
} |
121 |
|
122 |
@Override
|
123 |
public int getSimpleElementsLimit() { |
124 |
return this.limit; |
125 |
} |
126 |
|
127 |
@Override
|
128 |
public void setSimpleElementsLimit(int limit) { |
129 |
this.limit = limit;
|
130 |
} |
131 |
|
132 |
@Override
|
133 |
public void removeSymbolTable(String name) { |
134 |
this.symbolTables.remove(name);
|
135 |
} |
136 |
|
137 |
@Override
|
138 |
public void setScriptsEnabled(boolean enabled) { |
139 |
this.scriptsEnabled = enabled;
|
140 |
} |
141 |
|
142 |
@Override
|
143 |
public boolean getScriptsEnabled() { |
144 |
return this.scriptsEnabled; |
145 |
} |
146 |
|
147 |
@Override
|
148 |
public SymbolTable getPreviewSymbolTable() {
|
149 |
return this.previewSymbolTable; |
150 |
} |
151 |
|
152 |
@Override
|
153 |
public void setPreviewSymbolTable(SymbolTable symbolTable) { |
154 |
this.previewSymbolTable = symbolTable;
|
155 |
} |
156 |
|
157 |
@Override
|
158 |
public void setSQLCompatible(boolean SQLCompatible) { |
159 |
this.SQLCompatible = SQLCompatible;
|
160 |
} |
161 |
|
162 |
@Override
|
163 |
public boolean isSQLCompatible() { |
164 |
return SQLCompatible;
|
165 |
} |
166 |
|
167 |
@Override
|
168 |
public Object getProperty(String string) { |
169 |
return this.propertiesSupportHelper.getProperty(string); |
170 |
} |
171 |
|
172 |
@Override
|
173 |
public void setProperty(String string, Object o) { |
174 |
this.propertiesSupportHelper.setProperty(string, o);
|
175 |
} |
176 |
|
177 |
@Override
|
178 |
public Map<String, Object> getProperties() { |
179 |
return this.propertiesSupportHelper.getProperties(); |
180 |
} |
181 |
|
182 |
@Override
|
183 |
public boolean getShowLabelsOfElements() { |
184 |
return this.showLabelsOfAttributes; |
185 |
} |
186 |
|
187 |
@Override
|
188 |
public void setShowLabelsOfElements(boolean showLabels) { |
189 |
this.showLabelsOfAttributes = showLabels;
|
190 |
} |
191 |
|
192 |
|
193 |
} |