Revision 47340

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

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

  
42 34
/**
43 35
 *
......
119 111
        );
120 112
    }
121 113

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

  
154 115
    @Override
155 116
    public void actionPerformed(ActionEvent e) {
156 117
        try {
157
            DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager();
158 118
//            this.setEnabled(false);
159 119
            DataStore store = this.context.getStore();
160 120
            if (!(store instanceof FeatureStore)) {
161 121
                return;
162 122
            }
163
            List<ReportAction> actions = new ArrayList<>();
164
            List<JsonObject> reports = this.getReports((FeatureStore) store);
165
            if (reports != null && !reports.isEmpty()) {
166
                for (JsonObject json : reports) {
167
                    ReportAction action = null;
168
                    for (ReportActionFactory theFactory : dataSwingManager.getReportActionFactories()) {
169
                        if( theFactory.isApplicable(json,this.context, e)) {
170
                            action = theFactory.createReportAction(
171
                                    (FeatureStore) store,
172
                                    this.context.getQuery(),
173
                                    this.context.getSelecteds(),
174
                                    json
175
                            );
176
                        }
177
                    }
178
                    if( action != null ) {
179
                        String label = (String) action.getValue(Action.NAME);
180
                        if( StringUtils.isBlank(label) ) {
181
                            action.putValue(Action.NAME, action.getLabel());
182
                        }
183
                        actions.add(action);
184
                    }
185
                }
186
            }
187
            Collections.sort(
188
                    actions, 
189
                    (ReportAction o1, ReportAction o2) -> StringUtils.compare(o1.getLabel(), o2.getLabel())
190
            );
123
            List<ReportAction> actions = getReportActions(store, null, context, e);
191 124
            JPopupMenu popup = new JPopupMenu();
192 125
            for (ReportAction action : actions) {
193 126
                popup.add(new JMenuItem(action));
......
218 151
                return false;
219 152
            }
220 153
            DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager();
221
            List<JsonObject> reports = this.getReports((FeatureStore) store);
154
            List<JsonObject> reports = getReports((FeatureStore) store);
222 155
            if (reports != null && !reports.isEmpty()) {
223 156
                for (JsonObject json : reports) {
224 157
                    for (ReportActionFactory thefactory : dataSwingManager.getReportActionFactories()) {
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/ReportUtils.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.impl.actions;
7

  
8
import java.awt.event.ActionEvent;
9
import java.io.InputStream;
10
import java.util.ArrayList;
11
import java.util.Collections;
12
import java.util.List;
13
import java.util.function.Predicate;
14
import javax.json.Json;
15
import javax.json.JsonObject;
16
import javax.swing.Action;
17
import org.apache.commons.io.IOUtils;
18
import org.apache.commons.lang3.StringUtils;
19
import org.gvsig.fmap.dal.DataStore;
20
import org.gvsig.fmap.dal.feature.FeatureStore;
21
import org.gvsig.fmap.dal.swing.DALActionFactory;
22
import org.gvsig.fmap.dal.swing.DALSwingLocator;
23
import org.gvsig.fmap.dal.swing.DataSwingManager;
24
import org.gvsig.fmap.dal.swing.report.ReportAction;
25
import org.gvsig.fmap.dal.swing.report.ReportActionFactory;
26
import org.gvsig.tools.dispose.DisposeUtils;
27
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30

  
31
/**
32
 *
33
 * @author fdiaz
34
 */
35
public class ReportUtils {
36
    
37
    private static final Logger LOGGER = LoggerFactory.getLogger(ReportUtils.class);
38
    
39
    private ReportUtils(){
40
        
41
    }
42

  
43
    public static List<JsonObject> getReports(FeatureStore store) {
44
        List<JsonObject> reports = new ArrayList<>();
45
        ResourcesStorage resources = null;
46
        try {
47
            resources = store.getResourcesStorage();
48
            if (resources != null) {
49
                List<ResourcesStorage.Resource> reportsResources = resources.getResources("report");
50
                if (reportsResources != null && !reportsResources.isEmpty()) {
51
                    for (ResourcesStorage.Resource resource : reportsResources) {
52
                        InputStream is = null;
53
                        try {
54
                            is = resource.asInputStream();
55
                            JsonObject json = Json.createReader(is).readObject();
56
                            reports.add(json);
57
                        } catch (Exception ex) {
58
                            LOGGER.warn("Can't load report form resource (" + resource.getURL() + ")", ex);
59
                        } finally {
60
                            IOUtils.closeQuietly(is);
61
                        }
62
                        DisposeUtils.disposeQuietly(resource);
63
                    }
64
                }
65
            }
66
        } finally {
67
            DisposeUtils.disposeQuietly(resources);
68
        }
69
        if (reports.isEmpty()) {
70
            return null;
71
        }
72
        return reports;
73
    }
74

  
75
    public static List<ReportAction> getReportActions(DataStore store) {
76
        return getReportActions(store, null, null, null);
77
    }
78
    
79
    public static List<ReportAction> getReportActions(DataStore store, Predicate filter) {
80
        return getReportActions(store, filter, null, null);
81
    }
82
    
83
    public static List<ReportAction> getReportActions(DataStore store, Predicate<JsonObject> filter, DALActionFactory.DALActionContext context, ActionEvent e) {
84
        DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager();
85
        List<ReportAction> actions = new ArrayList<>();
86
        List<JsonObject> reports = getReports((FeatureStore) store);
87
        if (reports != null && !reports.isEmpty()) {
88
            for (JsonObject json : reports) {
89
                if(filter == null || filter.test(json)){
90
                    ReportAction action = null;
91
                    for (ReportActionFactory theFactory : dataSwingManager.getReportActionFactories()) {
92
                        if( theFactory.isApplicable(json,context, e)) {
93
                            if(context == null){
94
                                action = theFactory.createReportAction(
95
                                        (FeatureStore) store,
96
                                        null,
97
                                        null,
98
                                        json
99
                                );
100
                            } else {
101
                                action = theFactory.createReportAction(
102
                                        (FeatureStore) store,
103
                                        context.getQuery(),
104
                                        context.getSelecteds(),
105
                                        json
106
                                );
107
                            }
108
                        }
109
                    }
110
           
111
                    if( action != null ) {
112
                        String name = action.getReportName();
113
                        if( StringUtils.isBlank(name) ) {
114
                            action.setReportName(store.getName());
115
                        }
116
                        String label = action.getReportLabel();
117
                        if( StringUtils.isBlank(label) ) {
118
                            action.setReportLabel(action.getReportName());
119
                        }
120
                        actions.add(action);
121
                    }
122
                }
123
            }
124
        }
125
        Collections.sort(
126
                actions,
127
                (ReportAction o1, ReportAction o2) -> StringUtils.compare(o1.getReportLabel(), o2.getReportLabel())
128
        );
129
        return actions;
130
    }
131

  
132

  
133
    
134
}
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
33 33
import java.util.List;
34 34
import java.util.Map;
35 35
import java.util.function.Predicate;
36
import javax.json.JsonObject;
36 37
import javax.swing.AbstractButton;
37 38
import javax.swing.Action;
38 39
import javax.swing.Icon;
......
107 108
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel;
108 109
import org.gvsig.fmap.dal.swing.impl.actions.ReportStoreAction;
109 110
import org.gvsig.fmap.dal.swing.impl.actions.ReportStoreAction.ReportStoreActionFactory;
111
import org.gvsig.fmap.dal.swing.impl.actions.ReportUtils;
110 112
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.DefaultFeatureStoreElement2;
111 113
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.CheckTableFieldsSuggestionProviderFactory;
112 114
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.DivSuggestionProviderFactory;
......
139 141
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionDialog;
140 142
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel;
141 143
import org.gvsig.fmap.dal.swing.jdbc.JDBCServerExplorerParametersController;
144
import org.gvsig.fmap.dal.swing.report.ReportAction;
142 145
import org.gvsig.fmap.dal.swing.report.ReportActionFactory;
143 146
import org.gvsig.fmap.dal.swing.report.ReportActionFactory.ReportCustomActionFactory;
144 147
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcessFactory;
......
963 966
        }
964 967
        return false;
965 968
    }
969

  
970
    @Override
971
    public List<JsonObject> getReports(FeatureStore store) {
972
        return ReportUtils.getReports(store);
973
    }
974

  
975
    @Override
976
    public List<ReportAction> getReportActions(DataStore store) {
977
        return ReportUtils.getReportActions(store);
978
    }
979

  
980
    @Override
981
    public List<ReportAction> getReportActions(DataStore store, Predicate filter) {
982
        return ReportUtils.getReportActions(store, filter);
983
    }
966 984
}
967 985
        
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;
31 32
import javax.swing.Icon;
32 33
import javax.swing.JButton;
......
46 47
import org.gvsig.featureform.swing.JFeatureForm;
47 48
import org.gvsig.featureform.swing.JFeatureReferencesForm;
48 49
import org.gvsig.featureform.swing.JFeaturesForm;
50
import org.gvsig.fmap.dal.DataStore;
49 51
import org.gvsig.fmap.dal.StoresRepository;
50 52
import org.gvsig.fmap.dal.feature.Feature;
51 53
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
......
57 59
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
58 60
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext;
59 61
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement;
60
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorPickerController;
61
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel;
62
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel;
63
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel;
64
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel;
65
import org.gvsig.tools.dynobject.DynStruct;
66
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionDialog;
67
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory;
68 62
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryOrderPanel;
69 63
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryPickerController;
70 64
import org.gvsig.fmap.dal.swing.featuretable.SimpleFeaturesTableModel;
71 65
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorAndExpressionPickerController;
66
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorPickerController;
72 67
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeListCellRenderer;
73 68
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeTableCellRenderer;
74 69
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel;
70
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel;
71
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel;
72
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionDialog;
73
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel;
75 74
import org.gvsig.fmap.dal.swing.jdbc.JDBCServerExplorerParametersController;
75
import org.gvsig.fmap.dal.swing.report.ReportAction;
76 76
import org.gvsig.fmap.dal.swing.report.ReportActionFactory;
77 77
import org.gvsig.fmap.dal.swing.report.ReportActionFactory.ReportCustomActionFactory;
78

  
79 78
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcessFactory;
79
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel;
80
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory;
80 81
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters;
81 82
import org.gvsig.fmap.dal.swing.storesrepository.StoresRepositoryController;
82 83
import org.gvsig.tools.dynform.DynFormDefinition;
84
import org.gvsig.tools.dynobject.DynStruct;
83 85

  
84 86

  
85 87
/**
......
254 256
    public ReportActionFactory getReportActionFactory(String name);
255 257
    
256 258
    public boolean connectToDatabaseWorkspace(JDBCServerExplorerParameters conn);
259
    
260
    public List<JsonObject> getReports(FeatureStore store);
261

  
262
    public List<ReportAction> getReportActions(DataStore store);
263
    
264
    public List<ReportAction> getReportActions(DataStore store, Predicate filter);
265

  
257 266
}
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
27 27
    
28 28
    private final ReportActionFactory factory;
29 29
    private SimpleTaskStatus status;
30
    
31
    private String reportName;
30 32

  
31 33

  
32 34
    @SuppressWarnings("OverridableMethodCallInConstructor")
......
46 48
    }
47 49

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

  
53 55
    @Override
54
    public String getLabel() {
56
    public String getReportName() {
57
        return reportName;
58
    }
59

  
60
    @Override
61
    public void setReportName(String name) {
62
        reportName = name;
63
    }
64
    
65
    @Override
66
    public String getReportLabel() {
55 67
        return (String) this.getValue(Action.NAME);
56 68
    }
57 69

  
58
    protected void setLabel(String label) {
70
    @Override
71
    public void setReportLabel(String label) {
59 72
        this.putValue(Action.NAME, label);
60 73
    }
74

  
75
    @Override
76
    public String getLabel() {
77
        return getReportLabel();
78
    }
61 79
    
62 80
    @Override
63 81
    public ReportAction getValue() {
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
12 12
 */
13 13
public interface ReportAction extends Action, LabeledValue<ReportAction>{
14 14

  
15
    public String getName();
15
    public String getTypeName();
16 16
    
17
    public String getReportName();
18

  
19
    public void setReportName(String name);
20
    
21
    public String getReportLabel();
22

  
23
    public void setReportLabel(String label);
24
    
17 25
    public ReportActionFactory getFactory();
18 26

  
19 27
    public String formatFieldValue(Feature feature, String fieldname);
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/i18n/text.properties
757 757
Ver=Ver
758 758
ver_error_capa=Ver errores
759 759
ver_tabla_atributos=Ver Tabla de atributos
760
ver_tags=Ver
760
ver_tags=Ver etiquetas
761 761
ver_tooltip=Muestra la ventana de proyecto
762 762
vertical=Vertical
763 763
vertical_space=Espacio vertical

Also available in: Unified diff