Changeset 2480 in josm for trunk/src/org


Ignore:
Timestamp:
2009-11-19T13:30:09+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed #3937: Closed changeset (due to timeout) remains in the upload dialog

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

Legend:

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

    r2402 r2480  
    3838import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3939import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     40import org.openstreetmap.josm.io.ChangesetClosedException;
    4041import org.openstreetmap.josm.io.OsmApi;
    4142import org.openstreetmap.josm.io.OsmApiException;
    4243import org.openstreetmap.josm.io.OsmApiInitializationException;
    4344import org.openstreetmap.josm.io.OsmApiPrimitiveGoneException;
    44 import org.openstreetmap.josm.io.OsmChangesetCloseException;
    4545import org.openstreetmap.josm.io.OsmServerWriter;
    4646import org.openstreetmap.josm.io.OsmTransferException;
     
    480480        }
    481481
    482         if (e instanceof OsmChangesetCloseException) {
    483             ExceptionDialogUtil.explainOsmChangesetCloseException((OsmChangesetCloseException)e);
    484             return;
    485         }
    486482        if (e instanceof OsmApiPrimitiveGoneException) {
    487483            handleGone((OsmApiPrimitiveGoneException)e);
     
    674670            }
    675671            layer.onPostUploadToServer();
    676             UploadDialog.getUploadDialog().setOrUpdateChangeset(changeset);
     672            if (lastException != null && lastException instanceof ChangesetClosedException) {
     673                UploadDialog.getUploadDialog().removeChangeset(changeset);
     674            } else {
     675                UploadDialog.getUploadDialog().setOrUpdateChangeset(changeset);
     676            }
    677677        }
    678678
  • trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java

    r2413 r2480  
    1414
    1515import org.openstreetmap.josm.Main;
     16import org.openstreetmap.josm.io.ChangesetClosedException;
    1617import org.openstreetmap.josm.io.OsmApiException;
    1718import org.openstreetmap.josm.io.OsmApiInitializationException;
    18 import org.openstreetmap.josm.io.OsmChangesetCloseException;
    1919import org.openstreetmap.josm.io.OsmTransferException;
    2020import org.openstreetmap.josm.tools.BugReportExceptionHandler;
     
    4949
    5050    /**
    51      * handles an exception caught during OSM API initialization
     51     * handles a ChangesetClosedException
    5252     *
    5353     * @param e the exception
    5454     */
    55     public static void explainOsmChangesetCloseException(OsmChangesetCloseException e) {
    56         HelpAwareOptionPane.showOptionDialog(
    57                 Main.parent,
    58                 ExceptionUtil.explainOsmChangesetCloseException(e),
     55    public static void explainChangesetClosedException(ChangesetClosedException e) {
     56        HelpAwareOptionPane.showOptionDialog(
     57                Main.parent,
     58                ExceptionUtil.explainChangesetClosedException(e),
    5959                tr("Error"),
    6060                JOptionPane.ERROR_MESSAGE,
    61                 ht("/ErrorMessages#OsmChangesetCloseException")
     61                ht("/ErrorMessages#ChangesetClosedException")
    6262        );
    6363    }
     
    294294            return;
    295295        }
    296         if (e instanceof OsmChangesetCloseException) {
    297             explainOsmChangesetCloseException((OsmChangesetCloseException) e);
     296
     297        if (e instanceof ChangesetClosedException) {
     298            explainChangesetClosedException((ChangesetClosedException)e);
    298299            return;
    299300        }
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r2447 r2480  
    334334    public void setOrUpdateChangeset(Changeset cs) {
    335335        pnlChangesetSelection.setOrUpdateChangeset(cs);
     336    }
     337
     338    /**
     339     * Removes <code>cs</code> from the list of open changesets in the upload
     340     * dialog
     341     *
     342     * @param cs the changeset. Ignored if null.
     343     */
     344    public void removeChangeset(Changeset cs) {
     345        if (cs == null) return;
     346        pnlChangesetSelection.removeChangeset(cs);
    336347    }
    337348
     
    842853        public void setOrUpdateChangeset(Changeset cs) {
    843854            if (cs == null) {
    844                 tagEditorPanel.getModel().clear();
    845                 tagEditorPanel.getModel().add("created_by", getDefaultCreatedBy());
     855                cs = new Changeset();
     856                cs.put("created_by", getDefaultCreatedBy());
     857                tagEditorPanel.getModel().initFromPrimitive(cs);
    846858                tagEditorPanel.getModel().appendNewTag();
     859                prepareDialogForNextUpload(cs);
    847860            } else if (cs.getId() == 0) {
    848861                if (cs.get("created_by") == null) {
     
    851864                tagEditorPanel.getModel().initFromPrimitive(cs);
    852865                tagEditorPanel.getModel().appendNewTag();
     866                prepareDialogForNextUpload(cs);
    853867            } else if (cs.getId() > 0 && cs.isOpen()){
    854868                if (cs.get("created_by") == null) {
     
    859873                cs = model.getChangesetById(cs.getId());
    860874                cbOpenChangesets.setSelectedItem(cs);
     875                prepareDialogForNextUpload(cs);
    861876            } else if (cs.getId() > 0 && !cs.isOpen()){
     877                removeChangeset(cs);
     878            }
     879        }
     880
     881        /**
     882         * Remove a changeset from the list of open changeset
     883         *
     884         * @param cs the changeset to be removed. Ignored if null.
     885         */
     886        public void removeChangeset(Changeset cs) {
     887            if (cs ==  null) return;
     888            Changeset selected = (Changeset)model.getSelectedItem();
     889            model.removeChangeset(cs);
     890            if (model.getSize() == 0 || selected == cs) {
     891                // no more changesets or removed changeset is the currently selected
     892                // changeset? Switch to using a new changeset.
     893                //
     894                rbUseNew.setSelected(true);
     895                model.setSelectedItem(null);
     896                southTabbedPane.setTitleAt(1, tr("Tags of new changeset"));
     897
     898                cs = new Changeset();
    862899                if (cs.get("created_by") == null) {
    863900                    cs.put("created_by", getDefaultCreatedBy());
     901                    cs.put("comment", getUploadComment());
    864902                }
    865903                tagEditorPanel.getModel().initFromPrimitive(cs);
    866                 model.removeChangeset(cs);
    867                 if (model.getSize() == 0) {
    868                     rbUseNew.setSelected(true);
    869                     model.setSelectedItem(null);
    870                     southTabbedPane.setTitleAt(1, tr("Tags of new changeset"));
    871                 }
    872904            }
    873905            prepareDialogForNextUpload(cs);
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r2478 r2480  
    338338     * @throws OsmTransferException if something goes wrong.
    339339     * @throws IllegalArgumentException if changeset is null
    340      * @throws IllegalArgumentException if changeset.getId() == 0
     340     * @throws IllegalArgumentException if changeset.getId() <= 0
    341341     *
    342342     */
     
    359359                    monitor
    360360            );
     361        } catch(OsmApiException e) {
     362            if (e.getResponseCode() == HttpURLConnection.HTTP_CONFLICT)
     363                throw new ChangesetClosedException(e.getErrorHeader());
     364            throw e;
    361365        } finally {
    362366            monitor.finishTask();
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r2387 r2480  
    1414import java.text.SimpleDateFormat;
    1515import java.util.Date;
     16import java.util.Locale;
    1617import java.util.regex.Matcher;
    1718import java.util.regex.Pattern;
    1819
    1920import org.openstreetmap.josm.Main;
     21import org.openstreetmap.josm.io.ChangesetClosedException;
    2022import org.openstreetmap.josm.io.OsmApi;
    2123import org.openstreetmap.josm.io.OsmApiException;
    2224import org.openstreetmap.josm.io.OsmApiInitializationException;
    23 import org.openstreetmap.josm.io.OsmChangesetCloseException;
    2425import org.openstreetmap.josm.io.OsmTransferException;
    2526
     
    3940                + "Check the server URL in your preferences and your internet connection.</html>", Main.pref.get(
    4041                        "osm-server.url", "http://api.openstreetmap.org/api"));
    41         return msg;
    42     }
    43 
    44     /**
    45      * handles an exception caught during OSM API initialization
    46      *
    47      * @param e the exception
    48      */
    49     public static String explainOsmChangesetCloseException(OsmChangesetCloseException e) {
    50         e.printStackTrace();
    51         String changsetId = e.getChangeset() == null ? tr("unknown") : Long.toString(e.getChangeset().getId());
    52         String msg = tr(
    53                 "<html>Failed to close changeset ''{0}'' on the OSM server ''{1}''.<br>"
    54                 + "The changeset will automatically be closed by the server after a timeout.</html>", changsetId,
    55                 Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api"));
    5642        return msg;
    5743    }
     
    115101            if (m.matches()) {
    116102                long changesetId = Long.parseLong(m.group(1));
    117                 // Example: Tue Oct 15 10:00:00 UTC 2009
    118                 DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
     103                // Example: Tue Oct 15 10:00:00 UTC 2009. Always parsed with english locale, regardless
     104                // of the current locale in JOSM
     105                DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
    119106                Date closeDate = null;
    120107                try {
     
    153140
    154141    /**
     142     * Explains an exception thrown during upload because the changeset which data is
     143     * uploaded to is already closed.
     144     *
     145     * @param e the exception
     146     */
     147    public static String explainChangesetClosedException(ChangesetClosedException e) {
     148        String msg;
     149        SimpleDateFormat dateFormat = new SimpleDateFormat();
     150        msg = tr(
     151                "<html>Failed to upload to changeset <strong>{0}</strong><br>"
     152                +"because it has already been closed on {1}.</html>",
     153                e.getChangesetId(),
     154                dateFormat.format(e.getClosedOn())
     155        );
     156        e.printStackTrace();
     157        return msg;
     158    }
     159
     160    /**
    155161     * Explains an exception with a generic message dialog
    156162     *
     
    338344        if (e instanceof OsmApiInitializationException)
    339345            return explainOsmApiInitializationException((OsmApiInitializationException) e);
    340         if (e instanceof OsmChangesetCloseException)
    341             return explainOsmChangesetCloseException((OsmChangesetCloseException) e);
     346
     347        if (e instanceof ChangesetClosedException)
     348            return explainChangesetClosedException((ChangesetClosedException)e);
    342349
    343350        if (e instanceof OsmApiException) {
Note: See TracChangeset for help on using the changeset viewer.