Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / table / gui / TableModelProperties.java @ 24923

History | View | Annotate | Download (5.26 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.project.documents.table.gui;
42

    
43

    
44
import java.util.BitSet;
45

    
46
import javax.swing.table.AbstractTableModel;
47

    
48
import org.gvsig.fmap.dal.exception.DataException;
49
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
50
import org.gvsig.fmap.dal.feature.FeatureStore;
51
import org.gvsig.tools.exception.DriverException;
52

    
53
import com.iver.andami.PluginServices;
54
import com.iver.andami.messages.NotificationManager;
55
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
56

    
57

    
58
/**
59
 * Modelo para la JTable de MapProperties
60
 *
61
 * @author Fernando Gonz?lez Cort?s
62
 */
63
public class TableModelProperties extends AbstractTableModel {
64
    private BitSet visibles = new BitSet();
65
    private String[] alias;
66
    private ProjectTable table;
67

    
68
    /**
69
     * Creates a new MyTableModel object.
70
     *
71
     * @param t Tabla del proyecto que se quiere mostrar
72
     * @throws DriverException
73
     */
74
    public TableModelProperties(ProjectTable t) {
75
        FeatureStore ds = t.getOriginal();
76
        if (ds == null) {
77
            ds = t.getModel();
78
        }
79
        alias = t.getAliases();
80
        int[] mapping = t.getMapping();
81
        visibles = new BitSet();
82
        for (int i = 0; i < mapping.length; i++) {
83
            visibles.set(mapping[i]);
84
        }
85

    
86
        table = t;
87
    }
88

    
89
    /**
90
     * @see javax.swing.table.TableModel#getColumnCount()
91
     */
92
    public int getColumnCount() {
93
        return 3;
94
    }
95

    
96
    /* (non-Javadoc)
97
     * @see javax.swing.table.TableModel#getRowCount()
98
     */
99
    public int getRowCount() {
100
        try {
101
                        return table.getModel().getDefaultFeatureType().size();
102
                } catch (DataException e) {
103
                        NotificationManager.addError("No se pudo leer la informaci?n de la tabla", e);
104
                return 0;
105
                }
106
    }
107

    
108
    /* (non-Javadoc)
109
     * @see javax.swing.table.TableModel#getValueAt(int, int)
110
     */
111
    public Object getValueAt(int rowIndex, int columnIndex) {
112
        if (columnIndex == 0) {
113
            return new Boolean(visibles.get(rowIndex));
114
        } else if (columnIndex == 1) {
115
                try {
116
                return ((FeatureAttributeDescriptor)table.getModel().getDefaultFeatureType().get(rowIndex));
117
            } catch (DataException e) {
118
                NotificationManager.addError("Error accediendo al nombre del campo", e);
119
                return "error!";
120
            }
121
        } else {
122
                // rowIndex++;
123
                return alias[rowIndex];
124
        }
125
    }
126

    
127
    /* (non-Javadoc)
128
     * @see javax.swing.table.TableModel#getColumnClass(int)
129
     */
130
    public Class getColumnClass(int columnIndex) {
131
        if (columnIndex == 0) {
132
            return Boolean.class;
133
        }
134

    
135
        return String.class;
136
    }
137

    
138
    /* (non-Javadoc)
139
     * @see javax.swing.table.TableModel#isCellEditable(int, int)
140
     */
141
    public boolean isCellEditable(int rowIndex, int columnIndex) {
142
        return (columnIndex != 1);
143
    }
144

    
145
    /* (non-Javadoc)
146
     * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
147
     */
148
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
149
        if (columnIndex == 0) {
150
            visibles.set(rowIndex, ((Boolean) aValue).booleanValue());
151
        } else {
152
            alias[rowIndex] = aValue.toString();
153
        }
154
    }
155

    
156
    /* (non-Javadoc)
157
     * @see javax.swing.table.TableModel#getColumnName(int)
158
     */
159
    public String getColumnName(int column) {
160
        String ret = null;
161

    
162
        switch (column) {
163
        case 0:
164
            ret = PluginServices.getText(this, "visible");
165

    
166
            break;
167

    
168
        case 1:
169
            ret = PluginServices.getText(this, "campo");
170

    
171
            break;
172

    
173
        case 2:
174
            ret = PluginServices.getText(this, "alias");
175

    
176
            break;
177
        }
178

    
179
        return ret;
180
    }
181

    
182
    public String[] getAliases() {
183
        // return table.getAliases();
184
            return alias;
185
    }
186

    
187
    public int[] getFieldMapping() {
188
        int[] mapping = new int[visibles.cardinality()];
189
        int index = 0;
190
        for(int i=visibles.nextSetBit(0); i>=0; i=visibles.nextSetBit(i+1)) {
191
            mapping[index] = i;
192
            index++;
193
        }
194

    
195
        return mapping;
196
    }
197
}