Revision 9524 org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.swing/org.gvsig.online.swing.impl/src/main/java/org/gvsig/online/swing/impl/changes/LocalChangesController.java

View differences:

LocalChangesController.java
53 53
import org.gvsig.featureform.swing.JFeatureForm;
54 54
import org.gvsig.fmap.dal.feature.Feature;
55 55
import org.gvsig.fmap.dal.feature.FeatureStore;
56
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
56 57
import org.gvsig.fmap.dal.swing.DALSwingLocator;
57 58
import org.gvsig.fmap.dal.swing.DataSwingManager;
58 59
import org.gvsig.fmap.geom.Geometry;
......
68 69
import static org.gvsig.online.lib.api.OnlineManager.STATE_DISCONNECTED;
69 70
import org.gvsig.online.lib.api.OnlineRuntimeException;
70 71
import org.gvsig.online.lib.api.workingcopy.OnlineChange;
72
import org.gvsig.online.lib.api.workingcopy.OnlineChanges;
71 73
import org.gvsig.online.lib.api.workingcopy.OnlineEntity;
72 74
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy;
73 75
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChange;
......
79 81
import org.gvsig.online.swing.impl.OnlineSwingCommons;
80 82
import static org.gvsig.online.swing.impl.OnlineSwingCommons.cleanHighligthed;
81 83
import static org.gvsig.online.swing.impl.OnlineSwingCommons.notInSwingThreadInvokeLater;
82
import static org.gvsig.online.swing.impl.OnlineSwingCommons.refreshDocument;
84
import static org.gvsig.online.swing.impl.OnlineSwingCommons.refreshDocumentByParams;
83 85
import static org.gvsig.online.swing.impl.OnlineSwingCommons.showAuthenticationErrors;
84 86
import org.gvsig.tools.ToolsLocator;
85 87
import org.gvsig.tools.dispose.DisposeUtils;
......
91 93
import org.gvsig.tools.swing.api.pickercontroller.PickerController;
92 94
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
93 95
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
96
import org.gvsig.tools.task.SimpleTaskStatus;
94 97
import org.gvsig.tools.task.UserCancelTaskException;
95 98
import org.slf4j.Logger;
96 99
import org.slf4j.LoggerFactory;
97
import org.gvsig.online.lib.api.workingcopy.OnlineChanges;
98 100

  
99 101
/**
100 102
 *
......
114 116
    private final JButton btnLocalUnCheckAll;
115 117
    private final JButton btnLocalShowForm;
116 118
    private final JButton btnLocalRefresh;
117
    private final JButton btnLocalCommit;
119
    private final JButton btnLocalUpload;
118 120
    private final JButton btnLocalRevert;
119 121
    private final PickerController<OnlineWorkingcopy> workspacePicker;    
120 122
    private final OnlineJChangesImpl context;
......
124 126
    private final JLabel lblLocalChangesCount;
125 127

  
126 128
    private OnlineChanges<OnlineWorkingcopyChange> changes;
127
    private LocalChangesTableModel localChangesTableModel;
128 129
    private List<OnlineEntity> entitiesWithSelectedChanges = null;
129 130

  
130 131
    private final Set<String> entitiesToUnCheckAll;
......
141 142
        JButton btnLocalUnCheckAll,
142 143
        JButton btnLocalShowForm,
143 144
        JButton btnLocalRefresh,
144
        JButton btnLocalCommit,
145
        JButton btnLocalUpload,
145 146
        JButton btnLocalRevert,
146 147
        JButton btnLocalZoom,
147 148
        JButton btnLocalCenter,
......
158 159
        this.tblLocalChanges = tblLocalChanges;
159 160
        this.btnLocalCheckAll = btnLocalCheckAll;
160 161
        
161
        this.btnLocalCommit = btnLocalCommit;
162
        this.btnLocalUpload = btnLocalUpload;
162 163
        this.btnLocalRefresh = btnLocalRefresh;
163 164
        this.btnLocalRevert = btnLocalRevert;
164 165
        this.btnLocalShowForm = btnLocalShowForm;
......
183 184
//        this.btnLocalCheckAllEntities.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
184 185
//        this.btnLocalUnCheckAllEntities.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
185 186
        this.btnLocalCheckAll.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
186
        this.btnLocalCommit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
187
        this.btnLocalUpload.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
187 188
        this.btnLocalRefresh.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
188 189
        this.btnLocalRevert.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
189 190
        this.btnLocalShowForm.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
......
234 235
//            }
235 236
//        });
236 237

  
238
        this.tblLocalChanges.setModel(new LocalChangesTableModel());
239

  
237 240
        this.tblLocalChanges.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
238 241

  
239 242
        this.tblLocalChanges.addKeyListener(new KeyAdapter() {
......
269 272
            doShowForm();
270 273
        });
271 274

  
272
        this.btnLocalCommit.addActionListener((ActionEvent e) -> {
273
            doCommit();
275
        this.btnLocalUpload.addActionListener((ActionEvent e) -> {
276
            doUpload();
274 277
        });
275 278

  
276 279
        this.btnLocalRevert.addActionListener((ActionEvent e) -> {
......
325 328
//        swingManager.translate(this.btnLocalCheckAllEntities);
326 329
//        swingManager.translate(this.btnLocalUnCheckAllEntities);
327 330
        swingManager.translate(this.btnLocalCheckAll);
328
        swingManager.translate(this.btnLocalCommit);
331
        swingManager.translate(this.btnLocalUpload);
329 332
        swingManager.translate(this.btnLocalRefresh);
330 333
        swingManager.translate(this.btnLocalRevert);
331 334
        swingManager.translate(this.btnLocalShowForm);
......
541 544
            this.btnLocalRevert.setVisible(true);
542 545
            if (ws != null
543 546
                    && !context.processing
544
                    && changes != null
547
                    && !changesIsEmpty
545 548
                    && !this.changes.isSelectionEmpty()
546 549
                    && CollectionUtils.isNotEmpty(checkedEntities)
547 550
                    && entitiesWithSelectedChanges != null
......
549 552
                    && !isSelectionFromEntitiesEmpty
550 553
                    ) {
551 554
                MutableObject<String> msg = new MutableObject<>();
552
                if( areConflictEntities(checkedEntities) ) {
555
                if( areConflictCheckedEntities() ) {
553 556
                    context.alert("_There_are_selected_entities_that_have_conflicts");
554
                    this.btnLocalCommit.setEnabled(false);
555
                    LOGGER.info("Can't enable commit (1.2). There are selected entities that have conflicts.");
557
                    this.btnLocalUpload.setEnabled(false);
558
                    LOGGER.info("Can't enable upload (1.2). There are selected entities that have conflicts.");
556 559
                } else if( areCorruptOrDisconnectedEntities(checkedEntities) ) {
557 560
                    context.alert("_There_are_selected_corrupted_or_disconnected_entities");
558
                    this.btnLocalCommit.setEnabled(false);
559
                    LOGGER.info("Can't enable commit (1.2). There are selected corrputed or diconnected entities.");
561
                    this.btnLocalUpload.setEnabled(false);
562
                    LOGGER.info("Can't enable upload (1.2). There are selected corrputed or diconnected entities.");
560 563
                } else if (!ws.canUpload(msg, getEntityCodes(checkedEntities))) {
561 564
                    context.alert(msg.getValue());
562
                    this.btnLocalCommit.setEnabled(false);
563
                    LOGGER.info("Can't enable commit (1). "+ msg.getValue());
565
                    this.btnLocalUpload.setEnabled(false);
566
                    LOGGER.info("Can't enable upload (1). "+ msg.getValue());
564 567
                } else {
565
                    this.btnLocalCommit.setEnabled(true);
568
                    this.btnLocalUpload.setEnabled(true);
566 569
                }
567 570

  
568 571
            } else {
569 572
                try {
570 573
                    if( CollectionUtils.isEmpty(checkedEntities) ) {
571 574
                        this.context.message("_Select_tables_to_view_changes");
572
                        LOGGER.info("Can't enable commit (2).");
573
                    } else if( changes == null || this.changes.isSelectionEmpty() ) {
574
                        this.context.message("_Select_the_changes_to_commit");
575
                        LOGGER.info("Can't enable commit (3).");
575
                        LOGGER.info("Can't enable upload (2).");
576
                    } else if( changesIsEmpty || this.changes.isSelectionEmpty() ) {
577
                        this.context.message("_Select_the_changes_to_upload");
578
                        LOGGER.info("Can't enable upload (3).");
576 579
                    } else if( entitiesWithSelectedChanges == null || entitiesWithSelectedChanges.isEmpty() ) {
577 580
                        this.context.message("_Cant_locate_the_tables_related_to_changes");
578
                        LOGGER.info("Can't enable commit (4).");
581
                        LOGGER.info("Can't enable upload (4).");
579 582
                    } else if( isSelectionFromEntitiesEmpty ) { 
580 583
                        this.context.message("_Cant_locate_changes_in_selected_tables");
581
                        LOGGER.info("Can't enable commit (5).");
584
                        LOGGER.info("Can't enable upload (5).");
582 585
                    } else {
583
                        LOGGER.info("Can't enable commit (6).");
586
                        LOGGER.info("Can't enable upload (6).");
584 587
                    }
585 588
                } catch(Exception ex) {
586
                    LOGGER.info("Can't enable commit (7).");
589
                    LOGGER.info("Can't enable upload (7).");
587 590
                }
588
                this.btnLocalCommit.setEnabled(false);
591
                this.btnLocalUpload.setEnabled(false);
589 592
            }
590 593
            //Show form
591 594
            boolean enableShowForm = false;
......
601 604

  
602 605
            Geometry geom = getGeometryOfSelectedChange();
603 606
            Geometry originalGeom = getOriginalGeometryOfSelectedChange();
604
            this.btnLocalCenter.setEnabled(!context.processing); // && (geom != null || originalGeom != null));
607
            this.btnLocalCenter.setEnabled(!context.processing && (geom != null || originalGeom != null));
605 608
            this.btnLocalHighlight.setEnabled(!context.processing && (geom != null || originalGeom != null));
606
            this.btnLocalZoom.setEnabled(!context.processing); // && (geom != null || originalGeom != null));
609
            this.btnLocalZoom.setEnabled(!context.processing && (geom != null || originalGeom != null));
607 610
            this.btnLocalCleanHighlighted.setEnabled(!context.processing);
608 611
        } catch (OnlineRuntimeException e1) {
609 612
            LOGGER.warn("Can't updating components.", e1);
......
650 653

  
651 654
            List<OnlineEntity> checkedEntities = context.getEntitySelector().getCheckedEntities();
652 655
            if(CollectionUtils.isEmpty(checkedEntities)) {
653
                localChangesTableModel = new LocalChangesTableModel(ws);
656
                LocalChangesTableModel localChangesTableModel = new LocalChangesTableModel(ws);
654 657
                this.tblLocalChanges.setModel(localChangesTableModel);
655 658
                return;
656 659
            }
657 660
            
658 661
            changes = ws.getLocalChanges(checkedEntities);
659 662

  
660
            localChangesTableModel = new LocalChangesTableModel(changes, ws);
663
            LocalChangesTableModel localChangesTableModel = new LocalChangesTableModel(changes, ws);
661 664
            this.tblLocalChanges.setModel(localChangesTableModel);
662 665

  
663 666
            int columns = this.tblLocalChanges.getColumnModel().getColumnCount();
......
730 733

  
731 734
    }
732 735
    
733
    private void doCommit() {
736
    private void doUpload() {
734 737
        I18nManager i18n = ToolsLocator.getI18nManager();
735 738
        ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
736 739
        
737 740
        OnlineWorkingcopy ws = getUndisposableWorkspace();
738 741
        if( ws==null ) {
739
            // TODO: Mensaje al usuario ??
742
            LOGGER.warn("Can't do upload action because can't get undisposable workingcopy");
740 743
            return;
741 744
        }
742 745
        List<OnlineEntity> entities = context.getEntitySelector().getCheckedEntities();
......
745 748
            // TODO: Mensaje al usuario ??
746 749
            return;
747 750
        }
748
//        this.context.updateEntitiesFromRepository(false);
751
        for (OnlineEntity entity : entities) {
752
            if(ws.isSynchOutdated(entity)) {
753
                int n = dialogs.confirmDialog(
754
                    i18n.getTranslation("_Outdated_synchronization")
755
                        + "\n" 
756
                        + i18n.getTranslation("_Do_you_want_to_continue_anyway"),
757
                    i18n.getTranslation("_Upload"), 
758
                    JOptionPane.YES_NO_OPTION,
759
                    JOptionPane.QUESTION_MESSAGE
760
                );
761
                if(n!=JOptionPane.YES_OPTION) {
762
                    return;
763
                }
764
            }
765
        }
766

  
749 767
        MutableObject<String> message = new MutableObject<>();
750 768
        if( !ws.canUpload(message, entityCodes) ) {
751 769
            dialogs.messageDialog(
752
                    i18n.getTranslation("_Cant_commit") + "\n" + message.getValue(),
753
                    i18n.getTranslation("_Commit"), 
770
                    i18n.getTranslation("_Cant_upload") + "\n" + message.getValue(),
771
                    i18n.getTranslation("_Upload"), 
754 772
                    JOptionPane.WARNING_MESSAGE
755 773
            );
756 774
            return;
757 775
        }
758 776
        this.tblLocalChanges.setModel(new LocalChangesTableModel(ws));
759 777
        
760
//        List<VCSGisTopologyPlanStatus> topologicPlanStatusList = new ArrayList<>();
761
//        
762
//        Thread task = new Thread(() -> {
763
//            try {
764
//                context.processing = true;
765
//                context.doUpdateComponents();
766
//                if(!existsAllTopologyPlansLocally(ws, entities)) {
767
//                    ws.updateTopologyPlansFromRepository(null);
768
//                }
769
//                if( !executeTopologyPlans(ws, entities, topologicPlanStatusList) ) {
770
//                    dialogs.messageDialog(
771
//                            i18n.getTranslation("_Cant_pass_topology_plans"),
772
//                            i18n.getTranslation("_Commit"), 
773
//                            JOptionPane.WARNING_MESSAGE
774
//                    );
775
//                    return;
776
//                }
777
//                int r = ws.commit(
778
//                        entityCodes,
779
//                        null,
780
//                        effectiveDate, 
781
//                        this.txtLocalComment.getText(), 
782
//                        this.context.getTaskStatusController().getSimpleTaskStatus(),
783
//                        topologicPlanStatusList
784
//                );
785
//                if(r==OnlineManager.ERR_TOPOLOGYPLAN_OUTDATED){
786
//                    ws.updateTopologyPlansFromRepository(null);
787
//                }
788
//                doPostCommit(r);
789
//            } catch(UserCancelledException ex) {
790
//                LOGGER.warn("User cancelled");
791
//            } finally {
792
//                context.processing = false;
793
//                context.doUpdateComponents();
794
//            }
795
//        }, "VCSGisCommit");
796
//
797
//        context.processing = true;
798
//        context.doUpdateComponents();
799
//        task.start();
778
        Thread task = new Thread(() -> {
779
            try {
780
                context.processing = true;
781
                context.doUpdateComponents();
782
                int r = ws.upload(entityCodes, SimpleTaskStatus.FAKE_STATUS);
783

  
784
                doPostUpload(r, entityCodes);
785
            } finally {
786
                context.processing = false;
787
                context.doUpdateComponents();
788
            }
789
        }, "OnlineUpload");
790

  
791
        context.processing = true;
792
        context.doUpdateComponents();
793
        task.start();
800 794
    }
801 795

  
802
    private void doPostCommit(int commitStatus) {
803
        if (notInSwingThreadInvokeLater(() -> {doPostCommit(commitStatus);})) {
796
    private void doPostUpload(int uploadStatus, List<String> entityCodes) {
797
        if (notInSwingThreadInvokeLater(() -> {doPostUpload(uploadStatus, entityCodes);})) {
804 798
            return;
805 799
        }
806
        switch (commitStatus) {
800
        OnlineWorkingcopy ws = getUndisposableWorkspace();
801
        if( ws==null ) {
802
            LOGGER.warn("Can't do post upload action because can't get undisposable workingcopy");
803
            return;
804
        }
805
        Set<JDBCStoreParameters> params = new HashSet();
806
        for (String entityCode : entityCodes) {
807
            params.add(ws.getFeatureStoreParameters(ws.getEntity(entityCode).getEntityName()));
808
        }
809
        OnlineSwingLocator.getOnlineSwingManager().getDefaultServices().refreshDocumentByParams(params);
810

  
811
        switch (uploadStatus) {
807 812
            case ERR_OK:
808 813
                this.context.setVisibleStatus(false);
809 814
                break;
810 815
            default:
811
                showAuthenticationErrors("_VCS_Commit", commitStatus);
816
                showAuthenticationErrors("_Online_Upload", uploadStatus);
812 817
                break;
813 818
        }
814 819
        context.getEntitySelector().reloadEntities();
815 820
        context.updateLocalChangesTable();
816 821
        cleanHighligthed();
822
        context.message("_Online_upload_finished");
817 823
    }
818 824

  
819 825
    private void doRevert() {
......
865 871
            this.context.setVisibleStatus(false);
866 872
        }
867 873
        for (OnlineEntity entity : entities) {
868
            FeatureStore store = getUndisposableWorkspace().getFeatureStore(entity.getEntityName());
869
            refreshDocument(store);
874
            JDBCStoreParameters params = getUndisposableWorkspace().getFeatureStoreParameters(entity.getEntityName());
875
            refreshDocumentByParams(params);
870 876
        }
871 877
        context.updateLocalChangesTable();
872 878
        cleanHighligthed();
......
1209 1215
        if( workspace==null ) {
1210 1216
            return;
1211 1217
        }
1212
        Set<String> commitEntities = new HashSet<>();
1218
        Set<String> uploadEntities = new HashSet<>();
1213 1219
        Collection<OnlineEntity> entities = context.getEntitySelector().getEntities();
1214 1220
        for (OnlineEntity entity : entities) {
1215 1221
            if (workspace.existsInWorkspace(entity)) {
......
1218 1224
                    case OnlineManager.STATE_LOCAL_MODIFIED:
1219 1225
                    case OnlineManager.STATE_LOCAL_NEW:
1220 1226
                    default:
1221
                        commitEntities.add(entity.getEntityCode());
1227
                        uploadEntities.add(entity.getEntityCode());
1222 1228
                        break;
1223 1229
                    case OnlineManager.STATE_LOCAL_UNMODIFIED:
1224 1230
                    case OnlineManager.STATE_REMOTE_NEW:
......
1232 1238
                }
1233 1239
            }
1234 1240
        }
1235
        context.getEntitySelector().setCheck(commitEntities, true);
1241
        context.getEntitySelector().setCheck(uploadEntities, true);
1236 1242
    }
1237 1243

  
1238 1244
    private boolean areCorruptOrDisconnectedEntities(List<OnlineEntity> entities) {
......
1249 1255
        return false;
1250 1256
    }
1251 1257

  
1252
    private boolean areConflictEntities(List<OnlineEntity> entities) {
1253
        for (OnlineEntity entity : entities) {
1254
            if( entity instanceof OnlineEntity ) {
1255
                OnlineEntity lentity = (OnlineEntity) entity;
1256
                int maskState = lentity.getState();
1257
                if( (maskState & STATE_CONFLICT)  == STATE_CONFLICT) {
1258
                    return true;
1259
                }
1260
            }
1261
        }
1262
        return false;
1258
    private boolean areConflictCheckedEntities() {
1259
        return context.hasRemotesChanges();
1263 1260
    }
1261
    
1262
    public int getSelectedRowCount() {
1263
        return this.tblLocalChanges.getSelectedRowCount();
1264
    }
1264 1265
}

Also available in: Unified diff