gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.swing / org.gvsig.online.swing.impl / src / main / java / org / gvsig / online / swing / impl / changes / LocalChangesTableModel.java @ 9512
History | View | Annotate | Download (4.95 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.online.swing.impl.changes; |
24 |
|
25 |
import javax.swing.event.ChangeEvent; |
26 |
import javax.swing.table.AbstractTableModel; |
27 |
import org.gvsig.online.lib.api.workingcopy.OnlineChange; |
28 |
import org.gvsig.online.lib.api.workingcopy.OnlineEntity; |
29 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy; |
30 |
import org.gvsig.online.swing.impl.OnlineSwingCommons; |
31 |
import org.gvsig.tools.ToolsLocator; |
32 |
import org.gvsig.tools.i18n.I18nManager; |
33 |
import org.gvsig.online.lib.api.workingcopy.OnlineChanges; |
34 |
//import org.gvsig.vcsgis.lib.OnlineChange;
|
35 |
//import org.gvsig.vcsgis.lib.OnlineEntity;
|
36 |
//import org.gvsig.vcsgis.lib.workspace.OnlineWorkingcopy;
|
37 |
//import org.gvsig.vcsgis.lib.workspace.OnlineChanges;
|
38 |
//import org.gvsig.vcsgis.swing.impl.OnlineSwingCommons;
|
39 |
|
40 |
/**
|
41 |
*
|
42 |
* @author gvSIG Team
|
43 |
*/
|
44 |
public class LocalChangesTableModel extends AbstractTableModel { |
45 |
|
46 |
private final OnlineChanges<OnlineChange> changes; |
47 |
private final OnlineWorkingcopy ws; |
48 |
|
49 |
private static String[] columnNames; |
50 |
private static final Class<?>[] COLUMNCLASS = new Class[] { |
51 |
Boolean.class,
|
52 |
String.class,
|
53 |
Integer.class,
|
54 |
String.class,
|
55 |
String.class
|
56 |
}; |
57 |
|
58 |
public LocalChangesTableModel(OnlineWorkingcopy ws) {
|
59 |
this(null, ws); |
60 |
} |
61 |
|
62 |
public LocalChangesTableModel(OnlineChanges changes, OnlineWorkingcopy ws) {
|
63 |
this.ws = ws;
|
64 |
|
65 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
66 |
|
67 |
columnNames = new String[]{ |
68 |
i18n.getTranslation("select"),
|
69 |
i18n.getTranslation("table"),
|
70 |
i18n.getTranslation("operation"),
|
71 |
i18n.getTranslation("label"),
|
72 |
i18n.getTranslation("code")
|
73 |
}; |
74 |
this.changes = changes;
|
75 |
if( this.changes!=null ) { |
76 |
this.changes.addChangeListener((ChangeEvent e) -> { |
77 |
fireTableDataChanged(); |
78 |
}); |
79 |
} |
80 |
} |
81 |
|
82 |
@Override
|
83 |
public int getRowCount() { |
84 |
if(this.changes == null){ |
85 |
return 0; |
86 |
} |
87 |
try {
|
88 |
return (int) this.changes.size64(); |
89 |
} catch (Exception e) { |
90 |
return 0; |
91 |
} |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public int getColumnCount() { |
96 |
return columnNames.length;
|
97 |
} |
98 |
|
99 |
@Override
|
100 |
public Object getValueAt(int rowIndex, int columnIndex) { |
101 |
if(this.changes == null){ |
102 |
return null; |
103 |
} |
104 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
105 |
OnlineChange row = this.changes.get64(rowIndex);
|
106 |
switch(columnIndex){
|
107 |
case 0: |
108 |
return row.isSelected();
|
109 |
case 1: |
110 |
OnlineEntity entity = ws.getEntity(row.getEntityCode()); |
111 |
if(entity==null){ |
112 |
return "unknown ("+row.getEntityCode()+")"; |
113 |
} |
114 |
return ws.getEntity(row.getEntityCode()).getEntityName();
|
115 |
|
116 |
case 2: |
117 |
int op = row.getOperation();
|
118 |
return i18n.getTranslation(OnlineSwingCommons.getOperationLabel(op));
|
119 |
|
120 |
case 3: |
121 |
default:
|
122 |
return row.getLabel();
|
123 |
case 4: |
124 |
return row.getRelatedFeatureCode();
|
125 |
|
126 |
} |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
131 |
if(this.changes == null){ |
132 |
return;
|
133 |
} |
134 |
OnlineChange row = this.changes.get64(rowIndex);
|
135 |
switch(columnIndex){
|
136 |
case 0: |
137 |
Boolean selected = (Boolean)aValue; |
138 |
if(selected) {
|
139 |
this.changes.addSelected(rowIndex);
|
140 |
} else {
|
141 |
this.changes.removeSelected(rowIndex);
|
142 |
} |
143 |
break;
|
144 |
} |
145 |
} |
146 |
|
147 |
|
148 |
@Override
|
149 |
public Class<?> getColumnClass(int columnIndex) { |
150 |
return COLUMNCLASS[columnIndex];
|
151 |
} |
152 |
|
153 |
@Override
|
154 |
public String getColumnName(int column) { |
155 |
return columnNames[column];
|
156 |
} |
157 |
|
158 |
@Override
|
159 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
160 |
if(columnIndex == 0){ |
161 |
return true; |
162 |
} |
163 |
return false; |
164 |
} |
165 |
|
166 |
} |