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 / searchpanel / DefaultSearchPanel.java @ 44402

History | View | Annotate | Download (23.6 KB)

1 44259 jjdelcerro
package org.gvsig.fmap.dal.swing.impl.searchpanel;
2
3 44351 jjdelcerro
import java.awt.BorderLayout;
4 44263 jjdelcerro
import java.awt.Cursor;
5 44259 jjdelcerro
import java.awt.Dimension;
6 44263 jjdelcerro
import java.awt.FlowLayout;
7 44259 jjdelcerro
import java.awt.event.ActionEvent;
8
import java.awt.event.ActionListener;
9
import java.net.URL;
10
import java.util.ArrayList;
11 44263 jjdelcerro
import java.util.Collection;
12 44275 jjdelcerro
import java.util.HashMap;
13 44259 jjdelcerro
import java.util.List;
14 44275 jjdelcerro
import java.util.Map;
15 44351 jjdelcerro
import javax.swing.AbstractAction;
16 44263 jjdelcerro
import javax.swing.Action;
17 44351 jjdelcerro
import static javax.swing.Action.ACTION_COMMAND_KEY;
18
import static javax.swing.Action.NAME;
19 44275 jjdelcerro
import javax.swing.BorderFactory;
20 44259 jjdelcerro
import javax.swing.ImageIcon;
21 44263 jjdelcerro
import javax.swing.JButton;
22 44259 jjdelcerro
import javax.swing.JComponent;
23 44262 jjdelcerro
import javax.swing.SwingUtilities;
24 44259 jjdelcerro
import javax.swing.event.ListSelectionEvent;
25
import javax.swing.event.ListSelectionListener;
26 44262 jjdelcerro
import javax.swing.table.TableModel;
27 44259 jjdelcerro
import org.apache.commons.io.FilenameUtils;
28 44262 jjdelcerro
import org.apache.commons.lang.mutable.MutableObject;
29 44351 jjdelcerro
import org.apache.commons.lang3.StringUtils;
30
import org.gvsig.configurableactions.ConfigurableActionsMamager;
31 44292 jjdelcerro
import org.gvsig.expressionevaluator.Code;
32 44259 jjdelcerro
import org.gvsig.expressionevaluator.Expression;
33
import org.gvsig.expressionevaluator.ExpressionBuilder;
34
import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_AND;
35
import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_OR;
36
import org.gvsig.expressionevaluator.ExpressionUtils;
37
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator;
38
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager;
39
import org.gvsig.expressionevaluator.swing.ExpressionPickerController;
40 44351 jjdelcerro
import static org.gvsig.fmap.dal.DataManager.DAL_USE_LABELS;
41
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_BOTH;
42
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_NO;
43
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_YES;
44 44281 jjdelcerro
import org.gvsig.fmap.dal.DataStore;
45 44262 jjdelcerro
import org.gvsig.fmap.dal.complements.Search;
46 44259 jjdelcerro
import org.gvsig.fmap.dal.exception.DataException;
47
import org.gvsig.fmap.dal.feature.Feature;
48
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
49
import org.gvsig.fmap.dal.feature.FeatureStore;
50
import org.gvsig.fmap.dal.feature.FeatureType;
51 44281 jjdelcerro
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory.AbstractDALActionContext;
52
import org.gvsig.fmap.dal.swing.DALActionFactory;
53 44259 jjdelcerro
import org.gvsig.fmap.dal.swing.DALSwingLocator;
54 44340 jjdelcerro
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModel;
55 44259 jjdelcerro
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel;
56 44262 jjdelcerro
import org.gvsig.tools.ToolsLocator;
57 44351 jjdelcerro
import org.gvsig.tools.dynobject.Tags;
58
import org.gvsig.tools.i18n.I18nManager;
59 44259 jjdelcerro
import org.gvsig.tools.swing.api.ActionListenerSupport;
60
import org.gvsig.tools.swing.api.ToolsSwingLocator;
61
import org.gvsig.tools.swing.icontheme.IconTheme;
62 44351 jjdelcerro
import org.gvsig.tools.util.ToolsUtilLocator;
63 44259 jjdelcerro
import org.slf4j.Logger;
64
import org.slf4j.LoggerFactory;
65
66
/**
67
 *
68
 * @author jjdelcerro
69
 */
70 44351 jjdelcerro
@SuppressWarnings({"UseSpecificCatch","Convert2Lambda"})
71 44259 jjdelcerro
public class DefaultSearchPanel
72
        extends DefaultSearchPanelView
73
        implements FeatureStoreSearchPanel {
74
75
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSearchPanel.class);
76
    private Expression currentSearch;
77 44275 jjdelcerro
78 44351 jjdelcerro
    static /* friend */ Integer useLabels = null;
79
80
    public static class UseLabelsYesAction extends AbstractAction {
81
82
        public UseLabelsYesAction() {
83
            I18nManager i18n = ToolsLocator.getI18nManager();
84
85
            this.putValue(NAME, i18n.getTranslation("_Use_labels"));
86
            this.putValue(ACTION_COMMAND_KEY, "UseLabelsYes");
87
        }
88
89
        @Override
90
        public void actionPerformed(ActionEvent ae) {
91
            DefaultSearchPanel.useLabels = USE_LABELS_YES;
92
        }
93
    }
94
95
    public static class UseLabelsNoAction extends AbstractAction {
96
97
        public UseLabelsNoAction() {
98
            I18nManager i18n = ToolsLocator.getI18nManager();
99
100
            this.putValue(NAME, i18n.getTranslation("_Use_names"));
101
            this.putValue(ACTION_COMMAND_KEY, "UseLabelsNo");
102
        }
103
104
        @Override
105
        public void actionPerformed(ActionEvent ae) {
106
            DefaultSearchPanel.useLabels = USE_LABELS_NO;
107
        }
108
    }
109
110
    public static class UseLabelsBothAction extends AbstractAction {
111
112
        public UseLabelsBothAction() {
113
            I18nManager i18n = ToolsLocator.getI18nManager();
114
115
            this.putValue(NAME, i18n.getTranslation("_Use_labels_and_names"));
116
            this.putValue(ACTION_COMMAND_KEY, "UseLabelsBoth");
117
        }
118
119
        @Override
120
        public void actionPerformed(ActionEvent ae) {
121
            DefaultSearchPanel.useLabels = USE_LABELS_BOTH;
122
        }
123
    }
124
125
126 44275 jjdelcerro
    private class ActionButtons {
127
128 44281 jjdelcerro
        private final DALActionFactory factory;
129
        private final Action action;
130
        private final JButton button;
131 44275 jjdelcerro
132 44281 jjdelcerro
        public ActionButtons(DALActionFactory factory, Action action, JButton button) {
133 44275 jjdelcerro
            this.factory = factory;
134
            this.action = action;
135
            this.button = button;
136
        }
137
    }
138 44259 jjdelcerro
139 44281 jjdelcerro
    public static class SearchActionContext extends AbstractDALActionContext {
140
141
        private final DefaultSearchPanel panel;
142
143
        public SearchActionContext(DefaultSearchPanel panel) {
144
            super(FeatureStoreSearchPanel.ACTION_CONTEXT_NAME);
145
            this.panel = panel;
146
        }
147
148
        @Override
149
        public DataStore getStore() {
150
            return this.panel.getStore();
151
        }
152
153
        @Override
154
        public Expression getFilter() {
155
            return this.panel.getCurrentSearch();
156
        }
157
158
        @Override
159
        public JComponent getActionButton(String actionName) {
160
            return this.panel.getActionButton(actionName);
161
        }
162
163
        @Override
164
        public int getSelectedsCount() {
165
            return this.panel.getSelectedFeatureCount();
166
        }
167
168
        @Override
169
        public Expression getFilterForSelecteds() {
170
            return this.panel.getSearchForSelectedFeature();
171
        }
172
    }
173
174 44259 jjdelcerro
    private final FeatureStore store;
175
    private final ActionListenerSupport acctionListeners;
176 44288 jjdelcerro
    private List<SearchFieldController> searchFields;
177 44259 jjdelcerro
    private ExpressionPickerController advancedExpression;
178 44275 jjdelcerro
    private final Map<String, ActionButtons> actions;
179 44288 jjdelcerro
    private boolean showActions = true;
180 44297 jjdelcerro
    private int maxSearhFields = 4;
181 44259 jjdelcerro
182
    public DefaultSearchPanel(FeatureStore store) {
183
        this.store = store;
184
        this.acctionListeners = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
185 44288 jjdelcerro
        this.searchFields = null;
186 44275 jjdelcerro
        this.actions = new HashMap<>();
187 44259 jjdelcerro
    }
188
189
    @Override
190
    public JComponent asJComponent() {
191 44288 jjdelcerro
        if( this.searchFields==null ) {
192
            this.initComponents();
193
        }
194 44259 jjdelcerro
        return this;
195
    }
196
197 44263 jjdelcerro
    private void addActions() {
198 44288 jjdelcerro
        if( !this.showActions ) {
199
            return;
200
        }
201 44263 jjdelcerro
        this.pnlActions.removeAll();
202 44275 jjdelcerro
        this.pnlActions.setLayout(new FlowLayout(FlowLayout.TRAILING, 8, 4));
203 44281 jjdelcerro
        SearchActionContext actionContext = new SearchActionContext(this);
204
        Collection<DALActionFactory> factories = DALSwingLocator.getSwingManager().getStoreActions();
205
        for (DALActionFactory factory : factories) {
206
            Action action = factory.createAction(actionContext);
207 44263 jjdelcerro
            JButton button = new JButton(action);
208 44275 jjdelcerro
            this.actions.put(factory.getName(), new ActionButtons(factory, action, button));
209
            button.setBorder(BorderFactory.createEmptyBorder());
210 44263 jjdelcerro
            button.setBorderPainted(false);
211
            button.setFocusPainted(false);
212
            button.setContentAreaFilled(false);
213
            button.setCursor(new Cursor(Cursor.HAND_CURSOR));
214
            this.pnlActions.add(button);
215
        }
216
        this.pnlActions.revalidate();
217
        this.pnlActions.repaint();
218
    }
219
220 44259 jjdelcerro
    @Override
221
    public void addActionListener(ActionListener listener) {
222
        this.acctionListeners.addActionListener(listener);
223
    }
224
225
    @Override
226
    public ActionListener[] getActionListeners() {
227
        return this.acctionListeners.getActionListeners();
228
    }
229
230
    @Override
231
    public void removeActionListener(ActionListener listener) {
232
        this.acctionListeners.removeActionListener(listener);
233
    }
234
235
    @Override
236
    public void removeAllActionListener() {
237
        this.acctionListeners.removeAllActionListener();
238
    }
239
240
    @Override
241
    public void fireActionEvent(ActionEvent event) {
242
        this.acctionListeners.fireActionEvent(event);
243
    }
244
245
    @Override
246
    public boolean hasActionListeners() {
247
        return this.acctionListeners.hasActionListeners();
248
    }
249
250
    private void initComponents() {
251 44351 jjdelcerro
        ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager();
252
        JComponent c = cfgActionsManager.getConfigurableActionsComponent(CONFIGURABLE_PANEL_ID, this);
253
        this.pnlCfgActions.setLayout(new BorderLayout(0,0));
254
        this.pnlCfgActions.add(c, BorderLayout.CENTER);
255
256 44288 jjdelcerro
        this.searchFields = new ArrayList<>();
257 44259 jjdelcerro
        SearchFieldController controller = new SearchFieldController(
258
                store,
259
                lblField1,
260
                lblExtraFields1,
261
                lblRelationalOperator1,
262
                cboValue1,
263
                lblLogicalOperators1
264
        );
265
        this.searchFields.add(controller);
266
        controller = new SearchFieldController(
267
                store,
268
                lblField2,
269
                lblExtraFields2,
270
                lblRelationalOperator2,
271
                cboValue2,
272
                lblLogicalOperators2
273
        );
274
        this.searchFields.add(controller);
275
        controller = new SearchFieldController(
276
                store,
277
                lblField3,
278
                lblExtraFields3,
279
                lblRelationalOperator3,
280
                cboValue3,
281
                lblLogicalOperators3
282
        );
283
        this.searchFields.add(controller);
284
        controller = new SearchFieldController(
285
                store,
286
                lblField4,
287
                lblExtraFields4,
288
                lblRelationalOperator4,
289
                cboValue4,
290
                null
291
        );
292
        this.searchFields.add(controller);
293 44262 jjdelcerro
        try {
294
            Search search = (Search) ToolsLocator.getComplementsManager().get(
295
                    Search.COMPLEMENT_MANE, this.store.getDefaultFeatureType()
296
            );
297 44337 jjdelcerro
            List<Search.OrderedAttribute> orderedAttributes = search.getOrderedAttributes(
298 44262 jjdelcerro
                    Search.BASIC_TYPES_FILTER,
299
                    Search.STR_INT_LONG_LABEL_ORDER,
300
                    5
301
            );
302 44297 jjdelcerro
            this.maxSearhFields = Integer.min(orderedAttributes.size(), 4);
303 44262 jjdelcerro
            int n = 0;
304
            for (SearchFieldController searchField : searchFields) {
305 44297 jjdelcerro
                if( n<this.maxSearhFields ) {
306 44337 jjdelcerro
                    searchField.setAttribute(orderedAttributes.get(n++).getDescriptor().getName());
307 44297 jjdelcerro
                } else {
308
                    searchField.setEnabled(false);
309
                }
310 44262 jjdelcerro
            }
311
        } catch (DataException ex) {
312
            LOGGER.warn("Can't determine order of attributes", ex);
313 44259 jjdelcerro
        }
314
315
        ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager();
316 44267 jjdelcerro
        this.advancedExpression = expressionSwingManager.createExpressionPickerController(
317
                txtAdvancedExpression,
318
                btnAdvancedExpression,
319
                btnAdvancedExpressionHistory,
320
                btnAdvancedExpressionBookmarks
321
        );
322 44285 jjdelcerro
        this.advancedExpression.addElement(
323
            DALSwingLocator.getSwingManager().createFeatureStoreElement(store)
324
        );
325 44259 jjdelcerro
326
        this.btnSearch.addActionListener(new ActionListener() {
327
            @Override
328
            public void actionPerformed(ActionEvent e) {
329
                doSearch();
330
            }
331
        });
332
333
        this.tblResults.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
334
            @Override
335
            public void valueChanged(ListSelectionEvent e) {
336 44275 jjdelcerro
                for (ActionButtons actionButton : actions.values()) {
337
                    if( actionButton.action instanceof ListSelectionListener) {
338
                        ((ListSelectionListener) actionButton.action).valueChanged(e);
339 44263 jjdelcerro
                    }
340 44259 jjdelcerro
                }
341
            }
342
        });
343
        this.btnClear.addActionListener(new ActionListener() {
344
            @Override
345
            public void actionPerformed(ActionEvent e) {
346
                clear();
347
            }
348
        });
349 44263 jjdelcerro
        addActions();
350 44292 jjdelcerro
        this.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
351 44259 jjdelcerro
352
        doSearch(null);
353
    }
354
355 44262 jjdelcerro
    @Override
356
    public void setEnabled(boolean enabled) {
357 44288 jjdelcerro
        if( this.searchFields==null ) {
358
            initComponents();
359
        }
360 44297 jjdelcerro
        int n=0;
361 44262 jjdelcerro
        for (SearchFieldController searchField : searchFields) {
362 44297 jjdelcerro
            if( n<this.maxSearhFields ) {
363
                searchField.setEnabled(enabled);
364
            } else {
365
                searchField.setEnabled(false);
366
            }
367
            n++;
368 44262 jjdelcerro
        }
369
        this.btnClear.setEnabled(enabled);
370
        this.btnSearch.setEnabled(enabled);
371
        this.advancedExpression.setEnabled(enabled);
372 44275 jjdelcerro
        for (ActionButtons actionButton : actions.values()) {
373
            actionButton.action.setEnabled(enabled);
374 44263 jjdelcerro
        }
375 44262 jjdelcerro
    }
376
377 44259 jjdelcerro
    public void clear() {
378 44288 jjdelcerro
        if( this.searchFields==null ) {
379
            return;
380
        }
381 44259 jjdelcerro
        for (SearchFieldController searchField : searchFields) {
382
            searchField.clear();
383 44262 jjdelcerro
        }
384 44259 jjdelcerro
        this.advancedExpression.set(null);
385
    }
386 44262 jjdelcerro
387 44292 jjdelcerro
    @Override
388
    public Expression getFilter() {
389
        Expression filter;
390 44259 jjdelcerro
        int searchMode = this.tabSearchMode.getSelectedIndex();
391
        if (searchMode == 1) { // Avanzada
392 44292 jjdelcerro
            filter = this.advancedExpression.get();
393
        } else {
394
            ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
395
            String relational = OPERATOR_OR;
396
            for (SearchFieldController searchField : searchFields) {
397
                if (searchField.getAttribute() != null && searchField.getValue() != null) {
398
                    ExpressionBuilder.BinaryOperator cond = builder.binaryOperator(
399
                            searchField.getRelationalOperator(),
400
                            searchField.isAttributeAnExpression()
401
                            ? builder.custom(searchField.getAttribute())
402
                            : builder.column(searchField.getAttribute()),
403
                            builder.constant(searchField.getValue())
404
                    );
405
                    if (relational.equals(OPERATOR_AND)) {
406
                        builder.and(cond);
407
                    } else {
408
                        builder.or(cond);
409
                    }
410
                    relational = searchField.getLogicalOperator();
411 44259 jjdelcerro
                }
412
            }
413 44292 jjdelcerro
            if (builder.isEmpty()) {
414
                filter = null;
415
            } else {
416
                filter = ExpressionUtils.createExpression(builder.toString());
417
            }
418 44259 jjdelcerro
        }
419 44292 jjdelcerro
        if (ExpressionUtils.isPhraseEmpty(filter)) {
420
            return null;
421 44259 jjdelcerro
        }
422 44292 jjdelcerro
        return filter;
423 44259 jjdelcerro
    }
424 44292 jjdelcerro
425
    private void doSearch() {
426
        Expression filter = this.getFilter();
427
        doSearch(filter);
428
    }
429 44259 jjdelcerro
430 44262 jjdelcerro
    private void doSearch(final Expression exp) {
431
        final MutableObject model = new MutableObject(null);
432
433
        lblMsg.setText("Searching...");
434
        setEnabled(false);
435
        Thread th = new Thread(new Runnable() {
436
            @Override
437
            public void run() {
438
                try {
439
                    final List<Feature> features;
440
                    if (exp == null) {
441
                        features = store.getFeatures();
442
                    } else {
443
                        features = store.getFeatures(exp);
444
                    }
445
                    currentSearch = exp;
446 44340 jjdelcerro
                    model.setValue( new SimpleFeaturesTableModel(
447 44262 jjdelcerro
                            store.getDefaultFeatureType(),
448
                            null,
449
                            features
450
                        )
451
                    );
452
                } catch (DataException ex) {
453
                    LOGGER.warn("Can't get features or create table model",ex);
454
                } finally {
455
                    SwingUtilities.invokeLater(new Runnable() {
456
                        @Override
457
                        public void run() {
458
                            TableModel m = (TableModel) model.getValue();
459
                            tblResults.setModel(m);
460
                            lblMsg.setText(String.format("%d elementos", m.getRowCount()));
461
                            setEnabled(true);
462
                        }
463
                    });
464
                }
465 44259 jjdelcerro
            }
466 44262 jjdelcerro
        });
467
        th.start();
468 44259 jjdelcerro
    }
469
470 44263 jjdelcerro
    @Override
471
    public Expression getCurrentSearch() {
472
        return this.currentSearch;
473
    }
474
475
    @Override
476 44292 jjdelcerro
    public boolean setFilter(Expression filter) {
477
        try {
478
            if( this.advancedExpression==null ) {
479
                this.initComponents();
480
            }
481
            if( ExpressionUtils.isPhraseEmpty(filter) ) {
482
                this.clear();
483
                return true;
484
            }
485
            this.advancedExpression.set(filter);
486
            this.tabSearchMode.setSelectedIndex(1);
487
488
            Code code = filter.getCode();
489
            if( code.code()==Code.CALLER) {
490
                SearchFieldController searchField = this.searchFields.get(0);
491
                Code.Caller caller = (Code.Caller)code;
492
                if( searchField.isAValidRelationOperator(caller.name())) {
493
                    Code op1 = caller.parameters().get(0);
494
                    Code op2 = caller.parameters().get(1);
495
                    if( op1.code()==Code.IDENTIFIER && op2.code()==Code.CONSTANT ) {
496
                        if( searchField.setAttribute(((Code.Identifier)op1).name())>=0 ) {
497
                            searchField.setRelationalOperator(caller.name());
498
                            searchField.setValue(((Code.Constant)op2).value());
499
                            this.tabSearchMode.setSelectedIndex(0);
500
                        }
501
                    }
502
                }
503
            }
504 44340 jjdelcerro
            SimpleFeaturesTableModel model = new SimpleFeaturesTableModel(this.getStore());
505 44292 jjdelcerro
            tblResults.setModel(model);
506
            lblMsg.setText("");
507
            return true;
508
        } catch(Exception ex) {
509
            LOGGER.warn("Can't set current search", ex);
510
            return false;
511
        }
512
    }
513
514
    @Override
515
    public void setCurrentSearch(Expression filter) {
516
        if( this.setFilter(filter) ) {
517
            doSearch();
518
        }
519
    }
520
521
    @Override
522 44263 jjdelcerro
    public Expression getSearchForSelectedFeature() {
523 44288 jjdelcerro
        if( this.searchFields==null ) {
524
            return null;
525
        }
526 44263 jjdelcerro
        int selectedRow = this.tblResults.getSelectedRow();
527
        if (selectedRow < 0) {
528
            return null;
529
        }
530 44259 jjdelcerro
        try {
531 44340 jjdelcerro
            List<Feature> features = ((SimpleFeaturesTableModel) this.tblResults.getModel()).getFeatures();
532 44263 jjdelcerro
            Feature feature = features.get(selectedRow);
533
534
            ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
535
            FeatureType ftype = this.store.getDefaultFeatureType();
536
            for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
537
                builder.and(
538
                        builder.eq(
539
                                builder.column(attrdesc.getName()),
540
                                builder.constant(feature.get(attrdesc.getName()))
541
                        )
542
                );
543 44259 jjdelcerro
            }
544 44263 jjdelcerro
            Expression filter = ExpressionUtils.createExpression(builder.toString());
545
            return filter;
546 44259 jjdelcerro
        } catch (Exception ex) {
547 44263 jjdelcerro
            LOGGER.warn("Can't build search for the selected feature.", ex);
548
            return null;
549 44259 jjdelcerro
        }
550
    }
551
552 44267 jjdelcerro
    @Override
553 44263 jjdelcerro
    public FeatureStore getStore() {
554
        return store;
555
    }
556
557 44259 jjdelcerro
    @Override
558
    public ImageIcon loadImage(String imageName) {
559
        String name = FilenameUtils.getBaseName(imageName);
560
        IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault();
561
        if (theme.exists(name)) {
562
            return theme.get(name);
563
        }
564
        URL url = this.getClass().getResource(name + ".png");
565
        if (url == null) {
566
            return null;
567
        }
568
        return new ImageIcon(url);
569
    }
570
571
    public static void selfRegister() {
572 44262 jjdelcerro
        String[][] iconNames = new String[][]{
573
            new String[]{"dalswing", "featurestore-column"},
574
            new String[]{"dalswing", "featurestore-foreing-key"},
575 44263 jjdelcerro
            new String[]{"dalswing", "featurestore-table"},
576
            new String[]{"dalswing", "search-action-showform"},
577
            new String[]{"dalswing", "search-action-select"},
578
            new String[]{"dalswing", "search-action-select-add"},
579
            new String[]{"dalswing", "search-action-select-filter"}
580 44259 jjdelcerro
        };
581
        IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent();
582
        for (String[] icon : iconNames) {
583 44262 jjdelcerro
            URL url = DefaultSearchPanel.class.getResource(icon[1] + ".png");
584 44259 jjdelcerro
            theme.registerDefault("DALSwing", icon[0], icon[1], null, url);
585
        }
586 44262 jjdelcerro
587 44351 jjdelcerro
        ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager();
588
        cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsYesAction());
589
        cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsNoAction());
590
        cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsBothAction());
591
592 44259 jjdelcerro
    }
593 44263 jjdelcerro
594
    @Override
595
    public int getSelectedFeatureCount() {
596 44288 jjdelcerro
        if( this.searchFields==null ) {
597
            return 0;
598
        }
599 44263 jjdelcerro
        return this.tblResults.getSelectedRowCount();
600
    }
601
602 44275 jjdelcerro
    @Override
603
    public JComponent getActionButton(String name) {
604
        ActionButtons actionButton = this.actions.get(name);
605
        if( actionButton==null ) {
606
            return null;
607
        }
608
        return actionButton.button;
609
    }
610
611 44288 jjdelcerro
    @Override
612
    public void setShowActions(boolean showActions) {
613
        this.showActions = showActions;
614
    }
615
616
    @Override
617
    public boolean isShowActions() {
618
        return this.showActions;
619
    }
620 44351 jjdelcerro
621
622
    public static String getAttributeDescriptorLabel(FeatureAttributeDescriptor attrdesc, String tableName) {
623
        String theLabel;
624
        int theUseLabels;
625
        if( useLabels == null ) {
626
            Tags tags = attrdesc.getTags();
627
            if( tags.has(DAL_USE_LABELS) ) {
628
                theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO);
629
            } else {
630
                tags = attrdesc.getFeatureType().getTags();
631
                theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO);
632
            }
633
        } else {
634
            theUseLabels = useLabels;
635
        }
636
        switch(theUseLabels) {
637
            case USE_LABELS_YES:
638
                if( StringUtils.isBlank(tableName) ) {
639
                    theLabel = attrdesc.getLocalizedLabel();
640
                } else {
641
                    theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), tableName);
642
                }
643
                break;
644
            default:
645
            case USE_LABELS_NO:
646
                if( StringUtils.isBlank(tableName) ) {
647
                    theLabel = attrdesc.getName();
648
                } else {
649
                    theLabel = String.format("%s [%s]", attrdesc.getName(), tableName);
650
                }
651
                break;
652
            case USE_LABELS_BOTH:
653
                if( StringUtils.isBlank(tableName) ) {
654
                    theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName());
655
                } else {
656
                    theLabel = String.format("%s [%s/%s]", attrdesc.getLocalizedLabel(), attrdesc.getName(), tableName);
657
                }
658
                break;
659
        }
660
        return theLabel;
661
    }
662
663 44263 jjdelcerro
}