Revision 3319 org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.swing/org.gvsig.vcsgis.swing.impl/src/main/java/org/gvsig/vcsgis/swing/impl/changes/LocalChangesController.java
LocalChangesController.java | ||
---|---|---|
28 | 28 |
import java.awt.event.KeyAdapter; |
29 | 29 |
import java.awt.event.KeyEvent; |
30 | 30 |
import java.sql.Timestamp; |
31 |
import java.util.ArrayList; |
|
31 | 32 |
import java.util.Date; |
32 | 33 |
import java.util.HashMap; |
33 | 34 |
import java.util.HashSet; |
34 | 35 |
import java.util.Iterator; |
35 | 36 |
import java.util.List; |
36 | 37 |
import java.util.Map; |
37 |
import java.util.List; |
|
38 | 38 |
import java.util.Set; |
39 | 39 |
import java.util.logging.Level; |
40 | 40 |
import java.util.logging.Logger; |
41 | 41 |
import javax.json.JsonObject; |
42 | 42 |
import javax.swing.JButton; |
43 | 43 |
import javax.swing.JLabel; |
44 |
import javax.swing.JList; |
|
44 | 45 |
import javax.swing.JOptionPane; |
45 | 46 |
import javax.swing.JTable; |
46 | 47 |
import javax.swing.JTextField; |
... | ... | |
52 | 53 |
import javax.swing.event.TableModelListener; |
53 | 54 |
import javax.swing.table.DefaultTableCellRenderer; |
54 | 55 |
import javax.swing.table.TableModel; |
56 |
import org.apache.commons.collections.CollectionUtils; |
|
55 | 57 |
import org.apache.commons.lang3.StringUtils; |
56 | 58 |
import org.apache.commons.lang3.mutable.MutableObject; |
57 | 59 |
import org.gvsig.featureform.swing.CreateJFeatureFormException; |
... | ... | |
92 | 94 |
import org.gvsig.vcsgis.swing.VCSGisSwingServices; |
93 | 95 |
import static org.gvsig.vcsgis.swing.VCSGisSwingServices.HIGHLIGHT_WORKSPACE; |
94 | 96 |
import static org.gvsig.vcsgis.swing.VCSGisSwingServices.HIGHLIGHT_WORKSPACE_PREVIOUS; |
97 |
import org.gvsig.vcsgis.swing.impl.VCSGisEntitySelectorController; |
|
95 | 98 |
import org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons; |
96 | 99 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.cleanHighligthed; |
97 | 100 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.notInSwingThreadInvokeLater; |
... | ... | |
131 | 134 |
private TableModelListener tableModelListener; |
132 | 135 |
private boolean dissabledUncheckAllByEntities; |
133 | 136 |
private final JButton btnLocalCleanHighlighted; |
137 |
private final JTextField txtLocalTablesFilter; |
|
138 |
private final JButton btnLocalTable; |
|
139 |
private final JList lstLocalTables; |
|
140 |
private VCSGisEntitySelectorController entitySelector; |
|
134 | 141 |
|
135 | 142 |
public LocalChangesController( |
136 | 143 |
VCSGisJChangesImpl context, |
... | ... | |
150 | 157 |
JButton btnLocalZoom, |
151 | 158 |
JButton btnLocalCenter, |
152 | 159 |
JButton btnLocalCleanHighlighted, |
153 |
JLabel lblLocalChangesCount |
|
154 |
|
|
160 |
JLabel lblLocalChangesCount, |
|
161 |
JTextField txtLocalTablesFilter, |
|
162 |
JButton btnLocalTable, |
|
163 |
JList lstLocalTables |
|
155 | 164 |
) { |
156 | 165 |
this.dissabledUncheckAllByEntities = false; |
157 | 166 |
|
... | ... | |
173 | 182 |
this.btnLocalCenter = btnLocalCenter; |
174 | 183 |
this.btnLocalCleanHighlighted = btnLocalCleanHighlighted; |
175 | 184 |
this.lblLocalChangesCount= lblLocalChangesCount; |
185 |
|
|
186 |
this.txtLocalTablesFilter = txtLocalTablesFilter; |
|
187 |
this.btnLocalTable = btnLocalTable; |
|
188 |
this.lstLocalTables = lstLocalTables; |
|
176 | 189 |
|
177 | 190 |
this.entitiesToUnCheckAll = new HashSet<>(); |
178 | 191 |
|
... | ... | |
196 | 209 |
this.btnLocalCleanHighlighted.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
197 | 210 |
|
198 | 211 |
this.workspacePicker.addChangeListener((ChangeEvent e) -> { |
212 |
doReloadTables(); |
|
199 | 213 |
doUpdateTableLocalChanges(); |
200 |
doReloadRepositoryEntities(); |
|
214 |
// doReloadRepositoryEntities();
|
|
201 | 215 |
}); |
202 | 216 |
|
217 |
this.entitySelector = VCSGisEntitySelectorController.create( |
|
218 |
this.lstLocalTables, |
|
219 |
txtLocalTablesFilter, |
|
220 |
btnLocalTable |
|
221 |
); |
|
222 |
this.entitySelector.setViewFilter(VCSGisEntitySelectorController.LOCAL_ENTITIES); |
|
223 |
this.entitySelector.setFilter(VCSGisEntitySelectorController.LOCAL_ENTITIES); |
|
224 |
this.entitySelector.setChecksEnabled(true); |
|
225 |
this.entitySelector.addChangeListener((ChangeEvent e) -> { |
|
226 |
doUpdateTableLocalChanges(); |
|
227 |
// doUpdateComponents(); |
|
228 |
}); |
|
229 |
this.entitySelector.getCheckedModel().addListSelectionListener((ListSelectionEvent e) -> { |
|
230 |
doUpdateTableLocalChanges(); |
|
231 |
doUpdateComponents(); |
|
232 |
}); |
|
233 |
|
|
203 | 234 |
this.tblLocalChanges.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
204 | 235 |
|
205 | 236 |
this.tblLocalChanges.addKeyListener(new KeyAdapter() { |
... | ... | |
452 | 483 |
this.context.setVisibleStatus(context.processing); |
453 | 484 |
VCSGisWorkspace ws = getWorkspace(); |
454 | 485 |
this.context.updateEntitiesFromRepository(false); |
486 |
this.entitySelector.setEnabled(!context.processing); |
|
455 | 487 |
this.effectiveDatePicker.setEnabled(!context.processing); |
456 | 488 |
this.workspacePicker.setEnabled(!context.processing); |
457 | 489 |
this.btnLocalCheckAll.setEnabled(!context.processing && changes!=null && changes.size64()>0); |
458 | 490 |
this.btnLocalUnCheckAll.setEnabled(!context.processing && changes!=null && changes.size64()>0); |
459 |
this.btnLocalRefresh.setEnabled(!context.processing && changes!=null); |
|
491 |
List<VCSGisEntity> checkedEntities = entitySelector.getCheckedEntities(); |
|
492 |
this.btnLocalRefresh.setEnabled(!context.processing && changes!=null && CollectionUtils.isNotEmpty(checkedEntities)); |
|
460 | 493 |
this.btnLocalRevert.setEnabled(ws!=null && |
461 | 494 |
!context.processing && |
462 | 495 |
changes!=null && |
463 | 496 |
changes.size64()>0 && |
464 | 497 |
entitiesWithChanges != null && |
498 |
CollectionUtils.isNotEmpty(checkedEntities) && |
|
465 | 499 |
!entitiesWithChanges.isEmpty() |
466 | 500 |
); |
467 | 501 |
this.btnLocalRevert.setVisible(true); |
... | ... | |
469 | 503 |
!context.processing && |
470 | 504 |
changes!=null && |
471 | 505 |
!this.changes.isSelectionEmpty() && |
472 |
ws.canCommit() |
|
506 |
CollectionUtils.isNotEmpty(checkedEntities) && |
|
507 |
ws.canCommit(null, getEntityCodes(checkedEntities)) |
|
473 | 508 |
); |
474 | 509 |
//Show form |
475 | 510 |
boolean enableShowForm = false; |
... | ... | |
496 | 531 |
|
497 | 532 |
} |
498 | 533 |
|
534 |
public void doReloadTables() { |
|
535 |
this.entitySelector.setWorkspace(this.getWorkspace()); |
|
536 |
} |
|
537 |
|
|
538 |
|
|
499 | 539 |
public void doUpdateTableLocalChanges() { |
500 | 540 |
if( context.processing ) { |
501 | 541 |
return; |
... | ... | |
506 | 546 |
if(ws != null){ |
507 | 547 |
|
508 | 548 |
entitiesWithChanges = ws.getEntitiesWithChanges(); |
549 |
|
|
550 |
List<VCSGisEntity> checkedEntities = entitySelector.getCheckedEntities(); |
|
551 |
if(CollectionUtils.isEmpty(checkedEntities)) { |
|
552 |
localChangesTableModel = new ChangesTableModel(ws); |
|
553 |
this.tblLocalChanges.setModel(localChangesTableModel); |
|
554 |
return; |
|
555 |
} |
|
509 | 556 |
|
510 |
changes = ws.getLocalChanges(); |
|
557 |
changes = ws.getLocalChanges(checkedEntities); |
|
558 |
|
|
511 | 559 |
localChangesTableModel = new ChangesTableModel(changes, ws); |
512 | 560 |
this.tblLocalChanges.setModel(localChangesTableModel); |
513 | 561 |
|
... | ... | |
523 | 571 |
} |
524 | 572 |
}); |
525 | 573 |
} |
526 |
|
|
527 | 574 |
this.tableModelListener = null; |
528 | 575 |
localChangesTableModel.addTableModelListener(getTableModelListener()); |
529 | 576 |
context.message(i18n.getTranslation( |
530 |
"_Workspace_changes_list_updated",
|
|
531 |
new String[] { String.valueOf(changes.size64()) }
|
|
532 |
)
|
|
577 |
"_Workspace_changes_list_updated", |
|
578 |
new String[]{String.valueOf(changes.size64())}
|
|
579 |
) |
|
533 | 580 |
); |
534 | 581 |
this.lblLocalChangesCount.setText(String.valueOf(changes.size64())); |
535 | 582 |
} |
536 | 583 |
context.doUpdateComponents(); |
537 | 584 |
} |
538 | 585 |
|
539 |
private void doReloadRepositoryEntities() { |
|
540 |
VCSGisWorkspace ws = this.getWorkspace(); |
|
541 |
if (ws != null) { |
|
542 |
Thread task = new Thread(() -> { |
|
543 |
try { |
|
544 |
context.processing = true; |
|
545 |
context.doUpdateComponents(); |
|
546 |
ws.reloadRepositoryEntities(null); |
|
547 |
} finally { |
|
548 |
context.processing = false; |
|
549 |
context.doUpdateComponents(); |
|
550 |
} |
|
551 |
}, "VCSGisReloadRepositoryEntities"); |
|
552 |
|
|
553 |
context.processing = true; |
|
554 |
context.doUpdateComponents(); |
|
555 |
task.start(); |
|
556 |
} |
|
557 |
} |
|
558 |
|
|
559 | 586 |
private TableModelListener getTableModelListener() { |
560 | 587 |
if(tableModelListener == null){ |
561 | 588 |
tableModelListener = (TableModelEvent e) -> { |
... | ... | |
605 | 632 |
|
606 | 633 |
VCSGisWorkspace ws = getWorkspace(); |
607 | 634 |
if( ws==null ) { |
608 |
// TODO: Mensaje al usuario |
|
635 |
// TODO: Mensaje al usuario ??
|
|
609 | 636 |
return; |
610 | 637 |
} |
638 |
List<VCSGisEntity> entities = entitySelector.getCheckedEntities(); |
|
639 |
List<String> entityCodes = getEntityCodes(entities); |
|
640 |
if( CollectionUtils.isEmpty(entities)){ |
|
641 |
// TODO: Mensaje al usuario ?? |
|
642 |
return; |
|
643 |
} |
|
611 | 644 |
this.context.updateEntitiesFromRepository(false); |
612 | 645 |
MutableObject<String> message = new MutableObject<>(); |
613 |
if( !ws.canCommit(message) ) { |
|
646 |
if( !ws.canCommit(message, entityCodes) ) {
|
|
614 | 647 |
dialogs.messageDialog( |
615 | 648 |
i18n.getTranslation("_Cant_commit") + "\n" + message.getValue(), |
616 | 649 |
i18n.getTranslation("_Commit"), |
... | ... | |
621 | 654 |
Timestamp effectiveDate = new Timestamp(effectiveDatePicker.get().getTime()); |
622 | 655 |
this.tblLocalChanges.setModel(new ChangesTableModel(ws)); |
623 | 656 |
|
624 |
List<VCSGisEntity> entities = ws.getEntitiesOfLocalChanges(); |
|
625 | 657 |
Thread task = new Thread(() -> { |
626 | 658 |
try { |
627 | 659 |
context.processing = true; |
... | ... | |
635 | 667 |
return; |
636 | 668 |
} |
637 | 669 |
int r = ws.commit( |
670 |
entityCodes, |
|
671 |
null, |
|
638 | 672 |
effectiveDate, |
639 | 673 |
this.txtLocalComment.getText(), |
640 | 674 |
this.context.getTaskStatusController().getSimpleTaskStatus() |
... | ... | |
701 | 735 |
if( commitStatus ==ERR_OK) { |
702 | 736 |
this.context.setVisibleStatus(false); |
703 | 737 |
} |
738 |
doReloadTables(); |
|
704 | 739 |
context.updateLocalChangesTable(); |
705 | 740 |
} |
706 | 741 |
|
... | ... | |
717 | 752 |
context.processing = true; |
718 | 753 |
context.doUpdateComponents(); |
719 | 754 |
List<VCSGisWorkspaceEntity> entities = ws.getEntitiesWithChanges(); |
755 |
List<String> selectedEntityCodes = getEntityCodes(entitySelector.getCheckedEntities()); |
|
720 | 756 |
int r = ERR_OK; |
721 |
if(!entities.isEmpty()){ |
|
757 |
if(!entities.isEmpty() && CollectionUtils.isNotEmpty(selectedEntityCodes)){
|
|
722 | 758 |
for (VCSGisWorkspaceEntity entity : entities) { |
723 |
r = ws.revert(entity.getEntityCode(), |
|
724 |
this.context.getTaskStatusController().getSimpleTaskStatus() |
|
725 |
); |
|
759 |
if(selectedEntityCodes.contains(entity.getEntityCode())){ |
|
760 |
r = ws.revert(entity.getEntityCode(), |
|
761 |
this.context.getTaskStatusController().getSimpleTaskStatus() |
|
762 |
); |
|
763 |
} |
|
726 | 764 |
if(r != ERR_OK){ |
727 | 765 |
break; |
728 | 766 |
} |
... | ... | |
751 | 789 |
FeatureStore store = getWorkspace().getFeatureStore(entity.getEntityName()); |
752 | 790 |
refreshDocument(store); |
753 | 791 |
} |
792 |
doReloadTables(); |
|
754 | 793 |
context.updateLocalChangesTable(); |
755 | 794 |
} |
756 | 795 |
|
... | ... | |
823 | 862 |
} |
824 | 863 |
|
825 | 864 |
} |
865 |
|
|
866 |
private List<String> getEntityCodes(List<VCSGisEntity> entities) { |
|
867 |
List<String> res = new ArrayList(); |
|
868 |
for (VCSGisEntity entity : entities) { |
|
869 |
res.add(entity.getEntityCode()); |
|
870 |
} |
|
871 |
return res; |
|
872 |
} |
|
873 |
|
|
826 | 874 |
} |
Also available in: Unified diff