Changeset 34028 in osm for applications/editors
- Timestamp:
- 2018-01-23T21:36:34+01:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/reverter/src/reverter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java
r33572 r34028 14 14 import reverter.ChangesetReverter.RevertType; 15 15 16 @SuppressWarnings("serial")17 16 public class RevertChangesetAction extends JosmAction { 18 17 19 18 public RevertChangesetAction() { 20 19 super(tr("Revert changeset"), "revert-changeset", tr("Revert changeset"), 21 Shortcut.registerShortcut("tool:revert", 22 tr("Tool: {0}", tr("Revert changeset")), 23 KeyEvent.VK_T, Shortcut.CTRL_SHIFT), 20 Shortcut.registerShortcut("tool:revert", tr("Tool: {0}", tr("Revert changeset")), KeyEvent.VK_T, Shortcut.CTRL_SHIFT), 24 21 true); 25 22 } 26 23 27 24 @Override 28 public void actionPerformed(ActionEvent arg0) {25 public void actionPerformed(ActionEvent e) { 29 26 final ChangesetIdQuery dlg = new ChangesetIdQuery(); 30 27 if (dlg.showDialog().getValue() != 1) return; … … 35 32 boolean newLayer = dlg.isNewLayerRequired(); 36 33 final boolean autoConfirmDownload = newLayer || changesetIds.size() > 1; 37 for (Integer changesetId : changesetIds) { 38 MainApplication.worker.submit(new RevertChangesetTask(changesetId, revertType, autoConfirmDownload, newLayer)); 39 newLayer = false; // reuse layer for subsequent reverts 40 } 34 MainApplication.worker.submit(new RevertChangesetTask(changesetIds, revertType, autoConfirmDownload, newLayer)); 41 35 } 42 36 } -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetTask.java
r33572 r34028 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.text.MessageFormat; 7 import java.util.ArrayList; 8 import java.util.Collection; 9 import java.util.Collections; 6 10 import java.util.List; 7 11 import java.util.concurrent.Callable; … … 11 15 import org.openstreetmap.josm.Main; 12 16 import org.openstreetmap.josm.command.Command; 17 import org.openstreetmap.josm.command.SequenceCommand; 13 18 import org.openstreetmap.josm.command.conflict.ConflictAddCommand; 14 19 import org.openstreetmap.josm.gui.MainApplication; … … 19 24 import org.openstreetmap.josm.gui.util.GuiHelper; 20 25 import org.openstreetmap.josm.io.OsmTransferException; 26 import org.openstreetmap.josm.tools.Logging; 27 import org.openstreetmap.josm.tools.UserCancelException; 21 28 22 29 import reverter.ChangesetReverter.RevertType; 23 30 24 31 public class RevertChangesetTask extends PleaseWaitRunnable { 25 private final int changesetId;32 private final Collection<Integer> changesetIds; 26 33 private final RevertType revertType; 27 private finalboolean newLayer;34 private boolean newLayer; 28 35 29 36 private ChangesetReverter rev; 30 37 private boolean downloadConfirmed; 38 private int numberOfConflicts; 31 39 32 40 public RevertChangesetTask(int changesetId, RevertType revertType) { … … 39 47 40 48 public RevertChangesetTask(int changesetId, RevertType revertType, boolean autoConfirmDownload, boolean newLayer) { 49 this(Collections.singleton(changesetId), revertType, autoConfirmDownload, newLayer); 50 } 51 52 public RevertChangesetTask(Collection<Integer> changesetIds, RevertType revertType, boolean autoConfirmDownload, boolean newLayer) { 41 53 super(tr("Reverting...")); 42 this.changesetId = changesetId;54 this.changesetIds = new ArrayList<>(changesetIds); 43 55 this.revertType = revertType; 44 56 this.downloadConfirmed = autoConfirmDownload; … … 73 85 @Override 74 86 protected void realRun() throws OsmTransferException { 87 numberOfConflicts = 0; 88 final List<Command> allcmds = new ArrayList<>(); 89 Logging.info("Reverting {0} changeset(s): {1}", changesetIds.size(), changesetIds); 90 for (int changesetId : changesetIds) { 91 try { 92 Logging.info("Reverting changeset {0}", changesetId); 93 allcmds.add(revertChangeset(changesetId)); 94 Logging.info("Reverted changeset {0}", changesetId); 95 newLayer = false; // reuse layer for subsequent reverts 96 } catch (OsmTransferException e) { 97 Logging.error(e); 98 throw e; 99 } catch (UserCancelException e) { 100 Logging.warn("Revert canceled"); 101 Logging.trace(e); 102 return; 103 } 104 } 105 if (!allcmds.isEmpty()) { 106 Command cmd = allcmds.size() == 1 ? allcmds.get(0) : new SequenceCommand(tr("Revert changeset"), allcmds); 107 GuiHelper.runInEDT(() -> { 108 MainApplication.undoRedo.add(cmd); 109 if (numberOfConflicts > 0) { 110 MainApplication.getMap().conflictDialog.warnNumNewConflicts(numberOfConflicts); 111 } 112 }); 113 } 114 } 115 116 private RevertChangesetCommand revertChangeset(int changesetId) throws OsmTransferException, UserCancelException { 75 117 progressMonitor.indeterminateSubTask(tr("Downloading changeset")); 76 118 try { 77 rev = new ChangesetReverter(changesetId, revertType, newLayer, 78 progressMonitor.createSubTaskMonitor(0, true)); 119 rev = new ChangesetReverter(changesetId, revertType, newLayer, progressMonitor.createSubTaskMonitor(0, true)); 79 120 } catch (final RevertRedactedChangesetException e) { 80 GuiHelper.runInEDT(new Runnable() { 81 @Override 82 public void run() { 83 new Notification( 84 e.getMessage()+"<br>"+ 85 tr("See {0}", "<a href=\"https://www.openstreetmap.org/redactions\">https://www.openstreetmap.org/redactions</a>")) 86 .setIcon(JOptionPane.ERROR_MESSAGE) 87 .setDuration(Notification.TIME_LONG) 88 .show(); 89 } 90 }); 121 GuiHelper.runInEDT(() -> new Notification( 122 e.getMessage()+"<br>"+ 123 tr("See {0}", "<a href=\"https://www.openstreetmap.org/redactions\">https://www.openstreetmap.org/redactions</a>")) 124 .setIcon(JOptionPane.ERROR_MESSAGE) 125 .setDuration(Notification.TIME_LONG) 126 .show()); 91 127 progressMonitor.cancel(); 92 128 } 93 if (progressMonitor.isCanceled()) return; 129 if (progressMonitor.isCanceled()) 130 throw new UserCancelException(); 94 131 95 132 // Check missing objects … … 99 136 // If missing created or updated objects, ask user 100 137 rev.checkMissingDeleted(); 101 if (!checkAndDownloadMissing()) return; 138 if (!checkAndDownloadMissing()) 139 throw new UserCancelException(); 102 140 } else { 103 141 // Don't ask user to download primitives going to be undeleted … … 106 144 } 107 145 108 if (progressMonitor.isCanceled()) return; 146 if (progressMonitor.isCanceled()) 147 throw new UserCancelException(); 109 148 rev.downloadObjectsHistory(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 110 if (progressMonitor.isCanceled()) return; 111 if (!checkAndDownloadMissing()) return; 149 if (progressMonitor.isCanceled()) 150 throw new UserCancelException(); 151 if (!checkAndDownloadMissing()) 152 throw new UserCancelException(); 112 153 rev.fixNodesWithoutCoordinates(progressMonitor); 113 154 List<Command> cmds = rev.getCommands(); 114 final Command cmd = new RevertChangesetCommand(tr(revertType == RevertType.FULL ? "Revert changeset #{0}" : 115 "Partially revert changeset #{0}", changesetId), cmds); 116 int n = 0; 155 if (cmds.isEmpty()) { 156 String msg = MessageFormat.format("No revert commands found for changeset {0}", changesetId); 157 Logging.warn(msg); 158 throw new OsmTransferException(msg); 159 } 117 160 for (Command c : cmds) { 118 161 if (c instanceof ConflictAddCommand) { 119 n ++;162 numberOfConflicts++; 120 163 } 121 164 } 122 final int newConflicts = n; 123 GuiHelper.runInEDT(new Runnable() { 124 @Override 125 public void run() { 126 MainApplication.undoRedo.add(cmd); 127 if (newConflicts > 0) { 128 MainApplication.getMap().conflictDialog.warnNumNewConflicts(newConflicts); 129 } 130 } 131 }); 165 return new RevertChangesetCommand(tr(revertType == RevertType.FULL ? "Revert changeset #{0}" : 166 "Partially revert changeset #{0}", changesetId), cmds); 132 167 } 133 168 … … 139 174 protected void finish() { 140 175 } 176 177 public final int getNumberOfConflicts() { 178 return numberOfConflicts; 179 } 141 180 }
Note:
See TracChangeset
for help on using the changeset viewer.