Revision 45166 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/featurequery/DefaultFeatureQueryGroupByPanel.java
DefaultFeatureQueryGroupByPanel.java | ||
---|---|---|
17 | 17 |
import javax.swing.event.ListSelectionEvent; |
18 | 18 |
import org.apache.commons.io.FilenameUtils; |
19 | 19 |
import org.apache.commons.lang3.StringUtils; |
20 |
import org.gvsig.expressionevaluator.Code; |
|
21 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
22 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_LET; |
|
23 | 20 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
24 | 21 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
25 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
26 |
import org.gvsig.expressionevaluator.Formatter; |
|
27 | 22 |
import org.gvsig.expressionevaluator.Function; |
28 | 23 |
import org.gvsig.expressionevaluator.SymbolTable; |
29 | 24 |
import org.gvsig.expressionevaluator.SymbolTableFactory; |
30 |
import org.gvsig.fmap.dal.DALLocator; |
|
31 | 25 |
import org.gvsig.fmap.dal.exception.DataException; |
32 | 26 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
33 | 27 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
... | ... | |
43 | 37 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
44 | 38 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
45 | 39 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryGroupByPanel; |
46 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
47 | 40 |
import org.gvsig.tools.swing.api.FilteredListModel; |
48 | 41 |
|
49 | 42 |
/** |
... | ... | |
120 | 113 |
|
121 | 114 |
toolsSwingManager.translate(this.btnAttributesFilter); |
122 | 115 |
toolsSwingManager.translate(this.tabGroup); |
123 |
|
|
116 |
|
|
124 | 117 |
this.groupByPanel = new DefaultFeatureAttributesSelectionPanel(); |
125 | 118 |
this.groupByPanel.allowCalculatedAttributes(true); |
126 | 119 |
|
... | ... | |
215 | 208 |
for (FeatureAttributeDescriptor attr : featureType) { |
216 | 209 |
model.addElement(attr); |
217 | 210 |
} |
211 |
for (FeatureAttributeDescriptor attr : featureType.getExtraColumns().getColumns()) { |
|
212 |
model.addElement(attr); |
|
213 |
} |
|
214 |
for (EditableFeatureAttributeDescriptor attr : query.getExtraColumn().getColumns()) { |
|
215 |
model.addElement(attr); |
|
216 |
} |
|
218 | 217 |
model.setFilter(this.txtAttributesFilter.getText()); |
219 | 218 |
model.sort(true); |
220 | 219 |
this.lstAttributes.setModel(model); |
... | ... | |
235 | 234 |
query.getGroupByColumns().addAll(this.groupByPanel.getSelectedNames()); |
236 | 235 |
query.getAggregateFunctions().clear(); |
237 | 236 |
query.getAggregateFunctions().putAll(this.query.getAggregateFunctions()); |
238 |
|
|
239 |
List<String> selectedNames = this.groupByPanel.getSelectedNames(); |
|
240 |
for (String selectedName : selectedNames) { |
|
241 |
if (this.featureType.getAttributeDescriptor(selectedName) == null) { |
|
242 |
try { |
|
243 |
Code selectedNameCode = ExpressionUtils.compile(selectedName); |
|
244 |
if (selectedNameCode.code() == Code.CALLABLE) { |
|
245 |
Code.Callable callable = (Code.Callable) selectedNameCode; |
|
246 |
if (callable.name().equalsIgnoreCase(FUNCTION_LET)) { |
|
247 |
String exp = callable.parameters().get(1).toString(); |
|
248 |
String attrNameInExpression = (String) ((ExpressionBuilder.Constant) callable.parameters().get(0).toValue()).value(); |
|
249 |
if (query.getExtraColumn().get(attrNameInExpression)!=null) { |
|
250 |
query.getExtraColumn().remove(attrNameInExpression); |
|
251 |
} |
|
252 |
EditableFeatureAttributeDescriptor newExtraColumn = query.getExtraColumn().add(attrNameInExpression); |
|
253 |
newExtraColumn.setDataType(DataTypes.STRING); |
|
254 |
newExtraColumn.setSize(newExtraColumn.getDataType().getDefaultSize()); |
|
255 |
newExtraColumn.setFeatureAttributeEmulator( |
|
256 |
"current_row().getExtraValue('"+attrNameInExpression+"')"); |
|
257 |
//a?adirlo a las de visualizar |
|
258 |
} |
|
259 |
} |
|
260 |
} catch (Exception ex) { |
|
261 |
throw new RuntimeException("Not able to create column by expression in groupby query", ex); |
|
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
|
|
266 | 237 |
|
267 | 238 |
return query; |
268 | 239 |
} |
Also available in: Unified diff