Statistics
| Revision:

gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.swing / org.gvsig.vcsgis.swing.impl / src / main / java / org / gvsig / vcsgis / swing / impl / changes / ChangesTableModel.java @ 2707

History | View | Annotate | Download (4.02 KB)

1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 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, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22

    
23
package org.gvsig.vcsgis.swing.impl.changes;
24

    
25
import javax.swing.event.ChangeEvent;
26
import javax.swing.table.AbstractTableModel;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.i18n.I18nManager;
29
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace;
30
import org.gvsig.vcsgis.lib.VCSGisChange;
31
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceChanges;
32

    
33
/**
34
 *
35
 * @author gvSIG Team
36
 */
37
public class ChangesTableModel extends AbstractTableModel {
38

    
39
    private final VCSGisWorkspaceChanges<VCSGisChange> changes;
40
    private final VCSGisWorkspace ws;
41
    
42
    private static String[] columnNames;
43
    private static final Class<?>[] COLUMNCLASS = new Class[] {
44
        Boolean.class,
45
        String.class,
46
        Integer.class,
47
        String.class,
48
        String.class
49
    };
50
    
51
    public ChangesTableModel(VCSGisWorkspaceChanges changes, VCSGisWorkspace ws) {
52
        this.changes = changes;
53
        this.ws = ws;
54
        this.changes.addChangeListener((ChangeEvent e) -> {
55
            fireTableDataChanged();
56
        });
57
        
58
        I18nManager i18n = ToolsLocator.getI18nManager();
59
        
60
        columnNames = new String[]{
61
            i18n.getTranslation("select"),
62
            i18n.getTranslation("table"),
63
            i18n.getTranslation("operation"),
64
            i18n.getTranslation("label"),
65
            i18n.getTranslation("code")
66
        };
67
    }
68
    
69
    @Override
70
    public int getRowCount() {
71
        return (int) this.changes.size64();
72
    }
73

    
74
    @Override
75
    public int getColumnCount() {
76
        return ChangesTableModel.columnNames.length;
77
    }
78

    
79
    @Override
80
    public Object getValueAt(int rowIndex, int columnIndex) {
81
        VCSGisChange row = this.changes.get64(rowIndex);
82
        switch(columnIndex){
83
            case 0:
84
                return row.isSelected();
85
            case 1:
86
                return ws.getRepositoryEntityByCode(row.getEntityCode()).getEntityName();
87
            case 2:
88
                return row.getOperationLabel();
89
            case 3:
90
            default:
91
                return row.getLabel();
92
            case 4:
93
                return row.getRelatedFeatureCode();
94
                
95
        }
96
    }
97

    
98
    @Override
99
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
100
        VCSGisChange row = this.changes.get64(rowIndex);
101
        switch(columnIndex){
102
            case 0:
103
                Boolean selected = (Boolean)aValue;
104
                if(selected) {
105
                    this.changes.addSelectionInterval(rowIndex, rowIndex);
106
                } else {
107
                    this.changes.removeSelectionInterval(rowIndex, rowIndex);
108
                }
109
                break;
110
        }
111
    }
112
    
113

    
114
    @Override
115
    public Class<?> getColumnClass(int columnIndex) {
116
        return COLUMNCLASS[columnIndex];
117
    }
118

    
119
    @Override
120
    public String getColumnName(int column) {
121
        return columnNames[column];
122
    }
123

    
124
    @Override
125
    public boolean isCellEditable(int rowIndex, int columnIndex) {
126
        if(columnIndex ==  0){
127
            return true;
128
//            Change row = this.changes.get64(rowIndex);
129
//            return row.getOperation() != OP_ADD_ENTITY;
130
        }
131
        return false;
132
    }
133
    
134
    
135
    
136
    
137

    
138
}