svn-gvsig-desktop / 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 @ 47426
History | View | Annotate | Download (28 KB)
1 | 44270 | omartinez | package org.gvsig.export.swing.impl.panels; |
---|---|---|---|
2 | |||
3 | import java.awt.Component; |
||
4 | import java.awt.Font; |
||
5 | 44408 | jjdelcerro | import java.awt.event.ActionEvent; |
6 | import java.awt.event.ActionListener; |
||
7 | import java.awt.event.KeyAdapter; |
||
8 | import java.awt.event.KeyEvent; |
||
9 | 45232 | omartinez | import java.awt.event.MouseEvent; |
10 | 44408 | jjdelcerro | import java.net.URL; |
11 | 44270 | omartinez | import java.util.ArrayList; |
12 | import java.util.Comparator; |
||
13 | 44408 | jjdelcerro | import java.util.Iterator; |
14 | 44270 | omartinez | import java.util.List; |
15 | 44408 | jjdelcerro | import java.util.Objects; |
16 | 44860 | omartinez | import java.util.Timer; |
17 | import java.util.TimerTask; |
||
18 | 44270 | omartinez | import javax.swing.DefaultCellEditor; |
19 | import javax.swing.DefaultComboBoxModel; |
||
20 | 44408 | jjdelcerro | import javax.swing.DefaultListCellRenderer; |
21 | import javax.swing.ImageIcon; |
||
22 | import javax.swing.JButton; |
||
23 | import javax.swing.JCheckBox; |
||
24 | 44270 | omartinez | import javax.swing.JComboBox; |
25 | import javax.swing.JComponent; |
||
26 | import javax.swing.JLabel; |
||
27 | import javax.swing.JList; |
||
28 | import javax.swing.JOptionPane; |
||
29 | import javax.swing.JTable; |
||
30 | 44408 | jjdelcerro | import javax.swing.table.AbstractTableModel; |
31 | 45232 | omartinez | import javax.swing.table.JTableHeader; |
32 | 44408 | jjdelcerro | import javax.swing.table.TableCellRenderer; |
33 | import javax.swing.table.TableColumnModel; |
||
34 | 44270 | omartinez | import javax.swing.table.TableModel; |
35 | 44408 | jjdelcerro | import javax.swing.text.JTextComponent; |
36 | import org.apache.commons.io.FilenameUtils; |
||
37 | 44395 | omartinez | import org.apache.commons.lang.StringUtils; |
38 | 44270 | omartinez | import org.gvsig.export.ExportAttributes; |
39 | 44408 | jjdelcerro | import org.gvsig.export.ExportAttributes.ExportAttribute; |
40 | 44270 | omartinez | import org.gvsig.export.ExportParameters; |
41 | import org.gvsig.export.swing.JExportProcessPanel; |
||
42 | import org.gvsig.export.swing.spi.ExportPanel; |
||
43 | import org.gvsig.export.swing.spi.ExportPanelValidationException; |
||
44 | import org.gvsig.export.swing.spi.ExportPanelsManager; |
||
45 | import org.gvsig.fmap.dal.DataTypes; |
||
46 | 44408 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
47 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
48 | 44270 | omartinez | import org.gvsig.tools.ToolsLocator; |
49 | 44408 | jjdelcerro | import org.gvsig.tools.dataTypes.DataType; |
50 | 44270 | omartinez | import org.gvsig.tools.dataTypes.DataTypesManager; |
51 | import org.gvsig.tools.i18n.I18nManager; |
||
52 | 44861 | omartinez | import org.gvsig.tools.namestranslator.NamesTranslator; |
53 | 44408 | jjdelcerro | import org.gvsig.tools.swing.api.FilteredTableModel; |
54 | 44270 | omartinez | import org.gvsig.tools.swing.api.ListElement; |
55 | 44860 | omartinez | import org.gvsig.tools.swing.api.MessageBarController; |
56 | 44395 | omartinez | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
57 | import org.gvsig.tools.swing.api.ToolsSwingManager; |
||
58 | 46597 | fdiaz | import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
59 | 44408 | jjdelcerro | import org.gvsig.tools.swing.icontheme.IconTheme; |
60 | 44270 | omartinez | import org.slf4j.Logger; |
61 | import org.slf4j.LoggerFactory; |
||
62 | |||
63 | /**
|
||
64 | *
|
||
65 | * @author jjdelcerro
|
||
66 | */
|
||
67 | 44408 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
68 | 44270 | omartinez | public class SelectAttributesPanel |
69 | extends SelectAttributesPanelView
|
||
70 | implements ExportPanel {
|
||
71 | |||
72 | 44408 | jjdelcerro | private static final Logger LOGGER = LoggerFactory.getLogger(SelectAttributesPanel.class); |
73 | 44270 | omartinez | |
74 | 44408 | jjdelcerro | private static final int COLUMN_FIELD_EXPORT = 0; |
75 | private static final int COLUMN_FIELD_TYPE = 1; |
||
76 | private static final int COLUMN_FIELD_SIZE = 2; |
||
77 | 44801 | omartinez | private static final int COLUMN_FIELD_ORIGIN = 3; |
78 | private static final int COLUMN_FIELD_CALCULATED = 4; |
||
79 | private static final int COLUMN_FIELD_NAME = 5; |
||
80 | 44860 | omartinez | private static final int COLUMN_FIELD_NEW_NAME = 6; |
81 | |||
82 | 44801 | omartinez | private static final int COLUMN_FIELD_COUNT = 7; |
83 | 44860 | omartinez | |
84 | 44801 | omartinez | private static final int ORIGIN_REAL = 0; |
85 | 46556 | fdiaz | private static final int ORIGIN_QUERY_CALCULATED = 1; |
86 | private static final int ORIGIN_TABLE_CALCULATED = 2; |
||
87 | 44860 | omartinez | private MessageBarController messageController;
|
88 | 44270 | omartinez | |
89 | 44408 | jjdelcerro | private static class AttributesTableModel |
90 | extends AbstractTableModel |
||
91 | implements TableModel { |
||
92 | |||
93 | final private ExportAttributes attributes; |
||
94 | private final String[] columnNames = new String[COLUMN_FIELD_COUNT]; |
||
95 | private final Class[] columnClases = new Class[COLUMN_FIELD_COUNT]; |
||
96 | 45232 | omartinez | private final String[] columnToolTips = new String[COLUMN_FIELD_COUNT]; |
97 | 44408 | jjdelcerro | private final DataTypesManager dataManager; |
98 | 44860 | omartinez | private final SelectAttributesPanel panel; |
99 | 44408 | jjdelcerro | |
100 | 44860 | omartinez | public AttributesTableModel(ExportAttributes attributes, SelectAttributesPanel panel) {
|
101 | this.panel = panel;
|
||
102 | 44408 | jjdelcerro | this.attributes = attributes;
|
103 | this.dataManager = ToolsLocator.getDataTypesManager();
|
||
104 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
105 | columnNames[COLUMN_FIELD_NAME] = i18nManager.getTranslation("_name");
|
||
106 | 44801 | omartinez | columnNames[COLUMN_FIELD_NEW_NAME] = i18nManager.getTranslation("_New_name");
|
107 | columnNames[COLUMN_FIELD_ORIGIN] = i18nManager.getTranslation("_Origin");
|
||
108 | 44408 | jjdelcerro | columnNames[COLUMN_FIELD_TYPE] = i18nManager.getTranslation("_type");
|
109 | 44801 | omartinez | columnNames[COLUMN_FIELD_SIZE] = i18nManager.getTranslation("_Size");
|
110 | columnNames[COLUMN_FIELD_CALCULATED] = i18nManager.getTranslation("_Virtual");
|
||
111 | 44408 | jjdelcerro | columnNames[COLUMN_FIELD_EXPORT] = "";
|
112 | |||
113 | columnClases[COLUMN_FIELD_NAME] = String.class;
|
||
114 | columnClases[COLUMN_FIELD_NEW_NAME] = String.class;
|
||
115 | 44801 | omartinez | columnClases[COLUMN_FIELD_ORIGIN] = String.class;
|
116 | 44408 | jjdelcerro | columnClases[COLUMN_FIELD_TYPE] = String.class;
|
117 | columnClases[COLUMN_FIELD_SIZE] = Integer.class;
|
||
118 | columnClases[COLUMN_FIELD_EXPORT] = Boolean.class;
|
||
119 | 44572 | jjdelcerro | columnClases[COLUMN_FIELD_CALCULATED] = Boolean.class;
|
120 | 45232 | omartinez | |
121 | columnToolTips[COLUMN_FIELD_NAME] = i18nManager.getTranslation("_Actual_field_name");
|
||
122 | columnToolTips[COLUMN_FIELD_NEW_NAME] = i18nManager.getTranslation("_New_field_name_in_the_export");
|
||
123 | columnToolTips[COLUMN_FIELD_ORIGIN] = i18nManager.getTranslation("_Origin");
|
||
124 | columnToolTips[COLUMN_FIELD_TYPE] = i18nManager.getTranslation("_Attribute_descriptor_type");
|
||
125 | columnToolTips[COLUMN_FIELD_SIZE] = i18nManager.getTranslation("_Field_size");
|
||
126 | columnToolTips[COLUMN_FIELD_CALCULATED] = i18nManager.getTranslation("_Export_attribute_as_an_expression_or_as_a_real_field");
|
||
127 | columnToolTips[COLUMN_FIELD_EXPORT] = i18nManager.getTranslation("_Select_if_field_has_to_be_exported");
|
||
128 | 44408 | jjdelcerro | } |
129 | 45232 | omartinez | |
130 | public String getColumnToolTip(int column) { |
||
131 | return columnToolTips[column];
|
||
132 | } |
||
133 | 44408 | jjdelcerro | |
134 | @Override
|
||
135 | public int getRowCount() { |
||
136 | return this.attributes.size(); |
||
137 | } |
||
138 | |||
139 | @Override
|
||
140 | public int getColumnCount() { |
||
141 | return COLUMN_FIELD_COUNT;
|
||
142 | } |
||
143 | |||
144 | @Override
|
||
145 | public String getColumnName(int columnIndex) { |
||
146 | return this.columnNames[columnIndex]; |
||
147 | } |
||
148 | |||
149 | @Override
|
||
150 | public Class<?> getColumnClass(int columnIndex) { |
||
151 | return this.columnClases[columnIndex]; |
||
152 | } |
||
153 | |||
154 | @Override
|
||
155 | public boolean isCellEditable(int rowIndex, int columnIndex) { |
||
156 | switch (columnIndex) {
|
||
157 | case COLUMN_FIELD_NAME:
|
||
158 | return false; |
||
159 | 44801 | omartinez | case COLUMN_FIELD_ORIGIN:
|
160 | return false; |
||
161 | 44572 | jjdelcerro | case COLUMN_FIELD_CALCULATED: {
|
162 | ExportAttribute attr = this.attributes.get(rowIndex);
|
||
163 | DataType dataType = attr.getDescriptor().getDataType(); |
||
164 | 44860 | omartinez | if (dataType.isContainer()
|
165 | || dataType.isObject() |
||
166 | || dataType.isDynObject()) { |
||
167 | 44572 | jjdelcerro | return false; |
168 | } |
||
169 | 44801 | omartinez | if (attr.getDescriptor().isComputed()) {
|
170 | return true; |
||
171 | } |
||
172 | return false; |
||
173 | 44572 | jjdelcerro | } |
174 | 44408 | jjdelcerro | default:
|
175 | return true; |
||
176 | } |
||
177 | } |
||
178 | |||
179 | @Override
|
||
180 | public Object getValueAt(int rowIndex, int columnIndex) { |
||
181 | ExportAttribute attr = this.attributes.get(rowIndex);
|
||
182 | switch (columnIndex) {
|
||
183 | case COLUMN_FIELD_NAME:
|
||
184 | return attr.getName();
|
||
185 | case COLUMN_FIELD_NEW_NAME:
|
||
186 | return attr.getNewName();
|
||
187 | 44801 | omartinez | case COLUMN_FIELD_ORIGIN:
|
188 | if (attr.getDescriptor().isComputed()) {
|
||
189 | 46556 | fdiaz | if (attr.isFromQuery()){
|
190 | return ORIGIN_QUERY_CALCULATED;
|
||
191 | 44860 | omartinez | } else {
|
192 | 46556 | fdiaz | return ORIGIN_TABLE_CALCULATED;
|
193 | 44860 | omartinez | } |
194 | 44801 | omartinez | } else {
|
195 | return ORIGIN_REAL;
|
||
196 | } |
||
197 | 44408 | jjdelcerro | case COLUMN_FIELD_TYPE:
|
198 | 45323 | omartinez | try {
|
199 | return dataManager.getTypeName(attr.getNewDataType());
|
||
200 | } catch (Exception ex) { |
||
201 | return dataManager.getTypeName(attr.getDataType());
|
||
202 | } |
||
203 | 44408 | jjdelcerro | case COLUMN_FIELD_SIZE:
|
204 | return attr.getSize();
|
||
205 | case COLUMN_FIELD_EXPORT:
|
||
206 | return attr.isExported();
|
||
207 | 44572 | jjdelcerro | case COLUMN_FIELD_CALCULATED:
|
208 | return attr.isComputed();
|
||
209 | 44408 | jjdelcerro | default:
|
210 | return null; |
||
211 | } |
||
212 | } |
||
213 | |||
214 | @Override
|
||
215 | public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
||
216 | ExportAttribute attr = this.attributes.get(rowIndex);
|
||
217 | switch (columnIndex) {
|
||
218 | case COLUMN_FIELD_NAME:
|
||
219 | break;
|
||
220 | case COLUMN_FIELD_NEW_NAME:
|
||
221 | 44860 | omartinez | int indexChanged = attr.setNewName(Objects.toString(aValue, attr.getName()));
|
222 | 44861 | omartinez | NamesTranslator translator = this.attributes.getNamesTranslator();
|
223 | I18nManager i18 = ToolsLocator.getI18nManager(); |
||
224 | if (!StringUtils.equalsIgnoreCase(Objects.toString(aValue, attr.getName()),
|
||
225 | translator.getTranslation(attr.getName()))) { |
||
226 | StringBuilder changedLog = new StringBuilder(); |
||
227 | changedLog.append("'");
|
||
228 | changedLog.append(Objects.toString(aValue, attr.getName())); |
||
229 | changedLog.append("' ");
|
||
230 | changedLog.append(i18.getTranslation("_field_name_has_been_fixed_to"));
|
||
231 | changedLog.append(" '");
|
||
232 | changedLog.append(translator.getTranslation(attr.getName())); |
||
233 | changedLog.append("'");
|
||
234 | panel.setMessage(changedLog.toString()); |
||
235 | |||
236 | } |
||
237 | 44860 | omartinez | if (indexChanged != -1) { |
238 | 44861 | omartinez | String fieldSource = translator.getSource(indexChanged);
|
239 | String fieldTarget = translator.getTranslation(indexChanged);
|
||
240 | StringBuilder changedLog = new StringBuilder(); |
||
241 | 44860 | omartinez | changedLog.append("'");
|
242 | changedLog.append(fieldSource); |
||
243 | changedLog.append("' ");
|
||
244 | changedLog.append(i18.getTranslation("_has_been_changed_to_avoid_duplicates_for"));
|
||
245 | changedLog.append(" '");
|
||
246 | changedLog.append(fieldTarget); |
||
247 | changedLog.append("'");
|
||
248 | panel.setMessage(changedLog.toString()); |
||
249 | |||
250 | } |
||
251 | |||
252 | 44408 | jjdelcerro | break;
|
253 | 44860 | omartinez | |
254 | 44408 | jjdelcerro | case COLUMN_FIELD_TYPE:
|
255 | attr.setNewType(dataManager.getType(Objects.toString(aValue))); |
||
256 | break;
|
||
257 | case COLUMN_FIELD_SIZE:
|
||
258 | try {
|
||
259 | 44860 | omartinez | attr.setSize(Integer.parseInt(Objects.toString(aValue)));
|
260 | } catch (Exception ex) { |
||
261 | LOGGER.warn("Not been able to set size value of attribute " + attr.getName() + " (" + Objects.toString(aValue) + ").", ex); |
||
262 | } |
||
263 | break;
|
||
264 | 44408 | jjdelcerro | case COLUMN_FIELD_EXPORT:
|
265 | try {
|
||
266 | 44860 | omartinez | attr.setExported((boolean) dataManager.get(DataTypes.BOOLEAN).coerce(aValue));
|
267 | } catch (Exception ex) { |
||
268 | LOGGER.warn("Not been able to set exported value of attribute " + attr.getName() + " (" + Objects.toString(aValue) + ").", ex); |
||
269 | } |
||
270 | break;
|
||
271 | 44572 | jjdelcerro | case COLUMN_FIELD_CALCULATED:
|
272 | try {
|
||
273 | 44860 | omartinez | attr.setComputed((boolean) dataManager.get(DataTypes.BOOLEAN).coerce(aValue));
|
274 | } catch (Exception ex) { |
||
275 | LOGGER.warn("Not been able to set calculated value of attribute " + attr.getName() + " (" + Objects.toString(aValue) + ").", ex); |
||
276 | } |
||
277 | break;
|
||
278 | 44408 | jjdelcerro | default:
|
279 | break;
|
||
280 | } |
||
281 | this.fireTableCellUpdated(rowIndex, columnIndex);
|
||
282 | } |
||
283 | } |
||
284 | |||
285 | private static class TableFilterController { |
||
286 | |||
287 | private final JTable jtable; |
||
288 | private final JTextComponent jtext; |
||
289 | private final JButton btnFilter; |
||
290 | private final int filterColumn; |
||
291 | |||
292 | private FilteredTableModel tableModel;
|
||
293 | |||
294 | public TableFilterController(JTable jtable, JTextComponent jtext, JButton btnFilter, int filterColumn) { |
||
295 | this.jtable = jtable;
|
||
296 | this.filterColumn = filterColumn;
|
||
297 | this.btnFilter = btnFilter;
|
||
298 | this.jtext = jtext;
|
||
299 | this.tableModel = null; |
||
300 | ToolsSwingLocator.getToolsSwingManager().setDefaultPopupMenu(jtext); |
||
301 | ToolsSwingLocator.getToolsSwingManager().addClearButton(jtext, new ActionListener() { |
||
302 | @Override
|
||
303 | public void actionPerformed(ActionEvent e) { |
||
304 | if (tableModel != null) { |
||
305 | tableModel.setFilter(null);
|
||
306 | jtext.setText("");
|
||
307 | } |
||
308 | } |
||
309 | }); |
||
310 | this.jtext.addKeyListener(new KeyAdapter() { |
||
311 | @Override
|
||
312 | public void keyPressed(KeyEvent e) { |
||
313 | if (e.getKeyChar() == '\n') { |
||
314 | if (tableModel != null) { |
||
315 | tableModel.setFilter(jtext.getText()); |
||
316 | } |
||
317 | } |
||
318 | } |
||
319 | }); |
||
320 | this.btnFilter.addActionListener(new ActionListener() { |
||
321 | @Override
|
||
322 | public void actionPerformed(ActionEvent e) { |
||
323 | if (tableModel != null) { |
||
324 | tableModel.setFilter(jtext.getText()); |
||
325 | } |
||
326 | } |
||
327 | }); |
||
328 | } |
||
329 | |||
330 | public void setModel(TableModel tableModel) { |
||
331 | this.tableModel = ToolsSwingLocator.getToolsSwingManager().createFilteredTableModel(
|
||
332 | tableModel, |
||
333 | this.filterColumn
|
||
334 | ); |
||
335 | this.jtable.setModel(this.tableModel); |
||
336 | } |
||
337 | } |
||
338 | |||
339 | private class DataTypeCellRenderer |
||
340 | extends JLabel |
||
341 | implements TableCellRenderer { |
||
342 | |||
343 | public DataTypeCellRenderer() {
|
||
344 | } |
||
345 | |||
346 | @Override
|
||
347 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
||
348 | if (value != null) { |
||
349 | String name = (String) table.getModel().getValueAt(row, COLUMN_FIELD_NAME); |
||
350 | this.setText(value.toString());
|
||
351 | Font f = this.getFont(); |
||
352 | if (isOriginalType(row, value.toString())) {
|
||
353 | this.setFont(f.deriveFont(f.getStyle() & ~Font.BOLD)); |
||
354 | } else {
|
||
355 | this.setFont(f.deriveFont(f.getStyle() | Font.BOLD)); |
||
356 | } |
||
357 | } else {
|
||
358 | this.setText(""); |
||
359 | } |
||
360 | return this; |
||
361 | } |
||
362 | } |
||
363 | |||
364 | 44801 | omartinez | private class OriginCellRenderer |
365 | extends JLabel |
||
366 | implements TableCellRenderer { |
||
367 | |||
368 | public OriginCellRenderer() {
|
||
369 | } |
||
370 | |||
371 | @Override
|
||
372 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
||
373 | if (column == COLUMN_FIELD_ORIGIN) {
|
||
374 | int origin = (int) table.getModel().getValueAt(row, COLUMN_FIELD_ORIGIN); |
||
375 | IconTheme iconManager = ToolsSwingLocator.getIconThemeManager().getDefault(); |
||
376 | I18nManager i18Manager = ToolsLocator.getI18nManager(); |
||
377 | this.setHorizontalAlignment(JLabel.CENTER); |
||
378 | switch (origin) {
|
||
379 | 46556 | fdiaz | case ORIGIN_QUERY_CALCULATED:
|
380 | this.setToolTipText(i18Manager.getTranslation("_Query_calculated_field")); |
||
381 | 47426 | jjdelcerro | this.setIcon((iconManager.get("featurestore-query-calculated-column"))); |
382 | 44801 | omartinez | break;
|
383 | 46556 | fdiaz | case ORIGIN_TABLE_CALCULATED:
|
384 | this.setToolTipText(i18Manager.getTranslation("_Table_calculated_field")); |
||
385 | 47426 | jjdelcerro | this.setIcon((iconManager.get("featurestore-calculated-column"))); |
386 | 44801 | omartinez | break;
|
387 | case ORIGIN_REAL:
|
||
388 | this.setToolTipText(i18Manager.getTranslation("_Real_field")); |
||
389 | 47426 | jjdelcerro | this.setIcon((iconManager.get("featurestore-column"))); |
390 | 44801 | omartinez | break;
|
391 | default:
|
||
392 | this.setText(value.toString());
|
||
393 | break;
|
||
394 | } |
||
395 | return this; |
||
396 | } |
||
397 | return this; |
||
398 | } |
||
399 | } |
||
400 | |||
401 | 44408 | jjdelcerro | private class DataTypeCellEditor extends DefaultCellEditor { |
402 | |||
403 | private int currentRow = -1; |
||
404 | |||
405 | private class DataTypeListCellRenderer extends DefaultListCellRenderer { |
||
406 | |||
407 | @Override
|
||
408 | public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
||
409 | JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
||
410 | if (value != null) { |
||
411 | label.setText(value.toString()); |
||
412 | Font f = label.getFont();
|
||
413 | if (isOriginalType(currentRow, value.toString())) {
|
||
414 | label.setFont(f.deriveFont(f.getStyle() | Font.BOLD));
|
||
415 | } else {
|
||
416 | label.setFont(f.deriveFont(f.getStyle() & ~Font.BOLD));
|
||
417 | } |
||
418 | } |
||
419 | return label;
|
||
420 | } |
||
421 | } |
||
422 | 44860 | omartinez | |
423 | 44408 | jjdelcerro | public DataTypeCellEditor() {
|
424 | super(new JComboBox()); |
||
425 | JComboBox combo = (JComboBox) this.getComponent(); |
||
426 | combo.setRenderer(new DataTypeListCellRenderer());
|
||
427 | combo.setModel(this.getDataTypeComboModel());
|
||
428 | } |
||
429 | |||
430 | @Override
|
||
431 | public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
||
432 | this.currentRow = row;
|
||
433 | JComboBox combo = (JComboBox) super.getTableCellEditorComponent(table, value, isSelected, row, column); |
||
434 | ListElement.setSelected(combo, value); |
||
435 | return combo;
|
||
436 | } |
||
437 | |||
438 | private DefaultComboBoxModel getDataTypeComboModel() { |
||
439 | DataTypesManager dataManager = ToolsLocator.getDataTypesManager(); |
||
440 | List<ListElement<Integer>> fieldTypes = new ArrayList<>(); |
||
441 | Iterator<DataType> it = dataManager.iterator();
|
||
442 | while (it.hasNext()) {
|
||
443 | DataType dataType = it.next(); |
||
444 | 44860 | omartinez | fieldTypes.add(new ListElement<>(dataType.getName(), dataType.getType()));
|
445 | 44408 | jjdelcerro | } |
446 | fieldTypes.sort(new Comparator<ListElement<Integer>>() { |
||
447 | @Override
|
||
448 | public int compare(ListElement<Integer> o1, ListElement<Integer> o2) { |
||
449 | return o1.toString().compareTo(o2.toString());
|
||
450 | } |
||
451 | }); |
||
452 | |||
453 | DefaultComboBoxModel<ListElement<Integer>> model = new DefaultComboBoxModel<>(); |
||
454 | for (ListElement<Integer> element : fieldTypes) { |
||
455 | model.addElement(element); |
||
456 | } |
||
457 | return model;
|
||
458 | } |
||
459 | } |
||
460 | |||
461 | 44270 | omartinez | private final ExportParameters parameters; |
462 | private final JExportProcessPanel processPanel; |
||
463 | |||
464 | 44408 | jjdelcerro | // private Map<String, String> fieldAttributeTypes;
|
465 | // private FilteredTableModel filteredTableModel;
|
||
466 | private TableModel tableModel; |
||
467 | private TableFilterController tableFilterController;
|
||
468 | 44860 | omartinez | private FeatureType targetFeatureType;
|
469 | |||
470 | 44270 | omartinez | public SelectAttributesPanel(
|
471 | JExportProcessPanel processPanel, |
||
472 | ExportParameters parameters |
||
473 | ) { |
||
474 | this.processPanel = processPanel;
|
||
475 | this.parameters = parameters;
|
||
476 | 44395 | omartinez | this.parameters.getExportAttributes().setActive(true); |
477 | 44270 | omartinez | this.initComponents();
|
478 | } |
||
479 | |||
480 | @Override
|
||
481 | public String getIdPanel() { |
||
482 | return ExportPanelsManager.PANEL_ATTRIBUTES_SELECTION;
|
||
483 | } |
||
484 | |||
485 | @Override
|
||
486 | public String getTitlePanel() { |
||
487 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
488 | return i18n.getTranslation("_Attribute_Selection"); |
||
489 | } |
||
490 | |||
491 | @Override
|
||
492 | public boolean validatePanel() throws ExportPanelValidationException { |
||
493 | 46597 | fdiaz | ExportAttributes attributes = this.parameters.getExportAttributes();
|
494 | FeatureType theTargetFeatureType = attributes.getTargetFeatureType(); |
||
495 | boolean areComputed = false; |
||
496 | for (FeatureAttributeDescriptor featureAttributeDescriptor : theTargetFeatureType) {
|
||
497 | if(featureAttributeDescriptor.isComputed()){
|
||
498 | areComputed = true;
|
||
499 | break;
|
||
500 | } |
||
501 | } |
||
502 | if(areComputed){
|
||
503 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
504 | ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
||
505 | int r = dialogs.confirmDialog(
|
||
506 | i18n.getTranslation("_Virtual_attribute_have_been_selected_it_is_very_possible_that_the_result_can_only_be_opened_by_gvSIG")+"\n"+ |
||
507 | i18n.getTranslation("_do_you_wish_to_continue"), //message |
||
508 | i18n.getTranslation("_Attributes_selection"), //title |
||
509 | JOptionPane.YES_NO_OPTION, //OptionType |
||
510 | JOptionPane.WARNING_MESSAGE, //messageType |
||
511 | "_export_wizard_virtual_attributes_selection" //msgid |
||
512 | ); |
||
513 | if(r != JOptionPane.YES_OPTION){ |
||
514 | return false; |
||
515 | } |
||
516 | } |
||
517 | 44300 | omartinez | return true; |
518 | 44270 | omartinez | } |
519 | |||
520 | @Override
|
||
521 | 44300 | omartinez | public void enterPanel() { |
522 | this.fillTableWithAttributes();
|
||
523 | } |
||
524 | |||
525 | @Override
|
||
526 | public void previousPanel() { |
||
527 | this.fillTableWithAttributes();
|
||
528 | } |
||
529 | |||
530 | @Override
|
||
531 | public void nextPanel() { |
||
532 | 46597 | fdiaz | // ExportAttributes attributes = this.parameters.getExportAttributes();
|
533 | // FeatureType theTargetFeatureType = attributes.getTargetFeatureType();
|
||
534 | // boolean areComputed = false;
|
||
535 | // for (FeatureAttributeDescriptor featureAttributeDescriptor : theTargetFeatureType) {
|
||
536 | // if(featureAttributeDescriptor.isComputed()){
|
||
537 | // areComputed = true;
|
||
538 | // break;
|
||
539 | // }
|
||
540 | // }
|
||
541 | // if(areComputed){
|
||
542 | // I18nManager i18n = ToolsLocator.getI18nManager();
|
||
543 | // ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
|
||
544 | // dialogs.confirmDialog(
|
||
545 | // i18n.getTranslation("_There_are_selected_virtual_attributes_it_is_very_possible_that_the_result_can_only_be_opened_by_gvSIG")+"\n"+
|
||
546 | // i18n.getTranslation("_do_you_wish_to_continue"), //message
|
||
547 | // i18n.getTranslation("_Attributes_selection"), //title
|
||
548 | // JOptionPane.YES_NO_OPTION, //OptionType
|
||
549 | // JOptionPane.WARNING_MESSAGE, //messageType
|
||
550 | // "_virtual_attributes_selection" //msgid
|
||
551 | // );
|
||
552 | //
|
||
553 | // }
|
||
554 | 44300 | omartinez | //get params are in the validate method
|
555 | } |
||
556 | |||
557 | @Override
|
||
558 | 44270 | omartinez | public JComponent asJComponent() { |
559 | return this; |
||
560 | } |
||
561 | |||
562 | 44408 | jjdelcerro | private boolean isOriginalType(int row, String type) { |
563 | try {
|
||
564 | 44860 | omartinez | if (this.targetFeatureType == null) { |
565 | 44408 | jjdelcerro | return true; |
566 | 44270 | omartinez | } |
567 | 44408 | jjdelcerro | TableModel model = this.tblAttributes.getModel(); |
568 | String name = (String) model.getValueAt(row, COLUMN_FIELD_NAME); |
||
569 | FeatureAttributeDescriptor attr = this.targetFeatureType.getAttributeDescriptor(name);
|
||
570 | if (attr == null) { |
||
571 | return true; |
||
572 | } |
||
573 | return StringUtils.equalsIgnoreCase(type, attr.getDataTypeName());
|
||
574 | } catch (Exception ex) { |
||
575 | return true; |
||
576 | 44270 | omartinez | } |
577 | |||
578 | 44408 | jjdelcerro | } |
579 | 44270 | omartinez | |
580 | 44408 | jjdelcerro | private ExportAttributes getExportAttributes() {
|
581 | ExportAttributes attributes = this.parameters.getExportAttributes();
|
||
582 | return attributes;
|
||
583 | } |
||
584 | 44270 | omartinez | |
585 | 44408 | jjdelcerro | private void fillTableWithAttributes() { |
586 | ExportAttributes attributes = this.getExportAttributes();
|
||
587 | 44860 | omartinez | if (this.targetFeatureType == null) { |
588 | 44408 | jjdelcerro | this.targetFeatureType = this.getExportAttributes().getTargetFeatureType(); |
589 | 44270 | omartinez | } |
590 | |||
591 | 44860 | omartinez | this.tableModel = new AttributesTableModel(attributes, this); |
592 | 44408 | jjdelcerro | this.tblAttributes.setModel(this.tableModel); |
593 | this.tableFilterController.setModel(this.tableModel); |
||
594 | 44270 | omartinez | |
595 | 44408 | jjdelcerro | TableColumnModel columnModel = this.tblAttributes.getColumnModel(); |
596 | 44801 | omartinez | columnModel.getColumn(COLUMN_FIELD_ORIGIN).setCellRenderer(new OriginCellRenderer());
|
597 | 44408 | jjdelcerro | columnModel.getColumn(COLUMN_FIELD_TYPE).setCellEditor(new DataTypeCellEditor());
|
598 | columnModel.getColumn(COLUMN_FIELD_TYPE).setCellRenderer(new DataTypeCellRenderer());
|
||
599 | 44270 | omartinez | |
600 | 44860 | omartinez | columnModel.getColumn(COLUMN_FIELD_EXPORT).setPreferredWidth(new JCheckBox().getPreferredSize().width * 2); |
601 | columnModel.getColumn(COLUMN_FIELD_TYPE).setPreferredWidth(new JLabel("XIntegerX").getPreferredSize().width); |
||
602 | columnModel.getColumn(COLUMN_FIELD_SIZE).setPreferredWidth(new JLabel("00000").getPreferredSize().width); |
||
603 | columnModel.getColumn(COLUMN_FIELD_ORIGIN).setPreferredWidth(new JLabel("000").getPreferredSize().width); |
||
604 | columnModel.getColumn(COLUMN_FIELD_CALCULATED).setPreferredWidth(new JLabel("000").getPreferredSize().width); |
||
605 | |||
606 | 44408 | jjdelcerro | } |
607 | 44270 | omartinez | |
608 | 44408 | jjdelcerro | private void initComponents() { |
609 | 45232 | omartinez | I18nManager i18n = ToolsLocator.getI18nManager(); |
610 | this.tblAttributes.getTableHeader().setToolTipText(
|
||
611 | i18n.getTranslation("_Select_in_the_check_box_wich_fields_wanted_to_be_exported_and_configure_its_attributes"));
|
||
612 | 44860 | omartinez | this.messageController = ToolsSwingLocator.getToolsSwingManager().createMessageBarController(lblMessage, 10000); |
613 | 44408 | jjdelcerro | this.tblAttributes.setAutoCreateRowSorter(true); |
614 | this.tblAttributes.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); |
||
615 | 45237 | omartinez | //this.lblHeader.setText(i18n.getTranslation("_Select_name_type_size_and_attributes_to_export"));
|
616 | this.lblHeader.setText("<HTML>"+i18n.getTranslation("_Check_wich_fields_you_want_to_export_and_configure_its_attributes") + ". " + |
||
617 | i18n.getTranslation("_Select_the_name_of_the_new_field_size_and_type_that_each_field_will_have_in_the_export_result")+".</HTML>"); |
||
618 | 44860 | omartinez | |
619 | 44408 | jjdelcerro | this.tableFilterController = new TableFilterController( |
620 | this.tblAttributes,
|
||
621 | this.txtFilter,
|
||
622 | this.btnFilter,
|
||
623 | COLUMN_FIELD_NAME |
||
624 | ); |
||
625 | this.btnCheckAll.addActionListener(new ActionListener() { |
||
626 | 44281 | jjdelcerro | @Override
|
627 | 44408 | jjdelcerro | public void actionPerformed(ActionEvent e) { |
628 | doCheckAll(); |
||
629 | 44270 | omartinez | } |
630 | 44408 | jjdelcerro | }); |
631 | this.btnUncheckAll.addActionListener(new ActionListener() { |
||
632 | 44270 | omartinez | @Override
|
633 | 44408 | jjdelcerro | public void actionPerformed(ActionEvent e) { |
634 | doUncheckAll(); |
||
635 | 44270 | omartinez | } |
636 | 44408 | jjdelcerro | }); |
637 | 44270 | omartinez | |
638 | this.translate();
|
||
639 | } |
||
640 | |||
641 | 44408 | jjdelcerro | private void doUncheckAll() { |
642 | TableModel model = this.tblAttributes.getModel(); |
||
643 | for (int row = 0; row < model.getRowCount(); row++) { |
||
644 | model.setValueAt(false, row, COLUMN_FIELD_EXPORT);
|
||
645 | } |
||
646 | } |
||
647 | 44270 | omartinez | |
648 | 44408 | jjdelcerro | private void doCheckAll() { |
649 | TableModel model = this.tblAttributes.getModel(); |
||
650 | for (int row = 0; row < model.getRowCount(); row++) { |
||
651 | model.setValueAt(true, row, COLUMN_FIELD_EXPORT);
|
||
652 | } |
||
653 | 44270 | omartinez | } |
654 | |||
655 | 44300 | omartinez | private void translate() { |
656 | 44395 | omartinez | ToolsSwingManager manager = ToolsSwingLocator.getToolsSwingManager(); |
657 | manager.translate(this.lblHeader);
|
||
658 | 44270 | omartinez | } |
659 | 44300 | omartinez | |
660 | 44408 | jjdelcerro | @Override
|
661 | public ImageIcon loadImage(String imageName) { |
||
662 | String name = FilenameUtils.getBaseName(imageName);
|
||
663 | IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
||
664 | if (theme.exists(name)) {
|
||
665 | return theme.get(name);
|
||
666 | } |
||
667 | URL url = this.getClass().getResource(name + ".png"); |
||
668 | if (url == null) { |
||
669 | return null; |
||
670 | } |
||
671 | return new ImageIcon(url); |
||
672 | } |
||
673 | |||
674 | 44860 | omartinez | private void setMessage(String toString) { |
675 | this.messageController.setText(toString);
|
||
676 | } |
||
677 | 44270 | omartinez | } |