Revision 47693 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

View differences:

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