Statistics
| Revision:

svn-gvsig-desktop / 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 @ 46986

History | View | Annotate | Download (37.4 KB)

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

    
25
import java.awt.Component;
26
import java.awt.event.ActionEvent;
27
import java.net.URL;
28
import java.util.ArrayList;
29
import java.util.Collection;
30
import java.util.Collections;
31
import java.util.HashMap;
32
import java.util.LinkedHashMap;
33
import java.util.List;
34
import java.util.Map;
35
import java.util.function.Predicate;
36
import javax.swing.AbstractButton;
37
import javax.swing.Action;
38
import javax.swing.Icon;
39
import javax.swing.ImageIcon;
40
import javax.swing.JButton;
41
import javax.swing.JComboBox;
42
import javax.swing.JList;
43
import javax.swing.JOptionPane;
44
import javax.swing.JPanel;
45
import javax.swing.JTextField;
46
import javax.swing.JTree;
47
import javax.swing.text.JTextComponent;
48
import javax.swing.tree.TreeModel;
49
import org.apache.commons.lang3.StringUtils;
50
import org.gvsig.expressionevaluator.Expression;
51
import org.gvsig.expressionevaluator.ExpressionUtils;
52
import org.gvsig.expressionevaluator.swing.Element;
53
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig;
54
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator;
55
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager;
56
import org.gvsig.expressionevaluator.swing.ExpressionPickerController;
57
import org.gvsig.expressionevaluator.swing.JExpressionBuilder;
58
import org.gvsig.featureform.swing.CreateJFeatureFormException;
59
import org.gvsig.featureform.swing.FeaturesFormContext;
60
import org.gvsig.featureform.swing.JFeatureForm;
61
import org.gvsig.featureform.swing.JFeatureReferencesForm;
62
import org.gvsig.featureform.swing.JFeaturesForm;
63
import org.gvsig.featureform.swing.impl.DefaultFeaturesFormContext;
64
import org.gvsig.featureform.swing.impl.DefaultJFeatureForm;
65
import org.gvsig.featureform.swing.impl.DefaultJFeatureReferencesForm;
66
import org.gvsig.featureform.swing.impl.DefaultJFeaturesForm;
67
import org.gvsig.fmap.dal.DALLocator;
68
import org.gvsig.fmap.dal.DataManager;
69
import static org.gvsig.fmap.dal.DataManager.DAL_USE_LABELS;
70
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_BOTH;
71
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_NO;
72
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_YES;
73
import org.gvsig.fmap.dal.DataStore;
74
import org.gvsig.fmap.dal.DataStoreProviderFactory;
75
import org.gvsig.fmap.dal.StoresRepository;
76
import org.gvsig.fmap.dal.exception.DataException;
77
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
78
import org.gvsig.fmap.dal.feature.Feature;
79
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
80
import org.gvsig.fmap.dal.feature.FeatureQuery;
81
import org.gvsig.fmap.dal.feature.FeatureReference;
82
import org.gvsig.fmap.dal.feature.FeatureStore;
83
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
84
import org.gvsig.fmap.dal.feature.FeatureType;
85
import org.gvsig.fmap.dal.feature.FeatureTypeDefinitionsManager;
86
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper;
87
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
88
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory;
89
import org.gvsig.fmap.dal.swing.DALActionFactory;
90
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext;
91
import org.gvsig.fmap.dal.swing.DataSwingManager;
92
import org.gvsig.fmap.dal.swing.FeatureTableModel;
93
import org.gvsig.fmap.dal.swing.JFeatureTable;
94
import org.gvsig.fmap.dal.swing.ProjectionPickerController;
95
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement;
96
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryOrderPanel;
97
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryPickerController;
98
import org.gvsig.fmap.dal.swing.featuretable.SimpleFeaturesTableModel;
99
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorAndExpressionPickerController;
100
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorPickerController;
101
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeListCellRenderer;
102
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeTableCellRenderer;
103
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel;
104
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel;
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;
113
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.DefaultFeatureStoreElement2;
114
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.CheckTableFieldsSuggestionProviderFactory;
115
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.DivSuggestionProviderFactory;
116
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.QuotesForFieldNameSuggestionProviderFactory;
117
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.StorePointFieldSuggestionProviderFactory;
118
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.WrongNameFieldSuggestionProviderFactory;
119
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryOrderPanel;
120
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryPickerController;
121
import org.gvsig.fmap.dal.swing.impl.featuretable.FeatureTablePanel;
122
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleEditedFeaturesTableModelImpl;
123
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModelImpl;
124
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleSelectedFeaturesTableModelImpl;
125
import org.gvsig.fmap.dal.swing.impl.featuretable.table.DefaultFeatureTableModel;
126
import org.gvsig.fmap.dal.swing.impl.featuretable.table.EmptyFeatureTableModel;
127
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultAttributeDescriptorAndExpressionPickerController;
128
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultAttributeDescriptorPickerController;
129
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureAttributePanel;
130
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureAttributesSelectionPanel;
131
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureTypePanel;
132
import org.gvsig.fmap.dal.swing.impl.featuretype.FeatureAttributeListCellRendererImpl;
133
import org.gvsig.fmap.dal.swing.impl.featuretype.FeatureAttributeTableCellRendererImpl;
134
import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionDialog;
135
import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionPanel;
136
import org.gvsig.fmap.dal.swing.impl.jdbc.JDBCConnectionPickerController;
137
import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel;
138
import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchParameters;
139
import org.gvsig.fmap.dal.swing.impl.storesrepository.StoresRepositoryControllerImpl;
140
import org.gvsig.fmap.dal.swing.impl.storesrepository.StoresRepositoryTreeModel;
141
import org.gvsig.fmap.dal.swing.impl.visualdbmodeler.Visualdbmodeler;
142
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionDialog;
143
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel;
144
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcessFactory;
145
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel;
146
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory;
147
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters;
148
import org.gvsig.fmap.dal.swing.storesrepository.StoresRepositoryController;
149
import org.gvsig.fmap.geom.Geometry;
150
import org.gvsig.tools.ToolsLocator;
151
import org.gvsig.tools.dynform.DynFormDefinition;
152
import org.gvsig.tools.dynform.DynFormLocator;
153
import org.gvsig.tools.dynobject.DynClass;
154
import org.gvsig.tools.dynobject.DynStruct;
155
import org.gvsig.tools.dynobject.Tags;
156
import org.gvsig.tools.exception.BaseException;
157
import org.gvsig.tools.i18n.I18nManager;
158
import org.gvsig.tools.swing.api.pickercontroller.PickerController;
159
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
160
import org.slf4j.Logger;
161
import org.slf4j.LoggerFactory;
162

    
163

    
164
/**
165
 * @author fdiaz
166
 *
167
 */
168
@SuppressWarnings("UseSpecificCatch")
169
public class DefaultDataSwingManager implements DataSwingManager {
170

    
171
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDataSwingManager.class);
172
    
173
    private final Map<String,DALActionFactory> featureStoreSearchActions;
174
    private final Map<String,SearchPostProcessFactory> searchPostProcess;
175
    private Map<String,SearchConditionPanelFactory> searchConditionPanelFactories;
176
    private Integer useLabels;
177
    
178
    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
        
187
        this.searchPostProcess = new HashMap<>();
188
    }
189
    
190
    @Override
191
    public JFeaturesForm createJFeaturesForm(FeatureStore store) throws CreateJFeatureFormException {
192
        try {
193
            FeatureType featureType = store.getDefaultFeatureType();
194
            
195
            DefaultJFeaturesForm form = new DefaultJFeaturesForm();
196
            form.bind(store, featureType2DynClass(store, featureType), null);
197
            return form;
198
            
199
        } catch (Exception ex) {
200
            throw new CreateJFeatureFormException(ex);
201
        }
202
    }
203

    
204
    @Override
205
    public JFeaturesForm createJFeaturesForm(FeatureStore store, FeatureQuery query) throws CreateJFeatureFormException {
206
        try {
207
            FeatureType featureType = store.getDefaultFeatureType();
208
            
209
            DefaultJFeaturesForm form = new DefaultJFeaturesForm();
210
            form.bind(store, featureType2DynClass(store, featureType), query);
211
            return form;
212
            
213
        } catch (Exception ex) {
214
            throw new CreateJFeatureFormException(ex);
215
        }
216
    }
217

    
218
    public DynClass featureType2DynClass(FeatureStore store, FeatureType type) {
219
        FeatureTypeDefinitionsManager featureTypeDefinitionsManager = DALLocator.getFeatureTypeDefinitionsManager();
220
        if( featureTypeDefinitionsManager.contains(store,type) ) {
221
            // Force reload next call to get.
222
            featureTypeDefinitionsManager.remove(store,type);
223
        }
224
        DynClass dynClass = featureTypeDefinitionsManager.get(store,type);
225
        // Force reload next call to get.
226
        DynFormLocator.getDynFormManager().removeDefinition(dynClass.getName());
227
        return dynClass;
228
    }
229
    
230
    @Override
231
    public JDBCConnectionPanel createJDBCConnectionPanel() {
232
        JDBCConnectionPanel x = new DefaultJDBCConnectionPanel();
233
        return x;
234
    }
235

    
236
    @Override
237
    public JDBCConnectionDialog createJDBCConectionDialog() {
238
        JDBCConnectionDialog x = new DefaultJDBCConnectionDialog();
239
        return x;
240
    }
241

    
242
    @Override
243
    public void configureExpressionBuilder(ExpressionBuilderConfig builder, FeatureStore store) {
244
        DataManager dataManager = DALLocator.getDataManager();
245
        FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable();
246

    
247
        builder.removeAllElements();
248
        FeatureStoreProviderFactory storeFactory = (FeatureStoreProviderFactory) store.getProviderFactory();
249
        Feature sampleFeature = store.getSampleFeature();
250
        builder.setAllowedFunctions(storeFactory.allowFunction());
251
        if( sampleFeature!=null ) {
252
            featureSymbolTable.setFeature(sampleFeature);
253
            builder.setPreviewSymbolTable(featureSymbolTable.createParent());
254
        }
255
        builder.addSymbolTable(featureSymbolTable);
256
        FeatureStoreElement storeElement = new DefaultFeatureStoreElement2(store);
257
        builder.addElement(storeElement);
258
        if( store.getProviderFactory().hasSQLSupport()==DataStoreProviderFactory.YES ) {
259
            builder.getPreferences().setSQLCompatible(true);
260
        }        
261
        builder.addSuggestionFactory(new StorePointFieldSuggestionProviderFactory(store));
262
        builder.addSuggestionFactory(new QuotesForFieldNameSuggestionProviderFactory(store));
263
        builder.addSuggestionFactory(new WrongNameFieldSuggestionProviderFactory(store));
264
        builder.addSuggestionFactory(new CheckTableFieldsSuggestionProviderFactory(store));
265
        builder.addSuggestionFactory(new DivSuggestionProviderFactory(store));    
266
    }
267

    
268
    @Override
269
    public void resetExpressionBuilder(ExpressionBuilderConfig builder) {
270
        builder.removeAllElements();
271
        builder.removeAddedElements();
272
        builder.setPreviewSymbolTable(ExpressionUtils.createSymbolTable());
273
    }
274

    
275
    @Override
276
    public void addToExpressionBuilder(ExpressionBuilderConfig builder, FeatureStore store, String name) {
277
        this.addToExpressionBuilder(builder, store, name, false);
278
    }
279
    
280
    @Override
281
    public void addToExpressionBuilder(ExpressionBuilderConfig builder, FeatureStore store, String name, boolean useHostVariable) {
282
        // Este metodo permite a?adir mas de un store al builder llamandolo
283
        // con un name distinto para cada store. En el arbol se presentaran todos
284
        // los stores que se configuren en el builder.
285
        // Ojo, que las expresiones creadas por estos builder no son compatible
286
        // con SQL.
287
        DataManager dataManager = DALLocator.getDataManager();
288

    
289
        // Creamos el store-element y lo a?adimos al builder
290
        FeatureStoreElement n = new DefaultFeatureStoreElement2(store, name, useHostVariable);
291
        builder.addElement(n);
292

    
293
        // Creamos una tabla de simbolos de ejemplo basada en el store, y la
294
        // a?adimos a la tabla de simbolos de previsualizacion del builder.
295
        FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable();
296
        Feature sampleFeature = store.getSampleFeature();
297
        if( sampleFeature!=null ) {
298
            featureSymbolTable.setFeature(sampleFeature);
299
            builder.getPreviewSymbolTable().addSymbolTable(featureSymbolTable);
300
        }
301

    
302
        // forzamos a que al insertar campos de un store se indique siempre 
303
        // en nombre del store. Necesario si hay mas de un store en el builder.
304
        List<Element> elements = builder.getElements();
305
        for (Element item : elements) {
306
            if( item instanceof FeatureStoreElement ) {
307
                ((FeatureStoreElement)item).setUseFullyQualifiedNames(true);
308
            }
309
        }
310
        // Marcamos como no compatible sql las expresiones que vamos a generar.
311
        builder.getPreferences().setSQLCompatible(false);
312
        
313
        // A?adimos los generadores de sugerencias.
314
        builder.addSuggestionFactory(new StorePointFieldSuggestionProviderFactory(store));
315
        builder.addSuggestionFactory(new QuotesForFieldNameSuggestionProviderFactory(store));
316
        builder.addSuggestionFactory(new WrongNameFieldSuggestionProviderFactory(store));
317
        builder.addSuggestionFactory(new CheckTableFieldsSuggestionProviderFactory(store));    
318
        builder.addSuggestionFactory(new DivSuggestionProviderFactory(store));    
319
    }
320

    
321
    @Override
322
    public JExpressionBuilder createQueryFilterExpresion(FeatureStore store) {
323
        return this.createJExpressionBuilder(store);
324
    }
325

    
326
    @Override
327
    public JExpressionBuilder createJExpressionBuilder(final FeatureStore store) {
328
        ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager();
329
        final JExpressionBuilder builder = expressionSwingManager.createJExpressionBuilder();
330
        this.configureExpressionBuilder(builder.getConfig(), store);
331
        builder.expandElement(
332
                (Element t) -> t!=null && StringUtils.equals(t.getName(),store.getName())
333
        );
334
        return builder;
335
    }
336

    
337
    @Override
338
    public ExpressionPickerController createExpressionPickerController(FeatureStore store, JTextComponent text, JButton button, JButton bookmarks, JButton history) {
339
        ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager();
340
        ExpressionPickerController builder = expressionSwingManager.createExpressionPickerController(text, button, bookmarks, history);
341
        if( store !=null ) {
342
            this.configureExpressionBuilder(builder.getConfig(), store);
343
        }
344
        return builder;
345
    }
346

    
347
    @Override
348
    public AttributeDescriptorAndExpressionPickerController createExpressionPickerController(FeatureStore store, JComboBox combo, JButton button, JButton bookmarks, JButton history) {
349
        DefaultAttributeDescriptorAndExpressionPickerController controller = new DefaultAttributeDescriptorAndExpressionPickerController(combo, button, bookmarks, history, null);
350
        if( store !=null ) {
351
            this.configureExpressionBuilder(controller.getConfig(), store);
352
        }
353
        return controller;
354
    }
355

    
356
    @Override
357
    public JFeatureForm createJFeatureForm(FeatureStore store) throws CreateJFeatureFormException {
358
        JFeatureForm form = new DefaultJFeatureForm();
359
        form.setStore(store);
360
        return form;
361
    }
362

    
363
    @Override
364
    public JFeatureReferencesForm createJFeatureReferencesForm(FeatureStore store, List<FeatureReference> references) throws CreateJFeatureFormException {
365
        JFeatureReferencesForm form = new DefaultJFeatureReferencesForm();
366
        form.bind(store, references);
367
        return form;
368
    }
369
    
370
    @Override
371
    public JFeatureForm createJFeatureForm(Feature feature) throws CreateJFeatureFormException {
372
        JFeatureForm form = new DefaultJFeatureForm();
373
        form.setFeature(feature);
374
        return form;
375
    }
376

    
377
    @Override
378
    public JFeatureForm createJFeatureForm(DynFormDefinition definicion) throws CreateJFeatureFormException {
379
        JFeatureForm form = new DefaultJFeatureForm();
380
        form.setDefinition(definicion);
381
        return form;
382
    }
383

    
384
    @Override
385
    public JFeatureTable createJFeatureTable(FeatureTableModel model) {
386
        return this.createJFeatureTable(model, true);
387
    }
388
    
389
    @Override
390
    public JFeatureTable createJFeatureTable(FeatureTableModel model, boolean isDoubleBuffered) {
391
        return new FeatureTablePanel(model, isDoubleBuffered);
392
    }
393
    
394
    @Override
395
    public FeatureTableModel createEmptyFeatureTableModel(DynStruct struct) {
396
        return new EmptyFeatureTableModel(struct);
397
    }
398
    
399
    @Override
400
    public FeatureTableModel createFeatureTableModel(FeatureStore featureStore,
401
            FeatureQuery featureQuery) {
402
        try {
403
            FeaturePagingHelper pager = DALLocator.getDataManager().createFeaturePagingHelper(
404
                    featureStore, featureQuery,
405
                    FeaturePagingHelper.DEFAULT_PAGE_SIZE
406
            );
407
            return this.createFeatureTableModel(pager);
408
        } catch (BaseException ex) {
409
            throw new RuntimeException("Can't create a FeatureTableModel.", ex);
410
        }
411
    }
412
    
413
    @Override
414
    public FeatureTableModel createFeatureTableModel(FeaturePagingHelper featurePager) {
415
        return new DefaultFeatureTableModel(featurePager);
416
    }
417
    
418
    @Override
419
    public ProjectionPickerController createProjectionPickerController(
420
            JTextField txtProjection,
421
            JButton btnSelectProjection
422
        ) {
423
        ProjectionPickerControllerImpl picker = new ProjectionPickerControllerImpl(txtProjection, btnSelectProjection);
424
        return picker;
425
    }
426

    
427
    @Override
428
    public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo) {
429
        AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, null);
430
        return controller;
431
    }
432

    
433
    @Override
434
    public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list) {
435
        AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, null);
436
        return controller;
437
    }
438

    
439
    @Override
440
    public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo, Predicate<FeatureAttributeDescriptor> filter) {
441
        AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, filter);
442
        return controller;
443
    }
444

    
445
    @Override
446
    public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list, Predicate<FeatureAttributeDescriptor> filter) {
447
        AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, filter);
448
        return controller;
449
    }
450

    
451
    @Override
452
    public FeatureTypePanel createFeatureTypePanel() {
453
        FeatureTypePanel panel = new DefaultFeatureTypePanel();
454
        return panel;
455
    }
456
    
457
    @Override
458
    public FeatureTypeAttributePanel createFeatureTypeAttributePanel() {
459
        FeatureTypeAttributePanel panel = new DefaultFeatureAttributePanel();
460
        return panel;
461
    }
462

    
463
    @Override
464
    public FeatureStoreElement createFeatureStoreElement() {
465
        FeatureStoreElement e = new DefaultFeatureStoreElement2(null);
466
        return e;
467
    }
468

    
469
    @Override
470
    public FeatureStoreElement createFeatureStoreElement(FeatureStore store) {
471
        FeatureStoreElement e = new DefaultFeatureStoreElement2(store);
472
        return e;
473
    }
474

    
475
    @Override
476
    public ExpressionPickerController createExpressionPickerController(FeatureStore store, JTextComponent text, JButton button) {    
477
        FeatureSymbolTable previewSymbolTable = DALLocator.getManager().createFeatureSymbolTable();
478
        previewSymbolTable.setFeature(store.getSampleFeature());
479
        
480
        ExpressionPickerController controller = ExpressionEvaluatorSwingLocator.getManager().createExpressionPickerController(text, button);
481
        controller.getConfig().addElement(this.createFeatureStoreElement(store));
482
        controller.getConfig().setPreviewSymbolTable(previewSymbolTable);
483
        
484
        return controller;
485
    }
486
    
487

    
488
    @Override
489
    public FeatureStoreSearchPanel createFeatureStoreSearchPanel(FeatureStore store) {
490
        DefaultSearchPanel e = new DefaultSearchPanel(store);
491
        return e;
492
    }
493

    
494
    @Override
495
    public final void registerStoreAction(DALActionFactory action) {
496
        this.featureStoreSearchActions.put(action.getName().toLowerCase(), action);
497
    }
498
    
499
    @Override
500
    public  Collection<DALActionFactory> getStoreActions() {
501
        return Collections.unmodifiableCollection(this.featureStoreSearchActions.values());
502
    }
503

    
504
    @Override
505
    public Collection<DALActionFactory> getApplicableStoreActions(DALActionContext context) {
506
        Collection<DALActionFactory> factories = new ArrayList<>();
507
        try {
508
            for (DALActionFactory factory : this.featureStoreSearchActions.values()) {
509
                if (factory == null ) {
510
                    continue;
511
                }
512
                try {
513
                    if (factory.isApplicable(context)) {
514
                        factories.add(factory);
515
                    }
516
                } catch (Exception ex) {
517
                    LOGGER.warn("Can't access to DAL action factory " + factory.getName(), ex);
518
                }
519

    
520
            }
521
        } catch (Exception ex) {
522
            LOGGER.warn("Can't get DAL action factories", ex);
523
        }
524
        return factories;
525
    }
526

    
527
    @Override
528
    public  DALActionFactory getStoreAction(String name) {
529
        DALActionFactory action = this.featureStoreSearchActions.get(name.toLowerCase());
530
        return action;
531
    }
532
    
533
    @Override
534
    public void setStoreAction(AbstractButton component, String name, boolean preserveLabel, DALActionContext context) {
535
        DALActionFactory factory = this.getStoreAction(name);
536
        Action action = factory.createAction(context);
537
        if( preserveLabel ) {
538
            String s = component.getText();
539
            component.setAction(action);
540
            component.setText(s);
541
        } else {
542
            component.setAction(action);
543
        }
544
    }
545

    
546

    
547
    @Override
548
    public PickerController<JDBCServerExplorerParameters> createJDBCConnectionPickerController(
549
            JComboBox cboConnection, JButton btnConnection
550
        ) {
551
        JDBCConnectionPickerController x = new JDBCConnectionPickerController(cboConnection, btnConnection);
552
        return x;
553
    }
554

    
555
    @Override
556
    public SimpleFeaturesTableModel createSimpleFeaturesTableModel(FeatureStore store) {
557
        try {
558
            SimpleFeaturesTableModelImpl m = new SimpleFeaturesTableModelImpl(store);
559
            return m;
560
        } catch (DataException ex) {
561
            throw new RuntimeException("Can't creatre SimpleFeaturesTableModel.", ex);
562
        }
563
    }
564

    
565
    @Override
566
    public SimpleFeaturesTableModel createSimpleFeaturesTableModel(FeatureStore store, Expression filter) {
567
        try {
568
            SimpleFeaturesTableModelImpl m = new SimpleFeaturesTableModelImpl(store, filter);
569
            return m;
570
        } catch (DataException ex) {
571
            throw new RuntimeException("Can't creatre SimpleFeaturesTableModel.", ex);
572
        }
573
    }
574

    
575
    @Override
576
    public SimpleFeaturesTableModel createSimpleEditedFeaturesTableModel(FeatureStore store, Expression filter) {
577
        SimpleFeaturesTableModelImpl m = new SimpleEditedFeaturesTableModelImpl(store, filter);
578
        return m;
579
    }
580
    
581
    @Override
582
    public SimpleFeaturesTableModel createSimpleSelectedFeaturesTableModel(FeatureStore store, Expression filter) {
583
        SimpleFeaturesTableModelImpl m = new SimpleSelectedFeaturesTableModelImpl(store, filter);
584
        return m;
585
    }
586
    
587
    @Override
588
    public SimpleFeaturesTableModel createSimpleFeaturesTableModel(FeatureType featureType, List<String> columnNames, List<Feature> features) {
589
        SimpleFeaturesTableModelImpl m = new SimpleFeaturesTableModelImpl(featureType, columnNames, features);
590
        return m;
591
    }
592
    
593
    @Override
594
    public FeatureAttributeListCellRenderer createDefaultFeatureAttributeListCellRenderer() {
595
        FeatureAttributeListCellRenderer r = new FeatureAttributeListCellRendererImpl();
596
        return r;
597
    }
598

    
599
    @Override
600
    public FeatureAttributeTableCellRenderer createDefaultFeatureAttributeTableCellRenderer() {
601
        FeatureAttributeTableCellRenderer r = new FeatureAttributeTableCellRendererImpl();
602
        return r;
603
    }
604

    
605
    @Override
606
    public FeatureQueryOrderPanel createFeatureStoreOrderPanel() {
607
        DefaultFeatureQueryOrderPanel p = new DefaultFeatureQueryOrderPanel();
608
        return p;
609
    }
610
    
611
    @Override
612
    public Iterable<SearchConditionPanelFactory> getSearchConditionPanels() {
613
      if( this.searchConditionPanelFactories==null ) {
614
        return Collections.EMPTY_LIST;
615
      }
616
      return this.searchConditionPanelFactories.values();
617
    }
618

    
619
    @Override
620
    public void registerSearchConditionPanel(SearchConditionPanelFactory factory) {
621
      if( this.searchConditionPanelFactories==null ) {
622
        this.searchConditionPanelFactories = new HashMap<>();
623
      }
624
      this.searchConditionPanelFactories.put(factory.getName(), factory);
625
    }
626

    
627
    @Override
628
    public FeatureAttributesSelectionPanel createFeatureAttributeSelectionPanel() {
629
      FeatureAttributesSelectionPanel p = new DefaultFeatureAttributesSelectionPanel();
630
      return p;
631
    }
632

    
633
    @Override
634
    public void registerSearchPostProcess(SearchPostProcessFactory process) {
635
        this.searchPostProcess.put(process.getName(), process);
636
    }
637

    
638
    @Override
639
    public Map<String,SearchPostProcessFactory> getSearchPostProcess() {
640
        return this.searchPostProcess;
641
    }
642

    
643
    @Override
644
    public SearchPostProcessFactory getSearchPostProcess(String name) {
645
        SearchPostProcessFactory process = this.searchPostProcess.get(name);
646
        return process;
647
    }
648

    
649
    @Override
650
    public FeaturesFormContext createFeaturesFormContext(FeatureStore store) {
651
        DefaultFeaturesFormContext context = new DefaultFeaturesFormContext(store);
652
        return context;
653
    }
654

    
655
    @Override
656
    public TreeModel createTreeModel(StoresRepository repository) {
657
        StoresRepositoryTreeModel model = new StoresRepositoryTreeModel(repository);
658
        return model;
659
    }
660

    
661
    @Override
662
    public String getAttributeDescriptorLabel(FeatureAttributeDescriptor attrdesc) {
663
        return getAttributeDescriptorLabel(attrdesc, null);
664
    }
665
    
666
    @Override
667
    public String getAttributeDescriptorLabel(FeatureAttributeDescriptor attrdesc, String tableName) {
668
        String theLabel;
669
        int theUseLabels;
670
        if (getUseLabels() == null) {
671
            Tags tags = attrdesc.getTags();
672
            if (tags.has(DAL_USE_LABELS)) {
673
                theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO);
674
            } else {
675
                if (attrdesc.getFeatureType() != null) {
676
                    tags = attrdesc.getFeatureType().getTags();
677
                    theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO);
678
                } else {
679
                    theUseLabels = USE_LABELS_NO;
680
                }
681
            }
682
        } else {
683
            theUseLabels = getUseLabels();
684
        }
685
        switch (theUseLabels) {
686
            case USE_LABELS_BOTH:
687
                if (!StringUtils.equals(attrdesc.getLocalizedLabel(), attrdesc.getName())){
688
                    if (StringUtils.isBlank(tableName)) {
689
                        theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName());
690
                    } else {
691
                        theLabel = String.format("%s [%s/%s]", attrdesc.getLocalizedLabel(), attrdesc.getName(), tableName);
692
                    }
693
                    break;
694
                }
695
            case USE_LABELS_YES:
696
                if (StringUtils.isBlank(tableName)) {
697
                    theLabel = attrdesc.getLocalizedLabel();
698
                } else {
699
                    theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), tableName);
700
                }
701
                break;
702
            default:
703
            case USE_LABELS_NO:
704
                if (StringUtils.isBlank(tableName)) {
705
                    theLabel = attrdesc.getName();
706
                } else {
707
                    theLabel = String.format("%s [%s]", attrdesc.getName(), tableName);
708
                }
709
                break;
710
        }
711
        return theLabel;
712
    }
713

    
714
    /**
715
     * @return the useLabels
716
     */
717
    @Override
718
    public Integer getUseLabels() {
719
        return useLabels;
720
    }
721

    
722
    /**
723
     * @param useLabels the useLabels to set
724
     */
725
    @Override
726
    public void setUseLabels(Integer useLabels) {
727
        this.useLabels = useLabels;
728
    }
729

    
730
    @Override
731
    public SearchParameters createFeatureStoreSearchPanelParameters() {
732
        return new DefaultSearchParameters();
733
    }
734

    
735
    public FeatureQueryPickerController createFeatureQueryPickerController(JTextComponent text, JButton button, JButton history, JButton bookmarks) {
736
        DefaultFeatureQueryPickerController controller = new DefaultFeatureQueryPickerController(text, button, history, bookmarks);
737
        return controller;
738
    }
739

    
740
    @Override
741
    public StoresRepositoryController createStoresRepositoryController(JTree tree) {
742
        StoresRepositoryControllerImpl src = new StoresRepositoryControllerImpl(tree);
743
        return src;
744
    }
745
    
746
    @Override
747
    public Icon getStoreGeometryIcon(FeatureStore store) {
748
        try {
749
            if( store == null ) {
750
                return null;
751
            }
752
            FeatureType ft = store.getDefaultFeatureTypeQuietly();
753
            if( ft == null ) {
754
                return null;
755
            }
756
            FeatureAttributeDescriptor geomattr = ft.getDefaultGeometryAttribute();
757
            if( geomattr == null ) {
758
                return null;
759
            }
760
            int geometryType = geomattr.getGeomType().getType();
761
            String name;
762
            switch (geometryType) {
763
                case Geometry.TYPES.LINE:
764
                    name = "store-geomtype-line";
765
                    break;
766
                case Geometry.TYPES.POINT:
767
                    name = "store-geomtype-point";
768
                    break;
769
                case Geometry.TYPES.POLYGON:
770
                    name = "store-geomtype-polygon";
771
                    break;
772
                case Geometry.TYPES.MULTILINE:
773
                    name = "store-geomtype-multiline";
774
                    break;
775
                case Geometry.TYPES.MULTIPOINT:
776
                    name = "store-geomtype-multipoint";
777
                    break;
778
                case Geometry.TYPES.MULTIPOLYGON:
779
                    name = "store-geomtype-multipolygon";
780
                    break;
781
                case Geometry.TYPES.GEOMETRY:
782
                    name = "store-geomtype-mix";
783
                    break;
784
                default:
785
                    return null;
786
            }
787
            if (!store.isFeatureSelectionEmpty()) {
788
                name = name + "-sel";
789
            }
790
            name = name + ".png";
791
            URL url = this.getClass().getResource("/storegeomtypes/" + name);
792
            if (url == null) {
793
                return null;
794
            }
795
            Icon icon = new ImageIcon(url);
796
            return icon;
797
        } catch (Exception ex) {
798
            return null;
799
        }
800
    }
801
    
802
    @Override
803
    public int askUserStopEditing(FeatureStore featureStore) {
804
        return this.askUserStopEditing(null, featureStore, true);
805
    }
806

    
807
    public int askUserStopEditing(FeatureStore featureStore, boolean allowContinue) {
808
        return this.askUserStopEditing(null, featureStore, allowContinue);
809
    }
810

    
811
    public int askUserStopEditing(Component parent, FeatureStore featureStore, boolean allowContinue) {
812
        boolean allowWrite = featureStore.allowWrite();
813

    
814
        I18nManager i18n = ToolsLocator.getI18nManager();
815
        String message;
816
        String[] options = new String[allowContinue?3:2];
817
        int defaultoption;
818

    
819
        message = "<html>"+
820
            "<p>"+i18n.getTranslation("stop_edition")+"</p><br>";
821
        if( allowWrite ) {
822
            message = message + 
823
                "<b>"+i18n.getTranslation("_Guardar")+": </b>"+i18n.getTranslation("_Save_changes")+"<br>";
824
            options[0] = i18n.getTranslation("_Guardar");
825
            defaultoption = 0;
826
        } else {
827
            message = message + 
828
                "<b>"+i18n.getTranslation("_Export")+": </b>"+i18n.getTranslation("_Export_table")+"<br>";
829
            options[0] = i18n.getTranslation("_Export");
830
            defaultoption = allowContinue?2:0;
831
        }
832
        message = message + 
833
                "<b>"+i18n.getTranslation("_Descartar")+": </b>"+i18n.getTranslation("_Discard_and_lose_changes")+"<br>";
834
        options[1] = i18n.getTranslation("_Descartar");
835
        if( allowContinue ) {
836
            message = message + 
837
                "<b>"+i18n.getTranslation("_Continuar")+": </b>"+i18n.getTranslation("_Continue_editing_without_saving")+"<br>";
838
            options[2] = i18n.getTranslation("_Continuar");
839
        }
840
        message = message + "</html>";
841
        
842
        int resp = JOptionPane
843
                .showOptionDialog(
844
                        parent,
845
                        message,
846
                        i18n.getTranslation("stop_edition"),
847
                        allowContinue?JOptionPane.YES_NO_CANCEL_OPTION:JOptionPane.YES_NO_OPTION,
848
                        JOptionPane.QUESTION_MESSAGE, null, options,
849
                        options[defaultoption]);
850
       
851
        switch( resp ) {
852
        case 0:
853
            if( allowWrite )
854
                return STOP_EDITING_SAVE;
855
            return STOP_EDITING_EXPORT;
856
        case 1:
857
            return STOP_EDITING_DISCARD;
858
        default:
859
        case 2:
860
            return STOP_EDITING_CONTINUE;
861
        }
862
    }
863
    
864
    public boolean exportStore(FeatureStore store, WindowManager.MODE mode) {
865
        DALActionFactory exportActionFactory = null;
866
        for (DALActionFactory action : this.getStoreActions()) {
867
            if( StringUtils.equalsIgnoreCase("Export", action.getName()) ) {
868
                exportActionFactory = action;
869
                break;
870
            }
871
        }
872
        if( exportActionFactory == null ) {
873
            return false;
874
        }
875
        DALActionContext context = new AbstractDALActionFactory.AbstractDALActionContext("ExportActionContext") {
876
            @Override
877
            public DataStore getStore() {
878
                return store;
879
            }
880
        };
881
        context.set("WindowMode", mode);
882
        Action action = exportActionFactory.createAction(context);
883
        action.actionPerformed(new ActionEvent(store, 0, exportActionFactory.getName()));
884
        return true;
885
    }
886
        
887
    public JPanel createVisualdbModelerPanel() {
888
        return new Visualdbmodeler();
889
    }
890

    
891
}
892