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

refactor duplicated code

Location:
trunk/src/org/openstreetmap/josm/actions/downloadtasks
Files:
3 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    }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/ChangesetHeaderDownloadTask.java

    r10124 r10129  
    66import java.awt.Component;
    77import java.io.IOException;
    8 import java.lang.reflect.InvocationTargetException;
    98import java.util.Collection;
    109import java.util.Collections;
    1110import java.util.HashSet;
    1211import java.util.Set;
    13 
    14 import javax.swing.SwingUtilities;
    1512
    1613import org.openstreetmap.josm.Main;
     
    2017import org.openstreetmap.josm.io.OsmTransferException;
    2118import org.openstreetmap.josm.tools.CheckParameterUtil;
    22 import org.openstreetmap.josm.tools.ExceptionUtil;
    23 import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
    2419import org.xml.sax.SAXException;
    2520
     
    7469                ExceptionDialogUtil.explainException(lastException);
    7570            }
    76             Runnable r = new Runnable() {
    77                 @Override
    78                 public void run() {
    79                     ChangesetCache.getInstance().update(downloadedChangesets);
    80                 }
    81             };
    82 
    83             if (SwingUtilities.isEventDispatchThread()) {
    84                 r.run();
    85             } else {
    86                 try {
    87                     SwingUtilities.invokeAndWait(r);
    88                 } catch (InterruptedException e) {
    89                     Main.warn("InterruptedException in "+getClass().getSimpleName()+" while updating changeset cache");
    90                 } catch (InvocationTargetException e) {
    91                     Throwable t = e.getTargetException();
    92                     if (t instanceof RuntimeException) {
    93                         BugReportExceptionHandler.handleException(t);
    94                     } else if (t instanceof Exception) {
    95                         ExceptionUtil.explainException(e);
    96                     } else {
    97                         BugReportExceptionHandler.handleException(t);
    98                     }
    99                 }
    100             }
     71            updateChangesets();
    10172        }
    10273    }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/ChangesetQueryTask.java

    r10124 r10129  
    66import java.awt.Component;
    77import java.io.IOException;
    8 import java.lang.reflect.InvocationTargetException;
    98
    109import javax.swing.JOptionPane;
    11 import javax.swing.SwingUtilities;
    1210
    1311import org.openstreetmap.josm.Main;
    14 import org.openstreetmap.josm.data.osm.ChangesetCache;
    1512import org.openstreetmap.josm.data.osm.UserInfo;
    1613import org.openstreetmap.josm.gui.JosmUserIdentityManager;
     
    2219import org.openstreetmap.josm.tools.CheckParameterUtil;
    2320import org.openstreetmap.josm.tools.ExceptionUtil;
    24 import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
    2521import org.xml.sax.SAXException;
    2622
     
    10399                return;
    104100            }
    105 
    106             // update the global changeset cache with the downloaded changesets.
    107             // this will trigger change events which views are listening to. They
    108             // will update their views accordingly.
    109             //
    110             // Run on the EDT because UI updates are triggered.
    111             //
    112             Runnable r = new Runnable() {
    113                 @Override public void run() {
    114                     ChangesetCache.getInstance().update(downloadedChangesets);
    115                 }
    116             };
    117             if (SwingUtilities.isEventDispatchThread()) {
    118                 r.run();
    119             } else {
    120                 try {
    121                     SwingUtilities.invokeAndWait(r);
    122                 } catch (InterruptedException e) {
    123                     Main.warn("InterruptedException in "+getClass().getSimpleName()+" while updating changeset cache");
    124                 } catch (InvocationTargetException e) {
    125                     Throwable t = e.getTargetException();
    126                     if (t instanceof RuntimeException) {
    127                         BugReportExceptionHandler.handleException(t);
    128                     } else if (t instanceof Exception) {
    129                         ExceptionUtil.explainException(e);
    130                     } else {
    131                         BugReportExceptionHandler.handleException(t);
    132                     }
    133                 }
    134             }
     101            updateChangesets();
    135102        }
    136103
Note: See TracChangeset for help on using the changeset viewer.