Revision 47049

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/fmap/dal/swing/DataSwingManager.java
27 27
import java.util.List;
28 28
import java.util.Map;
29 29
import java.util.function.Predicate;
30
import javax.json.JsonObject;
30 31
import javax.swing.AbstractButton;
32
import javax.swing.Action;
31 33
import javax.swing.Icon;
32 34
import javax.swing.JButton;
33 35
import javax.swing.JComboBox;
......
35 37
import javax.swing.JPanel;
36 38
import javax.swing.JTextField;
37 39
import javax.swing.JTree;
38
import javax.swing.table.TableModel;
39 40
import javax.swing.text.JTextComponent;
40 41
import javax.swing.tree.TreeModel;
41 42
import org.gvsig.expressionevaluator.Expression;
......
52 53
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
53 54
import org.gvsig.fmap.dal.feature.FeatureQuery;
54 55
import org.gvsig.fmap.dal.feature.FeatureReference;
56
import org.gvsig.fmap.dal.feature.FeatureSelection;
55 57
import org.gvsig.fmap.dal.feature.FeatureStore;
56 58
import org.gvsig.fmap.dal.feature.FeatureType;
57 59
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper;
......
74 76
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeListCellRenderer;
75 77
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeTableCellRenderer;
76 78
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel;
79
import org.gvsig.fmap.dal.swing.report.ReportAction;
80
import org.gvsig.fmap.dal.swing.report.ReportActionFactory;
81
import org.gvsig.fmap.dal.swing.report.ReportActionFactory.ReportCustomActionFactory;
77 82

  
78 83
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcessFactory;
79 84
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters;
......
243 248
    public int askUserStopEditing(Component parent, FeatureStore featureStore, boolean allowContinue);
244 249
    
245 250
    public JPanel createVisualdbModelerPanel();
251

  
252
    public void registerReportAction(ReportActionFactory factory);
253
    
254
    public Collection<ReportActionFactory> getReportActionFactories();
255
    
256
    public void registerReportsCustomAction(ReportCustomActionFactory factory, boolean insertSeparator);
257

  
258
    public ReportActionFactory getReportActionFactory(String name);
246 259
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/fmap/dal/swing/report/ReportActionFactory.java
1
package org.gvsig.fmap.dal.swing.report;
2

  
3
import java.awt.event.ActionEvent;
4
import javax.json.JsonObject;
5
import javax.swing.Action;
6
import org.gvsig.fmap.dal.feature.FeatureQuery;
7
import org.gvsig.fmap.dal.feature.FeatureSelection;
8
import org.gvsig.fmap.dal.feature.FeatureStore;
9
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext;
10
import org.gvsig.tools.util.IsApplicable;
11

  
12
public interface ReportActionFactory extends IsApplicable {
13

  
14
    public String getName();
15
    
16
    public ReportAction createReportAction(FeatureStore store, FeatureQuery query, FeatureSelection selecteds, JsonObject json);
17

  
18
    public interface ReportCustomActionFactory {
19
        public String getName();
20

  
21
        public Action createCustomAction(ActionEvent event, DALActionContext context);
22
    }
23
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/fmap/dal/swing/report/AbstractReportActionFactory.java
1
package org.gvsig.fmap.dal.swing.report;
2

  
3
public abstract class AbstractReportActionFactory implements ReportActionFactory {
4

  
5
    private final String name;
6

  
7
    protected AbstractReportActionFactory(String name) {
8
        this.name = name;
9
    }
10

  
11
    @Override
12
    public String getName() {
13
        return this.name;
14
    }
15
    
16
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/fmap/dal/swing/report/ReportAction.java
1
package org.gvsig.fmap.dal.swing.report;
2

  
3
import javax.swing.Action;
4
import org.gvsig.fmap.dal.feature.Feature;
5
import org.gvsig.fmap.dal.feature.FeatureSet;
6
import org.gvsig.tools.task.SimpleTaskStatus;
7
import org.gvsig.tools.util.LabeledValue;
8

  
9
/**
10
 *
11
 * @author jjdelcerro
12
 */
13
public interface ReportAction extends Action, LabeledValue<ReportAction>{
14

  
15
    public String getName();
16
    
17
    public ReportActionFactory getFactory();
18

  
19
    public String formatFieldValue(Feature feature, String fieldname);
20

  
21
    public SimpleTaskStatus getStatus();
22
    
23
    public FeatureSet rows();
24
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/fmap/dal/swing/report/AbstractReportAction.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.fmap.dal.swing.report;
7

  
8
import javax.swing.AbstractAction;
9
import javax.swing.Action;
10
import org.apache.commons.lang3.StringUtils;
11
import org.apache.commons.text.StringEscapeUtils;
12
import org.gvsig.fmap.dal.feature.Feature;
13
import org.gvsig.fmap.dal.feature.FeatureSet;
14
import static org.gvsig.fmap.dal.feature.FeatureSet.EMPTY_FEATURESET;
15
import org.gvsig.tools.ToolsLocator;
16
import org.gvsig.tools.task.SimpleTaskStatus;
17
import org.slf4j.Logger;
18
import org.slf4j.LoggerFactory;
19

  
20
/**
21
 *
22
 * @author jjdelcerro
23
 */
24
public abstract class AbstractReportAction extends AbstractAction implements ReportAction{
25

  
26
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractReportAction.class);
27
    
28
    private final ReportActionFactory factory;
29
    private SimpleTaskStatus status;
30

  
31

  
32
    @SuppressWarnings("OverridableMethodCallInConstructor")
33
    protected AbstractReportAction(ReportActionFactory factory, String label) {
34
        this.status = null;
35
        this.factory = factory;
36
        if( label == null ) {
37
            this.putValue(Action.NAME, factory.getName());
38
        } else {
39
            this.putValue(Action.NAME, label);
40
        }
41
    }
42

  
43
    @Override
44
    public ReportActionFactory getFactory() {
45
        return this.factory;
46
    }
47

  
48
    @Override
49
    public String getName() {
50
        return this.factory.getName();
51
    }
52

  
53
    @Override
54
    public String getLabel() {
55
        return (String) this.getValue(Action.NAME);
56
    }
57

  
58
    protected void setLabel(String label) {
59
        this.putValue(Action.NAME, label);
60
    }
61
    
62
    @Override
63
    public ReportAction getValue() {
64
        return this;
65
    }
66
    
67
    @Override
68
    public boolean isEnabled() {
69
        return true;
70
    }
71

  
72
    @Override
73
    public String toString() {
74
        return this.getLabel();
75
    }
76
    
77
    @Override
78
    public SimpleTaskStatus getStatus() {
79
        if( this.status == null ) {
80
            this.status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("Report "+this.getLabel());
81
        }
82
        return this.status;
83
    }    
84

  
85
    @Override
86
    public FeatureSet rows() {
87
        return EMPTY_FEATURESET;
88
    }
89

  
90
    @Override
91
    public String formatFieldValue(Feature feature, String fieldname) {
92
        if( StringUtils.isBlank(fieldname) ) {
93
            LOGGER.warn("Illegal fieldname value (null)");
94
            return "NULL";
95
        }
96
        if( feature == null ) {
97
            LOGGER.warn("Can't access attribute '"+fieldname+"', feature is null.");
98
            return "NULL";
99
        }
100
        String v = null;
101
        try {
102
            v = feature.getLabelOfValue(fieldname);
103
        } catch(Exception ex) {
104
            LOGGER.debug("Esto no deberia estar pasando (1)!!!",ex);
105
        }
106
        try {
107
            v = StringEscapeUtils.escapeHtml4(v);
108
        } catch(Exception ex) {
109
            LOGGER.debug("Esto no deberia estar pasando (2)!!!",ex);
110
        }
111
        return v;
112
    }
113
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/pom.xml
14 14
    
15 15
  <dependencies>
16 16
    <dependency>
17
      <groupId>org.apache.commons</groupId>
18
      <artifactId>commons-text</artifactId>
19
      <scope>compile</scope>
20
    </dependency>
21
    <dependency>
17 22
      <groupId>org.gvsig</groupId>
18 23
      <artifactId>org.gvsig.tools.lib</artifactId>
19 24
      <scope>compile</scope>
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/SelectionFilterAction.java
19 19
import org.slf4j.Logger;
20 20
import org.slf4j.LoggerFactory;
21 21
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext;
22
import org.gvsig.fmap.dal.swing.DALSwingLocator;
23
import org.gvsig.fmap.dal.swing.DataSwingManager;
22 24

  
23 25
/**
24 26
 *
......
41 43
        public Action createAction(DALActionContext context) {
42 44
            return new SelectionFilterAction(context);
43 45
        }
44
        
46

  
47
        public static void selfRegister() {
48
            DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager();
49
            dalSwingManager.registerStoreAction(new SelectionFilterActionFactory());
50
        }            
45 51
    }
46 52

  
47 53
    private static final Logger LOGGER = LoggerFactory.getLogger(SelectionFilterAction.class);
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/SelectionAddAction.java
16 16
import org.slf4j.Logger;
17 17
import org.slf4j.LoggerFactory;
18 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;
19 21

  
20 22
/**
21 23
 *
......
38 40
        public Action createAction(DALActionContext context) {
39 41
            return new SelectionAddAction(context);
40 42
        }
43

  
44
        public static void selfRegister() {
45
            DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager();
46
            dalSwingManager.registerStoreAction(new SelectionAddActionFactory());
47
        }        
48
     
41 49
    }
42 50
    
43 51
    private static final Logger LOGGER = LoggerFactory.getLogger(SelectionAddAction.class);
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/ShowFormForOpenStoreParametersAction.java
12 12
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_REPOSITORY_PARAMETERS;
13 13
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_REPOSITORY_NAME;
14 14
import org.gvsig.fmap.dal.swing.DALSwingLocator;
15
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanelManager;
16
import org.gvsig.fmap.dal.swing.impl.dataStoreParameters.DataStoreDynObjectParametersPanelFactory;
15
import org.gvsig.fmap.dal.swing.DataSwingManager;
17 16
import org.gvsig.tools.dynform.JDynFormField;
18 17
import org.gvsig.tools.dynform.spi.DynFormSPILocator;
19 18
import org.gvsig.tools.dynform.spi.DynFormSPIManager;
......
56 55
            return new ShowFormForOpenStoreParametersAction(jfield);
57 56
        }
58 57

  
58

  
59
        public static void selfRegister() {
60
            DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager();
61
            dalSwingManager.registerStoreAction(new ShowFormAction.ShowFormActionFactory());
62
        }     
59 63
    }
60 64

  
61 65
    private final JDynFormField jfield;
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/GraphAction.java
76 76
        public boolean isApplicable(Object... args) {
77 77
            return false; // args[0] instanceof SearchActionContext;
78 78
        }
79

  
80
        public static void selfRegister() {
81
            DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager();
82
            dalSwingManager.registerStoreAction(new GraphActionFactory());
83
        }        
79 84
        
80 85
    }
81 86

  
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
16 16
import org.slf4j.Logger;
17 17
import org.slf4j.LoggerFactory;
18 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;
19 21
import org.gvsig.tools.dispose.DisposeUtils;
20 22

  
21 23
/**
......
39 41
        public Action createAction(DALActionContext context) {
40 42
            return new SelectionSetAction(context);
41 43
        }
42
        
44

  
45
        public static void selfRegister() {
46
            DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager();
47
            dalSwingManager.registerStoreAction(new SelectionSetActionFactory());
48
        }        
43 49
    }
44 50

  
45 51
    private static final Logger LOGGER = LoggerFactory.getLogger(SelectionSetAction.class);
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/ShowFormAction.java
44 44
        public Action createAction(DALActionContext context) {
45 45
            return new ShowFormAction(context);
46 46
        }
47
        
47

  
48
        public static void selfRegister() {
49
            DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager();
50
            dalSwingManager.registerStoreAction(new ShowFormActionFactory());
51
        }               
48 52
    }
49 53

  
50 54

  
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/ReportStoreAction.java
1
package org.gvsig.fmap.dal.swing.impl.actions;
2

  
3
import java.awt.event.ActionEvent;
4
import java.io.InputStream;
5
import java.net.URL;
6
import java.util.ArrayList;
7
import java.util.Collections;
8
import java.util.LinkedHashMap;
9
import java.util.List;
10
import java.util.Map;
11
import javax.json.Json;
12
import javax.json.JsonObject;
13
import javax.swing.AbstractAction;
14
import javax.swing.Action;
15
import javax.swing.JComponent;
16
import javax.swing.JMenuItem;
17
import javax.swing.JPopupMenu;
18
import org.apache.commons.io.IOUtils;
19
import org.apache.commons.lang3.StringUtils;
20
import org.apache.commons.lang3.tuple.ImmutablePair;
21
import org.apache.commons.lang3.tuple.Pair;
22
import org.gvsig.fmap.dal.DataStore;
23
import org.gvsig.fmap.dal.feature.FeatureStore;
24
import org.gvsig.fmap.dal.swing.DALSwingLocator;
25
import org.gvsig.fmap.dal.swing.DataSwingManager;
26
import org.gvsig.tools.ToolsLocator;
27
import org.gvsig.tools.i18n.I18nManager;
28
import org.gvsig.tools.swing.api.ToolsSwingLocator;
29
import org.gvsig.tools.swing.icontheme.IconTheme;
30
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
31
import org.gvsig.tools.resourcesstorage.ResourcesStorage.Resource;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34
import org.gvsig.fmap.dal.swing.DALActionFactory;
35
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext;
36
import org.gvsig.fmap.dal.swing.report.ReportAction;
37
import org.gvsig.fmap.dal.swing.report.ReportActionFactory;
38
import org.gvsig.fmap.dal.swing.report.ReportActionFactory.ReportCustomActionFactory;
39
import org.gvsig.tools.dispose.DisposeUtils;
40

  
41
/**
42
 *
43
 * @author jjdelcerro
44
 */
45
@SuppressWarnings("UseSpecificCatch")
46
public class ReportStoreAction
47
        extends AbstractAction {
48

  
49
    public static String ACTION_NAME = "Reports";
50

  
51
    public static class ReportStoreActionFactory implements DALActionFactory {
52

  
53
        private final Map<String,Pair<ReportCustomActionFactory,Boolean>> customActions;
54
        
55
        public ReportStoreActionFactory() {
56
            this.customActions = new LinkedHashMap<>();
57
        }
58
        
59
        @Override
60
        public String getName() {
61
            return ACTION_NAME;
62
        }
63

  
64
        @Override
65
        public Action createAction(DALActionContext context) {
66
            return new ReportStoreAction(this, context);
67
        }
68

  
69
        @Override
70
        public boolean isApplicable(Object... args) {
71
            return true;
72
        }
73

  
74
        public void registerCustomAction(ReportCustomActionFactory factory, boolean insertSeparator) {
75
            this.customActions.put(factory.getName(), new ImmutablePair<>(factory,insertSeparator));
76
        }
77
        
78
        public Map<String, Pair<ReportCustomActionFactory, Boolean>> getCustomActions() {
79
            return this.customActions;
80
        }
81
        
82
        public static void selfRegister() {
83
            DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager();
84
            dalSwingManager.registerStoreAction(new ReportStoreActionFactory());
85
            String[][] iconNames = new String[][]{
86
                new String[]{"Report", "report-select-reports"}
87
            };
88
            IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent();
89
            for (String[] icon : iconNames) {
90
                URL url = ReportStoreAction.class.getResource("images/" + icon[1] + ".png");
91
                theme.registerDefault("Report", icon[0], icon[1], null, url);
92
            }
93
        }
94

  
95
    }
96

  
97
    private static final Logger LOGGER = LoggerFactory.getLogger(ReportStoreAction.class);
98

  
99
    private final DALActionContext context;
100
    private final ReportStoreActionFactory factory;
101

  
102
    @SuppressWarnings("OverridableMethodCallInConstructor")
103
    public ReportStoreAction(ReportStoreActionFactory factory, DALActionContext context) {
104
        this.factory = factory;
105
        this.context = context;
106
        I18nManager i18n = ToolsLocator.getI18nManager();
107
        this.putValue(
108
                Action.ACTION_COMMAND_KEY,
109
                ACTION_NAME
110
        );
111
        this.putValue(
112
                Action.SHORT_DESCRIPTION,
113
                i18n.getTranslation("_Reports")
114
        );
115
        this.putValue(
116
                Action.SMALL_ICON,
117
                ToolsSwingLocator.getIconThemeManager().getCurrent().get("report-select-reports")
118
        );
119
    }
120

  
121
    private List<JsonObject> getReports(FeatureStore store) {
122
        List<JsonObject> reports = new ArrayList<>();
123
        ResourcesStorage resources = null;
124
        try {
125
            resources = store.getResourcesStorage();
126
            if (resources != null) {
127
                List<Resource> reportsResources = resources.getResources("report");
128
                if (reportsResources != null && !reportsResources.isEmpty()) {
129
                    for (Resource resource : reportsResources) {
130
                        InputStream is = null;
131
                        try {
132
                            is = resource.asInputStream();
133
                            JsonObject json = Json.createReader(is).readObject();
134
                            reports.add(json);
135
                        } catch (Exception ex) {
136
                            LOGGER.warn("Can't load report form resource (" + resource.getURL() + ")", ex);
137
                        } finally {
138
                            IOUtils.closeQuietly(is);
139
                        }
140
                    }
141
                }
142
            }
143
        } finally {
144
            DisposeUtils.disposeQuietly(resources);
145
        }
146
        if (reports.isEmpty()) {
147
            return null;
148
        }
149
        return reports;
150
    }
151

  
152
    @Override
153
    public void actionPerformed(ActionEvent e) {
154
        try {
155
            DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager();
156
//            this.setEnabled(false);
157
            DataStore store = this.context.getStore();
158
            if (!(store instanceof FeatureStore)) {
159
                return;
160
            }
161
            List<ReportAction> actions = new ArrayList<>();
162
            List<JsonObject> reports = this.getReports((FeatureStore) store);
163
            if (reports != null && !reports.isEmpty()) {
164
                for (JsonObject json : reports) {
165
                    ReportAction action = null;
166
                    for (ReportActionFactory theFactory : dataSwingManager.getReportActionFactories()) {
167
                        if( theFactory.isApplicable(json,this.context, e)) {
168
                            action = theFactory.createReportAction(
169
                                    (FeatureStore) store,
170
                                    this.context.getQuery(),
171
                                    this.context.getSelecteds(),
172
                                    json
173
                            );
174
                        }
175
                    }
176
                    if( action != null ) {
177
                        String label = (String) action.getValue(Action.NAME);
178
                        if( StringUtils.isBlank(label) ) {
179
                            action.putValue(Action.NAME, action.getLabel());
180
                        }
181
                        actions.add(action);
182
                    }
183
                }
184
            }
185
            Collections.sort(
186
                    actions, 
187
                    (ReportAction o1, ReportAction o2) -> StringUtils.compare(o1.getLabel(), o2.getLabel())
188
            );
189
            JPopupMenu popup = new JPopupMenu();
190
            for (ReportAction action : actions) {
191
                popup.add(new JMenuItem(action));
192
            }
193
            for (Pair<ReportCustomActionFactory, Boolean> customAction : this.factory.getCustomActions().values()) {
194
                Action action = customAction.getLeft().createCustomAction(e, context);
195
                if( action !=null ) {
196
                    if( customAction.getRight() && popup.getComponentCount()>0 ) {
197
                        popup.addSeparator();
198
                    }
199
                    popup.add(action);
200
                }
201
            }
202
            JComponent button = this.context.getActionButton(ACTION_NAME);
203
            popup.show(button, 0, button.getHeight());
204
        } catch (Exception ex) {
205
            LOGGER.warn("Can't show form", ex);
206
        } finally {
207
//            this.setEnabled(true);
208
        }
209
    }
210

  
211
    @Override
212
    public boolean isEnabled() {
213
        try {
214
            DataStore store = this.context.getStore();
215
            if (!(store instanceof FeatureStore)) {
216
                return false;
217
            }
218
            DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager();
219
            List<JsonObject> reports = this.getReports((FeatureStore) store);
220
            if (reports != null && !reports.isEmpty()) {
221
                for (JsonObject json : reports) {
222
                    for (ReportActionFactory thefactory : dataSwingManager.getReportActionFactories()) {
223
                        if( thefactory.isApplicable(json,this.context)) {
224
                            return true;
225
                        }
226
                    }
227
                }
228
            }
229
        } catch (Exception ex) {
230
            LOGGER.warn("Can't check isEnabled", ex);            
231
        }
232
        return false;
233
    }
234

  
235
}
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/DefaultDataSwingManager.java
103 103
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel;
104 104
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel;
105 105
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel;
106
import org.gvsig.fmap.dal.swing.impl.actions.CopyFormAction;
107
import org.gvsig.fmap.dal.swing.impl.actions.CopyFormAction.CopyFormActionFactory;
108
import org.gvsig.fmap.dal.swing.impl.actions.GraphAction.GraphActionFactory;
109
import org.gvsig.fmap.dal.swing.impl.actions.SelectionAddAction.SelectionAddActionFactory;
110
import org.gvsig.fmap.dal.swing.impl.actions.SelectionFilterAction.SelectionFilterActionFactory;
111
import org.gvsig.fmap.dal.swing.impl.actions.SelectionSetAction.SelectionSetActionFactory;
112
import org.gvsig.fmap.dal.swing.impl.actions.ShowFormAction.ShowFormActionFactory;
106
import org.gvsig.fmap.dal.swing.impl.actions.ReportStoreAction;
107
import org.gvsig.fmap.dal.swing.impl.actions.ReportStoreAction.ReportStoreActionFactory;
113 108
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.DefaultFeatureStoreElement2;
114 109
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.CheckTableFieldsSuggestionProviderFactory;
115 110
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.DivSuggestionProviderFactory;
......
141 136
import org.gvsig.fmap.dal.swing.impl.visualdbmodeler.Visualdbmodeler;
142 137
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionDialog;
143 138
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel;
139
import org.gvsig.fmap.dal.swing.report.ReportActionFactory;
140
import org.gvsig.fmap.dal.swing.report.ReportActionFactory.ReportCustomActionFactory;
144 141
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcessFactory;
145 142
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel;
146 143
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory;
......
170 167

  
171 168
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDataSwingManager.class);
172 169
    
173
    private final Map<String,DALActionFactory> featureStoreSearchActions;
170
    private final Map<String,DALActionFactory> featureStoreActions;
174 171
    private final Map<String,SearchPostProcessFactory> searchPostProcess;
175 172
    private Map<String,SearchConditionPanelFactory> searchConditionPanelFactories;
176 173
    private Integer useLabels;
177 174
    
178 175
    public DefaultDataSwingManager() {
179
        this.featureStoreSearchActions = new LinkedHashMap<>();
180
        this.registerStoreAction(new SelectionAddActionFactory());
181
        this.registerStoreAction(new SelectionFilterActionFactory());
182
        this.registerStoreAction(new SelectionSetActionFactory());
183
        this.registerStoreAction(new ShowFormActionFactory());
184
        this.registerStoreAction(new GraphActionFactory());
185
        this.registerStoreAction(new CopyFormActionFactory());
186
        
176
        this.featureStoreActions = new LinkedHashMap<>();
187 177
        this.searchPostProcess = new HashMap<>();
188 178
    }
189 179
    
......
493 483

  
494 484
    @Override
495 485
    public final void registerStoreAction(DALActionFactory action) {
496
        this.featureStoreSearchActions.put(action.getName().toLowerCase(), action);
486
        this.featureStoreActions.put(action.getName().toLowerCase(), action);
497 487
    }
498 488
    
499 489
    @Override
500 490
    public  Collection<DALActionFactory> getStoreActions() {
501
        return Collections.unmodifiableCollection(this.featureStoreSearchActions.values());
491
        return Collections.unmodifiableCollection(this.featureStoreActions.values());
502 492
    }
503 493

  
504 494
    @Override
505 495
    public Collection<DALActionFactory> getApplicableStoreActions(DALActionContext context) {
506 496
        Collection<DALActionFactory> factories = new ArrayList<>();
507 497
        try {
508
            for (DALActionFactory factory : this.featureStoreSearchActions.values()) {
498
            for (DALActionFactory factory : this.featureStoreActions.values()) {
509 499
                if (factory == null ) {
510 500
                    continue;
511 501
                }
......
526 516

  
527 517
    @Override
528 518
    public  DALActionFactory getStoreAction(String name) {
529
        DALActionFactory action = this.featureStoreSearchActions.get(name.toLowerCase());
519
        DALActionFactory action = this.featureStoreActions.get(name.toLowerCase());
530 520
        return action;
531 521
    }
532 522
    
......
732 722
        return new DefaultSearchParameters();
733 723
    }
734 724

  
725
    @Override
735 726
    public FeatureQueryPickerController createFeatureQueryPickerController(JTextComponent text, JButton button, JButton history, JButton bookmarks) {
736 727
        DefaultFeatureQueryPickerController controller = new DefaultFeatureQueryPickerController(text, button, history, bookmarks);
737 728
        return controller;
......
804 795
        return this.askUserStopEditing(null, featureStore, true);
805 796
    }
806 797

  
798
    @Override
807 799
    public int askUserStopEditing(FeatureStore featureStore, boolean allowContinue) {
808 800
        return this.askUserStopEditing(null, featureStore, allowContinue);
809 801
    }
810 802

  
803
    @Override
811 804
    public int askUserStopEditing(Component parent, FeatureStore featureStore, boolean allowContinue) {
812 805
        boolean allowWrite = featureStore.allowWrite();
813 806

  
......
884 877
        return true;
885 878
    }
886 879
        
880
    @Override
887 881
    public JPanel createVisualdbModelerPanel() {
888 882
        return new Visualdbmodeler();
889 883
    }
890 884

  
885
    private Map<String,ReportActionFactory> reportActionFactories;
886
    
887
    @Override
888
    public void registerReportAction(ReportActionFactory factory) {
889
        if( this.reportActionFactories == null ) {
890
            this.reportActionFactories = new HashMap<>();
891
        }
892
        this.reportActionFactories.put(factory.getName().toLowerCase(), factory);
893
    }
894
    
895
    @Override
896
    public ReportActionFactory getReportActionFactory(String name) {
897
        if( StringUtils.isBlank(name) ) {
898
            return null;
899
        }
900
        return this.reportActionFactories.get(name.toLowerCase());
901
    }
902

  
903
    @Override
904
    public Collection<ReportActionFactory> getReportActionFactories() {
905
        return this.reportActionFactories.values();
906
    }
907
    
908
    @Override
909
    public void registerReportsCustomAction(ReportCustomActionFactory customFactory, boolean insertSeparator) {
910
        ReportStoreActionFactory factory = (ReportStoreActionFactory) this.getStoreAction(ReportStoreAction.ACTION_NAME);
911
        factory.registerCustomAction(customFactory, insertSeparator);
912
    }    
913

  
891 914
}
892 915
        
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/DefaultDALSwingLibrary.java
35 35
import org.gvsig.fmap.dal.swing.DALSwingLibrary;
36 36
import org.gvsig.fmap.dal.swing.DALSwingLocator;
37 37
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanelManager;
38
import org.gvsig.fmap.dal.swing.impl.actions.CopyFormAction.CopyFormActionFactory;
39
import org.gvsig.fmap.dal.swing.impl.actions.GraphAction.GraphActionFactory;
40
import org.gvsig.fmap.dal.swing.impl.actions.ReportStoreAction.ReportStoreActionFactory;
41
import org.gvsig.fmap.dal.swing.impl.actions.SelectionAddAction.SelectionAddActionFactory;
42
import org.gvsig.fmap.dal.swing.impl.actions.SelectionFilterAction.SelectionFilterActionFactory;
43
import org.gvsig.fmap.dal.swing.impl.actions.SelectionSetAction.SelectionSetActionFactory;
44
import org.gvsig.fmap.dal.swing.impl.actions.ShowFormAction.ShowFormActionFactory;
38 45
import org.gvsig.fmap.dal.swing.impl.actions.ShowFormForOpenStoreParametersAction;
39 46
import org.gvsig.fmap.dal.swing.impl.dataStoreParameters.DataStoreDynObjectParametersPanelFactory;
40 47
import org.gvsig.fmap.dal.swing.impl.dataStoreParameters.DefaultDataStoreParametersPanelManager;
......
150 157
            DistinctOn.registerAggregateOperation(new NullAggregateOperationFactory());
151 158
            
152 159
            ShowFormForOpenStoreParametersAction.selfRegister();
153

  
160
            
161
            SelectionAddActionFactory.selfRegister();
162
            SelectionFilterActionFactory.selfRegister();
163
            SelectionSetActionFactory.selfRegister();
164
            ShowFormActionFactory.selfRegister();
165
            CopyFormActionFactory.selfRegister();
166
            ReportStoreActionFactory.selfRegister();
167
            GraphActionFactory.selfRegister();
168
        
154 169
        } catch(Exception ex) {
155 170
            LOGGER.warn("Can't register DAL components in DynForms",ex);
156 171
        }
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/DisposableFeatureSetIterable.java
1
package org.gvsig.fmap.dal.feature;
2

  
3
import java.util.Collections;
4
import java.util.Iterator;
5
import org.gvsig.tools.dispose.DisposableIterable;
6
import org.gvsig.tools.util.IsEmpty;
7
import org.gvsig.tools.util.Size64;
8

  
9
/**
10
 *
11
 * @author jjdelcerro
12
 */
13
public interface DisposableFeatureSetIterable
14
        extends DisposableIterable<Feature>, Iterator<Feature>, Size64, IsEmpty {
15

  
16
    public static DisposableFeatureSetIterable EMPTY_DISPOSABLE_FEATURE_SET_ITERABLE = new DisposableFeatureSetIterable() {
17
        @Override
18
        public FeatureSet getFeatureSet() {
19
            return null;
20
        }
21

  
22
        @Override
23
        public Iterator<Feature> iterator() {
24
            return Collections.EMPTY_LIST.iterator();
25
        }
26

  
27
        @Override
28
        public void dispose() {
29
        }
30

  
31
        @Override
32
        public boolean hasNext() {
33
            return false;
34
        }
35

  
36
        @Override
37
        public Feature next() {
38
            return null;
39
        }
40

  
41
        @Override
42
        public long size64() {
43
            return 0;
44
        }
45

  
46
        @Override
47
        public boolean isEmpty() {
48
            return false;
49
        }
50
    };
51

  
52
    public FeatureSet getFeatureSet();
53

  
54
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureSelection.java
32 32
import java.util.List;
33 33
import javax.json.JsonArray;
34 34
import javax.json.JsonArrayBuilder;
35
import org.gvsig.expressionevaluator.Expression;
35 36
import org.gvsig.fmap.dal.DataStore;
36 37
import org.gvsig.fmap.dal.exception.DataException;
37 38
import org.gvsig.tools.dispose.DisposableIterator;
......
311 312
        public Object clone() throws CloneNotSupportedException {
312 313
            return this;
313 314
        }
315

  
316
        @Override
317
        public Expression makeFilter(int maxfeatures) {
318
            return null;
319
        }
314 320
        
315 321
        
316 322
    };
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureSet.java
23 23
 */
24 24
package org.gvsig.fmap.dal.feature;
25 25

  
26
import java.util.Collections;
27
import java.util.Iterator;
28 26
import java.util.List;
29 27
import javax.json.JsonArray;
30 28
import javax.json.JsonArrayBuilder;
29
import org.gvsig.expressionevaluator.Expression;
31 30
import org.gvsig.fmap.dal.DataSet;
31
import org.gvsig.fmap.dal.DataStore;
32 32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.tools.dispose.DisposableIterable;
33
import static org.gvsig.fmap.dal.feature.DisposableFeatureSetIterable.EMPTY_DISPOSABLE_FEATURE_SET_ITERABLE;
34
import org.gvsig.json.Json;
34 35
import org.gvsig.tools.dispose.DisposableIterator;
36
import static org.gvsig.tools.dispose.DisposableIterator.EMPTY_DISPOSABLE_ITERATOR;
35 37
import org.gvsig.tools.dynobject.DynObject;
36 38
import org.gvsig.tools.dynobject.DynObjectSet;
39
import static org.gvsig.tools.dynobject.DynObjectSet.EMPTY_DYNOBJECTSET;
37 40
import org.gvsig.tools.exception.BaseException;
38 41
import org.gvsig.tools.util.IsEmpty;
39 42
import org.gvsig.tools.util.Size;
......
68 71
 */
69 72
public interface FeatureSet extends DataSet, Size64, Size, IsEmpty, IndexedVisitable, Iterable<Feature> {
70 73

  
71
    public interface DisposableFeatureSetIterable
72
            extends DisposableIterable<Feature>, Iterator<Feature>, Size64, IsEmpty {
73
        
74
        public static DisposableFeatureSetIterable EMPTY_DISPOSABLE_FEATURE_SET_ITERABLE = new DisposableFeatureSetIterable() {
75
            @Override
76
            public FeatureSet getFeatureSet() {
77
                return null;
78
            }
74
    public static FeatureSet EMPTY_FEATURESET = new FeatureSet() {
75
        @Override
76
        public FeatureType getDefaultFeatureType() {
77
            return null;
78
        }
79 79

  
80
            @Override
81
            public Iterator<Feature> iterator() {
82
                return Collections.EMPTY_LIST.iterator();
83
            }
80
        @Override
81
        public List getFeatureTypes() {
82
            return null;
83
        }
84 84

  
85
            @Override
86
            public void dispose() {
87
            }
85
        @Override
86
        public long getSize() throws DataException {
87
            return 0;
88
        }
88 89

  
89
            @Override
90
            public boolean hasNext() {
91
                return false;
92
            }
90
        @Override
91
        public DisposableIterator iterator(long index) throws DataException {
92
            return EMPTY_DISPOSABLE_ITERATOR;
93
        }
93 94

  
94
            @Override
95
            public Feature next() {
96
                return null;
97
            }
95
        @Override
96
        public DisposableIterator iterator(long index, long elements) throws DataException {
97
            return EMPTY_DISPOSABLE_ITERATOR;
98
        }
98 99

  
99
            @Override
100
            public long size64() {
101
                return 0;
102
            }
100
        @Override
101
        public DisposableFeatureSetIterable iterable() {
102
            return EMPTY_DISPOSABLE_FEATURE_SET_ITERABLE;
103
        }
103 104

  
104
            @Override
105
            public boolean isEmpty() {
106
                return false;
107
            }
108
        };
105
        @Override
106
        public DisposableFeatureSetIterable iterable(boolean disposeFeatureSet) {
107
            return EMPTY_DISPOSABLE_FEATURE_SET_ITERABLE;
108
        }
109

  
110
        @Override
111
        public DisposableIterator fastIterator() throws DataException {
112
            return EMPTY_DISPOSABLE_ITERATOR;
113
        }
114

  
115
        @Override
116
        public DisposableIterator fastIterator(long index) throws DataException {
117
            return EMPTY_DISPOSABLE_ITERATOR;
118
        }
119

  
120
        @Override
121
        public DisposableIterator fastIterator(long index, long elemets) throws DataException {
122
            return EMPTY_DISPOSABLE_ITERATOR;
123
        }
124

  
125
        @Override
126
        public Feature first() {
127
            return null;
128
        }
129

  
130
        @Override
131
        public void update(EditableFeature feature) throws DataException {
132
        }
133

  
134
        @Override
135
        public void commitChanges() throws DataException {
136
        }
137

  
138
        @Override
139
        public void delete(Feature feature) throws DataException {
140
        }
141

  
142
        @Override
143
        public void insert(EditableFeature feature) throws DataException {
144
        }
145

  
146
        @Override
147
        public DynObjectSet getDynObjectSet() {
148
            return EMPTY_DYNOBJECTSET;
149
        }
150

  
151
        @Override
152
        public DynObjectSet getDynObjectSet(boolean fast) {
153
            return EMPTY_DYNOBJECTSET;
154
        }
155

  
156
        @Override
157
        public void accept(Visitor visitor, long firstValueIndex) throws BaseException {
158
        }
159

  
160
        @Override
161
        public void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException {
162
        }
163

  
164
        @Override
165
        public FeatureStore getFeatureStore() {
166
            return null;
167
        }
168

  
169
        @Override
170
        public JsonArray toJSON() {
171
            return toJson();
172
        }
173

  
174
        @Override
175
        public JsonArray toJson() {
176
            return Json.createArrayBuilder().build();
177
        }
178

  
179
        @Override
180
        public JsonArrayBuilder toJsonBuilder() {
181
            return Json.createArrayBuilder();
182
        }
183

  
184
        @Override
185
        public boolean isFromStore(DataStore store) {
186
            return false;
187
        }
188

  
189
        @Override
190
        public void accept(Visitor visitor) throws BaseException {
191
        }
192

  
193
        @Override
194
        public void dispose() {
195
            // Do nothing
196
        }
197

  
198
        @Override
199
        public long size64() {
200
            return 0;
201
        }
202

  
203
        @Override
204
        public int size() {
205
            return 0;
206
        }
207

  
208
        @Override
209
        public boolean isEmpty() {
210
            return true;
211
        }
212

  
213
        @Override
214
        public DisposableIterator<Feature> iterator() {
215
            return EMPTY_DISPOSABLE_ITERATOR;
216
        }
217

  
218
        @Override
219
        public Expression makeFilter(int maxfeatures) {
220
            return null;
221
        }
109 222
        
110
        public FeatureSet getFeatureSet();
111
    }
112

  
223
    };
224
    
113 225
    /**
114 226
     * Returns the default {@link FeatureType} of this FeatureSet.
115 227
     *
......
369 481

  
370 482
    public JsonArrayBuilder toJsonBuilder();
371 483
    
484
    public Expression makeFilter(int maxfeatures);
485
    
372 486
}
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/DefaultFeatureStore.java
72 72
import org.gvsig.fmap.dal.exception.ReadException;
73 73
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
74 74
import org.gvsig.fmap.dal.exception.WriteException;
75
import org.gvsig.fmap.dal.feature.DisposableFeatureSetIterable;
75 76
import org.gvsig.fmap.dal.feature.EditableFeature;
76 77
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
77 78
import org.gvsig.fmap.dal.feature.EditableFeatureType;
......
91 92
import org.gvsig.fmap.dal.feature.FeatureReferenceSelection;
92 93
import org.gvsig.fmap.dal.feature.FeatureSelection;
93 94
import org.gvsig.fmap.dal.feature.FeatureSet;
94
import org.gvsig.fmap.dal.feature.FeatureSet.DisposableFeatureSetIterable;
95 95
import org.gvsig.fmap.dal.feature.FeatureStore;
96 96
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
97 97
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
......
188 188
import org.gvsig.tools.util.ChainedIterator;
189 189
import org.gvsig.tools.util.GetItemWithSizeIsEmptyAndIterator64;
190 190
import org.gvsig.tools.util.HasAFile;
191
import org.gvsig.tools.util.Invocable;
192 191
import org.gvsig.tools.util.PropertiesSupportHelper;
193 192
import org.gvsig.tools.util.UnmodifiableBasicMap;
194 193
import org.gvsig.tools.visitor.VisitCanceledException;
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/DefaultForeingKey.java
20 20
import org.gvsig.fmap.dal.StoresRepository;
21 21
import org.gvsig.fmap.dal.exception.DataException;
22 22
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
23
import org.gvsig.fmap.dal.feature.DisposableFeatureSetIterable;
23 24
import org.gvsig.fmap.dal.feature.Feature;
24 25
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
25 26
import org.gvsig.fmap.dal.feature.FeatureQuery;
26
import org.gvsig.fmap.dal.feature.FeatureSet;
27 27
import org.gvsig.fmap.dal.feature.FeatureStore;
28 28
import org.gvsig.fmap.dal.feature.FeatureType;
29 29
import static org.gvsig.fmap.dal.feature.ForeingKey.MAX_AVAILABLE_VALUES;
......
518 518
    }
519 519
    
520 520
    private DynObjectValueItem[] getAvailableValuesFromStore(FeatureStore store) {
521
        FeatureSet.DisposableFeatureSetIterable set = null;
521
        DisposableFeatureSetIterable set = null;
522 522
        DynObjectValueItem[] values = null;
523 523
        try {
524 524
            Expression labelExpression = this.getLabelExpression(null);
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/featureset/AbstractFeatureSet.java
28 28
import javax.json.JsonArray;
29 29
import javax.json.JsonArrayBuilder;
30 30
import javax.json.JsonObject;
31
import org.apache.commons.lang3.mutable.MutableInt;
32
import org.gvsig.expressionevaluator.Expression;
33
import org.gvsig.expressionevaluator.ExpressionBuilder;
34
import org.gvsig.expressionevaluator.ExpressionUtils;
31 35
import org.gvsig.fmap.dal.DataStore;
32 36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.feature.DisposableFeatureSetIterable;
33 38
import org.gvsig.fmap.dal.feature.Feature;
39
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
34 40
import org.gvsig.fmap.dal.feature.FeatureSet;
35 41
import org.gvsig.fmap.dal.feature.FeatureStore;
42
import org.gvsig.fmap.dal.feature.FeatureType;
36 43
import org.gvsig.fmap.dal.feature.impl.DefaultFeature;
37 44
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DynObjectSetFeatureSetFacade;
38
import org.gvsig.json.JsonObjectBuilder;
39 45
import org.gvsig.tools.dispose.DisposableIterator;
40 46
import org.gvsig.tools.dispose.DisposeUtils;
41 47
import org.gvsig.tools.dynobject.DynObjectSet;
......
47 53
import org.slf4j.LoggerFactory;
48 54

  
49 55

  
56
@SuppressWarnings("UseSpecificCatch")
50 57
public abstract class AbstractFeatureSet 
51 58
    extends AbstractIndexedVisitable 
52 59
    implements FeatureSet {
53 60

  
61
    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractFeatureSet.class);
62
    
54 63
    private static class DisposableFeatureSetIterableImpl implements DisposableFeatureSetIterable {
55 64

  
56 65
        private final FeatureSet fset;
......
103 112
    
104 113
    protected static final Logger LOG = LoggerFactory.getLogger(AbstractFeatureSet.class);
105 114

  
115
    @Override
106 116
    public abstract FeatureStore getFeatureStore();
107 117
    
108 118
    @Override
......
111 121
            doAccept(visitor, firstValueIndex, elements);
112 122
        } catch (VisitCanceledException ex) {
113 123
            // The visit has been cancelled by the visitor, so we finish here.
114
            LOG.debug(
115
                    "The visit, beggining on position {}, has been cancelled "
116
                    + "by the visitor: {}", new Long(firstValueIndex),
124
            LOG.debug("The visit, beggining on position {}, has been cancelled "
125
                    + "by the visitor: {}", firstValueIndex,
117 126
                    visitor);
118 127
        }
119 128
    }
......
237 246
        // tendria que construirse en memoria el JSON entero.
238 247
        try {
239 248
            JsonArrayBuilder builder = Json.createArrayBuilder();
240
            this.accept(new Visitor() {
241
                @Override
242
                public void visit(Object obj) throws VisitCanceledException, BaseException {
243
                    DefaultFeature f = (DefaultFeature) obj;
244
                    JsonObject fjson = f.toJson();
245
                    builder.add(fjson);
246
                }
249
            this.accept((Object obj) -> {
250
                DefaultFeature f = (DefaultFeature) obj;
251
                JsonObject fjson = f.toJson();
252
                builder.add(fjson);
247 253
            });
248 254
            return builder;        
249 255
        } catch (Exception ex) {
......
252 258
    }
253 259
    
254 260
    @Deprecated
261
    @Override
255 262
    public JsonArray toJSON() {
256 263
        return this.toJson();
257 264
    }
265

  
266
    @Override
267
    public Expression makeFilter(int maxfeatures) {
268
        try {
269
            FeatureType ftype = this.getDefaultFeatureType();
270
            if( !ftype.hasPrimaryKey() ) {
271
                return null;
272
            }
273
            ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
274
            final MutableInt counter = new MutableInt(0);
275
            this.accept((Object obj) -> {
276
                if( counter.getAndIncrement()>maxfeatures ) {
277
                    throw new VisitCanceledException();
278
                }
279
                Feature feature = (Feature) obj;
280
                for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
281
                    builder.and(
282
                            builder.eq(
283
                                    builder.column(attrdesc.getName()),
284
                                    builder.constant(feature.get(attrdesc.getName()))
285
                            )
286
                    );
287
                }
288
            });
289
            Expression filter = ExpressionUtils.createExpression(builder.toString());
290
            return filter;
291
        } catch (Exception ex) {
292
            LOGGER.warn("Can't build filter expression.", ex);
293
            return null;
294
        }
295
    }
296
        
258 297
}
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/featureset/DefaultFeatureSet.java
47 47
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStoreTransforms;
48 48
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureType;
49 49
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider;
50
import org.gvsig.tools.ToolsLocator;
51 50
import org.gvsig.tools.dispose.DisposableIterator;
52 51
import org.gvsig.tools.dispose.DisposeUtils;
53 52
import org.gvsig.tools.evaluator.Evaluator;
54
import org.gvsig.tools.exception.BaseException;
55 53
import org.gvsig.tools.observer.Observable;
56 54
import org.gvsig.tools.observer.Observer;
57 55

  

Also available in: Unified diff