Revision 5675

View differences:

org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.swing/org.gvsig.vcsgis.swing.impl/src/main/java/org/gvsig/vcsgis/swing/impl/downloadworkspace/DownloadWorkingcopyImpl.java
38 38
import org.apache.commons.lang3.BooleanUtils;
39 39
import org.apache.commons.lang3.StringUtils;
40 40
import org.apache.http.client.utils.URIBuilder;
41
import org.gvsig.fmap.dal.DALLocator;
42
import org.gvsig.fmap.dal.DataManager;
41 43
import org.gvsig.fmap.dal.store.h2.H2SpatialUtils;
44
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
42 45
import org.gvsig.tools.ToolsLocator;
43 46
import org.gvsig.tools.dispose.DisposeUtils;
44 47
import org.gvsig.tools.folders.FoldersManager;
......
486 489
        ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
487 490
        I18nManager i18n = ToolsLocator.getI18nManager();
488 491
        FoldersManager foldersManager = ToolsLocator.getFoldersManager();
489

  
492
        VCSGisManager manager = VCSGisLocator.getVCSGisManager();
493
        VCSGisWorkspace ws = null;
494
        
490 495
        File targetZip_file = this.getTargetZipFile();
491 496
        URI targetZip_uri = this.getTargetZipURI();
492 497
        URL url = this.getDownloadURL();
......
512 517
            }
513 518
            return -1;
514 519
        }
515
        if (changes_in_localcopy(targetZip_file)) {
516
            int n = dialogs.confirmDialog(
517
                    i18n.getTranslation("A local working copy with changes already exists. If you continue your changes will be lost. Do you want to continue with the download?"),
518
                    i18n.getTranslation("_VCS_Download_workingcopy"),
519
                    JOptionPane.YES_NO_OPTION,
520
                    JOptionPane.WARNING_MESSAGE
521
            );
522
            if (n != JOptionPane.YES_OPTION) {
523
                return VCSGisManager.ERR_USER_CANCELLED;
520

  
521
        try {
522
            ws = manager.openWorkspace(H2SpatialUtils.normalizeH2File(targetZip_file));
523
            if ( ws!=null ) {
524
                if( ws.hasLocalChanges(null) ) {
525
                    int n = dialogs.confirmDialog(
526
                            i18n.getTranslation("A local working copy with changes already exists. If you continue your changes will be lost. Do you want to continue with the download?"),
527
                            i18n.getTranslation("_VCS_Download_workingcopy"),
528
                            JOptionPane.YES_NO_OPTION,
529
                            JOptionPane.WARNING_MESSAGE
530
                    );
531
                    if (n != JOptionPane.YES_OPTION) {
532
                        return VCSGisManager.ERR_USER_CANCELLED;
533
                    }
534
                }
535
                JDBCServerExplorer explorer = ws.getExplorer();
536
                explorer.execute("SHUTDOWN");
524 537
            }
538
        } finally {
539
            DisposeUtils.dispose(ws);
540
            ws = null;
525 541
        }
526 542
        this.setStatusVisible(true);
527 543
        SimpleTaskStatus status = this.taskStatusController.getSimpleTaskStatus();
......
530 546
            if (overwrite) {
531 547
                FileUtils.deleteQuietly(targetZip_file);
532 548
            }
533
            status.message("_Stoping_h2_server");
549
            status.message(i18n.getTranslation("_Stoping_h2_server"));
534 550
            H2SpatialUtils.server_stop();
535 551
            sleep(3);
536
            status.message("_Download_working_copy");
552
            status.message(i18n.getTranslation("_Download_working_copy"));
537 553
            sleep(1);
538 554
            this.downloadFile(
539 555
                    url,
......
543 559

  
544 560
            if (overwrite) {
545 561
                // Delete H2 files of the working copy
546
                status.message("_Removing_local_working_copy");
562
                status.message(i18n.getTranslation("_Removing_local_working_copy"));
547 563
                sleep(1);
548 564
                File[] files = H2SpatialUtils.getH2Files(targetZip_file);
549 565
                for (File file : files) {
......
557 573
                }
558 574
            }
559 575
            // Unzip files of working copy
560
            status.message("_Extracting_local_working_copy");
576
            status.message(i18n.getTranslation("_Extracting_local_working_copy"));
561 577
            sleep(1);
562 578
            this.unzip(targetZip_uri, targetZip_file.getParentFile(), status);
563 579

  
......
584 600
            H2SpatialUtils.server_start();
585 601
        }
586 602
        // Register the downloaded working copy
587
        status.message("_Registering_working_copy");
603
        status.message(i18n.getTranslation("_Registering_working_copy"));
588 604
        sleep(1);
589
        VCSGisWorkspace ws = null;
590 605
        try {
591
            VCSGisManager manager = VCSGisLocator.getVCSGisManager();
592 606
            ws = manager.openWorkspace(H2SpatialUtils.normalizeH2File(targetZip_file));
607
            ws.addToConnectionPool();
593 608
            manager.registerWorkspace(ws);
594 609
            process_models(ws);
595
            status.message("_Dounload_terminate");
610
            VCSGisSwingServices services = VCSGisSwingLocator.getVCSGisSwingManager().getDefaultServices();
611
            services.refreshDocuments();
612
            status.message(i18n.getTranslation("_Dounload_terminate"));
596 613
            status.terminate();
597 614
//            status.restart();
598 615
            this.setStatusVisible(false);
599 616
            return ERR_OK;
600 617
        } catch (Exception ex) {
601 618
            LOGGER.warn("Can't register workspace", ex);
602
            status.message("Can't register workspace");
619
            status.message(i18n.getTranslation("_Cant_register_workspace"));
603 620
            status.abort();
604 621
            return ERR_EXCEPTION;
605 622
        } finally {

Also available in: Unified diff