Revision 44408 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.impl/src/main/java/org/gvsig/export/swing/impl/panels/SelectAttributesPanel.java
SelectAttributesPanel.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.awt.Component; |
4 | 4 |
import java.awt.Font; |
5 |
import java.awt.event.ActionEvent; |
|
6 |
import java.awt.event.ActionListener; |
|
7 |
import java.awt.event.KeyAdapter; |
|
8 |
import java.awt.event.KeyEvent; |
|
9 |
import java.net.URL; |
|
5 | 10 |
import java.util.ArrayList; |
6 | 11 |
import java.util.Comparator; |
7 |
import java.util.HashMap;
|
|
12 |
import java.util.Iterator;
|
|
8 | 13 |
import java.util.List; |
14 |
import java.util.Map; |
|
15 |
import java.util.Objects; |
|
9 | 16 |
import javax.swing.DefaultCellEditor; |
10 | 17 |
import javax.swing.DefaultComboBoxModel; |
18 |
import javax.swing.DefaultListCellRenderer; |
|
19 |
import javax.swing.ImageIcon; |
|
20 |
import javax.swing.JButton; |
|
21 |
import javax.swing.JCheckBox; |
|
11 | 22 |
import javax.swing.JComboBox; |
12 | 23 |
import javax.swing.JComponent; |
13 | 24 |
import javax.swing.JLabel; |
14 | 25 |
import javax.swing.JList; |
15 | 26 |
import javax.swing.JOptionPane; |
16 | 27 |
import javax.swing.JTable; |
17 |
import javax.swing.ListCellRenderer; |
|
18 |
import javax.swing.table.DefaultTableModel; |
|
28 |
import javax.swing.table.AbstractTableModel; |
|
29 |
import javax.swing.table.TableCellRenderer; |
|
30 |
import javax.swing.table.TableColumnModel; |
|
19 | 31 |
import javax.swing.table.TableModel; |
32 |
import javax.swing.text.JTextComponent; |
|
33 |
import org.apache.commons.io.FilenameUtils; |
|
20 | 34 |
import org.apache.commons.lang.StringUtils; |
21 | 35 |
import org.gvsig.export.ExportAttributes; |
36 |
import org.gvsig.export.ExportAttributes.ExportAttribute; |
|
22 | 37 |
import org.gvsig.export.ExportParameters; |
23 | 38 |
import org.gvsig.export.swing.JExportProcessPanel; |
24 | 39 |
import org.gvsig.export.swing.spi.ExportPanel; |
25 | 40 |
import org.gvsig.export.swing.spi.ExportPanelValidationException; |
26 | 41 |
import org.gvsig.export.swing.spi.ExportPanelsManager; |
27 | 42 |
import org.gvsig.fmap.dal.DataTypes; |
43 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
44 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
28 | 45 |
import org.gvsig.tools.ToolsLocator; |
46 |
import org.gvsig.tools.dataTypes.DataType; |
|
29 | 47 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
30 | 48 |
import org.gvsig.tools.i18n.I18nManager; |
49 |
import org.gvsig.tools.swing.api.FilteredTableModel; |
|
31 | 50 |
import org.gvsig.tools.swing.api.ListElement; |
32 | 51 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
33 | 52 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
53 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
|
54 |
import org.gvsig.tools.util.LabeledValue; |
|
55 |
import org.gvsig.tools.util.LabeledValueImpl; |
|
34 | 56 |
import org.slf4j.Logger; |
35 | 57 |
import org.slf4j.LoggerFactory; |
36 | 58 |
|
... | ... | |
38 | 60 |
* |
39 | 61 |
* @author jjdelcerro |
40 | 62 |
*/ |
63 |
@SuppressWarnings("UseSpecificCatch") |
|
41 | 64 |
public class SelectAttributesPanel |
42 | 65 |
extends SelectAttributesPanelView |
43 | 66 |
implements ExportPanel { |
44 | 67 |
|
45 |
private static final Logger LOG = LoggerFactory.getLogger(SelectAttributesPanel.class); |
|
68 |
private static final Logger LOGGER = LoggerFactory.getLogger(SelectAttributesPanel.class);
|
|
46 | 69 |
|
47 |
public static final int COLUMN_FIELD_NAME = 0;
|
|
48 |
public static final int COLUMN_FIELD_NEW_NAME = 1;
|
|
49 |
public static final int COLUMN_FIELD_TYPE = 2;
|
|
50 |
public static final int COLUMN_FIELD_SIZE = 3;
|
|
51 |
public static final int COLUMN_FIELD_EXPORT = 4;
|
|
70 |
private static final int COLUMN_FIELD_EXPORT = 0;
|
|
71 |
private static final int COLUMN_FIELD_TYPE = 1;
|
|
72 |
private static final int COLUMN_FIELD_SIZE = 2;
|
|
73 |
private static final int COLUMN_FIELD_NAME = 3;
|
|
74 |
private static final int COLUMN_FIELD_NEW_NAME = 4;
|
|
52 | 75 |
|
76 |
private static final int COLUMN_FIELD_COUNT = 5; |
|
77 |
|
|
78 |
private static class AttributesTableModel |
|
79 |
extends AbstractTableModel |
|
80 |
implements TableModel { |
|
81 |
|
|
82 |
final private ExportAttributes attributes; |
|
83 |
private final String[] columnNames = new String[COLUMN_FIELD_COUNT]; |
|
84 |
private final Class[] columnClases = new Class[COLUMN_FIELD_COUNT]; |
|
85 |
private final DataTypesManager dataManager; |
|
86 |
|
|
87 |
public AttributesTableModel(ExportAttributes attributes) { |
|
88 |
this.attributes = attributes; |
|
89 |
this.dataManager = ToolsLocator.getDataTypesManager(); |
|
90 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
91 |
columnNames[COLUMN_FIELD_NAME] = i18nManager.getTranslation("_name"); |
|
92 |
columnNames[COLUMN_FIELD_NEW_NAME] = i18nManager.getTranslation("_new_name"); |
|
93 |
columnNames[COLUMN_FIELD_TYPE] = i18nManager.getTranslation("_type"); |
|
94 |
columnNames[COLUMN_FIELD_SIZE] = i18nManager.getTranslation("_size"); |
|
95 |
columnNames[COLUMN_FIELD_EXPORT] = ""; |
|
96 |
|
|
97 |
columnClases[COLUMN_FIELD_NAME] = String.class; |
|
98 |
columnClases[COLUMN_FIELD_NEW_NAME] = String.class; |
|
99 |
columnClases[COLUMN_FIELD_TYPE] = String.class; |
|
100 |
columnClases[COLUMN_FIELD_SIZE] = Integer.class; |
|
101 |
columnClases[COLUMN_FIELD_EXPORT] = Boolean.class; |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public int getRowCount() { |
|
106 |
return this.attributes.size(); |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public int getColumnCount() { |
|
111 |
return COLUMN_FIELD_COUNT; |
|
112 |
} |
|
113 |
|
|
114 |
@Override |
|
115 |
public String getColumnName(int columnIndex) { |
|
116 |
return this.columnNames[columnIndex]; |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public Class<?> getColumnClass(int columnIndex) { |
|
121 |
return this.columnClases[columnIndex]; |
|
122 |
} |
|
123 |
|
|
124 |
@Override |
|
125 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
|
126 |
switch (columnIndex) { |
|
127 |
case COLUMN_FIELD_NAME: |
|
128 |
return false; |
|
129 |
default: |
|
130 |
return true; |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
@Override |
|
135 |
public Object getValueAt(int rowIndex, int columnIndex) { |
|
136 |
ExportAttribute attr = this.attributes.get(rowIndex); |
|
137 |
switch (columnIndex) { |
|
138 |
case COLUMN_FIELD_NAME: |
|
139 |
return attr.getName(); |
|
140 |
case COLUMN_FIELD_NEW_NAME: |
|
141 |
return attr.getNewName(); |
|
142 |
case COLUMN_FIELD_TYPE: |
|
143 |
return dataManager.getTypeName(attr.getNewDataType()); |
|
144 |
case COLUMN_FIELD_SIZE: |
|
145 |
return attr.getSize(); |
|
146 |
case COLUMN_FIELD_EXPORT: |
|
147 |
return attr.isExported(); |
|
148 |
default: |
|
149 |
return null; |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
@Override |
|
154 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
|
155 |
ExportAttribute attr = this.attributes.get(rowIndex); |
|
156 |
switch (columnIndex) { |
|
157 |
case COLUMN_FIELD_NAME: |
|
158 |
break; |
|
159 |
case COLUMN_FIELD_NEW_NAME: |
|
160 |
attr.setNewName(Objects.toString(aValue, attr.getName())); |
|
161 |
break; |
|
162 |
case COLUMN_FIELD_TYPE: |
|
163 |
attr.setNewType(dataManager.getType(Objects.toString(aValue))); |
|
164 |
break; |
|
165 |
case COLUMN_FIELD_SIZE: |
|
166 |
try { |
|
167 |
attr.setSize(Integer.parseInt(Objects.toString(aValue))); |
|
168 |
} catch (Exception ex) { |
|
169 |
LOGGER.warn("Not been able to set size value of attribute " + attr.getName() + " (" + Objects.toString(aValue) + ").", ex); |
|
170 |
} |
|
171 |
break; |
|
172 |
case COLUMN_FIELD_EXPORT: |
|
173 |
try { |
|
174 |
attr.setExported((boolean) dataManager.get(DataTypes.BOOLEAN).coerce(aValue)); |
|
175 |
} catch (Exception ex) { |
|
176 |
LOGGER.warn("Not been able to set exported value of attribute " + attr.getName() + " (" + Objects.toString(aValue) + ").", ex); |
|
177 |
} |
|
178 |
break; |
|
179 |
default: |
|
180 |
break; |
|
181 |
} |
|
182 |
this.fireTableCellUpdated(rowIndex, columnIndex); |
|
183 |
} |
|
184 |
} |
|
185 |
|
|
186 |
private static class TableFilterController { |
|
187 |
|
|
188 |
private final JTable jtable; |
|
189 |
private final JTextComponent jtext; |
|
190 |
private final JButton btnFilter; |
|
191 |
private final int filterColumn; |
|
192 |
|
|
193 |
private FilteredTableModel tableModel; |
|
194 |
|
|
195 |
public TableFilterController(JTable jtable, JTextComponent jtext, JButton btnFilter, int filterColumn) { |
|
196 |
this.jtable = jtable; |
|
197 |
this.filterColumn = filterColumn; |
|
198 |
this.btnFilter = btnFilter; |
|
199 |
this.jtext = jtext; |
|
200 |
this.tableModel = null; |
|
201 |
ToolsSwingLocator.getToolsSwingManager().setDefaultPopupMenu(jtext); |
|
202 |
ToolsSwingLocator.getToolsSwingManager().addClearButton(jtext, new ActionListener() { |
|
203 |
@Override |
|
204 |
public void actionPerformed(ActionEvent e) { |
|
205 |
if (tableModel != null) { |
|
206 |
tableModel.setFilter(null); |
|
207 |
jtext.setText(""); |
|
208 |
} |
|
209 |
} |
|
210 |
}); |
|
211 |
this.jtext.addKeyListener(new KeyAdapter() { |
|
212 |
@Override |
|
213 |
public void keyPressed(KeyEvent e) { |
|
214 |
if (e.getKeyChar() == '\n') { |
|
215 |
if (tableModel != null) { |
|
216 |
tableModel.setFilter(jtext.getText()); |
|
217 |
} |
|
218 |
} |
|
219 |
} |
|
220 |
}); |
|
221 |
this.btnFilter.addActionListener(new ActionListener() { |
|
222 |
@Override |
|
223 |
public void actionPerformed(ActionEvent e) { |
|
224 |
if (tableModel != null) { |
|
225 |
tableModel.setFilter(jtext.getText()); |
|
226 |
} |
|
227 |
} |
|
228 |
}); |
|
229 |
} |
|
230 |
|
|
231 |
public void setModel(TableModel tableModel) { |
|
232 |
this.tableModel = ToolsSwingLocator.getToolsSwingManager().createFilteredTableModel( |
|
233 |
tableModel, |
|
234 |
this.filterColumn |
|
235 |
); |
|
236 |
this.jtable.setModel(this.tableModel); |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
240 |
private class DataTypeCellRenderer |
|
241 |
extends JLabel |
|
242 |
implements TableCellRenderer { |
|
243 |
|
|
244 |
public DataTypeCellRenderer() { |
|
245 |
} |
|
246 |
|
|
247 |
@Override |
|
248 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
|
249 |
if (value != null) { |
|
250 |
String name = (String) table.getModel().getValueAt(row, COLUMN_FIELD_NAME); |
|
251 |
this.setText(value.toString()); |
|
252 |
Font f = this.getFont(); |
|
253 |
if (isOriginalType(row, value.toString())) { |
|
254 |
this.setFont(f.deriveFont(f.getStyle() & ~Font.BOLD)); |
|
255 |
} else { |
|
256 |
this.setFont(f.deriveFont(f.getStyle() | Font.BOLD)); |
|
257 |
} |
|
258 |
} else { |
|
259 |
this.setText(""); |
|
260 |
} |
|
261 |
return this; |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
265 |
private class DataTypeCellEditor extends DefaultCellEditor { |
|
266 |
|
|
267 |
private int currentRow = -1; |
|
268 |
|
|
269 |
private class DataTypeListCellRenderer extends DefaultListCellRenderer { |
|
270 |
|
|
271 |
@Override |
|
272 |
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
|
273 |
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
|
274 |
if (value != null) { |
|
275 |
label.setText(value.toString()); |
|
276 |
Font f = label.getFont(); |
|
277 |
if (isOriginalType(currentRow, value.toString())) { |
|
278 |
label.setFont(f.deriveFont(f.getStyle() | Font.BOLD)); |
|
279 |
} else { |
|
280 |
label.setFont(f.deriveFont(f.getStyle() & ~Font.BOLD)); |
|
281 |
} |
|
282 |
} |
|
283 |
return label; |
|
284 |
} |
|
285 |
} |
|
286 |
|
|
287 |
public DataTypeCellEditor() { |
|
288 |
super(new JComboBox()); |
|
289 |
JComboBox combo = (JComboBox) this.getComponent(); |
|
290 |
combo.setRenderer(new DataTypeListCellRenderer()); |
|
291 |
combo.setModel(this.getDataTypeComboModel()); |
|
292 |
} |
|
293 |
|
|
294 |
@Override |
|
295 |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
|
296 |
this.currentRow = row; |
|
297 |
JComboBox combo = (JComboBox) super.getTableCellEditorComponent(table, value, isSelected, row, column); |
|
298 |
ListElement.setSelected(combo, value); |
|
299 |
return combo; |
|
300 |
} |
|
301 |
|
|
302 |
private DefaultComboBoxModel getDataTypeComboModel() { |
|
303 |
DataTypesManager dataManager = ToolsLocator.getDataTypesManager(); |
|
304 |
List<ListElement<Integer>> fieldTypes = new ArrayList<>(); |
|
305 |
Iterator<DataType> it = dataManager.iterator(); |
|
306 |
while (it.hasNext()) { |
|
307 |
DataType dataType = it.next(); |
|
308 |
fieldTypes.add( new ListElement<>(dataType.getName(), dataType.getType()) ); |
|
309 |
} |
|
310 |
fieldTypes.sort(new Comparator<ListElement<Integer>>() { |
|
311 |
@Override |
|
312 |
public int compare(ListElement<Integer> o1, ListElement<Integer> o2) { |
|
313 |
return o1.toString().compareTo(o2.toString()); |
|
314 |
} |
|
315 |
}); |
|
316 |
|
|
317 |
DefaultComboBoxModel<ListElement<Integer>> model = new DefaultComboBoxModel<>(); |
|
318 |
for (ListElement<Integer> element : fieldTypes) { |
|
319 |
model.addElement(element); |
|
320 |
} |
|
321 |
return model; |
|
322 |
} |
|
323 |
} |
|
324 |
|
|
53 | 325 |
private final ExportParameters parameters; |
54 | 326 |
private final JExportProcessPanel processPanel; |
55 |
private HashMap<String, String> layerAttributeDescriptor; |
|
56 | 327 |
|
328 |
// private Map<String, String> fieldAttributeTypes; |
|
329 |
// private FilteredTableModel filteredTableModel; |
|
330 |
private TableModel tableModel; |
|
331 |
private TableFilterController tableFilterController; |
|
332 |
private FeatureType targetFeatureType ; |
|
333 |
|
|
57 | 334 |
public SelectAttributesPanel( |
58 | 335 |
JExportProcessPanel processPanel, |
59 | 336 |
ExportParameters parameters |
... | ... | |
77 | 354 |
|
78 | 355 |
@Override |
79 | 356 |
public boolean validatePanel() throws ExportPanelValidationException { |
80 |
ExportAttributes expAttrs; |
|
81 |
expAttrs = this.parameters.getExportAttributes(); |
|
82 |
DataTypesManager dataManager = ToolsLocator.getDataTypesManager(); |
|
83 |
TableModel model = this.tblAttributes.getModel(); |
|
84 |
for (int i = 0; i < model.getRowCount(); i++) { |
|
85 |
String object = (String) model.getValueAt(i, COLUMN_FIELD_NAME); |
|
86 |
for (ExportAttributes.ExportAttribute expAttr : expAttrs) { // assign valuen from table to ExportAttribute |
|
87 |
if (object == null ? expAttr.getName() == null : object.equals(expAttr.getName())) { |
|
88 |
try { |
|
89 |
expAttr.setNewName((String) model.getValueAt(i, COLUMN_FIELD_NEW_NAME)); |
|
90 |
Object value = model.getValueAt(i, COLUMN_FIELD_TYPE); |
|
91 |
int dataType = dataManager.getType(value.toString()); |
|
92 |
expAttr.setNewType(dataType); |
|
93 |
int sizeValue; |
|
94 |
try { |
|
95 |
sizeValue = Integer.parseInt(model.getValueAt(i, COLUMN_FIELD_SIZE).toString()); |
|
96 |
} catch (NumberFormatException ex) { |
|
97 |
LOG.error("Not been able to set size value" + expAttr.getName() + ".Exception:" + ex); |
|
98 |
sizeValue = expAttr.getSize(); |
|
99 |
} |
|
100 |
expAttr.setSize(sizeValue); |
|
101 |
expAttr.setExported((boolean) model.getValueAt(i, COLUMN_FIELD_EXPORT)); |
|
102 |
} catch (Exception ex) { |
|
103 |
// TODO |
|
104 |
// break for incorrect values |
|
105 |
LOG.error("Not been able to set Export attribute for field" + expAttr.getName() + ".Exception:" + ex); |
|
106 |
|
|
107 |
} |
|
108 |
|
|
109 |
} |
|
110 |
|
|
111 |
} |
|
112 |
} |
|
113 |
|
|
357 |
ExportAttributes expAttrs = this.parameters.getExportAttributes(); |
|
114 | 358 |
if (!expAttrs.isAttributeNamesValid()) { |
115 | 359 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
116 | 360 |
int as = JOptionPane.showConfirmDialog( |
... | ... | |
150 | 394 |
return this; |
151 | 395 |
} |
152 | 396 |
|
153 |
private void fillTableWithAttributes() { |
|
154 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
155 |
String[] columnNames = new String[]{ |
|
156 |
i18nManager.getTranslation("_Field_name"), |
|
157 |
i18nManager.getTranslation("_Change_field_name"), |
|
158 |
i18nManager.getTranslation("_Change_field_type"), |
|
159 |
i18nManager.getTranslation("_Change_field_size"), |
|
160 |
i18nManager.getTranslation("_Check_export")}; |
|
161 |
|
|
162 |
DataTypesManager dataManager = ToolsLocator.getDataTypesManager(); |
|
163 |
List<ListElement<Integer>> fieldTypes = new ArrayList<>(); |
|
164 |
fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.BOOLEAN), DataTypes.BOOLEAN)); |
|
165 |
fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.DATE), DataTypes.DATE)); |
|
166 |
fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.INT), DataTypes.INT)); |
|
167 |
fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.DOUBLE), DataTypes.DOUBLE)); |
|
168 |
fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.LONG), DataTypes.LONG)); |
|
169 |
fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.STRING), DataTypes.STRING)); |
|
170 |
fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.GEOMETRY), DataTypes.GEOMETRY)); |
|
171 |
|
|
172 |
fieldTypes.sort(new Comparator<ListElement<Integer>>() { |
|
173 |
@Override |
|
174 |
public int compare(ListElement<Integer> o1, ListElement<Integer> o2) { |
|
175 |
return o1.toString().compareTo(o2.toString()); |
|
397 |
private boolean isOriginalType(int row, String type) { |
|
398 |
try { |
|
399 |
if( this.targetFeatureType==null ) { |
|
400 |
return true; |
|
176 | 401 |
} |
177 |
}); |
|
178 |
|
|
179 |
// model = new ComboModelDataType(fieldTypes, fad.getType()); |
|
180 |
DefaultComboBoxModel<ListElement<Integer>> modelTypes = new DefaultComboBoxModel<>(); |
|
181 |
for (ListElement<Integer> element : fieldTypes) { |
|
182 |
modelTypes.addElement(element); |
|
402 |
TableModel model = this.tblAttributes.getModel(); |
|
403 |
String name = (String) model.getValueAt(row, COLUMN_FIELD_NAME); |
|
404 |
FeatureAttributeDescriptor attr = this.targetFeatureType.getAttributeDescriptor(name); |
|
405 |
if (attr == null) { |
|
406 |
return true; |
|
407 |
} |
|
408 |
return StringUtils.equalsIgnoreCase(type, attr.getDataTypeName()); |
|
409 |
} catch (Exception ex) { |
|
410 |
return true; |
|
183 | 411 |
} |
184 | 412 |
|
185 |
JComboBox comboBoxFieldTypes = new JComboBox(); |
|
186 |
comboBoxFieldTypes.setModel(modelTypes); |
|
413 |
} |
|
187 | 414 |
|
188 |
// Values to field the table are taken from the parameter.getExportAttributes |
|
189 |
Object[][] propertyFields = new Object[this.parameters.getExportAttributes().size()][5]; |
|
190 |
this.layerAttributeDescriptor = new HashMap<>(); |
|
191 |
for (int nAttr = 0; nAttr < this.parameters.getExportAttributes().size(); nAttr++) { |
|
192 |
//ExportAttributes.ExportAttribute exportAttr : this.parameters.getExportAttributes()) { |
|
193 |
ExportAttributes.ExportAttribute exportAttr = this.parameters.getExportAttributes().get(nAttr); |
|
194 |
propertyFields[nAttr][COLUMN_FIELD_NAME] = exportAttr.getName(); |
|
195 |
propertyFields[nAttr][COLUMN_FIELD_NEW_NAME] = exportAttr.getNewName(); |
|
196 |
propertyFields[nAttr][COLUMN_FIELD_TYPE] = dataManager.getTypeName(exportAttr.getDataType()); |
|
197 |
propertyFields[nAttr][COLUMN_FIELD_SIZE] = exportAttr.getSize(); |
|
198 |
propertyFields[nAttr][COLUMN_FIELD_EXPORT] = exportAttr.isExported(); |
|
415 |
private ExportAttributes getExportAttributes() { |
|
416 |
ExportAttributes attributes = this.parameters.getExportAttributes(); |
|
417 |
return attributes; |
|
418 |
} |
|
199 | 419 |
|
200 |
this.layerAttributeDescriptor.put(
|
|
201 |
exportAttr.getName(),
|
|
202 |
dataManager.getTypeName(exportAttr.getDataType())
|
|
203 |
); |
|
420 |
private void fillTableWithAttributes() {
|
|
421 |
ExportAttributes attributes = this.getExportAttributes();
|
|
422 |
if( this.targetFeatureType == null ) {
|
|
423 |
this.targetFeatureType = this.getExportAttributes().getTargetFeatureType();
|
|
204 | 424 |
} |
205 | 425 |
|
206 |
DefaultTableModel model = new DefaultTableModel(propertyFields, columnNames) { |
|
426 |
|
|
427 |
this.tableModel = new AttributesTableModel(attributes); |
|
428 |
this.tblAttributes.setModel(this.tableModel); |
|
429 |
this.tableFilterController.setModel(this.tableModel); |
|
207 | 430 |
|
208 |
private static final long serialVersionUID = 1L; |
|
431 |
TableColumnModel columnModel = this.tblAttributes.getColumnModel(); |
|
432 |
columnModel.getColumn(COLUMN_FIELD_TYPE).setCellEditor(new DataTypeCellEditor()); |
|
433 |
columnModel.getColumn(COLUMN_FIELD_TYPE).setCellRenderer(new DataTypeCellRenderer()); |
|
434 |
|
|
435 |
columnModel.getColumn(COLUMN_FIELD_EXPORT).setPreferredWidth( new JCheckBox().getPreferredSize().width*2); |
|
436 |
columnModel.getColumn(COLUMN_FIELD_TYPE).setPreferredWidth( new JLabel("XXIntegerXX").getPreferredSize().width); |
|
437 |
columnModel.getColumn(COLUMN_FIELD_SIZE).setPreferredWidth( new JLabel("00000").getPreferredSize().width); |
|
209 | 438 |
|
210 |
@Override |
|
211 |
public boolean isCellEditable(int row, int col) { |
|
212 |
return col != 0; |
|
213 |
} |
|
439 |
} |
|
214 | 440 |
|
441 |
private void initComponents() { |
|
442 |
|
|
443 |
this.tblAttributes.setAutoCreateRowSorter(true); |
|
444 |
this.tblAttributes.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); |
|
445 |
|
|
446 |
this.tableFilterController = new TableFilterController( |
|
447 |
this.tblAttributes, |
|
448 |
this.txtFilter, |
|
449 |
this.btnFilter, |
|
450 |
COLUMN_FIELD_NAME |
|
451 |
); |
|
452 |
this.btnCheckAll.addActionListener(new ActionListener() { |
|
215 | 453 |
@Override |
216 |
public Class getColumnClass(int column) { |
|
217 |
switch (column) { |
|
218 |
case 0: |
|
219 |
case 1: |
|
220 |
case 3: |
|
221 |
return String.class; |
|
222 |
case 2: |
|
223 |
return JComboBox.class; |
|
224 |
case 4: |
|
225 |
return Boolean.class; |
|
226 |
|
|
227 |
} |
|
228 |
return getValueAt(0, column).getClass(); |
|
454 |
public void actionPerformed(ActionEvent e) { |
|
455 |
doCheckAll(); |
|
229 | 456 |
} |
230 |
}; |
|
231 |
|
|
232 |
this.tblAttributes.setModel(model); |
|
233 |
|
|
234 |
class TypeDefaultCellEditor extends DefaultCellEditor { |
|
235 |
|
|
236 |
private final HashMap<String, String> attributes; |
|
237 |
|
|
238 |
public TypeDefaultCellEditor(JComboBox comboBox, HashMap attributes) { |
|
239 |
super(comboBox); |
|
240 |
this.attributes = attributes; |
|
241 |
} |
|
242 |
|
|
457 |
}); |
|
458 |
this.btnUncheckAll.addActionListener(new ActionListener() { |
|
243 | 459 |
@Override |
244 |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, |
|
245 |
int row, int column) { |
|
246 |
|
|
247 |
JComboBox editor = (JComboBox) super.getTableCellEditorComponent(table, value, isSelected, row, column); |
|
248 |
Object labelField = table.getModel().getValueAt(row, 0); |
|
249 |
String initialType = this.attributes.get(labelField.toString()); |
|
250 |
|
|
251 |
editor.getModel().setSelectedItem(value); |
|
252 |
|
|
253 |
class ComboBoxRenderer extends JLabel implements ListCellRenderer { |
|
254 |
|
|
255 |
private final String actualValue; |
|
256 |
private final String initialType; |
|
257 |
|
|
258 |
public ComboBoxRenderer(String value, String initialType) { |
|
259 |
this.actualValue = value; |
|
260 |
this.initialType = initialType; |
|
261 |
} |
|
262 |
|
|
263 |
@Override |
|
264 |
public Component getListCellRendererComponent(JList list, |
|
265 |
Object value, |
|
266 |
int index, |
|
267 |
boolean isSelected, |
|
268 |
boolean cellHasFocus) { |
|
269 |
if (value != null) { |
|
270 |
this.setText(value.toString()); |
|
271 |
} |
|
272 |
Font f = this.getFont(); |
|
273 |
if (StringUtils.equals(value.toString(), initialType)) { |
|
274 |
this.setFont(f.deriveFont(f.getStyle() | Font.BOLD)); |
|
275 |
} else { |
|
276 |
this.setFont(f.deriveFont(f.getStyle() & ~Font.BOLD)); |
|
277 |
} |
|
278 |
|
|
279 |
return this; |
|
280 |
} |
|
281 |
} |
|
282 |
ListCellRenderer cmbRenderer = new ComboBoxRenderer(value.toString(), initialType); |
|
283 |
editor.setRenderer(cmbRenderer); |
|
284 |
|
|
285 |
return editor; |
|
460 |
public void actionPerformed(ActionEvent e) { |
|
461 |
doUncheckAll(); |
|
286 | 462 |
} |
287 |
} |
|
288 |
DefaultCellEditor cellEditor = new TypeDefaultCellEditor(comboBoxFieldTypes, this.layerAttributeDescriptor); |
|
289 |
this.tblAttributes.getColumnModel().getColumn(COLUMN_FIELD_TYPE).setCellEditor(cellEditor); |
|
463 |
}); |
|
290 | 464 |
|
291 | 465 |
this.translate(); |
292 | 466 |
} |
293 | 467 |
|
294 |
private void initComponents() { |
|
295 |
// init default values |
|
468 |
private void doUncheckAll() { |
|
469 |
TableModel model = this.tblAttributes.getModel(); |
|
470 |
for (int row = 0; row < model.getRowCount(); row++) { |
|
471 |
model.setValueAt(false, row, COLUMN_FIELD_EXPORT); |
|
472 |
} |
|
473 |
} |
|
296 | 474 |
|
297 |
// init all UI |
|
298 |
this.fillTableWithAttributes(); |
|
299 |
|
|
475 |
private void doCheckAll() { |
|
476 |
TableModel model = this.tblAttributes.getModel(); |
|
477 |
for (int row = 0; row < model.getRowCount(); row++) { |
|
478 |
model.setValueAt(true, row, COLUMN_FIELD_EXPORT); |
|
479 |
} |
|
300 | 480 |
} |
301 | 481 |
|
302 | 482 |
private void translate() { |
... | ... | |
304 | 484 |
manager.translate(this.lblHeader); |
305 | 485 |
} |
306 | 486 |
|
487 |
@Override |
|
488 |
public ImageIcon loadImage(String imageName) { |
|
489 |
String name = FilenameUtils.getBaseName(imageName); |
|
490 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
|
491 |
if (theme.exists(name)) { |
|
492 |
return theme.get(name); |
|
493 |
} |
|
494 |
URL url = this.getClass().getResource(name + ".png"); |
|
495 |
if (url == null) { |
|
496 |
return null; |
|
497 |
} |
|
498 |
return new ImageIcon(url); |
|
499 |
} |
|
500 |
|
|
307 | 501 |
} |
Also available in: Unified diff