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/featuretype/TagsController.java

View differences:

TagsController.java
20 20
import javax.swing.text.JTextComponent;
21 21
import org.apache.commons.lang3.StringUtils;
22 22
import org.gvsig.tools.ToolsLocator;
23
import org.gvsig.tools.dynobject.DynField;
24
import org.gvsig.tools.dynobject.DynObjectValueItem;
23 25
import org.gvsig.tools.dynobject.Tags;
24 26
import org.gvsig.tools.i18n.I18nManager;
25 27
import org.gvsig.tools.swing.api.ToolsSwingLocator;
26 28
import org.gvsig.tools.swing.api.ToolsSwingManager;
29
import org.gvsig.tools.util.LabeledValue;
27 30
import org.gvsig.tools.util.UnmodifiableBasicMap;
28 31

  
29 32
/**
30 33
 *
31 34
 * @author jjdelcerro
32 35
 */
36
@SuppressWarnings("Convert2Lambda")
33 37
class TagsController {
34 38
    
35 39
    private final JTable tblTags;
36 40
    private final JComboBox cboName;
37
    private final JTextComponent txtValue;
41
    private final JComboBox cboValue;
38 42
    private final JButton btnAdd;
39 43
    private final JButton btnUpdate;
40 44
    private final JButton btnRemove;
41
    private final UnmodifiableBasicMap<String, String> tagDescriptions;
45
    private final UnmodifiableBasicMap<String, DynField> tagDefinitions;
42 46
    private final JLabel lblDescription;
43 47

  
44 48
    public TagsController(
45 49
            JTable tblTags, 
46 50
            JComboBox cboName, 
47
            JTextComponent txtValue, 
51
            JComboBox cboValue, 
48 52
            JButton btnAdd, 
49 53
            JButton btnUpdate, 
50 54
            JButton btnRemove,
......
52 56
        ) {
53 57
        this.tblTags = tblTags;
54 58
        this.cboName = cboName;
55
        this.txtValue = txtValue;
59
        this.cboValue = cboValue;
56 60
        this.btnAdd = btnAdd;
57 61
        this.btnUpdate = btnUpdate;
58 62
        this.btnRemove = btnRemove;
59 63
        this.lblDescription = lblDescription;
60
        this.tagDescriptions = ToolsLocator.getDynObjectManager().getTags();
64
        this.tagDefinitions = ToolsLocator.getDynObjectManager().getTags();
61 65
        this.initComponents();
62 66
    }
63 67
    
64 68
    private void initComponents() {
65 69
        ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager();
66 70
        swingManager.setDefaultPopupMenu(this.cboName);
67
        swingManager.setDefaultPopupMenu(this.txtValue);
71
        swingManager.setDefaultPopupMenu(this.cboValue);
68 72
        
69
        swingManager.addClearButton(this.txtValue);
73
        swingManager.addClearButton(this.cboValue);
70 74

  
71 75
        swingManager.translate(this.btnAdd);
72 76
        swingManager.translate(this.btnUpdate);
......
101 105
            }
102 106
        });
103 107
        List<String> tagsNames = new ArrayList<>();
104
        for (String tag : this.tagDescriptions.keySet()) {
108
        for (String tag : this.tagDefinitions.keySet()) {
105 109
            tagsNames.add(tag);
106 110
        }
107 111
        tagsNames.sort(null);
......
124 128
    public void clean() {
125 129
        this.tblTags.setModel(new DefaultTableModel());
126 130
        this.cboName.setSelectedIndex(-1);
127
        this.txtValue.setText("");
131
        this.cboValue.setSelectedItem("");
128 132
        this.tblTags.getSelectionModel().clearSelection();
129 133
        this.lblDescription.setText("");
130 134
    }
......
161 165
    public void setEditable(boolean editable) {
162 166
        this.tblTags.setEnabled(editable);
163 167
        this.cboName.setEnabled(editable);
164
        this.txtValue.setEditable(editable);
168
        this.cboValue.setEditable(editable);
165 169
        this.btnAdd.setEnabled(editable);
166 170
        this.btnUpdate.setEnabled(editable);
167 171
        this.btnRemove.setEnabled(editable);
......
171 175
        int row = this.tblTags.getSelectedRow();
172 176
        if (row < 0) {
173 177
            this.cboName.setSelectedIndex(-1);
174
            this.txtValue.setText("");
178
            this.cboValue.setSelectedItem("");
175 179
            this.btnAdd.setEnabled(true);
176 180
            this.btnUpdate.setEnabled(false);
177 181
            this.btnRemove.setEnabled(false);
......
179 183
        }
180 184
        DefaultTableModel model = (DefaultTableModel) this.tblTags.getModel();
181 185
        this.cboName.setSelectedItem(model.getValueAt(row, 0));
182
        this.txtValue.setText((String) model.getValueAt(row, 1));
186
        this.cboValue.setSelectedItem((String) model.getValueAt(row, 1));
183 187
        this.btnAdd.setEnabled(true);
184 188
        this.btnUpdate.setEnabled(true);
185 189
        this.btnRemove.setEnabled(true);
......
204 208
        if (row < 0) {
205 209
            return; // EEhh?? esto no deberia pasar
206 210
        }
211
        String name = StringUtils.defaultIfBlank((String) this.cboName.getSelectedItem(), "");
212
        Object value = this.cboValue.getSelectedItem();
213
        if( value instanceof LabeledValue ) {
214
            value = ((LabeledValue)value).getValue();
215
        }
207 216
        DefaultTableModel model = (DefaultTableModel) this.tblTags.getModel();
208
        model.setValueAt(StringUtils.defaultIfBlank((String) this.cboName.getSelectedItem(), ""), row, 0);
209
        model.setValueAt(this.txtValue.getText(), row, 1);
217
        model.setValueAt(name, row, 0);
218
        model.setValueAt(Objects.toString(value,""), row, 1);
210 219
    }
211 220

  
212 221
    private void doRemove() {
......
233 242
            this.lblDescription.setText("");
234 243
            return;
235 244
        }
236
        for (String tagname2 : tagDescriptions) {
237
            if( tagname.equalsIgnoreCase(tagname2) ) {
238
                String description = this.tagDescriptions.get(tagname2);
239
                this.lblDescription.setText("<html>"+description+"<html>");
245
        for (DynField tagDefinition : tagDefinitions) {
246
            if( tagname.equalsIgnoreCase(tagDefinition.getName()) ) {
247
                this.lblDescription.setText("<html>"+tagDefinition.getDescription()+"<html>");
248
                DefaultComboBoxModel model = new DefaultComboBoxModel();
249
                LabeledValue[] values = tagDefinition.getAvailableValues();
250
                if( values != null ) {
251
                    for (LabeledValue value : values) {
252
                        model.addElement(value);
253
                    }
254
                }
255
                this.cboValue.setModel(model);
240 256
                return;
241 257
            }
242 258
        }

Also available in: Unified diff