Changeset 10444 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2016-06-21T00:05:47+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13018 - Use new test rules for AutosaveTaskTest, increase coverage (patch by michael2402) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/AutosaveTask.java

    r10386 r10444  
    2424import java.util.Timer;
    2525import java.util.TimerTask;
     26import java.util.concurrent.ExecutionException;
     27import java.util.concurrent.Future;
    2628import java.util.regex.Pattern;
    2729
     
    108110    }
    109111
     112    /**
     113     * Starts the autosave background task.
     114     */
    110115    public void schedule() {
    111116        if (PROP_INTERVAL.get() > 0) {
     
    129134            timer = new Timer(true);
    130135            timer.schedule(this, 1000L, PROP_INTERVAL.get() * 1000L);
    131             Main.getLayerManager().addLayerChangeListener(this);
    132             if (Main.isDisplayingMapView()) {
    133                 for (OsmDataLayer l: Main.getLayerManager().getLayersOfType(OsmDataLayer.class)) {
    134                     registerNewlayer(l);
    135                 }
    136             }
     136            Main.getLayerManager().addLayerChangeListener(this, true);
    137137        }
    138138    }
     
    357357    }
    358358
    359     public void recoverUnsavedLayers() {
     359    /**
     360     * Recover the unsaved layers and open them asynchronously.
     361     * @return A future that can be used to wait for the completion of this task.
     362     */
     363    public Future<?> recoverUnsavedLayers() {
    360364        List<File> files = getUnsavedLayersFiles();
    361365        final OpenFileTask openFileTsk = new OpenFileTask(files, null, tr("Restoring files"));
    362         Main.worker.submit(openFileTsk);
    363         Main.worker.submit(new Runnable() {
     366        final Future<?> openFilesFuture = Main.worker.submit(openFileTsk);
     367        return Main.worker.submit(new Runnable() {
    364368            @Override
    365369            public void run() {
    366                 for (File f: openFileTsk.getSuccessfullyOpenedFiles()) {
    367                     moveToDeletedLayersFolder(f);
     370                try {
     371                    // Wait for opened tasks to be generated.
     372                    openFilesFuture.get();
     373                    for (File f: openFileTsk.getSuccessfullyOpenedFiles()) {
     374                        moveToDeletedLayersFolder(f);
     375                    }
     376                } catch (InterruptedException | ExecutionException e) {
     377                    Main.error(e);
    368378                }
    369379            }
     
    406416    }
    407417
     418    /**
     419     * Mark all unsaved layers as deleted. They are still preserved in the deleted layers folder.
     420     */
    408421    public void discardUnsavedLayers() {
    409422        for (File f: getUnsavedLayersFiles()) {
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r10442 r10444  
    410410        final MainFrame mainFrame = new MainFrame(contentPanePrivate, mainPanel, geometry);
    411411        Main.parent = mainFrame;
     412        mainPanel.reAddListeners();
    412413
    413414        if (args.containsKey(Option.LOAD_PREFERENCES)) {
  • trunk/src/org/openstreetmap/josm/gui/MainPanel.java

    r10432 r10444  
    4141        super(new BorderLayout());
    4242        this.layerManager = layerManager;
    43         reAddListeners();
    4443    }
    4544
Note: See TracChangeset for help on using the changeset viewer.