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 / copytable / CopyTable2Panel.java @ 47701
History | View | Annotate | Download (36.3 KB)
1 |
package org.gvsig.app.extension.copytable; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
import java.net.URL; |
8 |
import java.util.ArrayList; |
9 |
import java.util.Iterator; |
10 |
import java.util.List; |
11 |
import java.util.Objects; |
12 |
import javax.swing.AbstractCellEditor; |
13 |
import javax.swing.ImageIcon; |
14 |
import javax.swing.JComboBox; |
15 |
import javax.swing.JLabel; |
16 |
import javax.swing.JTable; |
17 |
import javax.swing.ListSelectionModel; |
18 |
import javax.swing.SwingUtilities; |
19 |
import javax.swing.event.ChangeEvent; |
20 |
import javax.swing.event.TreeSelectionEvent; |
21 |
import javax.swing.table.AbstractTableModel; |
22 |
import javax.swing.table.DefaultTableColumnModel; |
23 |
import javax.swing.table.TableCellEditor; |
24 |
import javax.swing.table.TableColumn; |
25 |
import org.apache.commons.io.FilenameUtils; |
26 |
import org.apache.commons.lang3.StringUtils; |
27 |
import org.apache.commons.text.similarity.LevenshteinDistance; |
28 |
import org.gvsig.app.ApplicationLocator; |
29 |
import org.gvsig.app.extension.copytable.CopyTable2ProcessParameters.ProcessFieldParameters; |
30 |
import org.gvsig.configurableactions.ConfigurableActionsMamager; |
31 |
import org.gvsig.expressionevaluator.Expression; |
32 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
33 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
34 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
35 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
36 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
37 |
import org.gvsig.expressionevaluator.swing.JExpressionPicker; |
38 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
40 |
import org.gvsig.fmap.dal.feature.FeatureType; |
41 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
42 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
43 |
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorPickerController; |
44 |
import org.gvsig.fmap.dal.swing.storesrepository.StoresRepositoryController; |
45 |
import org.gvsig.tools.ToolsLocator; |
46 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
47 |
import org.gvsig.tools.bookmarksandhistory.History; |
48 |
import org.gvsig.tools.dispose.DisposeUtils; |
49 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
50 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
51 |
import org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue; |
52 |
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_GETVALUE; |
53 |
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_SETVALUE; |
54 |
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController; |
55 |
import org.gvsig.tools.swing.api.bookmarkshistory.HistoryController; |
56 |
import org.gvsig.tools.swing.api.documentfilters.IntegerDocumentFilter; |
57 |
import org.gvsig.tools.swing.api.task.TaskStatusController; |
58 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
59 |
import org.gvsig.tools.task.SimpleTaskStatus; |
60 |
import org.gvsig.tools.util.ToolsUtilLocator; |
61 |
|
62 |
/**
|
63 |
*
|
64 |
* @author jjdelcerro
|
65 |
*/
|
66 |
public class CopyTable2Panel extends CopyTable2PanelView { |
67 |
|
68 |
private static final String BOOKMARKSANDHISTORY_NAME = "CopyTablePanel"; |
69 |
private static final String CONFIGURABLE_PANEL_ID = "CopyTablePanel"; |
70 |
|
71 |
private static final Integer MAX_DISTANCE_TO_ASSIGN_FIELD = 3; |
72 |
private AttributeDescriptorPickerController pickerSourceFieldJoin;
|
73 |
private FeatureStore source;
|
74 |
private FeatureStore target;
|
75 |
private AttributeDescriptorPickerController pickerTargetFieldJoin;
|
76 |
private ExpressionPickerController pickerSourceFilter;
|
77 |
private ExpressionPickerController pickerTargetUpdateExpression;
|
78 |
private DefaultTableColumnModel fieldsColumnModel; |
79 |
private SimpleTaskStatus taskStatus;
|
80 |
private TaskStatusController status;
|
81 |
private StoresRepositoryController treeSourceTableController;
|
82 |
private StoresRepositoryController treeTargetTableController;
|
83 |
|
84 |
private final Bookmarks bookmarks; |
85 |
private final History history; |
86 |
private BookmarksController bookmarksController;
|
87 |
private HistoryController historyController;
|
88 |
private ExpressionPickerController pickerJoinExpression;
|
89 |
private DataSwingManager dataSwingManager;
|
90 |
|
91 |
|
92 |
private class FeatureAttributeCellEditor extends AbstractCellEditor implements TableCellEditor { |
93 |
|
94 |
private final AttributeDescriptorPickerController picker; |
95 |
private final JComboBox combo; |
96 |
|
97 |
public FeatureAttributeCellEditor() {
|
98 |
DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager(); |
99 |
this.combo = new JComboBox(); |
100 |
this.picker = dataSwingManager.createAttributeDescriptorPickerController(this.combo); |
101 |
} |
102 |
|
103 |
@Override
|
104 |
public Component getTableCellEditorComponent(JTable jtable, Object value, boolean isSelected, int row, int column) { |
105 |
if( value == null ) { |
106 |
this.picker.clean();
|
107 |
return this.combo; |
108 |
} |
109 |
this.picker.setFeatureType(source.getDefaultFeatureTypeQuietly());
|
110 |
this.picker.setAllowNull(true); |
111 |
this.picker.set(Objects.toString(value,"")); |
112 |
return this.combo; |
113 |
} |
114 |
|
115 |
@Override
|
116 |
public Object getCellEditorValue() { |
117 |
return this.picker.getName(); |
118 |
} |
119 |
} |
120 |
|
121 |
private class ExpressionCellEditor extends AbstractCellEditor implements TableCellEditor { |
122 |
|
123 |
private final JExpressionPicker picker; |
124 |
|
125 |
public ExpressionCellEditor() {
|
126 |
ExpressionEvaluatorSwingManager manager = ExpressionEvaluatorSwingLocator.getManager(); |
127 |
this.picker = manager.createJExpressionPicker();
|
128 |
this.picker.removeBorder();
|
129 |
} |
130 |
|
131 |
@Override
|
132 |
public Component getTableCellEditorComponent(JTable jtable, Object value, boolean isSelected, int row, int column) { |
133 |
try {
|
134 |
DataSwingManager manager = DALSwingLocator.getDataSwingManager(); |
135 |
manager.configureExpressionBuilder(picker.getConfig(), source); |
136 |
if( value == null ) { |
137 |
this.picker.setExpression(null); |
138 |
} else {
|
139 |
this.picker.setExpression(ExpressionUtils.createExpression((String) value)); |
140 |
} |
141 |
return this.picker.asJComponent(); |
142 |
} catch(Exception ex) { |
143 |
return new JLabel(); |
144 |
} |
145 |
} |
146 |
|
147 |
@Override
|
148 |
public Object getCellEditorValue() { |
149 |
Expression exp = this.picker.getExpression(); |
150 |
if( exp==null ) { |
151 |
return null; |
152 |
} |
153 |
return exp.getPhrase();
|
154 |
} |
155 |
} |
156 |
|
157 |
private class MyTableModel extends AbstractTableModel implements Iterable<MyTableModel.Row>{ |
158 |
|
159 |
private final List<Row> rows; |
160 |
private final String[] columnNames; |
161 |
private final Class[] columnClass; |
162 |
private FeatureType tableType;
|
163 |
|
164 |
private class Row { |
165 |
String attrname;
|
166 |
String attrlabel;
|
167 |
String expression;
|
168 |
boolean update;
|
169 |
|
170 |
public Row(String attrlabel, String attrname, String expression, boolean update) { |
171 |
this.attrlabel = attrlabel;
|
172 |
this.attrname = attrname;
|
173 |
this.expression = expression;
|
174 |
this.update = update;
|
175 |
} |
176 |
|
177 |
public Object get(int index) { |
178 |
switch(index) {
|
179 |
case 0: |
180 |
return update;
|
181 |
case 1: |
182 |
return attrlabel;
|
183 |
case 2: |
184 |
return expression;
|
185 |
default:
|
186 |
return null; |
187 |
} |
188 |
} |
189 |
|
190 |
public void set(int index, Object value) { |
191 |
switch(index) {
|
192 |
case 0: |
193 |
this.update = (boolean) value; |
194 |
break;
|
195 |
case 1: |
196 |
this.attrlabel = (String) value; |
197 |
break;
|
198 |
case 2: |
199 |
this.expression = (String) value; |
200 |
break;
|
201 |
default:
|
202 |
break;
|
203 |
} |
204 |
} |
205 |
|
206 |
public String getAttrname() { |
207 |
return attrname;
|
208 |
} |
209 |
|
210 |
public String getExpression() { |
211 |
return expression;
|
212 |
} |
213 |
|
214 |
public boolean isUpdate() { |
215 |
return update;
|
216 |
} |
217 |
|
218 |
private void setExpression(String expression) { |
219 |
this.expression = expression;
|
220 |
} |
221 |
|
222 |
private void setUpdate(boolean update) { |
223 |
this.update = update;
|
224 |
} |
225 |
|
226 |
private void setAttrname(String name) { |
227 |
this.attrname = name;
|
228 |
this.attrlabel = name;
|
229 |
} |
230 |
} |
231 |
|
232 |
|
233 |
public MyTableModel() {
|
234 |
this.rows = new ArrayList<>(); |
235 |
this.tableType = null; |
236 |
if( target!=null ) { |
237 |
this.tableType = target.getDefaultFeatureTypeQuietly();
|
238 |
for (FeatureAttributeDescriptor targetAttr : tableType) {
|
239 |
Row row = new Row(
|
240 |
getDataSwingManager().getAttributeDescriptorLabel(targetAttr), |
241 |
targetAttr.getName(), |
242 |
getSourceExpression(targetAttr.getName()), |
243 |
!(targetAttr.isComputed()) |
244 |
); |
245 |
this.rows.add(row);
|
246 |
} |
247 |
} |
248 |
for (Row row : this.rows) { |
249 |
if(row.getExpression() == null){ |
250 |
continue;
|
251 |
} |
252 |
// Row first = null;
|
253 |
boolean dup = false; |
254 |
for (Row row1 : this.rows) { |
255 |
if(row == row1){
|
256 |
continue;
|
257 |
} |
258 |
if(StringUtils.equalsIgnoreCase(row.getExpression(), row1.getExpression())){
|
259 |
// if(first == null){
|
260 |
// first = row;
|
261 |
// }
|
262 |
dup = true;
|
263 |
row1.setExpression(null);
|
264 |
} |
265 |
} |
266 |
// if (first != null) {
|
267 |
// first.expression = null;
|
268 |
// }
|
269 |
if(dup){
|
270 |
row.setExpression(null);
|
271 |
} |
272 |
} |
273 |
this.columnNames = new String[] { |
274 |
"Actualizar",
|
275 |
"Campo",
|
276 |
"Expresion"
|
277 |
}; |
278 |
this.columnClass = new Class[] { |
279 |
Boolean.class,
|
280 |
String.class,
|
281 |
String.class
|
282 |
}; |
283 |
} |
284 |
|
285 |
final String getSourceExpression(String targetFieldName){ |
286 |
FeatureType sourceType = source.getDefaultFeatureTypeQuietly(); |
287 |
ExpressionBuilder expBuilder = source.createExpressionBuilder(); |
288 |
Integer minDistance = Integer.MAX_VALUE; |
289 |
String minDistanceSourceFieldName = null; |
290 |
FeatureAttributeDescriptor attr = sourceType.getAttributeDescriptor(targetFieldName); |
291 |
if(attr!=null){ |
292 |
return expBuilder.identifier(attr.getName());
|
293 |
} |
294 |
for (FeatureAttributeDescriptor featureAttributeDescriptor : sourceType) {
|
295 |
String sourceFieldName = featureAttributeDescriptor.getName();
|
296 |
// if(StringUtils.equalsIgnoreCase(targetFieldName, sourceFieldName)){
|
297 |
// return expBuilder.identifier(sourceFieldName);
|
298 |
// }
|
299 |
if(StringUtils.containsIgnoreCase(targetFieldName, sourceFieldName)){
|
300 |
return expBuilder.identifier(sourceFieldName);
|
301 |
} |
302 |
if(StringUtils.containsIgnoreCase(sourceFieldName, targetFieldName)){
|
303 |
return expBuilder.identifier(sourceFieldName);
|
304 |
} |
305 |
Integer distance = LevenshteinDistance.getDefaultInstance().apply(targetFieldName, sourceFieldName);
|
306 |
if(distance < minDistance){
|
307 |
minDistanceSourceFieldName = sourceFieldName; |
308 |
minDistance = distance; |
309 |
} |
310 |
} |
311 |
if(minDistance <= MAX_DISTANCE_TO_ASSIGN_FIELD) {
|
312 |
return expBuilder.identifier(minDistanceSourceFieldName);
|
313 |
} |
314 |
return null; |
315 |
} |
316 |
|
317 |
@Override
|
318 |
public String getColumnName(int column) { |
319 |
return this.columnNames[column]; |
320 |
} |
321 |
|
322 |
@Override
|
323 |
public Class<?> getColumnClass(int columnIndex) { |
324 |
return this.columnClass[columnIndex]; |
325 |
} |
326 |
|
327 |
@Override
|
328 |
public int getRowCount() { |
329 |
return this.rows.size(); |
330 |
} |
331 |
|
332 |
@Override
|
333 |
public int getColumnCount() { |
334 |
return 3; |
335 |
} |
336 |
|
337 |
@Override
|
338 |
public Object getValueAt(int rowIndex, int columnIndex) { |
339 |
switch (columnIndex) {
|
340 |
case 0: |
341 |
case 2: |
342 |
return this.rows.get(rowIndex).get(columnIndex); |
343 |
case 1: |
344 |
FeatureAttributeDescriptor attrdesc = this.tableType.getAttributeDescriptor(this.rows.get(rowIndex).getAttrname()); |
345 |
return attrdesc;
|
346 |
default:
|
347 |
return null; |
348 |
} |
349 |
} |
350 |
|
351 |
@Override
|
352 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
353 |
this.rows.get(rowIndex).set(columnIndex, aValue);
|
354 |
} |
355 |
|
356 |
@Override
|
357 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
358 |
FeatureAttributeDescriptor attrdesc = this.tableType.getAttributeDescriptor(rowIndex);
|
359 |
if( attrdesc == null ) { |
360 |
return false; |
361 |
} |
362 |
// Dejamos marcarlos todos, y el proceso de copia decidira saltarselos
|
363 |
// segun se este insertando registro nuevo o actualizando.
|
364 |
// if( attrdesc.isAutomatic() || attrdesc.isReadOnly() ) { //|| attrdesc.isPrimaryKey() ) {
|
365 |
// return false;
|
366 |
// }
|
367 |
switch(columnIndex) {
|
368 |
case 1: |
369 |
return false; |
370 |
case 0: |
371 |
case 2: |
372 |
default:
|
373 |
return true; |
374 |
} |
375 |
} |
376 |
|
377 |
@Override
|
378 |
public Iterator<Row> iterator() { |
379 |
return this.rows.iterator(); |
380 |
} |
381 |
|
382 |
@Override
|
383 |
public void fireTableDataChanged() { |
384 |
super.fireTableDataChanged();
|
385 |
} |
386 |
|
387 |
|
388 |
} |
389 |
|
390 |
public CopyTable2Panel() {
|
391 |
this.bookmarks = ToolsLocator.getBookmarksAndHistoryManager().getBookmarksGroup(BOOKMARKSANDHISTORY_NAME);
|
392 |
this.history = ToolsLocator.getBookmarksAndHistoryManager().getHistoryGroup(BOOKMARKSANDHISTORY_NAME);
|
393 |
|
394 |
this.initComponents();
|
395 |
} |
396 |
|
397 |
private DataSwingManager getDataSwingManager() {
|
398 |
if( this.dataSwingManager==null ) { |
399 |
this.dataSwingManager = DALSwingLocator.getSwingManager();
|
400 |
} |
401 |
return this.dataSwingManager; |
402 |
} |
403 |
|
404 |
private void initComponents() { |
405 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
406 |
this.status = ToolsSwingLocator.getTaskStatusSwingManager().createTaskStatusController(lblStatusLabel, lblStatusMessage, pbStatus);
|
407 |
|
408 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
409 |
cfgActionsManager.addConfigurableActions(CONFIGURABLE_PANEL_ID, this, btnConfigurableActions);
|
410 |
|
411 |
this.bookmarksController = ToolsSwingLocator.getToolsSwingManager().createBookmarksController(this.bookmarks, btnBookmarks); |
412 |
this.historyController = ToolsSwingLocator.getToolsSwingManager().createHistoryController(this.history, btnHistory); |
413 |
|
414 |
this.historyController.setFilter(null); |
415 |
|
416 |
ActionListener bookmarksAndHistoryListener = (ActionEvent e) -> { |
417 |
ActionEventWithCurrentValue<CopyTable2ProcessParameters> event = (ActionEventWithCurrentValue<CopyTable2ProcessParameters>) e; |
418 |
switch (event.getID()) {
|
419 |
case ID_GETVALUE:
|
420 |
event.setCurrentValue(fetch(null));
|
421 |
break;
|
422 |
case ID_SETVALUE:
|
423 |
put(event.getCurrentValue()); |
424 |
doUpdateComponents(); |
425 |
break;
|
426 |
} |
427 |
}; |
428 |
this.historyController.addActionListener(bookmarksAndHistoryListener);
|
429 |
this.bookmarksController.addActionListener(bookmarksAndHistoryListener);
|
430 |
|
431 |
this.treeSourceTableController = getDataSwingManager().createStoresRepositoryController(this.treeSourceTable); |
432 |
this.treeSourceTable.addTreeSelectionListener((TreeSelectionEvent e) -> { |
433 |
doChangeSource(); |
434 |
doUpdateComponents(); |
435 |
}); |
436 |
this.pickerSourceFieldJoin = getDataSwingManager().createAttributeDescriptorPickerController(cboSourceJoinField);
|
437 |
this.pickerSourceFieldJoin.setAllowNull(true); |
438 |
this.pickerSourceFieldJoin.addChangeListener((ChangeEvent e) -> { |
439 |
doUpdateComponents(); |
440 |
}); |
441 |
|
442 |
this.treeTargetTableController = getDataSwingManager().createStoresRepositoryController(this.treeTargetTable); |
443 |
this.treeTargetTable.addTreeSelectionListener((TreeSelectionEvent e) -> { |
444 |
doChangeTarget(); |
445 |
doUpdateComponents(); |
446 |
}); |
447 |
this.pickerTargetFieldJoin = getDataSwingManager().createAttributeDescriptorPickerController(cboTargetJoinField);
|
448 |
this.pickerTargetFieldJoin.setAllowNull(true); |
449 |
this.pickerTargetFieldJoin.addChangeListener((ChangeEvent e) -> { |
450 |
doUpdateComponents(); |
451 |
}); |
452 |
|
453 |
this.pickerSourceFilter = expressionSwingManager.createExpressionPickerController(
|
454 |
txtSourceFilter, |
455 |
btnSourceFilter, |
456 |
btnSourceFilterBookmarks, |
457 |
btnSourceFilterHistory |
458 |
); |
459 |
|
460 |
this.pickerTargetUpdateExpression = expressionSwingManager.createExpressionPickerController(
|
461 |
txtTargetUpdateWhenExpression, |
462 |
btnTargetUpdateWhenExpression, |
463 |
btnTargetUpdateWhenExpressionBookmarks, |
464 |
btnTargetUpdateWhenExpressionHistory |
465 |
); |
466 |
this.chkTargetInsertIfNotExistsInTarget.setSelected(false); |
467 |
this.chkTargetInsertIfNotExistsInTarget.addChangeListener((e) -> {
|
468 |
doUpdateComponents(); |
469 |
}); |
470 |
|
471 |
this.chkTargetUpdateIfExistsInTarget.setSelected(false); |
472 |
this.chkTargetUpdateIfExistsInTarget.addChangeListener((e) -> {
|
473 |
doUpdateComponents(); |
474 |
}); |
475 |
|
476 |
this.chkTargetDeleteIfNotExiststInSource.setEnabled(false); |
477 |
this.chkTargetDeleteIfNotExiststInSource.addChangeListener((e) -> {
|
478 |
doUpdateComponents(); |
479 |
}); |
480 |
|
481 |
this.tableFields.setAutoCreateColumnsFromModel(false); |
482 |
this.tableFields.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
483 |
this.fieldsColumnModel = new DefaultTableColumnModel(); |
484 |
|
485 |
this.rdbUseJoinExpression.addActionListener((ActionEvent e) -> { |
486 |
doUpdateComponents(); |
487 |
}); |
488 |
this.rdbUseJoinField.addActionListener((ActionEvent e) -> { |
489 |
doUpdateComponents(); |
490 |
}); |
491 |
this.pickerJoinExpression = expressionSwingManager.createExpressionPickerController(
|
492 |
txtJoinExpression, |
493 |
btnJoinExpression, |
494 |
btnJoinExpressionBookmarks, |
495 |
btnJoinExpressionHistory |
496 |
); |
497 |
|
498 |
TableColumn column = new TableColumn(); |
499 |
column.setHeaderValue("Actualizar");
|
500 |
column.setCellRenderer(null);
|
501 |
column.setResizable(true);
|
502 |
column.setModelIndex(0);
|
503 |
this.fieldsColumnModel.addColumn(column);
|
504 |
|
505 |
column = new TableColumn(); |
506 |
column.setHeaderValue("Campo destino");
|
507 |
column.setCellRenderer(getDataSwingManager().createDefaultFeatureAttributeTableCellRenderer()); |
508 |
column.setCellEditor(null);
|
509 |
column.setResizable(true);
|
510 |
column.setModelIndex(1);
|
511 |
this.fieldsColumnModel.addColumn(column);
|
512 |
|
513 |
column = new TableColumn(); |
514 |
column.setHeaderValue("Campo origen");
|
515 |
column.setCellRenderer(null);
|
516 |
column.setCellEditor(new ExpressionCellEditor());
|
517 |
column.setResizable(true);
|
518 |
column.setModelIndex(2);
|
519 |
this.fieldsColumnModel.addColumn(column);
|
520 |
|
521 |
this.btnCheckAllFields.addActionListener((ActionEvent e) -> { |
522 |
doSetAllChecksOfFields(true);
|
523 |
}); |
524 |
this.btnUnCheckAllFields.addActionListener((ActionEvent e) -> { |
525 |
doSetAllChecksOfFields(false);
|
526 |
}); |
527 |
|
528 |
this.tableFields.setColumnModel(this.fieldsColumnModel); |
529 |
|
530 |
SwingUtilities.invokeLater(() -> {
|
531 |
lblStatusLabel.setText("");
|
532 |
lblStatusMessage.setText("");
|
533 |
pbStatus.setVisible(false);
|
534 |
}); |
535 |
this.lblJoinExpressionMsg.setText("<html>"+this.lblJoinExpressionMsg.getText()+"</html>"); |
536 |
doUpdateComponents(); |
537 |
|
538 |
Dimension screensize = ApplicationLocator.getApplicationManager().getUIManager().getInternalSize();
|
539 |
ToolsSwingUtils.ensureHeightWitdh( |
540 |
this,
|
541 |
Math.max(3*(screensize.height/4), ToolsSwingUtils.rows2px(80)), |
542 |
Math.max(2*(screensize.width/4), ToolsSwingUtils.cols2px(35)), |
543 |
7*(screensize.height/8), |
544 |
3*(screensize.width/4) |
545 |
); |
546 |
// ToolsSwingUtils.ensureRowsCols(this, 35, 80, 30, 100);
|
547 |
} |
548 |
|
549 |
private void doSetAllChecksOfFields(boolean check) { |
550 |
MyTableModel model = (MyTableModel) this.tableFields.getModel();
|
551 |
for (MyTableModel.Row row : model) {
|
552 |
row.set(0, check);
|
553 |
} |
554 |
model.fireTableDataChanged(); |
555 |
} |
556 |
|
557 |
private void doUpdateComponents() { |
558 |
this.treeSourceTableController.setEnabled(
|
559 |
true
|
560 |
); |
561 |
|
562 |
this.pickerSourceFieldJoin.setEnabled(
|
563 |
this.source != null |
564 |
); |
565 |
|
566 |
this.pickerSourceFilter.setEnabled(
|
567 |
this.source != null |
568 |
); |
569 |
|
570 |
this.treeTargetTableController.setEnabled(
|
571 |
this.source != null |
572 |
); |
573 |
|
574 |
this.btnCheckAllFields.setEnabled(
|
575 |
this.source != null && |
576 |
this.target != null |
577 |
); |
578 |
this.btnUnCheckAllFields.setEnabled(
|
579 |
this.source != null && |
580 |
this.target != null |
581 |
); |
582 |
this.rdbUseJoinField.setEnabled(
|
583 |
this.source != null && |
584 |
this.target != null |
585 |
); |
586 |
this.rdbUseJoinExpression.setEnabled(
|
587 |
this.source != null && |
588 |
this.target != null |
589 |
); |
590 |
this.rdbNotJoin.setEnabled(
|
591 |
this.source != null && |
592 |
this.target != null |
593 |
); |
594 |
this.pickerTargetFieldJoin.setEnabled(
|
595 |
this.source != null && |
596 |
this.target != null && |
597 |
(this.rdbUseJoinField.isSelected() && this.rdbUseJoinField.isEnabled()) && |
598 |
this.pickerSourceFieldJoin.getName() != null |
599 |
); |
600 |
this.pickerJoinExpression.setEnabled(
|
601 |
this.source != null && |
602 |
this.target != null && |
603 |
(this.rdbUseJoinExpression.isSelected() && this.rdbUseJoinExpression.isEnabled()) |
604 |
); |
605 |
|
606 |
|
607 |
this.chkTargetInsertIfNotExistsInTarget.setEnabled(
|
608 |
this.source != null && |
609 |
this.target != null && ( |
610 |
(this.pickerSourceFieldJoin.getName() != null && this.pickerTargetFieldJoin.getName() != null) || |
611 |
this.rdbUseJoinExpression.isSelected()
|
612 |
) |
613 |
); |
614 |
|
615 |
this.chkTargetUpdateIfExistsInTarget.setEnabled(
|
616 |
this.source != null && |
617 |
this.target != null && ( |
618 |
(this.pickerSourceFieldJoin.getName() != null && this.pickerTargetFieldJoin.getName() != null) || |
619 |
this.rdbUseJoinExpression.isSelected()
|
620 |
) |
621 |
); |
622 |
this.chkTargetDeleteIfNotExiststInSource.setEnabled(
|
623 |
false // No esta implementado |
624 |
// this.source != null &&
|
625 |
// this.target != null && (
|
626 |
// (this.pickerSourceFieldJoin.getName() != null && this.pickerTargetFieldJoin.getName() != null) ||
|
627 |
// this.rdbUseJoinExpression.isSelected()
|
628 |
// )
|
629 |
); |
630 |
this.pickerTargetUpdateExpression.setEnabled(
|
631 |
this.chkTargetUpdateIfExistsInTarget.isSelected()
|
632 |
); |
633 |
|
634 |
if( !this.pickerSourceFieldJoin.isEnabled() ) { |
635 |
this.pickerSourceFieldJoin.clean();
|
636 |
} |
637 |
if( !this.pickerTargetFieldJoin.isEnabled() ) { |
638 |
this.pickerTargetFieldJoin.clean();
|
639 |
} |
640 |
if( !this.chkTargetInsertIfNotExistsInTarget.isEnabled() ) { |
641 |
this.chkTargetInsertIfNotExistsInTarget.setSelected(false); |
642 |
} |
643 |
if( !this.chkTargetUpdateIfExistsInTarget.isEnabled() ) { |
644 |
this.chkTargetUpdateIfExistsInTarget.setSelected(false); |
645 |
} |
646 |
if( !this.chkTargetDeleteIfNotExiststInSource.isEnabled() ) { |
647 |
this.chkTargetDeleteIfNotExiststInSource.setSelected(false); |
648 |
} |
649 |
if( !this.pickerSourceFilter.isEnabled() ) { |
650 |
this.pickerSourceFilter.set(null); |
651 |
} |
652 |
|
653 |
} |
654 |
|
655 |
|
656 |
private void doChangeSource() { |
657 |
FeatureStore theSource = this.treeSourceTableController.getSelectedFeatureStore();
|
658 |
if( theSource==null ) { |
659 |
return;
|
660 |
} |
661 |
if(this.source != null){ |
662 |
DisposeUtils.disposeQuietly(this.source);
|
663 |
} |
664 |
this.source = theSource;
|
665 |
|
666 |
getDataSwingManager().resetExpressionBuilder(this.pickerTargetUpdateExpression.getConfig());
|
667 |
getDataSwingManager().resetExpressionBuilder(this.pickerJoinExpression.getConfig());
|
668 |
getDataSwingManager().addToExpressionBuilder(this.pickerTargetUpdateExpression.getConfig(), this.source, "source"); |
669 |
getDataSwingManager().addToExpressionBuilder(this.pickerJoinExpression.getConfig(), this.source, "source", true); |
670 |
|
671 |
this.pickerSourceFieldJoin.setFeatureType(this.source.getDefaultFeatureTypeQuietly()); |
672 |
try {
|
673 |
this.pickerSourceFieldJoin.set(this.source.getDefaultFeatureTypeQuietly().getPrimaryKey()[0]); |
674 |
} catch (Exception e) { |
675 |
//Do nothing
|
676 |
} |
677 |
|
678 |
if( this.target!=null ) { |
679 |
this.tableFields.setModel(new MyTableModel()); |
680 |
getDataSwingManager().addToExpressionBuilder(this.pickerTargetUpdateExpression.getConfig(), this.target, "target"); |
681 |
getDataSwingManager().addToExpressionBuilder(this.pickerJoinExpression.getConfig(), this.target, "target"); |
682 |
} |
683 |
} |
684 |
|
685 |
private void doChangeTarget() { |
686 |
FeatureStore theTarget = this.treeTargetTableController.getSelectedFeatureStore();
|
687 |
if( theTarget==null ) { |
688 |
return;
|
689 |
} |
690 |
if(this.target != null){ |
691 |
DisposeUtils.disposeQuietly(this.target);
|
692 |
} |
693 |
this.target = theTarget;
|
694 |
getDataSwingManager().resetExpressionBuilder(this.pickerTargetUpdateExpression.getConfig());
|
695 |
getDataSwingManager().resetExpressionBuilder(this.pickerJoinExpression.getConfig());
|
696 |
getDataSwingManager().addToExpressionBuilder(this.pickerTargetUpdateExpression.getConfig(), this.target, "target"); |
697 |
getDataSwingManager().addToExpressionBuilder(this.pickerJoinExpression.getConfig(), this.target, "target"); |
698 |
|
699 |
this.pickerTargetFieldJoin.setFeatureType(this.target.getDefaultFeatureTypeQuietly()); |
700 |
try {
|
701 |
this.pickerTargetFieldJoin.set(this.target.getDefaultFeatureTypeQuietly().getPrimaryKey()[0]); |
702 |
} catch (Exception e) { |
703 |
//Do nothing
|
704 |
} |
705 |
|
706 |
if( this.source!=null ) { |
707 |
this.tableFields.setModel(new MyTableModel()); |
708 |
getDataSwingManager().addToExpressionBuilder(this.pickerTargetUpdateExpression.getConfig(), this.source, "source"); |
709 |
getDataSwingManager().addToExpressionBuilder(this.pickerJoinExpression.getConfig(), this.source, "source", true); |
710 |
} |
711 |
} |
712 |
|
713 |
// public FeatureStore getSource() {
|
714 |
// return this.source;
|
715 |
// }
|
716 |
//
|
717 |
// public String getSourceFieldJoin() {
|
718 |
// return this.pickerSourceFieldJoin.getName();
|
719 |
// }
|
720 |
//
|
721 |
// public Expression getSourceFilter() {
|
722 |
// return this.pickerSourceFilter.get();
|
723 |
// }
|
724 |
|
725 |
// public FeatureStore getTarget() {
|
726 |
// return this.target;
|
727 |
// }
|
728 |
//
|
729 |
// public String getTargetFieldJoin() {
|
730 |
// return this.pickerTargetFieldJoin.getName();
|
731 |
// }
|
732 |
//
|
733 |
// public Expression getUpdateIfExistsInTargetCondition() {
|
734 |
// return this.pickerTargetUpdateExpression.get();
|
735 |
// }
|
736 |
//
|
737 |
// public boolean getInsertIfNotExistsTarget() {
|
738 |
// return this.chkTargetInsertIfNotExistsInTarget.isSelected();
|
739 |
// }
|
740 |
//
|
741 |
// public boolean getUpdateIfExistsInTarget() {
|
742 |
// return this.chkTargetUpdateIfExistsInTarget.isSelected();
|
743 |
// }
|
744 |
//
|
745 |
// public boolean getDeleteIfNotExiststInSource() {
|
746 |
// return this.chkTargetDeleteIfNotExiststInSource.isSelected();
|
747 |
// }
|
748 |
|
749 |
public SimpleTaskStatus getStatus() {
|
750 |
if( this.taskStatus == null ) { |
751 |
this.taskStatus = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("Copy table"); |
752 |
this.status.bind(this.taskStatus); |
753 |
} |
754 |
lblStatusLabel.setVisible(true);
|
755 |
lblStatusMessage.setVisible(true);
|
756 |
pbStatus.setVisible(true);
|
757 |
|
758 |
return this.taskStatus; |
759 |
} |
760 |
|
761 |
// public Map<String/*target*/, String/*source*/> getFields() {
|
762 |
// Map<String/*target*/, String/*source*/> fields = new HashMap<>();
|
763 |
// MyTableModel model = (MyTableModel) this.tableFields.getModel();
|
764 |
// for (MyTableModel.Row row : model) {
|
765 |
// if( StringUtils.isNotBlank(row.source) ) {
|
766 |
// fields.put(row.target, row.source);
|
767 |
// }
|
768 |
// }
|
769 |
// return fields;
|
770 |
// }
|
771 |
//
|
772 |
// public List<String/*target*/> getFieldsToUpdate() {
|
773 |
// List<String> fields = new ArrayList<>();
|
774 |
// MyTableModel model = (MyTableModel) this.tableFields.getModel();
|
775 |
// for (MyTableModel.Row row : model) {
|
776 |
// if( StringUtils.isNotBlank(row.source) && row.update) {
|
777 |
// fields.add(row.target);
|
778 |
// }
|
779 |
// }
|
780 |
// return fields;
|
781 |
// }
|
782 |
//
|
783 |
public void put(CopyTable2ProcessParameters params) { |
784 |
FeatureStore sourceStore = params.getSourceStore(); |
785 |
this.treeSourceTableController.setSelectedStore(sourceStore);
|
786 |
doChangeSource(); |
787 |
|
788 |
FeatureStore targetStore = params.getTargetStore(); |
789 |
this.treeTargetTableController.setSelectedStore(targetStore);
|
790 |
doChangeTarget(); |
791 |
|
792 |
this.pickerSourceFieldJoin.set(params.getSourceFieldForJoin());
|
793 |
this.pickerSourceFilter.set(params.getSourceFilter());
|
794 |
|
795 |
this.pickerTargetFieldJoin.set(params.getTargetFieldForJoin());
|
796 |
|
797 |
this.pickerTargetUpdateExpression.set(params.getUpdateIfExistsInTargetCondition());
|
798 |
this.chkTargetInsertIfNotExistsInTarget.setSelected(params.isInsertIfNotExistsTargetActive());
|
799 |
this.chkTargetUpdateIfExistsInTarget.setSelected(params.isUpdateIfExistsTargetActive());
|
800 |
this.chkTargetDeleteIfNotExiststInSource.setSelected(params.isDeleteIfNotExiststInSourceActive());
|
801 |
|
802 |
MyTableModel fieldsModel = new MyTableModel();
|
803 |
this.tableFields.setModel(fieldsModel);
|
804 |
for (MyTableModel.Row row : fieldsModel.rows) {
|
805 |
ProcessFieldParameters paramfield = params.get(row.getAttrname()); |
806 |
row.setAttrname(paramfield.getName()); |
807 |
Expression expression = paramfield.getExpression();
|
808 |
if (expression != null) { |
809 |
row.setExpression(expression.getPhrase()); |
810 |
} else {
|
811 |
row.setExpression(null);
|
812 |
} |
813 |
row.setUpdate(paramfield.isCopyThisFieldActive()); |
814 |
} |
815 |
|
816 |
//Options
|
817 |
fieldsModel.fireTableDataChanged(); |
818 |
|
819 |
switch (params.getEditMode()) {
|
820 |
case FeatureStore.MODE_FULLEDIT:
|
821 |
default:
|
822 |
this.rdoOptionsFulledit.setSelected(true); |
823 |
this.rdoOptionsPassthrought.setSelected(false); |
824 |
break;
|
825 |
case FeatureStore.MODE_PASS_THROUGH:
|
826 |
this.rdoOptionsFulledit.setSelected(false); |
827 |
this.rdoOptionsPassthrought.setSelected(true); |
828 |
break;
|
829 |
} |
830 |
|
831 |
this.chkOptionsBeginEditIfNeed.setSelected(params.isBeginEditIfNeed());
|
832 |
this.chkOptionsFinishAndRestarEditEach.setSelected(params.isFinishAndRestarEdit());
|
833 |
this.chkOptionsNotifyUserIfNeedBeginEditing.setSelected(params.isNotifyUserIfNeedBeginEditing());
|
834 |
this.chkOptionsFinishEditAfterTerminate.setSelected(params.isFinishEditAfterTerminate());
|
835 |
IntegerDocumentFilter.setValue(txtOptionsFinishAndRestarEditEach, params.getFinishAndRestarEditEach()); |
836 |
|
837 |
} |
838 |
|
839 |
|
840 |
public CopyTable2ProcessParameters fetch(CopyTable2ProcessParameters params) {
|
841 |
if( params == null ) { |
842 |
params = new CopyTable2ProcessParametersImpl();
|
843 |
} |
844 |
params.setSourceStore(this.source);
|
845 |
params.setSourceFilter(this.pickerSourceFilter.get());
|
846 |
params.setSourceFieldForJoin(this.pickerSourceFieldJoin.getName());
|
847 |
|
848 |
params.setTargetStore(this.target);
|
849 |
if( this.rdbUseJoinExpression.isSelected() ) { |
850 |
params.setTargetFieldForJoin(null);
|
851 |
params.setJoinExpression(this.pickerJoinExpression.get());
|
852 |
} else if( this.rdbUseJoinField.isSelected() ) { |
853 |
params.setTargetFieldForJoin(this.pickerTargetFieldJoin.getName());
|
854 |
params.setJoinExpression(null);
|
855 |
} else {
|
856 |
params.setTargetFieldForJoin(null);
|
857 |
params.setJoinExpression(null);
|
858 |
} |
859 |
|
860 |
params.setUpdateIfExistsInTargetCondition(this.pickerTargetUpdateExpression.get());
|
861 |
params.setInsertIfNotExistsTargetActive(this.chkTargetInsertIfNotExistsInTarget.isSelected());
|
862 |
params.setUpdateIfExistsTargetActive(this.chkTargetUpdateIfExistsInTarget.isSelected());
|
863 |
params.setDeleteIfNotExiststInSourceActive(this.chkTargetDeleteIfNotExiststInSource.isSelected());
|
864 |
|
865 |
fetch_fields(params); |
866 |
fetch_options(params); |
867 |
|
868 |
return params;
|
869 |
} |
870 |
|
871 |
private void fetch_fields(CopyTable2ProcessParameters params) { |
872 |
if(this.tableFields.isEditing()) { |
873 |
this.tableFields.getCellEditor().stopCellEditing();
|
874 |
} |
875 |
MyTableModel model = (MyTableModel) this.tableFields.getModel();
|
876 |
for (MyTableModel.Row row : model) {
|
877 |
Expression exp = null; |
878 |
if( org.apache.commons.lang.StringUtils.isNotBlank(row.getExpression())) {
|
879 |
exp = ExpressionUtils.createExpression(row.getExpression()); |
880 |
} |
881 |
params.add(row.getAttrname(), row.isUpdate(), exp); |
882 |
} |
883 |
} |
884 |
|
885 |
private void fetch_options(CopyTable2ProcessParameters params) { |
886 |
if( this.rdoOptionsFulledit.isSelected() ) { |
887 |
params.setEditMode(FeatureStore.MODE_FULLEDIT); |
888 |
} else {
|
889 |
params.setEditMode(FeatureStore.MODE_PASS_THROUGH); |
890 |
} |
891 |
params.setBeginEditIfNeed(this.chkOptionsBeginEditIfNeed.isSelected());
|
892 |
params.setFinishAndRestarEdit(this.chkOptionsFinishAndRestarEditEach.isSelected());
|
893 |
params.setNotifyUserIfNeedBeginEditing(this.chkOptionsNotifyUserIfNeedBeginEditing.isSelected());
|
894 |
params.setFinishEditAfterTerminate(this.chkOptionsFinishEditAfterTerminate.isSelected());
|
895 |
params.setFinishAndRestarEditEach(IntegerDocumentFilter.getValue(txtOptionsFinishAndRestarEditEach)); |
896 |
} |
897 |
|
898 |
void message(String msg) { |
899 |
this.lblStatusMessage.setText(msg);
|
900 |
// if(this.taskStatus.getCompleted() >= 100){
|
901 |
// this.pbStatus.setVisible(false);
|
902 |
// }
|
903 |
|
904 |
} |
905 |
|
906 |
void addHistory(CopyTable2ProcessParameters params) {
|
907 |
this.history.add(params);
|
908 |
} |
909 |
|
910 |
@Override
|
911 |
public ImageIcon loadImage(String imageName) { |
912 |
String name = FilenameUtils.getBaseName(imageName);
|
913 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
914 |
if (theme.exists(name)) {
|
915 |
return theme.get(name);
|
916 |
} |
917 |
URL url = CopyTable2Panel.class.getResource("images/"+name + ".png"); |
918 |
if (url == null) { |
919 |
return null; |
920 |
} |
921 |
return new ImageIcon(url); |
922 |
} |
923 |
|
924 |
} |