Ignore:
Timestamp:
2016-04-09T23:24:01+02:00 (10 years ago)
Author:
Don-vip
Message:

refactor duplicated code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/AbstractChangesetDownloadTask.java

    r10124 r10129  
    33
    44import java.awt.Component;
     5import java.lang.reflect.InvocationTargetException;
    56import java.net.URL;
    67import java.util.HashSet;
     
    89import java.util.concurrent.Future;
    910
     11import javax.swing.SwingUtilities;
     12
    1013import org.openstreetmap.josm.Main;
    1114import org.openstreetmap.josm.data.Bounds;
    1215import org.openstreetmap.josm.data.osm.Changeset;
     16import org.openstreetmap.josm.data.osm.ChangesetCache;
    1317import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    1418import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1519import org.openstreetmap.josm.io.OsmServerChangesetReader;
     20import org.openstreetmap.josm.tools.ExceptionUtil;
     21import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
    1622
    1723/**
     
    4652            lastException = e;
    4753            setFailed(true);
     54        }
     55
     56        protected final void updateChangesets() {
     57            // update the global changeset cache with the downloaded changesets.
     58            // this will trigger change events which views are listening to. They
     59            // will update their views accordingly.
     60            //
     61            // Run on the EDT because UI updates are triggered.
     62            //
     63            Runnable r = new Runnable() {
     64                @Override public void run() {
     65                    ChangesetCache.getInstance().update(downloadedChangesets);
     66                }
     67            };
     68            if (SwingUtilities.isEventDispatchThread()) {
     69                r.run();
     70            } else {
     71                try {
     72                    SwingUtilities.invokeAndWait(r);
     73                } catch (InterruptedException e) {
     74                    Main.warn("InterruptedException in "+getClass().getSimpleName()+" while updating changeset cache");
     75                } catch (InvocationTargetException e) {
     76                    Throwable t = e.getTargetException();
     77                    if (t instanceof RuntimeException) {
     78                        BugReportExceptionHandler.handleException(t);
     79                    } else if (t instanceof Exception) {
     80                        ExceptionUtil.explainException(e);
     81                    } else {
     82                        BugReportExceptionHandler.handleException(t);
     83                    }
     84                }
     85            }
    4886        }
    4987    }
Note: See TracChangeset for help on using the changeset viewer.