Changeset 1663 in josm


Ignore:
Timestamp:
2009-06-10T23:15:32+02:00 (15 years ago)
Author:
Gubaer
Message:

#2437: cleaned up code for uploading and improved user feedback in case of 409 conflicts

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

Legend:

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

    r1630 r1663  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.EventQueue;
    67import java.awt.GridBagLayout;
    78import java.awt.event.ActionEvent;
    89import java.awt.event.KeyEvent;
     10import java.io.IOException;
     11import java.net.HttpURLConnection;
    912import java.util.Collection;
    1013import java.util.LinkedList;
    1114import java.util.List;
     15import java.util.concurrent.ExecutionException;
     16import java.util.concurrent.FutureTask;
     17import java.util.regex.Matcher;
     18import java.util.regex.Pattern;
    1219
    1320import javax.swing.JLabel;
     
    1623import javax.swing.JPanel;
    1724import javax.swing.JScrollPane;
     25import javax.swing.SwingUtilities;
    1826
    1927import org.openstreetmap.josm.Main;
    2028import org.openstreetmap.josm.data.osm.OsmPrimitive;
     29import org.openstreetmap.josm.data.osm.visitor.CreateOsmChangeVisitor;
    2130import org.openstreetmap.josm.gui.ExtendedDialog;
    2231import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    2332import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    2433import org.openstreetmap.josm.gui.historycombobox.SuggestingJHistoryComboBox;
     34import org.openstreetmap.josm.io.DiffResultReader;
     35import org.openstreetmap.josm.io.OsmApi;
     36import org.openstreetmap.josm.io.OsmApiException;
     37import org.openstreetmap.josm.io.OsmApiInitializationException;
    2538import org.openstreetmap.josm.io.OsmServerWriter;
    2639import org.openstreetmap.josm.tools.GBC;
    2740import org.openstreetmap.josm.tools.Shortcut;
    2841import org.xml.sax.SAXException;
     42
    2943
    3044/**
     
    6680    public UploadAction() {
    6781        super(tr("Upload to OSM..."), "upload", tr("Upload all changes to the OSM server."),
    68         Shortcut.registerShortcut("file:upload", tr("File: {0}", tr("Upload to OSM...")), KeyEvent.VK_U, Shortcut.GROUPS_ALT1+Shortcut.GROUP_HOTKEY), true);
     82                Shortcut.registerShortcut("file:upload", tr("File: {0}", tr("Upload to OSM...")), KeyEvent.VK_U, Shortcut.GROUPS_ALT1+Shortcut.GROUP_HOTKEY), true);
    6983
    7084        /**
     
    112126                while(true) {
    113127                    int result = new ExtendedDialog(Main.parent,
    114                         tr("Upload these changes?"),
    115                         p,
    116                         new String[] {tr("Upload Changes"), tr("Cancel")},
    117                         new String[] {"upload.png", "cancel.png"}).getValue();
     128                            tr("Upload these changes?"),
     129                            p,
     130                            new String[] {tr("Upload Changes"), tr("Cancel")},
     131                            new String[] {"upload.png", "cancel.png"}).getValue();
    118132
    119133                    // cancel pressed
     
    121135
    122136                    // don't allow empty commit message
    123                     if (cmt.getText().trim().length() < 3) continue;
     137                    if (cmt.getText().trim().length() < 3) {
     138                        continue;
     139                    }
    124140
    125141                    // store the history of comments
     
    151167        final LinkedList<OsmPrimitive> delete = new LinkedList<OsmPrimitive>();
    152168        for (OsmPrimitive osm : Main.ds.allPrimitives()) {
    153             if (osm.get("josm/ignore") != null)
     169            if (osm.get("josm/ignore") != null) {
    154170                continue;
    155             if (osm.id == 0 && !osm.deleted)
     171            }
     172            if (osm.id == 0 && !osm.deleted) {
    156173                add.addLast(osm);
    157             else if (osm.modified && !osm.deleted)
     174            } else if (osm.modified && !osm.deleted) {
    158175                update.addLast(osm);
    159             else if (osm.deleted && osm.id != 0)
     176            } else if (osm.deleted && osm.id != 0) {
    160177                delete.addFirst(osm);
     178            }
    161179        }
    162180
     
    178196        all.addAll(delete);
    179197
    180         PleaseWaitRunnable uploadTask = new PleaseWaitRunnable(tr("Uploading data")){
    181             @Override protected void realRun() throws SAXException {
    182                 server.uploadOsm(Main.ds.version, all);
    183             }
     198        class UploadDiffTask extends  PleaseWaitRunnable {
     199
     200            private boolean uploadCancelled = false;
     201            private boolean uploadFailed = false;
     202            private Exception lastException = null;
     203
     204            public UploadDiffTask() {
     205                super(tr("Uploading"),false /* don't ignore exceptions */);
     206            }
     207
     208            @Override protected void realRun() throws SAXException, IOException {
     209                try {
     210                    server.uploadOsm(Main.ds.version, all);
     211                    Main.main.editLayer().cleanData(server.processed, !add.isEmpty());
     212                } catch (Exception sxe) {
     213                    if (uploadCancelled) {
     214                        System.out.println("Ignoring exception caught because upload is cancelled. Exception is: " + sxe.toString());
     215                        return;
     216                    }
     217                    System.out.println("got exception: " + sxe.toString());
     218                    uploadFailed = true;
     219                    lastException = sxe;
     220                }
     221            }
     222
    184223            @Override protected void finish() {
    185                 Main.main.editLayer().cleanData(server.processed, !add.isEmpty());
    186             }
     224                if (uploadFailed) {
     225                    handleFailedUpload(lastException);
     226                }
     227            }
     228
    187229            @Override protected void cancel() {
    188                 // FIXME server.cancel();
    189             }
    190         };
    191         Main.worker.execute(uploadTask);
     230                server.disconnectActiveConnection();
     231                uploadCancelled = true;
     232            };
     233
     234        }
     235        Main.worker.execute(new UploadDiffTask());
     236    }
     237
     238    public void handleFailedUpload(Exception e) {
     239        if (e instanceof OsmApiInitializationException) {
     240            handleOsmApiInitializationException(e);
     241            return;
     242        }
     243        if (e instanceof OsmApiException) {
     244            OsmApiException ex = (OsmApiException)e;
     245            if(ex.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
     246                Pattern p = Pattern.compile("Version mismatch: Provided (\\d+), server had: (\\d+) of (\\S+) (\\d+)");
     247                Matcher m = p.matcher(ex.getErrorHeader());
     248                String msg;
     249                if (m.matches()) {
     250                    msg =  tr("<html>Uploading <strong>failed</strong> because the server has a newer version of one<br>"
     251                            + "of your nodes, ways or relations.<br>"
     252                            + "The conflict is cause by the <strong>{0}</strong> with id <strong>{1}</strong>,<br>"
     253                            + "the server has version {2}, your version is {3}.<br>"
     254                            + "Please synchronize your local dataset using <br>"
     255                            + "<strong>File-&gt;Update Data</strong>, resolve<br>"
     256                            + "any conflicts and try to upload again.</html>",
     257                            m.group(3),m.group(4), m.group(2), m.group(1)
     258                    );
     259                } else {
     260                    msg =  tr("<html>Uploading failed because the server has a newer version of one<br>"
     261                            + "of your nodes, ways or relations.<br>"
     262                            + "Please synchronize your local dataset using <br>"
     263                            + "<strong>File-&gt;Update Data</strong>, resolve<br>"
     264                            + "any conflicts and try to upload again.</html>"
     265                    );
     266                }
     267                JOptionPane.showMessageDialog(
     268                        null,
     269                        msg,
     270                        tr("Upload to OSM API failed"),
     271                        JOptionPane.WARNING_MESSAGE
     272                );
     273                return;
     274            }
     275        }
     276        JOptionPane.showMessageDialog(
     277                null,
     278                e.getMessage(),
     279                tr("Upload to OSM API failed"),
     280                JOptionPane.ERROR_MESSAGE
     281        );
     282    }
     283
     284    protected void handleOsmApiInitializationException(Exception e) {
     285        JOptionPane.showMessageDialog(
     286                null,
     287                tr(   "Failed to initialize communication with the OSM server {0}.\n"
     288                        + "Check the server URL in your preferences and your internet connection.",
     289                        Main.pref.get("osm-server.url")
     290                ),
     291                tr("Error"),
     292                JOptionPane.ERROR_MESSAGE
     293        );
     294        e.printStackTrace();
    192295    }
    193296}
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r1608 r1663  
    2323import java.util.Properties;
    2424import java.util.StringTokenizer;
    25 import java.util.concurrent.FutureTask;
    2625
    2726import javax.xml.parsers.SAXParserFactory;
     
    3433import org.openstreetmap.josm.data.osm.Way;
    3534import org.openstreetmap.josm.data.osm.visitor.CreateOsmChangeVisitor;
    36 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    3735import org.xml.sax.Attributes;
    3836import org.xml.sax.InputSource;
     
    5048 */
    5149public class OsmApi extends OsmConnection {
     50    /** max number of retries to send a request in case of HTTP 500 errors or timeouts */
     51    static public final int DEFAULT_MAX_NUM_RETRIES = 5;
    5252
    5353    /**
     
    9393                minVersion = atts.getValue("minimum");
    9494                maxVersion = atts.getValue("maximum");
    95             } else if (qName.equals("area"))
     95            } else if (qName.equals("area")) {
    9696                maxArea = atts.getValue("maximum");
     97            }
    9798        }
    9899    }
     
    132133     * @exception UnknownHostException thrown, if the API host is unknown
    133134     * @exception SocketTimeoutException thrown, if the connection to the API host  times out
    134      * @exception ConnectException throw, if the connection to the API host fails 
    135      * @exception Exception any other exception 
     135     * @exception ConnectException throw, if the connection to the API host fails
     136     * @exception Exception any other exception
    136137     */
    137138    public void initialize() throws UnknownHostException,SocketTimeoutException, ConnectException,Exception {
     
    149150                System.err.println(tr("This version of JOSM is incompatible with the configured server."));
    150151                System.err.println(tr("It supports protocol versions 0.5 and 0.6, while the server says it supports {0} to {1}.",
    151                     minVersion, maxVersion));
     152                        minVersion, maxVersion));
    152153                initialized = false;
    153154            }
    154155            System.out.println(tr("Communications with {0} established using protocol version {1}",
    155                 Main.pref.get("osm-server.url"),
    156                 version));
     156                    Main.pref.get("osm-server.url"),
     157                    version));
    157158            osmWriter.setVersion(version);
    158159        } catch (Exception ex) {
     
    302303    public Collection<OsmPrimitive> uploadDiff(final Collection<OsmPrimitive> list) throws OsmTransferException {
    303304
    304         if (changeset == null) {
     305        if (changeset == null)
    305306            throw new OsmTransferException(tr("No changeset present for diff upload"));
    306         }
    307 
    308307
    309308        final ArrayList<OsmPrimitive> processed = new ArrayList<OsmPrimitive>();
    310309
    311         // this is the asynchronous update task
    312         //
    313         class UploadDiffTask extends  PleaseWaitRunnable {
    314 
    315             private boolean uploadCancelled = false;
    316             private boolean uploadFailed = false;
    317             private Throwable lastThrowable = null;
    318 
    319             public UploadDiffTask(String title) {
    320                 super(title,false /* don't ignore exceptions */);
    321             }
    322 
    323             @Override protected void realRun() throws SAXException, IOException {
    324                 CreateOsmChangeVisitor duv = new CreateOsmChangeVisitor(changeset, OsmApi.this);
    325 
    326                 for (OsmPrimitive osm : list) {
    327                     int progress = Main.pleaseWaitDlg.progress.getValue();
    328                     Main.pleaseWaitDlg.currentAction.setText(tr("Preparing..."));
    329                     osm.visit(duv);
    330                     Main.pleaseWaitDlg.progress.setValue(progress+1);
    331                 }
    332 
    333                 Main.pleaseWaitDlg.currentAction.setText(tr("Uploading..."));
    334 
    335                 String diff = duv.getDocument();
    336                 try {
    337                     String diffresult = sendRequest("POST", "changeset/" + changeset.id + "/upload", diff);
    338                     DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(), Main.pleaseWaitDlg);
    339                 } catch (Exception sxe) {
    340                     if (isUploadCancelled()) {
    341                         // ignore exceptions thrown because the connection is aborted,
    342                         // i.e. IOExceptions or SocketExceptions
    343                         //
    344                         System.out.println("Ignoring exception caught because upload is cancelled. Exception is: " + sxe.toString());
    345                         return;
    346                     }
    347                     uploadFailed = true;
    348                     // remember last exception and don't throw it. If it was thrown again it would
    349                     // have to be encapsulated in a RuntimeException which would be nested in yet
    350                     // another RuntimeException by parent classes.
    351                     // Rather check isUploadFailed() and retrieve getLastThrowable() after the task
    352                     // is completed
    353                     //
    354                     lastThrowable = sxe;
    355                 }
    356             }
    357 
    358             @Override protected void finish() {
    359                 // do nothing
    360             }
    361 
    362             @Override protected void cancel() {
    363                 activeConnection.disconnect();
    364                 uploadCancelled = true;
    365             }
    366 
    367             public boolean isUploadCancelled() {
    368                 return uploadCancelled;
    369             }
    370 
    371             public boolean isUploadFailed() {
    372                 return uploadFailed;
    373             }
    374 
    375             public Throwable getLastThrowable() {
    376                 return lastThrowable;
    377             }
    378         }
    379 
    380         UploadDiffTask uploadTask = new UploadDiffTask(tr("Uploading data"));
    381 
    382         // run  data upload as asynchronous task
    383         //
     310
     311        CreateOsmChangeVisitor duv = new CreateOsmChangeVisitor(changeset, OsmApi.this);
     312
     313        for (OsmPrimitive osm : list) {
     314            int progress = Main.pleaseWaitDlg.progress.getValue();
     315            Main.pleaseWaitDlg.currentAction.setText(tr("Preparing..."));
     316            osm.visit(duv);
     317            Main.pleaseWaitDlg.progress.setValue(progress+1);
     318        }
     319
     320        Main.pleaseWaitDlg.currentAction.setText(tr("Uploading..."));
     321
     322        String diff = duv.getDocument();
     323        String diffresult = sendRequest("POST", "changeset/" + changeset.id + "/upload", diff);
    384324        try {
    385             Void result = null;
    386             FutureTask<Void> task = new FutureTask<Void>(uploadTask, result);
    387             task.run();
    388             task.get(); // wait for the task to complete, no return value expected, though
    389         }  catch(Throwable e) {
    390             if (uploadTask.isUploadCancelled()) {
    391                 throw new OsmTransferCancelledException();
    392             }
     325            DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(), Main.pleaseWaitDlg);
     326        } catch(Exception e) {
    393327            throw new OsmTransferException(e);
    394         }
    395 
    396         // handle failed upload
    397         //
    398         if (uploadTask.isUploadFailed()) {
    399             if (uploadTask.getLastThrowable() != null && uploadTask.getLastThrowable() instanceof OsmTransferException) {
    400                 OsmTransferException e = (OsmTransferException)uploadTask.getLastThrowable();
    401                 throw e;
    402             }
    403             // shouldn't happen, but just in case
    404             //
    405             throw new OsmTransferException(tr("Data upload failed for unknown reason"));
    406         }
    407 
    408         // handle cancelled upload
    409         //
    410         if (uploadTask.isUploadCancelled()) {
    411             throw new OsmTransferCancelledException();
    412328        }
    413329
     
    420336        // System.out.print("backing off for 10 seconds...");
    421337        for(int i=0; i < 10; i++) {
    422             if (cancel || isAuthCancelled()) {
     338            if (cancel || isAuthCancelled())
    423339                throw new OsmTransferCancelledException();
    424             }
    425340            try {
    426341                Thread.sleep(1000);
     
    450365
    451366        StringBuffer responseBody = new StringBuffer();
    452         StringBuffer statusMessage = new StringBuffer();
    453 
    454         int retries = 5; // configurable?
     367
     368        int retries = Main.pref.getInteger("osm-server.max-num-retries", DEFAULT_MAX_NUM_RETRIES);
     369        retries = Math.max(0,retries);
     370
    455371
    456372        while(true) { // the retry loop
     
    511427                    responseBody.append("\n");
    512428                }
    513 
    514                 statusMessage.setLength(0);
     429                String errorHeader = null;
    515430                // Look for a detailed error message from the server
    516431                if (activeConnection.getHeaderField("Error") != null) {
    517                     String er = activeConnection.getHeaderField("Error");
    518                     System.err.println("Error header: " + er);
    519                     statusMessage.append(tr(er));
     432                    errorHeader = activeConnection.getHeaderField("Error");
     433                    System.err.println("Error header: " + errorHeader);
    520434                } else if (retCode != 200 && responseBody.length()>0) {
    521435                    System.err.println("Error body: " + responseBody);
    522                     statusMessage.append(tr(responseBody.toString()));
    523                 } else {
    524                     statusMessage.append(activeConnection.getResponseMessage());
    525436                }
    526437                activeConnection.disconnect();
    527438
    528                 if (retCode != 200) {
    529                     throw new OsmTransferException(statusMessage.toString());
    530                 }
     439                if (retCode != 200)
     440                    throw new OsmApiException(retCode,errorHeader,responseBody.toString());
     441
    531442                return responseBody.toString();
    532443            } catch (UnknownHostException e) {
    533                 throw new OsmTransferException(tr("Unknown host")+": "+e.getMessage(), e);
     444                throw new OsmTransferException(e);
    534445            } catch (SocketTimeoutException e) {
    535                 if (retries-- > 0)
     446                if (retries-- > 0) {
    536447                    continue;
    537                 throw new OsmTransferException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
     448                }
     449                throw new OsmTransferException(e);
    538450            } catch (ConnectException e) {
    539                 if (retries-- > 0)
     451                if (retries-- > 0) {
    540452                    continue;
    541                 throw new OsmTransferException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
     453                }
     454                throw new OsmTransferException(e);
    542455            } catch (Exception e) {
    543456                if (e instanceof OsmTransferException) throw (OsmTransferException) e;
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r1630 r1663  
    77import java.util.LinkedList;
    88import java.util.List;
    9 
    10 import javax.swing.JOptionPane;
     9import java.util.logging.Logger;
    1110
    1211import org.openstreetmap.josm.Main;
     
    1413import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1514import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
    16 import org.openstreetmap.josm.gui.historycombobox.JHistoryComboBox;
    1715
    1816/**
     
    2422 */
    2523public class OsmServerWriter {
     24    static private final Logger logger = Logger.getLogger(OsmServerWriter.class.getName());
    2625
    2726    /**
     
    4544        long now = System.currentTimeMillis();
    4645        long elapsed = now - uploadStartTime;
    47         if (elapsed == 0)
     46        if (elapsed == 0) {
    4847            elapsed = 1;
     48        }
    4949        float uploads_per_ms = (float)progress / elapsed;
    5050        float uploads_left = list_size - progress;
     
    5353        int seconds_left = (ms_left / MSECS_PER_SECOND) % SECONDS_PER_MINUTE ;
    5454        String time_left_str = Integer.toString(minutes_left) + ":";
    55         if (seconds_left < 10)
     55        if (seconds_left < 10) {
    5656            time_left_str += "0";
     57        }
    5758        time_left_str += Integer.toString(seconds_left);
    5859        return time_left_str;
     
    6061
    6162    /**
     63     * retrieves the most recent changeset comment from the preferences
     64     *
     65     * @return the most recent changeset comment
     66     */
     67    protected String getChangesetComment() {
     68        String cmt = "";
     69        List<String> history = new LinkedList<String>(
     70                Main.pref.getCollection(UploadAction.HISTORY_KEY, new LinkedList<String>()));
     71        if(history.size() > 0) {
     72            cmt = history.get(0);
     73        }
     74        return cmt;
     75    }
     76
     77    /**
    6278     * Send the dataset to the server.
    63      * @param the_version version of the data set
    64      * @param list list of objects to send
     79     *
     80     * @param apiVersion version of the data set
     81     * @param primitives list of objects to send
    6582     */
    66     public void uploadOsm(String the_version, Collection<OsmPrimitive> list) {
     83    public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives) throws OsmTransferException {
    6784        processed = new LinkedList<OsmPrimitive>();
    6885
     
    7390            api.initialize();
    7491        } catch(Exception e) {
    75             JOptionPane.showMessageDialog(
    76                 null,
    77                 tr(   "Failed to initialize communication with the OSM server {0}.\n"
    78                     + "Check the server URL in your preferences and your internet connection.",
    79                     Main.pref.get("osm-server.url")
    80                 ),
    81                 tr("Error"),
    82                 JOptionPane.ERROR_MESSAGE
    83             );
    84             e.printStackTrace();
    85             return;
     92            throw new OsmApiInitializationException(e);
    8693        }
    8794
    88         Main.pleaseWaitDlg.progress.setMaximum(list.size());
     95        Main.pleaseWaitDlg.progress.setMaximum(primitives.size());
    8996        Main.pleaseWaitDlg.progress.setValue(0);
    9097
    91         boolean useChangesets = api.hasChangesetSupport();
    92 
    93         // controls whether or not we try and upload the whole bunch in one go
    94         boolean useDiffUploads = Main.pref.getBoolean("osm-server.atomic-upload",
    95             "0.6".equals(api.getVersion()));
    96 
    97         // create changeset if required
    98         try {
    99             if (useChangesets) {
    100                 // add the last entered comment to the changeset
    101                 String cmt = "";
    102                 List<String> history = new LinkedList<String>(
    103                 Main.pref.getCollection(UploadAction.HISTORY_KEY, new LinkedList<String>()));
    104                 if(history.size() > 0) {
    105                     cmt = history.get(0);
    106                 }
    107                 api.createChangeset(cmt);
    108             }
    109         } catch (OsmTransferException ex) {
    110             dealWithTransferException(ex);
    111             return;
     98        // check whether we can use changeset
     99        //
     100        boolean canUseChangeset = api.hasChangesetSupport();
     101        boolean useChangeset = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0);
     102        if (useChangeset && ! canUseChangeset) {
     103            System.out.println(tr("WARNING: preference '{0}' or api version {1} of dataset requires to use changesets, but API is not handle them. Ignoring changesets.", "osm-server.atomic-upload", apiVersion));
     104            useChangeset = false;
    112105        }
    113106
    114         try {
    115             if (useDiffUploads) {
    116                 // all in one go
    117                 processed.addAll(api.uploadDiff(list));
    118             } else {
    119                 // upload changes individually (90% of code is for the status display...)
    120                 NameVisitor v = new NameVisitor();
    121                 uploadStartTime = System.currentTimeMillis();
    122                 for (OsmPrimitive osm : list) {
    123                     osm.visit(v);
    124                     int progress = Main.pleaseWaitDlg.progress.getValue();
    125                     String time_left_str = timeLeft(progress, list.size());
    126                     Main.pleaseWaitDlg.currentAction.setText(
    127                             tr("{0}% ({1}/{2}), {3} left. Uploading {4}: {5} (id: {6})",
    128                                     Math.round(100.0*progress/list.size()), progress,
    129                                     list.size(), time_left_str, tr(v.className), v.name, osm.id));
    130                     makeApiRequest(osm);
    131                     processed.add(osm);
    132                     Main.pleaseWaitDlg.progress.setValue(progress+1);
     107        if (useChangeset) {
     108            // upload everything in one changeset
     109            //
     110            try {
     111                api.createChangeset(getChangesetComment());
     112                processed.addAll(api.uploadDiff(primitives));
     113            } catch(OsmTransferException e) {
     114                throw e;
     115            } finally {
     116                try {
     117                    if (canUseChangeset) {
     118                        api.stopChangeset();
     119                    }
     120                } catch (Exception ee) {
     121                    // ignore nested exception
    133122                }
    134123            }
    135             if (useChangesets) api.stopChangeset();
    136         } catch (OsmTransferException e) {
    137             try {
    138                 if (useChangesets) api.stopChangeset();
    139             } catch (Exception ee) {
    140                 // ignore nested exception
     124        } else {
     125            // upload changes individually (90% of code is for the status display...)
     126            //
     127            NameVisitor v = new NameVisitor();
     128            uploadStartTime = System.currentTimeMillis();
     129            for (OsmPrimitive osm : primitives) {
     130                osm.visit(v);
     131                int progress = Main.pleaseWaitDlg.progress.getValue();
     132                String time_left_str = timeLeft(progress, primitives.size());
     133                Main.pleaseWaitDlg.currentAction.setText(
     134                        tr("{0}% ({1}/{2}), {3} left. Uploading {4}: {5} (id: {6})",
     135                                Math.round(100.0*progress/primitives.size()), progress,
     136                                primitives.size(), time_left_str, tr(v.className), v.name, osm.id));
     137                makeApiRequest(osm);
     138                processed.add(osm);
     139                Main.pleaseWaitDlg.progress.setValue(progress+1);
    141140            }
    142             dealWithTransferException(e);
    143141        }
    144142    }
     
    154152    }
    155153
    156     private void dealWithTransferException (OsmTransferException e) {
    157         if (e instanceof OsmTransferCancelledException) {
    158             // ignore - don't bother the user with yet another message that he
    159             // has successfully cancelled the data upload
    160             //
    161             return;
     154    public void disconnectActiveConnection() {
     155        if (api != null && api.activeConnection != null) {
     156            api.activeConnection.disconnect();
    162157        }
    163 
    164         JOptionPane.showMessageDialog(Main.parent,
    165             /* tr("Error during upload: ") + */ e.getMessage());
    166158    }
    167159}
Note: See TracChangeset for help on using the changeset viewer.