svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / updatetable / UpdateTablePanelImpl.java @ 46628
History | View | Annotate | Download (27.6 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.app.extension.updatetable; |
7 |
|
8 |
import java.awt.Component; |
9 |
import java.awt.event.ActionEvent; |
10 |
import java.awt.event.ActionListener; |
11 |
import java.util.ArrayList; |
12 |
import java.util.Iterator; |
13 |
import java.util.List; |
14 |
import java.util.Objects; |
15 |
import javax.swing.AbstractCellEditor; |
16 |
import javax.swing.ImageIcon; |
17 |
import javax.swing.JComboBox; |
18 |
import javax.swing.JLabel; |
19 |
import javax.swing.JOptionPane; |
20 |
import javax.swing.JTable; |
21 |
import javax.swing.ListSelectionModel; |
22 |
import javax.swing.SwingUtilities; |
23 |
import javax.swing.event.ChangeEvent; |
24 |
import javax.swing.event.TreeSelectionEvent; |
25 |
import javax.swing.table.AbstractTableModel; |
26 |
import javax.swing.table.DefaultTableColumnModel; |
27 |
import javax.swing.table.TableCellEditor; |
28 |
import javax.swing.table.TableColumn; |
29 |
import org.apache.commons.io.FilenameUtils; |
30 |
import org.apache.commons.lang.StringUtils; |
31 |
import org.gvsig.app.extension.copytable.StoresRepositoryController; |
32 |
import static org.gvsig.app.extension.updatetable.UpdateTableProcessParameters.BATCHUPDATE_PROCESS_ALL; |
33 |
import static org.gvsig.app.extension.updatetable.UpdateTableProcessParameters.BATCHUPDATE_PROCESS_EDITEDS; |
34 |
import static org.gvsig.app.extension.updatetable.UpdateTableProcessParameters.BATCHUPDATE_PROCESS_SELECTION; |
35 |
import org.gvsig.app.extension.updatetable.UpdateTableProcessParameters.ProcessFieldParameters; |
36 |
import org.gvsig.configurableactions.ConfigurableActionsMamager; |
37 |
import org.gvsig.expressionevaluator.Expression; |
38 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
39 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
40 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
41 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
42 |
import org.gvsig.expressionevaluator.swing.JExpressionPicker; |
43 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
44 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
45 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
46 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
47 |
import org.gvsig.fmap.dal.feature.FeatureType; |
48 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
49 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
50 |
import org.gvsig.fmap.dal.swing.featuretable.SimpleFeaturesTableModel; |
51 |
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorPickerController; |
52 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel; |
53 |
import org.gvsig.tools.ToolsLocator; |
54 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
55 |
import org.gvsig.tools.bookmarksandhistory.History; |
56 |
import org.gvsig.tools.i18n.I18nManager; |
57 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
58 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
59 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
60 |
import org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue; |
61 |
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_GETVALUE; |
62 |
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_SETVALUE; |
63 |
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController; |
64 |
import org.gvsig.tools.swing.api.bookmarkshistory.HistoryController; |
65 |
import org.gvsig.tools.swing.api.documentfilters.IntegerDocumentFilter; |
66 |
import org.gvsig.tools.swing.api.task.TaskStatusController; |
67 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
68 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
69 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
70 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
71 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
72 |
import org.gvsig.tools.task.SimpleTaskStatus; |
73 |
import org.gvsig.tools.util.ToolsUtilLocator; |
74 |
|
75 |
/**
|
76 |
*
|
77 |
* @author jjdelcerro
|
78 |
*/
|
79 |
public class UpdateTablePanelImpl extends UpdateTablePanelView { |
80 |
|
81 |
private static final String BOOKMARKSANDHISTORY_NAME = "UpdateTablePanel"; |
82 |
private static final String CONFIGURABLE_PANEL_ID = "UpdateTablePanel"; |
83 |
|
84 |
private FeatureStore table;
|
85 |
private ExpressionPickerController pickerTableFilter;
|
86 |
private DefaultTableColumnModel fieldsColumnModel; |
87 |
private SimpleTaskStatus taskStatus;
|
88 |
private TaskStatusController status;
|
89 |
private List<String> previewColumns; |
90 |
private final Bookmarks bookmarks; |
91 |
private final History history; |
92 |
private BookmarksController bookmarksController;
|
93 |
private HistoryController historyController;
|
94 |
private StoresRepositoryController treeTableController;
|
95 |
|
96 |
private class FeatureAttributeCellEditor extends AbstractCellEditor implements TableCellEditor { |
97 |
|
98 |
private final AttributeDescriptorPickerController picker; |
99 |
private final JComboBox combo; |
100 |
|
101 |
public FeatureAttributeCellEditor() {
|
102 |
DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager(); |
103 |
this.combo = new JComboBox(); |
104 |
this.picker = dataSwingManager.createAttributeDescriptorPickerController(this.combo); |
105 |
} |
106 |
|
107 |
@Override
|
108 |
public Component getTableCellEditorComponent(JTable jtable, Object value, boolean isSelected, int row, int column) { |
109 |
if( value == null ) { |
110 |
this.picker.clean();
|
111 |
return this.combo; |
112 |
} |
113 |
this.picker.setFeatureType(table.getDefaultFeatureTypeQuietly());
|
114 |
this.picker.setAllowNull(true); |
115 |
this.picker.set(Objects.toString(value,"")); |
116 |
return this.combo; |
117 |
} |
118 |
|
119 |
@Override
|
120 |
public Object getCellEditorValue() { |
121 |
return this.picker.getName(); |
122 |
} |
123 |
} |
124 |
|
125 |
private class ExpressionCellEditor extends AbstractCellEditor implements TableCellEditor { |
126 |
|
127 |
private final JExpressionPicker picker; |
128 |
|
129 |
public ExpressionCellEditor() {
|
130 |
ExpressionEvaluatorSwingManager manager = ExpressionEvaluatorSwingLocator.getManager(); |
131 |
this.picker = manager.createJExpressionPicker();
|
132 |
this.picker.removeBorder();
|
133 |
} |
134 |
|
135 |
@Override
|
136 |
public Component getTableCellEditorComponent(JTable jtable, Object value, boolean isSelected, int row, int column) { |
137 |
try {
|
138 |
DataSwingManager manager = DALSwingLocator.getDataSwingManager(); |
139 |
manager.configureExpressionBuilder(picker.getConfig(), table); |
140 |
if( value == null ) { |
141 |
this.picker.setExpression(null); |
142 |
} else {
|
143 |
this.picker.setExpression(ExpressionUtils.createExpression((String) value)); |
144 |
} |
145 |
return this.picker.asJComponent(); |
146 |
} catch(Exception ex) { |
147 |
return new JLabel(); |
148 |
} |
149 |
} |
150 |
|
151 |
@Override
|
152 |
public Object getCellEditorValue() { |
153 |
Expression exp = this.picker.getExpression(); |
154 |
if( exp==null ) { |
155 |
return null; |
156 |
} |
157 |
return exp.getPhrase();
|
158 |
} |
159 |
} |
160 |
|
161 |
private class MyTableModel extends AbstractTableModel implements Iterable<MyTableModel.Row>{ |
162 |
|
163 |
private final List<Row> rows; |
164 |
private final String[] columnNames; |
165 |
private final Class[] columnClass; |
166 |
private final FeatureType tableType; |
167 |
|
168 |
private class Row { |
169 |
String attrname;
|
170 |
String expression;
|
171 |
boolean update;
|
172 |
|
173 |
public Object get(int index) { |
174 |
switch(index) {
|
175 |
case 0: |
176 |
return update;
|
177 |
case 1: |
178 |
return attrname;
|
179 |
case 2: |
180 |
return expression;
|
181 |
default:
|
182 |
return null; |
183 |
} |
184 |
} |
185 |
|
186 |
public void set(int index, Object value) { |
187 |
switch(index) {
|
188 |
case 0: |
189 |
this.update = (boolean) value; |
190 |
break;
|
191 |
case 1: |
192 |
this.attrname = (String) value; |
193 |
break;
|
194 |
case 2: |
195 |
this.expression = (String) value; |
196 |
break;
|
197 |
default:
|
198 |
break;
|
199 |
} |
200 |
} |
201 |
} |
202 |
|
203 |
public MyTableModel() {
|
204 |
this.rows = new ArrayList<>(); |
205 |
this.tableType = table.getDefaultFeatureTypeQuietly();
|
206 |
for (FeatureAttributeDescriptor targetAttr : tableType) {
|
207 |
Row row = new Row();
|
208 |
row.attrname = targetAttr.getName(); |
209 |
row.expression = null;
|
210 |
if( targetAttr.isAutomatic() || targetAttr.isReadOnly() || targetAttr.isPrimaryKey() ) {
|
211 |
row.update = false;
|
212 |
} else {
|
213 |
row.update = true;
|
214 |
} |
215 |
this.rows.add(row);
|
216 |
} |
217 |
this.columnNames = new String[] { |
218 |
"Actualizarxxxxx",
|
219 |
"Campo",
|
220 |
"Expresion"
|
221 |
}; |
222 |
this.columnClass = new Class[] { |
223 |
Boolean.class,
|
224 |
String.class,
|
225 |
String.class
|
226 |
}; |
227 |
} |
228 |
|
229 |
@Override
|
230 |
public String getColumnName(int column) { |
231 |
return this.columnNames[column]; |
232 |
} |
233 |
|
234 |
@Override
|
235 |
public Class<?> getColumnClass(int columnIndex) { |
236 |
return this.columnClass[columnIndex]; |
237 |
} |
238 |
|
239 |
@Override
|
240 |
public int getRowCount() { |
241 |
return this.rows.size(); |
242 |
} |
243 |
|
244 |
@Override
|
245 |
public int getColumnCount() { |
246 |
return 3; |
247 |
} |
248 |
|
249 |
@Override
|
250 |
public Object getValueAt(int rowIndex, int columnIndex) { |
251 |
return this.rows.get(rowIndex).get(columnIndex); |
252 |
} |
253 |
|
254 |
@Override
|
255 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
256 |
this.rows.get(rowIndex).set(columnIndex, aValue);
|
257 |
} |
258 |
|
259 |
@Override
|
260 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
261 |
FeatureAttributeDescriptor attrdesc = this.tableType.getAttributeDescriptor(rowIndex);
|
262 |
if( attrdesc == null ) { |
263 |
return false; |
264 |
} |
265 |
if( attrdesc.isAutomatic() || attrdesc.isReadOnly() || attrdesc.isPrimaryKey() ) {
|
266 |
return false; |
267 |
} |
268 |
switch(columnIndex) {
|
269 |
case 0: |
270 |
case 1: |
271 |
case 2: |
272 |
default:
|
273 |
return true; |
274 |
} |
275 |
} |
276 |
|
277 |
@Override
|
278 |
public Iterator<Row> iterator() { |
279 |
return this.rows.iterator(); |
280 |
} |
281 |
} |
282 |
|
283 |
public UpdateTablePanelImpl() {
|
284 |
this.bookmarks = ToolsLocator.getBookmarksAndHistoryManager().getBookmarksGroup(BOOKMARKSANDHISTORY_NAME);
|
285 |
this.history = ToolsLocator.getBookmarksAndHistoryManager().getHistoryGroup(BOOKMARKSANDHISTORY_NAME);
|
286 |
|
287 |
this.initComponents();
|
288 |
} |
289 |
|
290 |
private void initComponents() { |
291 |
// DataManager dataManager = DALLocator.getDataManager();
|
292 |
// DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager();
|
293 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
294 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
295 |
|
296 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
297 |
cfgActionsManager.addConfigurableActions(CONFIGURABLE_PANEL_ID, this, btnConfigurableActions);
|
298 |
|
299 |
this.bookmarksController = ToolsSwingLocator.getToolsSwingManager().createBookmarksController(this.bookmarks, btnBookmarks); |
300 |
this.historyController = ToolsSwingLocator.getToolsSwingManager().createHistoryController(this.history, btnHistory); |
301 |
|
302 |
this.historyController.setFilter(null); |
303 |
|
304 |
ActionListener bookmarksAndHistoryListener = (ActionEvent e) -> { |
305 |
ActionEventWithCurrentValue<UpdateTableProcessParameters> event = (ActionEventWithCurrentValue<UpdateTableProcessParameters>) e; |
306 |
switch (event.getID()) {
|
307 |
case ID_GETVALUE:
|
308 |
event.setCurrentValue(fetch(null));
|
309 |
break;
|
310 |
case ID_SETVALUE:
|
311 |
put(event.getCurrentValue()); |
312 |
break;
|
313 |
} |
314 |
}; |
315 |
this.historyController.addActionListener(bookmarksAndHistoryListener);
|
316 |
this.bookmarksController.addActionListener(bookmarksAndHistoryListener);
|
317 |
|
318 |
this.rdoOptionsFulledit.setSelected(true); |
319 |
this.rdoOptionsFulledit.addActionListener((ActionEvent e) -> { doChangeSelectedEditMode(); }); |
320 |
|
321 |
this.rdoOptionsPassthrought.setSelected(false); |
322 |
this.rdoOptionsPassthrought.addActionListener((ActionEvent e) -> { doChangeSelectedEditMode(); }); |
323 |
|
324 |
this.rdoRecordsAll.setSelected(true); |
325 |
this.rdoRecordsEditeds.setSelected(false); |
326 |
this.rdoRecordsSelecteds.setSelected(false); |
327 |
|
328 |
this.status = ToolsSwingLocator.getTaskStatusSwingManager().createTaskStatusController(
|
329 |
null,
|
330 |
this.lblStatusLabel,
|
331 |
this.lblStatusMessage,
|
332 |
this.pbStatus,
|
333 |
this.btnCancelStatus,
|
334 |
null
|
335 |
); |
336 |
this.treeTableController = new StoresRepositoryController(this.treeTable); |
337 |
this.treeTableController.addTreeSelectionListener((TreeSelectionEvent e) -> { |
338 |
doChangeTable(); |
339 |
}); |
340 |
|
341 |
|
342 |
this.pickerTableFilter = expressionSwingManager.createExpressionPickerController(
|
343 |
this.txtRecordFilter,
|
344 |
this.btnRecordFilter,
|
345 |
this.btnRecordFilterBookmarks,
|
346 |
this.btnRecordFilterHistory
|
347 |
); |
348 |
this.pickerTableFilter.addChangeListener((ChangeEvent e) -> { |
349 |
doUpdatePreviewTable(); |
350 |
}); |
351 |
|
352 |
this.tableFields.setAutoCreateColumnsFromModel(false); |
353 |
this.tableFields.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
354 |
this.fieldsColumnModel = new DefaultTableColumnModel(); |
355 |
|
356 |
TableColumn column;
|
357 |
|
358 |
column = new TableColumn(); |
359 |
column.setHeaderValue("Actualizar");
|
360 |
column.setCellRenderer(null);
|
361 |
column.setResizable(true);
|
362 |
column.setModelIndex(0);
|
363 |
this.fieldsColumnModel.addColumn(column);
|
364 |
|
365 |
column = new TableColumn(); |
366 |
column.setHeaderValue("Campo");
|
367 |
column.setCellRenderer(null);
|
368 |
column.setCellEditor(null);//new FeatureAttributeCellEditor()); |
369 |
column.setResizable(true);
|
370 |
column.setModelIndex(1);
|
371 |
this.fieldsColumnModel.addColumn(column);
|
372 |
|
373 |
column = new TableColumn(); |
374 |
column.setHeaderValue("Expresion");
|
375 |
column.setCellRenderer(null);
|
376 |
column.setCellEditor(new ExpressionCellEditor());
|
377 |
column.setResizable(true);
|
378 |
column.setModelIndex(2);
|
379 |
this.fieldsColumnModel.addColumn(column);
|
380 |
|
381 |
|
382 |
this.tableFields.setColumnModel(this.fieldsColumnModel); |
383 |
|
384 |
this.btnRecordsUpdatePreview.addActionListener((ActionEvent e) -> { |
385 |
doUpdatePreviewTable(); |
386 |
}); |
387 |
|
388 |
this.btnRecordsConfigurePreviewColumns.addActionListener((ActionEvent e) -> { |
389 |
doConfigurePreviewColumns(); |
390 |
}); |
391 |
this.btnRecordsUpdatePreview.setEnabled(false); |
392 |
this.btnRecordsConfigurePreviewColumns.setVisible(false); |
393 |
this.tblRecordsPreview.setVisible(false); |
394 |
|
395 |
this.btnFieldsDeselectAll.addActionListener((ActionEvent e) -> { |
396 |
MyTableModel model = (MyTableModel) tableFields.getModel(); |
397 |
for (MyTableModel.Row row : model) {
|
398 |
row.update = false;
|
399 |
} |
400 |
model.fireTableDataChanged(); |
401 |
}); |
402 |
this.btnFieldsSelectAll.addActionListener((ActionEvent e) -> { |
403 |
MyTableModel model = (MyTableModel) tableFields.getModel(); |
404 |
for (MyTableModel.Row row : model) {
|
405 |
row.update = true;
|
406 |
} |
407 |
model.fireTableDataChanged(); |
408 |
}); |
409 |
IntegerDocumentFilter.install(this.txtOptionsFinishAndRestarEditEach);
|
410 |
|
411 |
toolsSwingManager.removeBorder(this.tblRecordsPreview);
|
412 |
|
413 |
this.rdoRecordsAll.addActionListener((ActionEvent e) -> { doUpdateRecordsPreview(); }); |
414 |
this.rdoRecordsEditeds.addActionListener((ActionEvent e) -> { doUpdateRecordsPreview(); }); |
415 |
this.rdoRecordsSelecteds.addActionListener((ActionEvent e) -> { doUpdateRecordsPreview(); }); |
416 |
|
417 |
SwingUtilities.invokeLater(() -> {
|
418 |
this.lblStatusLabel.setText(""); |
419 |
this.lblStatusMessage.setText(""); |
420 |
this.status.setVisible(false); |
421 |
}); |
422 |
|
423 |
ToolsSwingUtils.ensureRowsCols(this, 20, 80, 24, 100); |
424 |
} |
425 |
|
426 |
private void doUpdateRecordsPreview() { |
427 |
if( this.table == null ) { |
428 |
this.tblRecordsPreview.setVisible(false); |
429 |
this.btnRecordsConfigurePreviewColumns.setVisible(false); |
430 |
this.btnRecordsUpdatePreview.setVisible(false); |
431 |
return;
|
432 |
} |
433 |
DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager(); |
434 |
SimpleFeaturesTableModel model = null;
|
435 |
if( this.rdoRecordsAll.isSelected() ) { |
436 |
model = dataSwingManager.createSimpleFeaturesTableModel(table, this.pickerTableFilter.get());
|
437 |
} else if( this.rdoRecordsEditeds.isSelected() ) { |
438 |
model = dataSwingManager.createSimpleEditedFeaturesTableModel(table, this.pickerTableFilter.get());
|
439 |
} else if( this.rdoRecordsSelecteds.isSelected() ) { |
440 |
model = dataSwingManager.createSimpleSelectedFeaturesTableModel(table, this.pickerTableFilter.get());
|
441 |
} else {
|
442 |
// FIXME
|
443 |
} |
444 |
model.setCellRenderers(tblRecordsPreview); |
445 |
this.tblRecordsPreview.setModel(model);
|
446 |
this.tblRecordsPreview.setVisible(true); |
447 |
this.btnRecordsConfigurePreviewColumns.setVisible(false); |
448 |
this.btnRecordsUpdatePreview.setVisible(false); |
449 |
this.btnRecordsUpdatePreview.setEnabled(true); |
450 |
} |
451 |
|
452 |
private void doChangeTable() { |
453 |
this.table = this.treeTableController.getSelectedFeatureStore(); |
454 |
if( this.table==null ) { |
455 |
return;
|
456 |
} |
457 |
DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager(); |
458 |
dataSwingManager.configureExpressionBuilder(pickerTableFilter.getConfig(), table); |
459 |
this.tableFields.setModel(new MyTableModel()); |
460 |
doUpdateRecordsPreview(); |
461 |
|
462 |
FeatureStoreProviderFactory providerFactory = (FeatureStoreProviderFactory) this.getTable().getProviderFactory();
|
463 |
switch( providerFactory.supportPassthroughMode() ) {
|
464 |
case DataStoreProviderFactory.NO:
|
465 |
this.rdoOptionsPassthrought.setSelected(false); |
466 |
this.rdoOptionsFulledit.setSelected(true); |
467 |
break;
|
468 |
case DataStoreProviderFactory.YES:
|
469 |
case DataStoreProviderFactory.UNKNOWN:
|
470 |
if( !this.rdoOptionsPassthrought.isSelected() ) { |
471 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
472 |
int n = dialogs.confirmDialog(
|
473 |
"La tabla seleccionada soporta el modo de paso-a-traves que es mas optimo que el actualmente seleccionado." +
|
474 |
"\n" +
|
475 |
"? Desea pasar a usar el modo de paso-a-traves ?",
|
476 |
"Update table",
|
477 |
JOptionPane.YES_NO_OPTION,
|
478 |
JOptionPane.QUESTION_MESSAGE,
|
479 |
"Desea pasar a usar el modo de paso-a-traves"
|
480 |
); |
481 |
if( n==JOptionPane.YES_OPTION ) { |
482 |
this.rdoOptionsPassthrought.setSelected(true); |
483 |
this.rdoOptionsFulledit.setSelected(false); |
484 |
this.doChangeSelectedEditMode();
|
485 |
} |
486 |
} |
487 |
break;
|
488 |
} |
489 |
} |
490 |
|
491 |
private void doUpdatePreviewTable() { |
492 |
DataSwingManager manager = DALSwingLocator.getDataSwingManager(); |
493 |
FeatureType ftype = this.table.getDefaultFeatureTypeQuietly();
|
494 |
SimpleFeaturesTableModel model = manager.createSimpleFeaturesTableModel( |
495 |
ftype, |
496 |
this.previewColumns,
|
497 |
this.table.getFeatures(this.pickerTableFilter.get()) |
498 |
); |
499 |
this.tblRecordsPreview.setModel(model);
|
500 |
this.btnRecordsConfigurePreviewColumns.setVisible(true); |
501 |
this.tblRecordsPreview.setVisible(true); |
502 |
if( this.previewColumns==null ) { |
503 |
this.previewColumns = model.getColumnNames();
|
504 |
} |
505 |
} |
506 |
|
507 |
private void doConfigurePreviewColumns() { |
508 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
509 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
510 |
|
511 |
FeatureType ftype = this.table.getDefaultFeatureTypeQuietly();
|
512 |
|
513 |
FeatureAttributesSelectionPanel panelSelectColumns = DALSwingLocator.getManager().createFeatureAttributeSelectionPanel(); |
514 |
panelSelectColumns.allowCalculatedAttributes(false);
|
515 |
panelSelectColumns.setFeatureType(ftype); |
516 |
panelSelectColumns.setSelectedNames(this.previewColumns);
|
517 |
final Dialog dialog = winmanager.createDialog( |
518 |
panelSelectColumns.asJComponent(), |
519 |
i18n.getTranslation("_Select_the_columns_to_display"),
|
520 |
null,
|
521 |
WindowManager_v2.BUTTONS_OK_CANCEL |
522 |
); |
523 |
dialog.addActionListener((ActionEvent e) -> {
|
524 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) {
|
525 |
this.previewColumns = panelSelectColumns.getSelectedNames();
|
526 |
doUpdatePreviewTable(); |
527 |
} |
528 |
}); |
529 |
dialog.show(WindowManager.MODE.DIALOG); |
530 |
} |
531 |
|
532 |
public FeatureStore getTable() {
|
533 |
return this.table; |
534 |
} |
535 |
|
536 |
public Expression getTableFilter() { |
537 |
return this.pickerTableFilter.get(); |
538 |
} |
539 |
|
540 |
public SimpleTaskStatus getStatus() {
|
541 |
if( this.taskStatus == null ) { |
542 |
this.taskStatus = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("Copy table"); |
543 |
this.status.bind(this.taskStatus); |
544 |
} |
545 |
this.status.setVisible(true); |
546 |
return this.taskStatus; |
547 |
} |
548 |
|
549 |
public void put(UpdateTableProcessParameters params) { |
550 |
this.table = null; |
551 |
switch(params.getEditMode()) {
|
552 |
case FeatureStore.MODE_FULLEDIT:
|
553 |
default:
|
554 |
this.rdoOptionsFulledit.setSelected(true); |
555 |
this.rdoOptionsPassthrought.setSelected(false); |
556 |
break;
|
557 |
case FeatureStore.MODE_PASS_THROUGH:
|
558 |
this.rdoOptionsFulledit.setSelected(false); |
559 |
this.rdoOptionsPassthrought.setSelected(true); |
560 |
break;
|
561 |
} |
562 |
this.chkOptionsBeginEditIfNeed.setSelected(params.isBeginEditIfNeed());
|
563 |
this.chkOptionsFinishAndRestarEditEach.setSelected(params.isFinishAndRestarEdit());
|
564 |
this.chkOptionsNotifyUserIfNeedBeginEditing.setSelected(params.isNotifyUserIfNeedBeginEditing());
|
565 |
this.chkOptionsFinishEditAfterTerminate.setSelected(params.isFinishEditAfterTerminate());
|
566 |
IntegerDocumentFilter.setValue(txtOptionsFinishAndRestarEditEach, params.getFinishAndRestarEditEach()); |
567 |
switch(params.getRowsToProcess()) {
|
568 |
case BATCHUPDATE_PROCESS_SELECTION:
|
569 |
this.rdoRecordsSelecteds.setSelected(true); |
570 |
this.rdoRecordsEditeds.setSelected(false); |
571 |
this.rdoRecordsAll.setSelected(false); |
572 |
break;
|
573 |
case BATCHUPDATE_PROCESS_EDITEDS:
|
574 |
this.rdoRecordsSelecteds.setSelected(false); |
575 |
this.rdoRecordsEditeds.setSelected(true); |
576 |
this.rdoRecordsAll.setSelected(false); |
577 |
break;
|
578 |
case BATCHUPDATE_PROCESS_ALL:
|
579 |
this.rdoRecordsSelecteds.setSelected(false); |
580 |
this.rdoRecordsEditeds.setSelected(false); |
581 |
this.rdoRecordsAll.setSelected(true); |
582 |
break;
|
583 |
} |
584 |
this.table = params.getStore();
|
585 |
MyTableModel fieldsModel = new MyTableModel();
|
586 |
this.tableFields.setModel(fieldsModel);
|
587 |
for (MyTableModel.Row row : fieldsModel.rows) {
|
588 |
ProcessFieldParameters paramfield = params.get(row.attrname); |
589 |
row.expression = paramfield.getExpression().getPhrase(); |
590 |
row.update = paramfield.isUpdate(); |
591 |
} |
592 |
fieldsModel.fireTableDataChanged(); |
593 |
} |
594 |
|
595 |
public UpdateTableProcessParameters fetch(UpdateTableProcessParameters params) {
|
596 |
if( params == null ) { |
597 |
params = new UpdateTableProcessParametersImpl();
|
598 |
} |
599 |
params.setStore(table); |
600 |
if( this.rdoRecordsSelecteds.isSelected() ) { |
601 |
params.setRowsToProcess(BATCHUPDATE_PROCESS_SELECTION); |
602 |
} |
603 |
if( this.rdoRecordsEditeds.isSelected() ) { |
604 |
params.setRowsToProcess(BATCHUPDATE_PROCESS_EDITEDS); |
605 |
} |
606 |
if( this.rdoRecordsAll.isSelected() ) { |
607 |
params.setRowsToProcess(BATCHUPDATE_PROCESS_ALL); |
608 |
} |
609 |
MyTableModel model = (MyTableModel) this.tableFields.getModel();
|
610 |
for (MyTableModel.Row row : model) {
|
611 |
Expression exp = null; |
612 |
if( StringUtils.isNotBlank(row.expression)) {
|
613 |
exp = ExpressionUtils.createExpression(row.expression); |
614 |
} |
615 |
params.add(row.attrname, row.update, exp); |
616 |
} |
617 |
if( this.rdoOptionsFulledit.isSelected() ) { |
618 |
params.setEditMode(FeatureStore.MODE_FULLEDIT); |
619 |
} else {
|
620 |
params.setEditMode(FeatureStore.MODE_PASS_THROUGH); |
621 |
} |
622 |
params.setBeginEditIfNeed(this.chkOptionsBeginEditIfNeed.isSelected());
|
623 |
params.setFinishAndRestarEdit(this.chkOptionsFinishAndRestarEditEach.isSelected());
|
624 |
params.setNotifyUserIfNeedBeginEditing(this.chkOptionsNotifyUserIfNeedBeginEditing.isSelected());
|
625 |
params.setFinishEditAfterTerminate(this.chkOptionsFinishEditAfterTerminate.isSelected());
|
626 |
params.setFinishAndRestarEditEach(IntegerDocumentFilter.getValue(txtOptionsFinishAndRestarEditEach)); |
627 |
return params;
|
628 |
} |
629 |
|
630 |
public void postProcess() { |
631 |
if( !SwingUtilities.isEventDispatchThread() ) { |
632 |
SwingUtilities.invokeLater(this::postProcess); |
633 |
return;
|
634 |
} |
635 |
// TODO
|
636 |
} |
637 |
|
638 |
@Override
|
639 |
public ImageIcon loadImage(String imageName) { |
640 |
String name = FilenameUtils.getBaseName(imageName);
|
641 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
642 |
if (theme.exists(name)) {
|
643 |
return theme.get(name);
|
644 |
} |
645 |
return null; |
646 |
} |
647 |
|
648 |
private void doChangeSelectedEditMode() { |
649 |
if( this.rdoOptionsPassthrought.isSelected() ) { |
650 |
this.chkOptionsBeginEditIfNeed.setEnabled(false); |
651 |
this.chkOptionsFinishAndRestarEditEach.setEnabled(false); |
652 |
this.chkOptionsFinishEditAfterTerminate.setEnabled(false); |
653 |
this.chkOptionsNotifyUserIfNeedBeginEditing.setEnabled(false); |
654 |
this.txtOptionsFinishAndRestarEditEach.setEnabled(false); |
655 |
|
656 |
this.rdoOptionsFulledit.setSelected(false); |
657 |
} |
658 |
|
659 |
if( this.rdoOptionsFulledit.isSelected() ) { |
660 |
this.chkOptionsBeginEditIfNeed.setEnabled(true); |
661 |
this.chkOptionsFinishAndRestarEditEach.setEnabled(true); |
662 |
this.chkOptionsFinishEditAfterTerminate.setEnabled(true); |
663 |
this.chkOptionsNotifyUserIfNeedBeginEditing.setEnabled(true); |
664 |
this.txtOptionsFinishAndRestarEditEach.setEnabled(true); |
665 |
|
666 |
} |
667 |
|
668 |
} |
669 |
} |