Revision 44351 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

View differences:

DefaultSearchPanel.java
1 1
package org.gvsig.fmap.dal.swing.impl.searchpanel;
2 2

  
3
import java.awt.BorderLayout;
3 4
import java.awt.Cursor;
4 5
import java.awt.Dimension;
5 6
import java.awt.FlowLayout;
......
11 12
import java.util.HashMap;
12 13
import java.util.List;
13 14
import java.util.Map;
15
import javax.swing.AbstractAction;
14 16
import javax.swing.Action;
17
import static javax.swing.Action.ACTION_COMMAND_KEY;
18
import static javax.swing.Action.NAME;
15 19
import javax.swing.BorderFactory;
16 20
import javax.swing.ImageIcon;
17 21
import javax.swing.JButton;
......
22 26
import javax.swing.table.TableModel;
23 27
import org.apache.commons.io.FilenameUtils;
24 28
import org.apache.commons.lang.mutable.MutableObject;
29
import org.apache.commons.lang3.StringUtils;
30
import org.gvsig.configurableactions.ConfigurableActionsMamager;
25 31
import org.gvsig.expressionevaluator.Code;
26 32
import org.gvsig.expressionevaluator.Expression;
27 33
import org.gvsig.expressionevaluator.ExpressionBuilder;
......
31 37
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator;
32 38
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager;
33 39
import org.gvsig.expressionevaluator.swing.ExpressionPickerController;
40
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;
34 44
import org.gvsig.fmap.dal.DataStore;
35 45
import org.gvsig.fmap.dal.complements.Search;
36 46
import org.gvsig.fmap.dal.exception.DataException;
......
44 54
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModel;
45 55
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel;
46 56
import org.gvsig.tools.ToolsLocator;
57
import org.gvsig.tools.dynobject.Tags;
58
import org.gvsig.tools.i18n.I18nManager;
47 59
import org.gvsig.tools.swing.api.ActionListenerSupport;
48 60
import org.gvsig.tools.swing.api.ToolsSwingLocator;
49 61
import org.gvsig.tools.swing.icontheme.IconTheme;
62
import org.gvsig.tools.util.ToolsUtilLocator;
50 63
import org.slf4j.Logger;
51 64
import org.slf4j.LoggerFactory;
52 65

  
......
54 67
 *
55 68
 * @author jjdelcerro
56 69
 */
57
@SuppressWarnings("UseSpecificCatch")
70
@SuppressWarnings({"UseSpecificCatch","Convert2Lambda"})
58 71
public class DefaultSearchPanel
59 72
        extends DefaultSearchPanelView
60 73
        implements FeatureStoreSearchPanel {
......
62 75
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSearchPanel.class);
63 76
    private Expression currentSearch;
64 77
    
78
    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
    
65 126
    private class ActionButtons {
66 127
        
67 128
        private final DALActionFactory factory;
......
187 248
    }
188 249

  
189 250
    private void initComponents() {
251
        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
        
190 256
        this.searchFields = new ArrayList<>();
191 257
        SearchFieldController controller = new SearchFieldController(
192 258
                store,
......
507 573
            new String[]{"dalswing", "featurestore-column"},
508 574
            new String[]{"dalswing", "featurestore-foreing-key"},
509 575
            new String[]{"dalswing", "featurestore-table"},
576
            new String[]{"dalswing", "featurestore-closedlist"},
510 577
            new String[]{"dalswing", "search-action-showform"},
511 578
            new String[]{"dalswing", "search-action-select"},
512 579
            new String[]{"dalswing", "search-action-select-add"},
......
518 585
            theme.registerDefault("DALSwing", icon[0], icon[1], null, url);
519 586
        }
520 587

  
588
        ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager();
589
        cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsYesAction());
590
        cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsNoAction());
591
        cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsBothAction());
592
        
521 593
    }
522 594

  
523 595
    @Override
......
546 618
    public boolean isShowActions() {
547 619
        return this.showActions;
548 620
    }
621

  
622

  
623
    public static String getAttributeDescriptorLabel(FeatureAttributeDescriptor attrdesc, String tableName) {
624
        String theLabel;
625
        int theUseLabels;
626
        if( useLabels == null ) {
627
            Tags tags = attrdesc.getTags();
628
            if( tags.has(DAL_USE_LABELS) ) {
629
                theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO);
630
            } else {
631
                tags = attrdesc.getFeatureType().getTags();
632
                theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO);
633
            }
634
        } else {
635
            theUseLabels = useLabels;
636
        }
637
        switch(theUseLabels) {
638
            case USE_LABELS_YES:
639
                if( StringUtils.isBlank(tableName) ) {
640
                    theLabel = attrdesc.getLocalizedLabel();
641
                } else {
642
                    theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), tableName);
643
                }
644
                break;
645
            default:
646
            case USE_LABELS_NO:
647
                if( StringUtils.isBlank(tableName) ) {
648
                    theLabel = attrdesc.getName();
649
                } else {
650
                    theLabel = String.format("%s [%s]", attrdesc.getName(), tableName);
651
                }
652
                break;
653
            case USE_LABELS_BOTH:
654
                if( StringUtils.isBlank(tableName) ) {
655
                    theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName());
656
                } else {
657
                    theLabel = String.format("%s [%s/%s]", attrdesc.getLocalizedLabel(), attrdesc.getName(), tableName);
658
                }
659
                break;
660
        }
661
        return theLabel;
662
    }
663
     
549 664
}

Also available in: Unified diff