Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / dal / feature / swing / table / ConfigurationTableModel.java @ 38409

History | View | Annotate | Download (4.29 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {Create a JTable TableModel for a FeatureQuery}
26
 */
27
package org.gvsig.fmap.mapcontrol.dal.feature.swing.table;
28

    
29
import javax.swing.table.AbstractTableModel;
30

    
31
import org.gvsig.i18n.Messages;
32

    
33
/**
34
 * TableModel to configure a ConfigurableFeatureTableModel.
35
 * 
36
 * Allows to set Feature attributes as visible or not, and to set aliases for
37
 * the Feature attribute names.
38
 * 
39
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
40
 */
41
public class ConfigurationTableModel extends AbstractTableModel {
42

    
43
    private static final long serialVersionUID = -825156698327593853L;
44

    
45
    private static final int VISIBILITY_COLUMN = 0;
46
    private static final int NAME_COLUMN = 1;
47
    private static final int ALIAS_COLUMN = 2;
48

    
49
    private ConfigurableFeatureTableModel configurable;
50

    
51
    public ConfigurationTableModel(ConfigurableFeatureTableModel configurable) {
52
        super();
53
        this.configurable = configurable;
54
    }
55

    
56
    public int getColumnCount() {
57
        // 1: visibility, 2: field name, 3: alias
58
        return 3;
59
    }
60

    
61
    public int getRowCount() {
62
        return configurable.getOriginalColumnCount();
63
    }
64

    
65
    public Object getValueAt(int rowIndex, int columnIndex) {
66
        String name = configurable.getOriginalColumnName(rowIndex);
67
        switch (columnIndex) {
68
        case VISIBILITY_COLUMN:
69
            return configurable.isVisible(name);
70
        case NAME_COLUMN:
71
            return name;
72
        case ALIAS_COLUMN:
73
            return configurable.getAliasForColumn(name);
74
        default:
75
            return null;
76
        }
77
    }
78

    
79
    @Override
80
    public void setValueAt(Object value, int rowIndex, int columnIndex) {
81
        String name = configurable.getOriginalColumnName(rowIndex);
82
        switch (columnIndex) {
83
        case VISIBILITY_COLUMN:
84
            configurable.setVisible(name, Boolean.TRUE.equals(value));
85
            break;
86
        case ALIAS_COLUMN:
87
            configurable.setAlias(name, (String) value);
88
            break;
89
        }
90
    }
91
    
92
    @Override
93
    public boolean isCellEditable(int rowIndex, int columnIndex) {
94
        switch (columnIndex) {
95
        case VISIBILITY_COLUMN:
96
        case ALIAS_COLUMN:
97
            return true;
98
        default:
99
            return false;
100
        }
101
    }
102

    
103
    @Override
104
    public Class<?> getColumnClass(int columnIndex) {
105
        switch (columnIndex) {
106
        case VISIBILITY_COLUMN:
107
            return Boolean.class;
108
        case NAME_COLUMN:
109
        case ALIAS_COLUMN:
110
            return String.class;
111
        default:
112
            return Object.class;
113
        }
114

    
115
    }
116

    
117
    @Override
118
    public String getColumnName(int columnIndex) {
119
        switch (columnIndex) {
120
        case VISIBILITY_COLUMN:
121
            return Messages.getText("Visible");
122
        case NAME_COLUMN:
123
            return Messages.getText("Nombre");
124
        case ALIAS_COLUMN:
125
            return Messages.getText("Alias");
126
        default:
127
            return "";
128
        }
129
    }
130

    
131
        public static int getVisibilityColumn() {
132
                return VISIBILITY_COLUMN;
133
        }
134
        
135
    /**
136
     * Make current changes in configuration (visible columns and aliases)
137
     * as definitive.
138
     */
139
        public void acceptChanges() {
140
                configurable.acceptChanges();
141
        }
142
        
143
    /**
144
     * Cancel current changes in configuration (visible columns and aliases)
145
     * and return to previous status.
146
     */
147
        public void cancelChanges() {
148
                configurable.cancelChanges();
149
        }
150
}