svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontrol / src / org / gvsig / fmap / data / feature / swing / table / ConfigurationTableModel.java @ 23795
History | View | Annotate | Download (3.73 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Gobernment (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.data.feature.swing.table; |
28 |
|
29 |
import javax.swing.table.AbstractTableModel; |
30 |
|
31 |
/**
|
32 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
33 |
*/
|
34 |
public class ConfigurationTableModel extends AbstractTableModel { |
35 |
|
36 |
private static final long serialVersionUID = -825156698327593853L; |
37 |
|
38 |
private static final int VISIBILITY_COLUMN = 0; |
39 |
private static final int NAME_COLUMN = 1; |
40 |
private static final int ALIAS_COLUMN = 2; |
41 |
|
42 |
private ConfigurableFeatureTableModel configurable;
|
43 |
|
44 |
public ConfigurationTableModel(ConfigurableFeatureTableModel configurable) {
|
45 |
super();
|
46 |
this.configurable = configurable;
|
47 |
} |
48 |
|
49 |
public int getColumnCount() { |
50 |
// 1: visibility, 2: field name, 3: alias
|
51 |
return 3; |
52 |
} |
53 |
|
54 |
public int getRowCount() { |
55 |
return configurable.getColumnCount();
|
56 |
} |
57 |
|
58 |
public Object getValueAt(int rowIndex, int columnIndex) { |
59 |
String name = configurable.getOriginalColumnName(rowIndex);
|
60 |
switch (columnIndex) {
|
61 |
case VISIBILITY_COLUMN:
|
62 |
return configurable.isVisible(name);
|
63 |
case NAME_COLUMN:
|
64 |
return name;
|
65 |
case ALIAS_COLUMN:
|
66 |
return configurable.getAliasForColumn(name);
|
67 |
default:
|
68 |
return null; |
69 |
} |
70 |
} |
71 |
|
72 |
@Override
|
73 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
74 |
switch (columnIndex) {
|
75 |
case VISIBILITY_COLUMN:
|
76 |
case ALIAS_COLUMN:
|
77 |
return true; |
78 |
default:
|
79 |
return false; |
80 |
} |
81 |
} |
82 |
|
83 |
@Override
|
84 |
public void setValueAt(Object value, int rowIndex, int columnIndex) { |
85 |
String name = configurable.getOriginalColumnName(rowIndex);
|
86 |
switch (columnIndex) {
|
87 |
case VISIBILITY_COLUMN:
|
88 |
configurable.setVisible(name, Boolean.TRUE.equals(value));
|
89 |
break;
|
90 |
case ALIAS_COLUMN:
|
91 |
configurable.setAlias(name, (String) value);
|
92 |
break;
|
93 |
} |
94 |
} |
95 |
|
96 |
@Override
|
97 |
@SuppressWarnings("unchecked") |
98 |
public Class getColumnClass(int columnIndex) { |
99 |
switch (columnIndex) {
|
100 |
case VISIBILITY_COLUMN:
|
101 |
return Boolean.class; |
102 |
case NAME_COLUMN:
|
103 |
case ALIAS_COLUMN:
|
104 |
return String.class; |
105 |
default:
|
106 |
return Object.class; |
107 |
} |
108 |
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* TODO: emplear I18n para obtener los nombres de las columnas.
|
113 |
*/
|
114 |
@Override
|
115 |
public String getColumnName(int columnIndex) { |
116 |
if (columnIndex == VISIBILITY_COLUMN) { // Visibility |
117 |
return "Visible"; |
118 |
} else if (columnIndex == NAME_COLUMN) { // Name |
119 |
return "Nombre"; |
120 |
} else if (columnIndex == ALIAS_COLUMN) { // Alias |
121 |
return "Alias"; |
122 |
} |
123 |
return ""; |
124 |
} |
125 |
} |