Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / dal / feature / swing / table / ConfigurationTableModel.java @ 41056

History | View | Annotate | Download (5.15 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2008 {DiSiD Technologies}  {Create a JTable TableModel for a FeatureQuery}
27
 */
28
package org.gvsig.fmap.mapcontrol.dal.feature.swing.table;
29

    
30
import javax.swing.table.AbstractTableModel;
31

    
32
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
33
import org.gvsig.i18n.Messages;
34

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

    
45
    private static final long serialVersionUID = -825156698327593853L;
46

    
47
    private static final int VISIBILITY_COLUMN = 0;
48
    private static final int NAME_COLUMN = 1;
49
    private static final int ALIAS_COLUMN = 2;
50
    private static final int TYPE_COLUMN = 3;
51
    private static final int SIZE_COLUMN = 4;
52

    
53
    private ConfigurableFeatureTableModel configurable;
54

    
55
    public ConfigurationTableModel(ConfigurableFeatureTableModel configurable) {
56
        super();
57
        this.configurable = configurable;
58
    }
59

    
60
    public int getColumnCount() {
61
        // 1: visibility, 2: field name, 3: alias, 4:Type, 5:size
62
        return 5;
63
    }
64

    
65
    public int getRowCount() {
66
        return configurable.getOriginalColumnCount();
67
    }
68

    
69
    public Object getValueAt(int rowIndex, int columnIndex) {
70
            FeatureAttributeDescriptor fad = null;
71
        String name = configurable.getOriginalColumnName(rowIndex);
72
        switch (columnIndex) {
73
        case VISIBILITY_COLUMN:
74
            return configurable.isVisible(name);
75
        case NAME_COLUMN:
76
            return name;
77
        case ALIAS_COLUMN:
78
            return configurable.getAliasForColumn(name);
79
        case TYPE_COLUMN:
80
                fad = configurable.internalGetFeatureDescriptorForColumn(rowIndex);
81
                if( fad == null ) {
82
                        return null;
83
                }
84
                    return fad.getDataType().getName();
85
        case SIZE_COLUMN:
86
                fad = configurable.internalGetFeatureDescriptorForColumn(rowIndex);
87
                if( fad == null ) {
88
                        return null;
89
                }
90
                    return fad.getSize();
91
        default:
92
            return null;
93
        }
94
    }
95

    
96
    @Override
97
    public void setValueAt(Object value, int rowIndex, int columnIndex) {
98
        String name = configurable.getOriginalColumnName(rowIndex);
99
        switch (columnIndex) {
100
        case VISIBILITY_COLUMN:
101
            configurable.setVisible(name, Boolean.TRUE.equals(value));
102
            break;
103
        case ALIAS_COLUMN:
104
            configurable.setAlias(name, (String) value);
105
            break;
106
        }
107
    }
108
    
109
    @Override
110
    public boolean isCellEditable(int rowIndex, int columnIndex) {
111
        switch (columnIndex) {
112
        case VISIBILITY_COLUMN:
113
        case ALIAS_COLUMN:
114
            return true;
115
        default:
116
            return false;
117
        }
118
    }
119

    
120
    @Override
121
    public Class<?> getColumnClass(int columnIndex) {
122
        switch (columnIndex) {
123
        case VISIBILITY_COLUMN:
124
            return Boolean.class;
125
        case NAME_COLUMN:
126
        case ALIAS_COLUMN:
127
        case TYPE_COLUMN:
128
            return String.class;
129
        case SIZE_COLUMN:
130
            return int.class;
131
        default:
132
            return Object.class;
133
        }
134

    
135
    }
136

    
137
    @Override
138
    public String getColumnName(int columnIndex) {
139
        switch (columnIndex) {
140
        case VISIBILITY_COLUMN:
141
            return Messages.getText("Visible");
142
        case NAME_COLUMN:
143
            return Messages.getText("Nombre");
144
        case ALIAS_COLUMN:
145
            return Messages.getText("Alias");
146
        case SIZE_COLUMN:
147
            return Messages.getText("Size");
148
        case TYPE_COLUMN:
149
            return Messages.getText("Type");
150
        default:
151
            return "";
152
        }
153
    }
154

    
155
        public static int getVisibilityColumn() {
156
                return VISIBILITY_COLUMN;
157
        }
158
        
159
    /**
160
     * Make current changes in configuration (visible columns and aliases)
161
     * as definitive.
162
     */
163
        public void acceptChanges() {
164
                configurable.acceptChanges();
165
        }
166
        
167
    /**
168
     * Cancel current changes in configuration (visible columns and aliases)
169
     * and return to previous status.
170
     */
171
        public void cancelChanges() {
172
                configurable.cancelChanges();
173
        }
174
}