Ignore:
Timestamp:
2020-11-05T15:23:26+01:00 (4 years ago)
Author:
GerdP
Message:

see #19582: Stays silent if download is incomplete cause of timeouts

  • rethrow OsmTransferException instead of only logging a warning so that a popup is shown
  • show a Notification if revert was cancelled, as it sometimes reacts a bit late

This will only improve reverter with JOSM 17920 or later, plugin is compatible with older versions.

Location:
applications/editors/josm/plugins/reverter/src/reverter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reverter/src/reverter/OsmServerMultiObjectReader.java

    r35382 r35638  
    4343        }
    4444    }
    45     private List<String> makeQueryStrings(OsmPrimitiveType type, Map<Long,Integer> list) {
     45    private static List<String> makeQueryStrings(OsmPrimitiveType type, Map<Long,Integer> list) {
    4646        List<String> result = new ArrayList<>((list.size()+maxQueryIds-1)/maxQueryIds);
    4747        StringBuilder sb = new StringBuilder();
     
    7373
    7474    protected static final int maxQueryIds = 128;
    75     public void readMultiObjects(OsmPrimitiveType type, Map<Long,Integer> list, ProgressMonitor progressMonitor) {
     75    public void readMultiObjects(OsmPrimitiveType type, Map<Long,Integer> list, ProgressMonitor progressMonitor) throws OsmTransferException {
    7676        for (String query : makeQueryStrings(type,list)) {
    7777            if (progressMonitor.isCanceled()) {
    7878                return;
    7979            }
    80             rdr.callback = new ParseCallback() {
    81                 @Override
    82                 public void primitiveParsed(PrimitiveId id) {
    83                     if (id.getType() == type && list.remove(id.getUniqueId()) != null) {
    84                         progressMonitor.worked(1);
    85                     }
     80            rdr.callback = id -> {
     81                if (id.getType() == type && list.remove(id.getUniqueId()) != null) {
     82                    progressMonitor.worked(1);
    8683                }
    8784            };
    8885            try (InputStream in = getInputStream(query, NullProgressMonitor.INSTANCE)) {
    8986                rdr.addData(in);
    90             } catch (IOException | IllegalDataException | OsmTransferException e) {
     87            } catch (IOException | IllegalDataException e) {
    9188                Logging.warn(e);
     89                throw new OsmTransferException(e);
    9290            } finally {
    9391                rdr.callback = null;
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetTask.java

    r35464 r35638  
    9898                newLayer = false; // reuse layer for subsequent reverts
    9999            } catch (OsmTransferException e) {
    100                 if (!allcmds.isEmpty()) {
    101                     GuiHelper.runInEDT(() -> UndoRedoHandler.getInstance().undo(allcmds.size()));
    102                 }
     100                rollback(allcmds);
    103101                Logging.error(e);
    104102                throw e;
    105103            } catch (UserCancelException e) {
    106                 if (!allcmds.isEmpty()) {
    107                     GuiHelper.runInEDT(() -> UndoRedoHandler.getInstance().undo(allcmds.size()));
    108                 }
    109                 Logging.warn("Revert canceled");
     104                rollback(allcmds);
     105                GuiHelper.executeByMainWorkerInEDT(() -> new Notification(tr("Revert was canceled")).show());
    110106                Logging.trace(e);
    111107                return;
     
    120116                }
    121117            });
     118        }
     119    }
     120
     121    private static void rollback(List<Command> allcmds) {
     122        if (!allcmds.isEmpty()) {
     123            GuiHelper.runInEDT(() -> UndoRedoHandler.getInstance().undo(allcmds.size()));
    122124        }
    123125    }
     
    185187    }
    186188
    187     @Override
    188     protected void cancel() {
     189        @Override
     190        protected void cancel() {
    189191        // nothing to do
    190     }
    191 
    192     @Override
    193     protected void finish() {
     192        }
     193
     194        @Override
     195        protected void finish() {
    194196        // nothing to do
    195197
    196     }
     198        }
    197199
    198200    /**
     201     * Return number of conflicts for this changeset.
    199202     * @return number of conflicts for this changeset
    200203     */
Note: See TracChangeset for help on using the changeset viewer.