Changeset 2097 in josm


Ignore:
Timestamp:
2009-09-12T06:45:07+02:00 (15 years ago)
Author:
Gubaer
Message:

applied #3318: patch by dmuecke: josm opens modal error dialog for every block that fails to download

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

Legend:

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

    r2013 r2097  
    1717import org.openstreetmap.josm.data.osm.DataSet;
    1818import org.openstreetmap.josm.data.osm.DataSource;
    19 import org.openstreetmap.josm.gui.ExceptionDialogUtil;
    2019import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    2120import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;
     
    2827import org.openstreetmap.josm.io.OsmServerReader;
    2928import org.openstreetmap.josm.io.OsmTransferException;
     29import org.openstreetmap.josm.tools.ExceptionUtil;
    3030import org.xml.sax.SAXException;
    3131
     
    107107                return;
    108108            if (lastException != null) {
    109                 ExceptionDialogUtil.explainException(lastException);
     109                getProgressMonitor().setErrorMessage(ExceptionUtil.explainException(lastException));
    110110                DownloadOsmTask.this.setFailed(true);
    111111                return;
     
    113113            if (dataSet == null)
    114114                return; // user canceled download or error occurred
    115             if (currentBounds == null) {
     115            if (currentBounds == null)
    116116                return; // no data retrieved
    117             }
    118117            if (dataSet.allPrimitives().isEmpty()) {
    119118                progressMonitor.setErrorMessage(tr("No data imported."));
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java

    r2077 r2097  
    9595        String errors = "";
    9696
     97        LinkedList<Integer> shown = new LinkedList<Integer>();
    9798        for(DownloadTask dt : osmTasks) {
    9899            String err = dt.getErrorMessage();
    99             if(err.equals("")) {
     100            // avoid display of identical messages
     101            if (err.equals("") || shown.contains(err.hashCode())) {
    100102                continue;
    101103            }
     104            shown.add(err.hashCode());
    102105            errors += "<br>* " + err;
    103106        }
  • trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java

    r2075 r2097  
    66import java.io.IOException;
    77import java.net.HttpURLConnection;
    8 import java.net.MalformedURLException;
    98import java.net.SocketException;
    10 import java.net.URL;
    119import java.net.UnknownHostException;
    1210
     
    1412
    1513import org.openstreetmap.josm.Main;
    16 import org.openstreetmap.josm.io.OsmApi;
    1714import org.openstreetmap.josm.io.OsmApiException;
    1815import org.openstreetmap.josm.io.OsmApiInitializationException;
    1916import org.openstreetmap.josm.io.OsmChangesetCloseException;
    2017import org.openstreetmap.josm.io.OsmTransferException;
     18import org.openstreetmap.josm.tools.ExceptionUtil;
    2119
    2220/**
     
    2927     * just static utility functions. no constructor
    3028     */
    31     private ExceptionDialogUtil() {}
     29    private ExceptionDialogUtil() {
     30    }
    3231
    3332    /**
     
    3736     */
    3837    public static void explainOsmApiInitializationException(OsmApiInitializationException e) {
    39         e.printStackTrace();
    40         JOptionPane.showMessageDialog(
    41                 Main.parent,
    42                 tr(   "<html>Failed to initialize communication with the OSM server {0}.<br>"
    43                         + "Check the server URL in your preferences and your internet connection.</html>",
    44                         Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api")
    45                 ),
    46                 tr("Error"),
    47                 JOptionPane.ERROR_MESSAGE
    48         );
     38        JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainOsmApiInitializationException(e), tr("Error"),
     39                JOptionPane.ERROR_MESSAGE);
    4940    }
    5041
     
    5546     */
    5647    public static void explainOsmChangesetCloseException(OsmChangesetCloseException e) {
    57         e.printStackTrace();
    58         String changsetId = e.getChangeset() == null ? tr("unknown") : Long.toString(e.getChangeset().getId());
    59         JOptionPane.showMessageDialog(
    60                 Main.parent,
    61                 tr(   "<html>Failed to close changeset ''{0}'' on the OSM server ''{1}''.<br>"
    62                         + "The changeset will automatically be closed by the server after a timeout.</html>",
    63                         changsetId,
    64                         Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api")
    65                 ),
    66                 tr("Error"),
    67                 JOptionPane.ERROR_MESSAGE
    68         );
    69     }
    70 
     48        JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainOsmChangesetCloseException(e), tr("Error"),
     49                JOptionPane.ERROR_MESSAGE);
     50    }
    7151
    7252    /**
     
    7656     */
    7757    public static void explainPreconditionFailed(OsmApiException e) {
    78         e.printStackTrace();
    79         JOptionPane.showMessageDialog(
    80                 Main.parent,
    81                 tr("<html>Uploading to the server <strong>failed</strong> because your current<br>"
    82                         +"dataset violates a precondition.<br>"
    83                         +"The error message is:<br>"
    84                         + "{0}"
    85                         + "</html>",
    86                         e.getMessage().replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
    87                 ),
    88                 tr("Precondition violation"),
    89                 JOptionPane.ERROR_MESSAGE
    90         );
    91     }
    92 
     58        JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainPreconditionFailed(e),
     59                tr("Precondition violation"), JOptionPane.ERROR_MESSAGE);
     60    }
    9361
    9462    /**
     
    9866     */
    9967    public static void explainGeneric(Exception e) {
    100         String msg = e.getMessage();
    101         if (msg == null || msg.trim().equals("")) {
    102             msg = e.toString();
    103         }
    104         e.printStackTrace();
    105         JOptionPane.showMessageDialog(
    106                 Main.parent,
    107                 msg,
    108                 tr("Error"),
    109                 JOptionPane.ERROR_MESSAGE
    110         );
     68        JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainGeneric(e), tr("Error"),
     69                JOptionPane.ERROR_MESSAGE);
    11170    }
    11271
     
    12079
    12180    public static void explainSecurityException(OsmTransferException e) {
    122         String apiUrl = OsmApi.getOsmApi().getBaseUrl();
    123         String host = tr("unknown");
    124         try {
    125             host = new URL(apiUrl).getHost();
    126         } catch(MalformedURLException ex) {
    127             // shouldn't happen
    128         }
    129 
    130         String message = tr("<html>Failed to open a connection to the remote server<br>"
    131                 + "''{0}''<br>"
    132                 + "for security reasons. This is most likely because you are running<br>"
    133                 + "in an applet and because you didn''t load your applet from ''{1}''.</html>",
    134                 apiUrl, host
    135         );
    136         JOptionPane.showMessageDialog(
    137                 Main.parent,
    138                 message,
    139                 tr("Security exception"),
    140                 JOptionPane.ERROR_MESSAGE
    141         );
     81        JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainSecurityException(e), tr("Security exception"),
     82                JOptionPane.ERROR_MESSAGE);
    14283    }
    14384
     
    15192
    15293    public static void explainNestedSocketException(OsmTransferException e) {
    153         String apiUrl = OsmApi.getOsmApi().getBaseUrl();
    154         String message = tr("<html>Failed to open a connection to the remote server<br>"
    155                 + "''{0}''.<br>"
    156                 + "Please check your internet connection.</html>",
    157                 apiUrl
    158         );
    159         e.printStackTrace();
    160         JOptionPane.showMessageDialog(
    161                 Main.parent,
    162                 message,
    163                 tr("Network exception"),
    164                 JOptionPane.ERROR_MESSAGE
    165         );
     94        JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainNestedSocketException(e),
     95                tr("Network exception"), JOptionPane.ERROR_MESSAGE);
    16696    }
    16797
     
    175105
    176106    public static void explainNestedIOException(OsmTransferException e) {
    177         IOException ioe = getNestedException(e, IOException.class);
    178         String apiUrl = OsmApi.getOsmApi().getBaseUrl();
    179         String message = tr("<html>Failed to upload data to or download data from<br>"
    180                 + "''{0}''<br>"
    181                 + "due to a problem with transferring data.<br>"
    182                 + "Details(untranslated): {1}</html>",
    183                 apiUrl, ioe.getMessage()
    184         );
    185         e.printStackTrace();
    186         JOptionPane.showMessageDialog(
    187                 Main.parent,
    188                 message,
    189                 tr("IO Exception"),
    190                 JOptionPane.ERROR_MESSAGE
    191         );
     107        JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainNestedIOException(e), tr("IO Exception"),
     108                JOptionPane.ERROR_MESSAGE);
    192109    }
    193110
     
    200117
    201118    public static void explainInternalServerError(OsmTransferException e) {
    202         String apiUrl = OsmApi.getOsmApi().getBaseUrl();
    203         String message = tr("<html>The OSM server<br>"
    204                 + "''{0}''<br>"
    205                 + "reported an internal server error.<br>"
    206                 + "This is most likely a temporary problem. Please try again later.</html>",
    207                 apiUrl
    208         );
    209         e.printStackTrace();
    210         JOptionPane.showMessageDialog(
    211                 Main.parent,
    212                 message,
    213                 tr("Internal Server Error"),
    214                 JOptionPane.ERROR_MESSAGE
    215         );
     119        JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainInternalServerError(e),
     120                tr("Internal Server Error"), JOptionPane.ERROR_MESSAGE);
    216121    }
    217122
     
    223128     */
    224129    public static void explainBadRequest(OsmApiException e) {
    225         String apiUrl = OsmApi.getOsmApi().getBaseUrl();
    226         String message = tr("The OSM server ''{0}'' reported a bad request.<br>",
    227                 apiUrl
    228         );
    229         if (e.getErrorHeader() != null && e.getErrorHeader().startsWith("The maximum bbox")) {
    230             message += "<br>" + tr("The area you tried to download is too big or your request was too large."
    231                     + "<br>Either request a smaller area or use an export file provided by the OSM community.");
    232         } else if (e.getErrorHeader() != null){
    233             message += tr("<br>Error message(untranslated): {0}", e.getErrorHeader());
    234         }
    235         message = "<html>" + message + "</html>";
    236         e.printStackTrace();
    237         JOptionPane.showMessageDialog(
    238                 Main.parent,
    239                 message,
    240                 tr("Bad Request"),
    241                 JOptionPane.ERROR_MESSAGE
    242         );
     130        JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainBadRequest(e), tr("Bad Request"),
     131                JOptionPane.ERROR_MESSAGE);
    243132    }
    244133
     
    252141
    253142    public static void explainNestedUnkonwnHostException(OsmTransferException e) {
    254         String apiUrl = OsmApi.getOsmApi().getBaseUrl();
    255         String host = tr("unknown");
    256         try {
    257             host = new URL(apiUrl).getHost();
    258         } catch(MalformedURLException ex) {
    259             // shouldn't happen
    260         }
    261 
    262         String message = tr("<html>Failed to open a connection to the remote server<br>"
    263                 + "''{0}''.<br>"
    264                 + "Host name ''{1}'' couldn''t be resolved. <br>"
    265                 + "Please check the API URL in your preferences and your internet connection.</html>",
    266                 apiUrl, host
    267         );
    268         e.printStackTrace();
    269         JOptionPane.showMessageDialog(
    270                 Main.parent,
    271                 message,
    272                 tr("Unknown host"),
    273                 JOptionPane.ERROR_MESSAGE
    274         );
     143        JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainNestedUnkonwnHostException(e),
     144                tr("Unknown host"), JOptionPane.ERROR_MESSAGE);
    275145    }
    276146
     
    290160            t = t.getCause();
    291161        }
    292         if (t== null)
     162        if (t == null)
    293163            return null;
    294164        else if (nestedClass.isInstance(t))
     
    319189            return;
    320190        }
    321         if (e instanceof OsmApiInitializationException){
    322             explainOsmApiInitializationException((OsmApiInitializationException)e);
    323             return;
    324         }
    325         if (e instanceof OsmChangesetCloseException){
    326             explainOsmChangesetCloseException((OsmChangesetCloseException)e);
     191        if (e instanceof OsmApiInitializationException) {
     192            explainOsmApiInitializationException((OsmApiInitializationException) e);
     193            return;
     194        }
     195        if (e instanceof OsmChangesetCloseException) {
     196            explainOsmChangesetCloseException((OsmChangesetCloseException) e);
    327197            return;
    328198        }
    329199
    330200        if (e instanceof OsmApiException) {
    331             OsmApiException oae = (OsmApiException)e;
     201            OsmApiException oae = (OsmApiException) e;
    332202            if (oae.getResponseCode() == HttpURLConnection.HTTP_PRECON_FAILED) {
    333203                explainPreconditionFailed(oae);
     
    358228     */
    359229    public static void explainGoneForUnknownPrimitive(OsmApiException e) {
    360         String msg =  tr("<html>Uploading <strong>failed</strong> because a primitive you tried to<br>"
    361                 + "delete on the server is already deleted.<br>"
    362                 + "<br>"
    363                 + "The error message is:<br>"
    364                 + "{0}"
    365                 + "</html>",
    366                 e.getMessage().replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
    367         );
    368         JOptionPane.showMessageDialog(
    369                 Main.parent,
    370                 msg,
    371                 tr("Primitive already deleted"),
    372                 JOptionPane.ERROR_MESSAGE
    373         );
     230        JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainGoneForUnknownPrimitive(e),
     231                tr("Primitive already deleted"), JOptionPane.ERROR_MESSAGE);
    374232
    375233    }
     
    382240    public static void explainException(Exception e) {
    383241        if (e instanceof OsmTransferException) {
    384             explainOsmTransferException((OsmTransferException)e);
     242            explainOsmTransferException((OsmTransferException) e);
    385243            return;
    386244        }
Note: See TracChangeset for help on using the changeset viewer.