Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / dataaccess / IsSelectedCurrentRowFunction.java @ 44748

History | View | Annotate | Download (2.57 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.expressionevaluator.impl.function.dataaccess;
25

    
26
import org.apache.commons.lang3.Range;
27
import org.gvsig.expressionevaluator.Interpreter;
28
import org.gvsig.expressionevaluator.impl.DALFunctions;
29
import org.gvsig.expressionevaluator.spi.AbstractFunction;
30
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW;
31
import static org.gvsig.fmap.dal.DataManager.FUNCTION_ISSELECTED_CURRENT_ROW;
32
import org.gvsig.fmap.dal.feature.Feature;
33
import org.gvsig.fmap.dal.feature.FeatureSelection;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35

    
36
/**
37
 *
38
 * @author jjdelcerro
39
 */
40
public class IsSelectedCurrentRowFunction extends AbstractFunction {
41
  
42
  public IsSelectedCurrentRowFunction() {
43
    super(
44
            DALFunctions.GROUP_DATA_ACCESS, 
45
            FUNCTION_ISSELECTED_CURRENT_ROW, 
46
            Range.is(0), 
47
            "Return if the current feature is selected in the store when used in a filter.\n" 
48
                    + "Return false if used outer a filter.", 
49
            FUNCTION_ISSELECTED_CURRENT_ROW+"()", 
50
            null, 
51
            "Boolean",
52
            false
53
    );
54
  }
55

    
56
  private Feature current_row(Interpreter interpreter) {
57
    try {
58
      Feature f = (Feature) interpreter.call(FUNCTION_CURRENT_ROW);
59
      return f;
60
    } catch (Exception ex) {
61
      return null;
62
    }
63
  }
64

    
65
  @Override
66
  public Object call(Interpreter interpreter, Object[] args) throws Exception {
67
    Feature feature = current_row(interpreter);
68
    if (feature == null) {
69
      return false;
70
    }
71
    FeatureStore store = feature.getStore();
72
    FeatureSelection selection = store.getFeatureSelection();
73
    return selection.isSelected(feature);
74
  }
75
  
76
}