Revision 47693

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureQuery.java
30 30
import java.util.Iterator;
31 31
import java.util.List;
32 32
import java.util.Map;
33
import java.util.logging.Level;
34 33
import javax.json.JsonObject;
35 34
import org.apache.commons.lang3.ArrayUtils;
36 35
import org.apache.commons.lang3.StringUtils;
......
38 37
import org.apache.commons.lang3.mutable.MutableBoolean;
39 38
import org.gvsig.expressionevaluator.Code;
40 39
import org.gvsig.expressionevaluator.CodeBuilder;
41
import org.gvsig.expressionevaluator.Codes;
42 40
import org.gvsig.expressionevaluator.Expression;
43 41
import org.gvsig.expressionevaluator.ExpressionEvaluator;
44 42
import org.gvsig.expressionevaluator.ExpressionUtils;
......
281 279
        if (this.hasExtraColumnDeclaredAsGroupByField()) {
282 280
            this.retrievesAllAttributes();
283 281
        }
282
        if(this.extraColumns == null || this.extraColumns.isEmpty()){
283
            return (String[])attributeNames.toArray(new String[attributeNames.size()]);
284
        }
285
        for (EditableFeatureAttributeDescriptor extraColumn : this.extraColumns) {
286
            for (String attributeName : attributeNames) {
287
                if(StringUtils.equalsIgnoreCase(attributeName, extraColumn.getName())){
288
                    attributeNames.remove(attributeName);
289
                    break;
290
                }
291
            }
292
        }
284 293
        return (String[])attributeNames.toArray(new String[attributeNames.size()]);
285 294
    }
286 295
    
......
376 385
        if (hasExtraColumnDeclaredAsGroupByField()) {
377 386
            return true;
378 387
        }
388
        if(this.extraColumns == null || this.extraColumns.isEmpty()){
389
            return !this.attributeNames.isEmpty();
390
        }
391
        for (EditableFeatureAttributeDescriptor extraColumn : this.extraColumns) {
392
            for (String attributeName : attributeNames) {
393
                if(StringUtils.equalsIgnoreCase(attributeName, extraColumn.getName())){
394
                    attributeNames.remove(attributeName);
395
                    break;
396
                }
397
            }
398
        }
379 399
        return !this.attributeNames.isEmpty();
380 400
    }
381 401

  
......
665 685
        this.featureTypeId = state.getString("featureTypeId");
666 686
        this.attributeNames = state.getList("attributeNames");
667 687
        List<Expression> filterList = state.getList("filter");
668
        String stateFilter = "";
669 688
        DataManager dataManager = DALLocator.getDataManager();
670 689
        if (filterList.isEmpty()) {
671 690
            this.filter = null;
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/actions/SelectionSetAction.java
1 1
package org.gvsig.fmap.dal.swing.impl.actions;
2 2

  
3 3
import java.awt.event.ActionEvent;
4
import java.util.Objects;
4 5
import javax.swing.AbstractAction;
5 6
import javax.swing.Action;
7
import org.apache.commons.lang3.StringUtils;
8
import org.apache.commons.lang3.mutable.MutableBoolean;
9
import org.gvsig.expressionevaluator.Code;
6 10
import org.gvsig.expressionevaluator.Expression;
7 11
import org.gvsig.fmap.dal.DataStore;
12
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
8 13
import org.gvsig.fmap.dal.feature.FeatureQuery;
9 14
import org.gvsig.fmap.dal.feature.FeatureSelection;
10 15
import org.gvsig.fmap.dal.feature.FeatureSet;
11 16
import org.gvsig.fmap.dal.feature.FeatureStore;
12 17
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory;
18
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext;
19
import org.gvsig.fmap.dal.swing.DALSwingLocator;
20
import org.gvsig.fmap.dal.swing.DataSwingManager;
13 21
import org.gvsig.tools.ToolsLocator;
22
import org.gvsig.tools.dispose.DisposeUtils;
23
import org.gvsig.tools.exception.BaseException;
14 24
import org.gvsig.tools.i18n.I18nManager;
15 25
import org.gvsig.tools.swing.api.ToolsSwingLocator;
26
import org.gvsig.tools.visitor.VisitCanceledException;
27
import org.gvsig.tools.visitor.Visitor;
16 28
import org.slf4j.Logger;
17 29
import org.slf4j.LoggerFactory;
18
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext;
19
import org.gvsig.fmap.dal.swing.DALSwingLocator;
20
import org.gvsig.fmap.dal.swing.DataSwingManager;
21
import org.gvsig.tools.dispose.DisposeUtils;
22 30

  
23 31
/**
24 32
 *
......
52 60
    
53 61
    private final DALActionContext context;
54 62

  
63
    @SuppressWarnings("OverridableMethodCallInConstructor")
55 64
    public SelectionSetAction(DALActionContext context) {
56 65
        this.context = context;
57 66
        I18nManager i18n = ToolsLocator.getI18nManager();
......
83 92
                featureStore.setSelection(currentSelection);
84 93
                return;
85 94
            }
86
            Expression filter = null;
87 95
            FeatureQuery query = null;
88 96
            FeatureQuery contextQuery = this.context.getQuery();
89 97
            if (contextQuery != null) {
90
                filter = contextQuery.getExpressionFilter();
98
                Expression filter = contextQuery.getExpressionFilter();
91 99
                if (filter != null) {
92 100
                    query = featureStore.createFeatureQuery();
93 101
                    query.setFilter(filter);
102
                    for (EditableFeatureAttributeDescriptor extraColumn : contextQuery.getExtraColumns()) {
103
                        if(expressionUseIdentifier(filter, extraColumn.getName())){
104
                            query.getExtraColumns().getColumns().add(extraColumn);
105
                        }
106
                    }
107
//                    query.retrievesAllAttributes();
94 108
                }
95 109
            } 
96 110
            currentSelection = featureStore.getFeatureSelection();
......
102 116
            currentSelection.deselectAll();
103 117
            currentSelection.select(selection);
104 118
        } catch (Exception ex) {
105
            LOGGER.warn("Can't build selecction.", ex);
119
            LOGGER.warn("Can't build selection.", ex);
106 120
        } finally {
107 121
            DisposeUtils.disposeQuietly(selection);
108 122
        }
109 123
    }
110 124

  
125
    @SuppressWarnings("Convert2Lambda")
126
    private boolean expressionUseIdentifier(Expression filter, String name) {
127
        MutableBoolean res = new MutableBoolean(false);
128
        try {
129
            filter.getCode().accept(new Visitor() {
130
                @Override
131
                public void visit(Object obj) throws VisitCanceledException, BaseException {
132
                    if (((Code) obj).code() == Code.IDENTIFIER) {
133
                        if (StringUtils.equalsIgnoreCase(name, ((Code.Identifier) obj).name())) {
134
                            res.setTrue();
135
                            throw new VisitCanceledException();
136
                        }
137
                    } else if (((Code) obj).code() == Code.CALLABLE) {
138
                        Code.Callable callable = (Code.Callable) obj;
139
                        if (StringUtils.equalsIgnoreCase("GETATTR", callable.name()) &&
140
                            callable.parameters().size() == 2 &&
141
                            callable.parameters().get(1).code() == Code.CONSTANT) {
142
                            Code.Constant p1 = (Code.Constant) callable.parameters().get(1);
143
                            if (StringUtils.equalsIgnoreCase(name, Objects.toString(p1.value(), null))) {
144
                                res.setTrue();
145
                                throw new VisitCanceledException();
146
                            }
147
                        }
148
                    }
149
                }
150
            });
151
        } catch (VisitCanceledException e) {
152
        } catch (Exception e) {
153
            throw new RuntimeException("Can't check if '"+name+"' is in '"+filter.getPhrase()+"'", e);
154
        }
155
        return res.booleanValue();
156
    }
157

  
158

  
111 159
}

Also available in: Unified diff