Changeset 32905 in osm for applications/editors/josm/plugins/reverter/src
- Timestamp:
- 2016-09-03T16:16:04+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/reverter/src/reverter
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reverter/src/reverter/ChangesetIdQuery.java
r32516 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 42 43 private final JRadioButton rbSelectionUndelete = new JRadioButton(tr("Revert selection and restore deleted objects")); 43 44 private final JCheckBox cbNewLayer = new JCheckBox(tr("Download as new layer")); 44 45 45 46 public Collection<Integer> getIdsInReverseOrder() { 46 47 return tcid.getIdsInReverseOrder(); 47 48 } 48 49 49 50 /** 50 51 * Replies true if the user requires to download into a new layer … … 64 65 65 66 public ChangesetIdQuery() { 66 super(Main.parent, tr("Revert changeset"), new String[] {tr("Revert"), tr("Cancel")}, true);67 contentInsets = new Insets(10, 10,10,5);68 67 super(Main.parent, tr("Revert changeset"), new String[] {tr("Revert"), tr("Cancel")}, true); 68 contentInsets = new Insets(10, 10, 10, 5); 69 69 70 panel.add(new JLabel(tr("Changeset id:"))); 70 71 … … 80 81 // forward the enter key stroke to the revert button 81 82 tcid.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false)); 82 83 83 84 panel.add(cbId, GBC.eol().fill(GBC.HORIZONTAL)); 84 85 … … 88 89 89 90 rbFull.setSelected(true); 90 panel.add(rbFull, GBC.eol().insets(0, 10,0,0).fill(GBC.HORIZONTAL));91 panel.add(rbFull, GBC.eol().insets(0, 10, 0, 0).fill(GBC.HORIZONTAL)); 91 92 panel.add(rbSelection, GBC.eol().fill(GBC.HORIZONTAL)); 92 93 panel.add(rbSelectionUndelete, GBC.eol().fill(GBC.HORIZONTAL)); … … 102 103 setButtonIcons(new String[] {"ok.png", "cancel.png" }); 103 104 setDefaultButton(1); 104 105 105 106 addWindowListener(new InternalWindowListener()); 106 107 super.setupDialog(); 107 108 108 109 final DataSet ds = Main.getLayerManager().getEditDataSet(); 109 110 110 111 // Disables "Download in new layer" choice if there is no current data set (i.e no data layer) 111 112 if (ds == null) { … … 118 119 rbSelectionUndelete.setEnabled(false); 119 120 } 120 121 121 122 // Enables/disables the Revert button when a changeset id is correctly set or not 122 123 tcid.getDocument().addDocumentListener(new DocumentListener() { 123 @Override public void removeUpdate(DocumentEvent e) { idChanged(); } 124 @Override public void insertUpdate(DocumentEvent e) { idChanged(); } 125 @Override public void changedUpdate(DocumentEvent e) { idChanged(); } 124 @Override public void removeUpdate(DocumentEvent e) { 125 idChanged(); 126 } 127 128 @Override public void insertUpdate(DocumentEvent e) { 129 idChanged(); 130 } 131 132 @Override public void changedUpdate(DocumentEvent e) { 133 idChanged(); 134 } 135 126 136 private void idChanged() { 127 137 if (tcid.hasFocus()) { … … 130 140 } 131 141 }); 132 133 if (Main.pref.getBoolean("downloadchangeset.autopaste", true)) { 142 143 if (Main.pref.getBoolean("downloadchangeset.autopaste", true)) { 134 144 tcid.tryToPasteFromClipboard(); 135 145 } 136 146 137 147 // Initially sets the revert button consistent with text id field contents 138 148 buttons.get(0).setEnabled(tcid.readIds()); … … 142 152 * Restore the current history from the preferences 143 153 * 144 * @param cbHistory 154 * @param cbHistory history combobox 145 155 */ 146 156 protected void restoreChangesetsHistory(HistoryComboBox cbHistory) { 147 List<String> cmtHistory = new LinkedList<>(Main.pref.getCollection(getClass().getName() + ".changesetsHistory", new LinkedList<String>())); 157 List<String> cmtHistory = new LinkedList<>( 158 Main.pref.getCollection(getClass().getName() + ".changesetsHistory", new LinkedList<String>())); 148 159 // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement() 149 160 Collections.reverse(cmtHistory); 150 161 cbHistory.setPossibleItems(cmtHistory); 151 162 } 152 163 153 164 /** 154 165 * Remind the current history in the preferences 155 * @param cbHistory 166 * @param cbHistory history combobox 156 167 */ 157 168 protected void remindChangesetsHistory(HistoryComboBox cbHistory) { … … 159 170 Main.pref.putCollection(getClass().getName() + ".changesetsHistory", cbHistory.getHistory()); 160 171 } 161 172 162 173 private class InternalWindowListener implements WindowListener { 163 174 @Override public void windowClosed(WindowEvent e) { … … 169 180 } 170 181 } 171 182 172 183 @Override public void windowOpened(WindowEvent e) {} 184 173 185 @Override public void windowClosing(WindowEvent e) {} 186 174 187 @Override public void windowIconified(WindowEvent e) {} 188 175 189 @Override public void windowDeiconified(WindowEvent e) {} 190 176 191 @Override public void windowActivated(WindowEvent e) {} 192 177 193 @Override public void windowDeactivated(WindowEvent e) {} 178 194 } -
applications/editors/josm/plugins/reverter/src/reverter/ChangesetIdsTextField.java
r31596 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 40 41 try { 41 42 final StringTokenizer tokenizer = new StringTokenizer(value, ",.+/ \t\n"); 42 while (tokenizer.hasMoreTokens()) {43 while (tokenizer.hasMoreTokens()) { 43 44 ids.add(Integer.parseInt(tokenizer.nextToken().trim())); 44 45 } -
applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java
r32516 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 50 51 public class ChangesetReverter { 51 52 52 public staticenum RevertType {53 public enum RevertType { 53 54 FULL, 54 55 SELECTION, 55 56 SELECTION_WITH_UNDELETE 56 57 } 57 58 58 59 public static final Collection<Long> MODERATOR_REDACTION_ACCOUNTS = Collections.unmodifiableCollection(Arrays.asList( 59 60 722137L, // OSMF Redaction Account … … 64 65 public final Changeset changeset; 65 66 public final RevertType revertType; 66 67 67 68 private final OsmDataLayer layer; // data layer associated with reverter 68 69 private final DataSet ds; // DataSet associated with reverter … … 84 85 } 85 86 } 87 86 88 private void addMissingHistoryIds(Iterable<HistoryOsmPrimitive> primitives) { 87 89 for (HistoryOsmPrimitive p : primitives) { 88 90 addIfMissing(p.getPrimitiveId()); 89 91 if (p.getType() == OsmPrimitiveType.WAY) { 90 for (long nd : ((HistoryWay) p).getNodes()) {91 addIfMissing(new SimplePrimitiveId(nd, OsmPrimitiveType.NODE));92 for (long nd : ((HistoryWay) p).getNodes()) { 93 addIfMissing(new SimplePrimitiveId(nd, OsmPrimitiveType.NODE)); 92 94 } 93 95 } … … 99 101 addIfMissing(p); 100 102 if (p.getType() == OsmPrimitiveType.WAY) { 101 for (Node nd : ((Way) p).getNodes()) {103 for (Node nd : ((Way) p).getNodes()) { 102 104 addIfMissing(nd); 103 105 } … … 124 126 /** 125 127 * creates a reverter for specific changeset and fetches initial data 126 * @param changesetId 127 * @param monitor 128 * @throws OsmTransferException 129 * @throws RevertRedactedChangesetException 128 * @param changesetId changeset id 129 * @param monitor progress monitor 130 * @throws OsmTransferException if data transfer errors occur 131 * @throws RevertRedactedChangesetException if a redacted changeset is requested 130 132 */ 131 133 public ChangesetReverter(int changesetId, RevertType revertType, boolean newLayer, ProgressMonitor monitor) … … 162 164 163 165 // Build our own lists of created/updated/modified objects for better performance 164 for (Iterator<ChangesetDataSetEntry> it = cds.iterator(); it.hasNext();) {166 for (Iterator<ChangesetDataSetEntry> it = cds.iterator(); it.hasNext();) { 165 167 ChangesetDataSetEntry entry = it.next(); 166 168 if (!checkOsmChangeEntry(entry)) continue; … … 174 176 } 175 177 } 178 176 179 public void checkMissingCreated() { 177 180 addMissingHistoryIds(created); 178 181 } 182 179 183 public void checkMissingUpdated() { 180 184 addMissingHistoryIds(updated); 181 185 } 186 182 187 public void checkMissingDeleted() { 183 188 addMissingHistoryIds(deleted); 184 189 } 185 186 private void readObjectVersion(OsmServerMultiObjectReader rdr, PrimitiveId id, int version, ProgressMonitor progressMonitor) throws OsmTransferException { 190 191 private void readObjectVersion(OsmServerMultiObjectReader rdr, PrimitiveId id, int version, ProgressMonitor progressMonitor) 192 throws OsmTransferException { 187 193 boolean readOK = false; 188 194 while (!readOK && version >= 1) { … … 209 215 /** 210 216 * fetch objects that were updated or deleted by changeset 211 * @param progressMonitor 212 * @throws OsmTransferException 217 * @param progressMonitor progress monitor 218 * @throws OsmTransferException if data transfer errors occur 213 219 */ 214 220 @SuppressWarnings("unchecked") … … 216 222 final OsmServerMultiObjectReader rdr = new OsmServerMultiObjectReader(); 217 223 218 progressMonitor.beginTask(tr("Downloading objects history"), updated.size()+deleted.size()+1);224 progressMonitor.beginTask(tr("Downloading objects history"), updated.size()+deleted.size()+1); 219 225 try { 220 226 for (HashSet<HistoryOsmPrimitive> collection : Arrays.asList(new HashSet[]{updated, deleted})) { … … 280 286 switch (p.getType()) { 281 287 case NODE: 282 return new Conflict<>((Node) p,new Node((Node)p), isMyDeleted);288 return new Conflict<>((Node) p, new Node((Node) p), isMyDeleted); 283 289 case CLOSEDWAY: 284 290 case WAY: 285 return new Conflict<>((Way) p,new Way((Way)p), isMyDeleted);291 return new Conflict<>((Way) p, new Way((Way) p), isMyDeleted); 286 292 case MULTIPOLYGON: 287 293 case RELATION: 288 return new Conflict<>((Relation) p,new Relation((Relation)p), isMyDeleted);294 return new Conflict<>((Relation) p, new Relation((Relation) p), isMyDeleted); 289 295 default: throw new AssertionError(); 290 296 } 291 297 } 292 298 293 private boolean hasEqualSemanticAttributes(OsmPrimitive current, HistoryOsmPrimitive history) {299 private boolean hasEqualSemanticAttributes(OsmPrimitive current, HistoryOsmPrimitive history) { 294 300 if (!current.getKeys().equals(history.getTags())) return false; 295 301 switch (current.getType()) { 296 302 case NODE: 297 LatLon currentCoor = ((Node) current).getCoor();298 LatLon historyCoor = ((HistoryNode) history).getCoords();303 LatLon currentCoor = ((Node) current).getCoor(); 304 LatLon historyCoor = ((HistoryNode) history).getCoords(); 299 305 if (currentCoor == historyCoor || (currentCoor != null && historyCoor != null && currentCoor.equals(historyCoor))) 300 306 return true; 301 307 // Handle case where a deleted note has been restored to avoid false conflicts (fix #josm8660) 302 308 if (currentCoor != null && historyCoor == null) { 303 LatLon previousCoor = ((Node) nds.getPrimitiveById(history.getPrimitiveId())).getCoor();309 LatLon previousCoor = ((Node) nds.getPrimitiveById(history.getPrimitiveId())).getCoor(); 304 310 return previousCoor != null && previousCoor.equals(currentCoor); 305 311 } 306 return false; 312 return false; 307 313 case CLOSEDWAY: 308 314 case WAY: 309 List<Node> currentNodes = ((Way) current).getNodes();310 List<Long> historyNodes = ((HistoryWay) history).getNodes();315 List<Node> currentNodes = ((Way) current).getNodes(); 316 List<Long> historyNodes = ((HistoryWay) history).getNodes(); 311 317 if (currentNodes.size() != historyNodes.size()) return false; 312 318 for (int i = 0; i < currentNodes.size(); i++) { … … 317 323 case RELATION: 318 324 List<org.openstreetmap.josm.data.osm.RelationMember> currentMembers = 319 ((Relation) current).getMembers();320 List<RelationMemberData> historyMembers = ((HistoryRelation) history).getMembers();325 ((Relation) current).getMembers(); 326 List<RelationMemberData> historyMembers = ((HistoryRelation) history).getMembers(); 321 327 if (currentMembers.size() != historyMembers.size()) return false; 322 328 for (int i = 0; i < currentMembers.size(); i++) { … … 326 332 if (!currentMember.getRole().equals(historyMember.getRole())) return false; 327 333 if (!currentMember.getMember().getPrimitiveId().equals(new SimplePrimitiveId( 328 historyMember.getMemberId(), historyMember.getMemberType()))) return false;334 historyMember.getMemberId(), historyMember.getMemberType()))) return false; 329 335 } 330 336 return true; … … 342 348 ////////////////////////////////////////////////////////////////////////// 343 349 // Create commands to restore/update all affected objects 344 DataSetCommandMerger merger = new DataSetCommandMerger(nds, ds);350 DataSetCommandMerger merger = new DataSetCommandMerger(nds, ds); 345 351 List<Command> cmds = merger.getCommandList(); 346 352 … … 368 374 369 375 for (Conflict<? extends OsmPrimitive> conflict : merger.getConflicts()) { 370 cmds.add(new ConflictAddCommand(layer, conflict));376 cmds.add(new ConflictAddCommand(layer, conflict)); 371 377 } 372 378 373 379 // Check objects versions 374 for (Iterator<ChangesetDataSetEntry> it = cds.iterator(); it.hasNext();) {380 for (Iterator<ChangesetDataSetEntry> it = cds.iterator(); it.hasNext();) { 375 381 ChangesetDataSetEntry entry = it.next(); 376 382 if (!checkOsmChangeEntry(entry)) continue; … … 385 391 /* Don't create conflict if changeset object and dataset object 386 392 * has same semantic attributes (but different versions) */ 387 !hasEqualSemanticAttributes(dp, hp)393 !hasEqualSemanticAttributes(dp, hp) 388 394 /* Don't create conflict if the object has to be deleted but has already been deleted */ 389 395 && !(toDelete.contains(dp) && dp.isDeleted())) { 390 cmds.add(new ConflictAddCommand(layer, CreateConflict(dp,396 cmds.add(new ConflictAddCommand(layer, CreateConflict(dp, 391 397 entry.getModificationType() == ChangesetModificationType.CREATED))); 392 398 conflicted.add(dp); … … 410 416 */ 411 417 if (!conflicted.contains(p)) { 412 cmds.add(new ConflictAddCommand(layer, CreateConflict(p, true)));418 cmds.add(new ConflictAddCommand(layer, CreateConflict(p, true))); 413 419 conflicted.add(p); 414 420 } … … 428 434 return cmds; 429 435 } 430 436 431 437 public boolean hasMissingObjects() { 432 438 return !missing.isEmpty(); 433 439 } 434 440 435 441 public void fixNodesWithoutCoordinates(ProgressMonitor progressMonitor) throws OsmTransferException { 436 442 for (Node n : nds.getNodes()) { … … 439 445 OsmPrimitive p = ds.getPrimitiveById(id); 440 446 if (p instanceof Node && p.getVersion() > 1) { 441 LatLon coor = ((Node) p).getCoor();447 LatLon coor = ((Node) p).getCoor(); 442 448 if (coor == null) { 443 449 final OsmServerMultiObjectReader rdr = new OsmServerMultiObjectReader(); … … 445 451 Collection<OsmPrimitive> result = rdr.parseOsm(progressMonitor.createSubTaskMonitor(1, true)).allPrimitives(); 446 452 if (!result.isEmpty()) { 447 coor = ((Node) result.iterator().next()).getCoor();453 coor = ((Node) result.iterator().next()).getCoor(); 448 454 } 449 455 } -
applications/editors/josm/plugins/reverter/src/reverter/DataSetCommandMerger.java
r31592 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 40 41 * constructor 41 42 */ 42 publicDataSetCommandMerger(DataSet sourceDataSet, DataSet targetDataSet) {43 DataSetCommandMerger(DataSet sourceDataSet, DataSet targetDataSet) { 43 44 this.sourceDataSet = sourceDataSet; 44 45 this.targetDataSet = targetDataSet; 45 46 merge(); 46 47 } 47 48 48 49 private void addChangeCommandIfNotEquals(OsmPrimitive target, OsmPrimitive newTarget, boolean nominal) { 49 50 if (!target.hasEqualSemanticAttributes(newTarget)) { 50 cmds.add(new ChangeCommand(target, newTarget));51 cmds.add(new ChangeCommand(target, newTarget)); 51 52 if (nominal) { 52 53 nominalRevertedPrimitives.add(target); … … 66 67 private void mergePrimitive(OsmPrimitive source, OsmPrimitive target, OsmPrimitive newTarget) { 67 68 newTarget.mergeFrom(source); 68 newTarget.setOsmId(target.getId(), (int)target.getVersion());69 newTarget.setOsmId(target.getId(), target.getVersion()); 69 70 newTarget.setVisible(target.isVisible()); 70 71 newTarget.setDeleted(false); … … 79 80 if (source.isIncomplete()) return; 80 81 if (!source.isVisible()) return; 81 Node target = (Node) getMergeTarget(source);82 Node target = (Node) getMergeTarget(source); 82 83 83 84 Node newTarget = new Node(target); 84 85 mergePrimitive(source, target, newTarget); 85 addChangeCommandIfNotEquals(target, newTarget,true);86 addChangeCommandIfNotEquals(target, newTarget, true); 86 87 } 87 88 … … 97 98 if (source.isIncomplete()) return; 98 99 if (!source.isVisible()) return; 99 Way target = (Way) getMergeTarget(source);100 Way target = (Way) getMergeTarget(source); 100 101 101 102 // use a set to avoid conflicts being added twice for closed ways, fixes #11811 … … 104 105 List<Node> newNodes = new ArrayList<>(source.getNodesCount()); 105 106 for (Node sourceNode : source.getNodes()) { 106 Node targetNode = (Node) getMergeTarget(sourceNode);107 Node targetNode = (Node) getMergeTarget(sourceNode); 107 108 // Target node is not deleted or it will be undeleted when running existing commands 108 109 if (!targetNode.isDeleted() || nominalRevertedPrimitives.contains(targetNode)) { … … 124 125 Main.warn("New conflict: "+c); 125 126 conflicts.add(c); 126 Node targetNode = (Node) c.getTheir();127 Node targetNode = (Node) c.getTheir(); 127 128 Node undeletedTargetNode = new Node(targetNode); 128 129 undeletedTargetNode.setDeleted(false); 129 addChangeCommandIfNotEquals(targetNode, undeletedTargetNode,false);130 addChangeCommandIfNotEquals(targetNode, undeletedTargetNode, false); 130 131 } 131 addChangeCommandIfNotEquals(target, newTarget,true);132 addChangeCommandIfNotEquals(target, newTarget, true); 132 133 } 133 134 } … … 152 153 OsmPrimitive undeletedTargetMember; 153 154 switch(targetMember.getType()) { 154 case NODE: undeletedTargetMember = new Node((Node) targetMember); break;155 case WAY: undeletedTargetMember = new Way((Way) targetMember); break;156 case RELATION: undeletedTargetMember = new Relation((Relation) targetMember); break;155 case NODE: undeletedTargetMember = new Node((Node) targetMember); break; 156 case WAY: undeletedTargetMember = new Way((Way) targetMember); break; 157 case RELATION: undeletedTargetMember = new Relation((Relation) targetMember); break; 157 158 default: throw new AssertionError(); 158 159 } 159 160 undeletedTargetMember.setDeleted(false); 160 addChangeCommandIfNotEquals(targetMember, undeletedTargetMember,false);161 addChangeCommandIfNotEquals(targetMember, undeletedTargetMember, false); 161 162 } 162 163 newMembers.add(new RelationMember(sourceMember.getRole(), targetMember)); … … 165 166 mergePrimitive(source, target, newRelation); 166 167 newRelation.setMembers(newMembers); 167 addChangeCommandIfNotEquals(target, newRelation,true);168 addChangeCommandIfNotEquals(target, newRelation, true); 168 169 } 169 170 170 171 private void merge() { 171 172 for (Node node: sourceDataSet.getNodes()) { -
applications/editors/josm/plugins/reverter/src/reverter/MultiOsmReader.java
r29548 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 24 25 setParser(parser); 25 26 parse(); 26 } catch (XMLStreamException e) {27 } catch (XMLStreamException e) { 27 28 throw new IllegalDataException(e); 28 } catch (Exception e) {29 } catch (Exception e) { 29 30 throw new IllegalDataException(e); 30 31 } 31 32 } 32 33 33 34 public void processData() throws IllegalDataException { 34 35 prepareDataSet(); -
applications/editors/josm/plugins/reverter/src/reverter/ObjectsHistoryAction.java
r31363 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 13 14 14 15 public ObjectsHistoryAction() { 15 super(tr("Objects history"), null,tr("History reverter"),16 super(tr("Objects history"), null, tr("History reverter"), 16 17 Shortcut.registerShortcut("tool:history", 17 18 tr("Tool: Display objects history dialog"), … … 20 21 setEnabled(false); 21 22 } 23 22 24 @Override 23 25 public void actionPerformed(ActionEvent arg0) { -
applications/editors/josm/plugins/reverter/src/reverter/ObjectsHistoryDialog.java
r23192 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 14 15 public class ObjectsHistoryDialog extends ExtendedDialog { 15 16 public ObjectsHistoryDialog() { 16 super(Main.parent, tr("Objects history"), new String[] {"Revert", "Cancel"}, false);17 contentInsets = new Insets(10, 10,10,5);17 super(Main.parent, tr("Objects history"), new String[] {"Revert", "Cancel"}, false); 18 contentInsets = new Insets(10, 10, 10, 5); 18 19 setButtonIcons(new String[] {"ok.png", "cancel.png" }); 19 20 setContent(new JPanel(new GridBagLayout())); -
applications/editors/josm/plugins/reverter/src/reverter/OsmServerMultiObjectReader.java
r30990 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 22 23 } 23 24 24 public void readObject(long id, int version,OsmPrimitiveType type,ProgressMonitor progressMonitor) throws OsmTransferException {25 public void readObject(long id, int version, OsmPrimitiveType type, ProgressMonitor progressMonitor) throws OsmTransferException { 25 26 StringBuffer sb = new StringBuffer(); 26 27 sb.append(type.getAPIName()); … … 38 39 } 39 40 } 41 40 42 /** 41 43 * Method to parse downloaded objects 42 44 * @return the data requested 43 * @throws SAXException 44 * @throws IOException 45 * @throws SAXException in case of SAX error 46 * @throws IOException in case of I/O error 45 47 */ 46 48 @Override -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java
r31625 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 17 18 18 19 public RevertChangesetAction() { 19 super(tr("Revert changeset"), "revert-changeset",tr("Revert changeset"),20 super(tr("Revert changeset"), "revert-changeset", tr("Revert changeset"), 20 21 Shortcut.registerShortcut("tool:revert", 21 22 tr("Tool: {0}", tr("Revert changeset")), … … 25 26 26 27 @Override 27 public void actionPerformed(ActionEvent arg0) 28 public void actionPerformed(ActionEvent arg0) { 28 29 final ChangesetIdQuery dlg = new ChangesetIdQuery(); 29 30 if (dlg.showDialog().getValue() != 1) return; -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetCommand.java
r27795 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 3 4 import java.util.Collection; 5 4 6 import javax.swing.Icon; 5 7 -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetHandler.java
r30258 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 11 12 public static final String permissionKey = "remotecontrol.permission.revert_changeset"; 12 13 public static final boolean permissionDefault = true; 13 14 14 15 private int changesetId; 15 16 … … 17 18 protected void handleRequest() throws RequestHandlerErrorException, 18 19 RequestHandlerBadRequestException { 19 try 20 { 20 try { 21 21 Main.worker.submit(new RevertChangesetTask(changesetId, ChangesetReverter.RevertType.FULL, true)); 22 22 } catch (Exception ex) { … … 25 25 throw new RequestHandlerErrorException(ex); 26 26 } 27 28 27 } 29 28 -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetTask.java
r31594 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 17 18 import org.openstreetmap.josm.gui.util.GuiHelper; 18 19 import org.openstreetmap.josm.io.OsmTransferException; 20 19 21 import reverter.ChangesetReverter.RevertType; 20 22 … … 30 32 this(changesetId, revertType, false); 31 33 } 32 34 33 35 public RevertChangesetTask(int changesetId, RevertType revertType, boolean autoConfirmDownload) { 34 36 this(changesetId, revertType, autoConfirmDownload, false); 35 37 } 36 38 37 39 public RevertChangesetTask(int changesetId, RevertType revertType, boolean autoConfirmDownload, boolean newLayer) { 38 40 super(tr("Reverting...")); … … 110 112 List<Command> cmds = rev.getCommands(); 111 113 final Command cmd = new RevertChangesetCommand(tr(revertType == RevertType.FULL ? "Revert changeset #{0}" : 112 "Partially revert changeset #{0}", changesetId),cmds);114 "Partially revert changeset #{0}", changesetId), cmds); 113 115 int n = 0; 114 116 for (Command c : cmds) { -
applications/editors/josm/plugins/reverter/src/reverter/RevertRedactedChangesetException.java
r30031 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 3 4 /** 4 * Exception thrown if a changeset created by a modeartor redaction account is being reverted. 5 * Exception thrown if a changeset created by a modeartor redaction account is being reverted. 5 6 */ 6 7 @SuppressWarnings("serial") -
applications/editors/josm/plugins/reverter/src/reverter/ReverterPlugin.java
r29854 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 -
applications/editors/josm/plugins/reverter/src/reverter/ReverterUploadHook.java
r32516 r32905 1 // License: GPL. For details, see LICENSE file. 1 2 package reverter; 2 3 … … 11 12 pluginString = "reverter_plugin/" + plugin.getPluginInformation().version; 12 13 } 14 13 15 @Override 14 16 public boolean checkUpload(APIDataSet apiDataSet) { -
applications/editors/josm/plugins/reverter/src/reverter/corehacks/ChangesetDataSet.java
r30737 r32905 6 6 import java.util.Iterator; 7 7 import java.util.Map; 8 import java.util.Map.Entry; 8 9 import java.util.Set; 9 import java.util.Map.Entry;10 10 11 11 import org.openstreetmap.josm.data.osm.PrimitiveId; … … 18 18 public class ChangesetDataSet { 19 19 20 public staticenum ChangesetModificationType {20 public enum ChangesetModificationType { 21 21 CREATED, 22 22 UPDATED, … … 24 24 } 25 25 26 public static interface ChangesetDataSetEntry { 27 public ChangesetModificationType getModificationType(); 28 public HistoryOsmPrimitive getPrimitive(); 29 public int getEarliestVersion(); 30 } 31 32 final private Map<PrimitiveId, Integer> earliestVersions = new HashMap<>(); 33 final private Map<PrimitiveId, HistoryOsmPrimitive> primitives = new HashMap<>(); 34 final private Map<PrimitiveId, ChangesetModificationType> modificationTypes = new HashMap<>(); 26 public interface ChangesetDataSetEntry { 27 ChangesetModificationType getModificationType(); 28 29 HistoryOsmPrimitive getPrimitive(); 30 31 int getEarliestVersion(); 32 } 33 34 private final Map<PrimitiveId, Integer> earliestVersions = new HashMap<>(); 35 private final Map<PrimitiveId, HistoryOsmPrimitive> primitives = new HashMap<>(); 36 private final Map<PrimitiveId, ChangesetModificationType> modificationTypes = new HashMap<>(); 35 37 36 38 /** … … 42 44 * @throws IllegalArgumentException thrown if cmt is null 43 45 */ 44 public void put(HistoryOsmPrimitive primitive, ChangesetModificationType cmt) throws IllegalArgumentException {45 CheckParameterUtil.ensureParameterNotNull(primitive, "primitive");46 CheckParameterUtil.ensureParameterNotNull(cmt, "cmt");46 public void put(HistoryOsmPrimitive primitive, ChangesetModificationType cmt) throws IllegalArgumentException { 47 CheckParameterUtil.ensureParameterNotNull(primitive, "primitive"); 48 CheckParameterUtil.ensureParameterNotNull(cmt, "cmt"); 47 49 PrimitiveId pid = primitive.getPrimitiveId(); 48 50 if (primitives.containsKey(pid)) { … … 51 53 Integer earliest = earliestVersions.get(pid); 52 54 if (earliest == null || primitive.getVersion() < earliest) { 53 earliestVersions.put(pid, (int) primitive.getVersion());55 earliestVersions.put(pid, (int) primitive.getVersion()); 54 56 if (cmt == ChangesetModificationType.CREATED) 55 57 modificationTypes.put(pid, cmt); … … 61 63 } 62 64 if (earliestVersions.get(pid) == null) { 63 earliestVersions.put(pid, (int) primitives.get(pid).getVersion());65 earliestVersions.put(pid, (int) primitives.get(pid).getVersion()); 64 66 } 65 67 } … … 93 95 public int getEarliestVersion(PrimitiveId id) { 94 96 Integer earliestVersion = earliestVersions.get(id); 95 if (earliestVersion == null) earliestVersion = (int) primitives.get(id).getVersion();97 if (earliestVersion == null) earliestVersion = (int) primitives.get(id).getVersion(); 96 98 return earliestVersion; 97 99 } … … 144 146 */ 145 147 public Set<HistoryOsmPrimitive> getPrimitivesByModificationType(ChangesetModificationType cmt) throws IllegalArgumentException { 146 CheckParameterUtil.ensureParameterNotNull(cmt, "cmt");148 CheckParameterUtil.ensureParameterNotNull(cmt, "cmt"); 147 149 HashSet<HistoryOsmPrimitive> ret = new HashSet<>(); 148 150 for (Entry<PrimitiveId, ChangesetModificationType> entry: modificationTypes.entrySet()) { … … 172 174 */ 173 175 public HistoryOsmPrimitive getPrimitive(PrimitiveId id) { 174 if (id == null) 176 if (id == null) return null; 175 177 return primitives.get(id); 176 178 } … … 185 187 private final int earliestVersion; 186 188 187 publicDefaultChangesetDataSetEntry(ChangesetModificationType modificationType, HistoryOsmPrimitive primitive, int earliestVersion) {189 DefaultChangesetDataSetEntry(ChangesetModificationType modificationType, HistoryOsmPrimitive primitive, int earliestVersion) { 188 190 this.modificationType = modificationType; 189 191 this.primitive = primitive; … … 191 193 } 192 194 195 @Override 193 196 public ChangesetModificationType getModificationType() { 194 197 return modificationType; 195 198 } 196 199 200 @Override 197 201 public HistoryOsmPrimitive getPrimitive() { 198 202 return primitive; 199 203 } 200 204 205 @Override 201 206 public int getEarliestVersion() { 202 207 return earliestVersion; … … 207 212 private final Iterator<Entry<PrimitiveId, ChangesetModificationType>> typeIterator; 208 213 209 publicDefaultIterator() {214 DefaultIterator() { 210 215 typeIterator = modificationTypes.entrySet().iterator(); 211 216 } 212 217 218 @Override 213 219 public boolean hasNext() { 214 220 return typeIterator.hasNext(); 215 221 } 216 222 223 @Override 217 224 public ChangesetDataSetEntry next() { 218 225 Entry<PrimitiveId, ChangesetModificationType> next = typeIterator.next(); … … 220 227 HistoryOsmPrimitive primitive = primitives.get(next.getKey()); 221 228 Integer earliestVersion = earliestVersions.get(next.getKey()); 222 if (earliestVersion == null) earliestVersion = (int) primitive.getVersion();229 if (earliestVersion == null) earliestVersion = (int) primitive.getVersion(); 223 230 return new DefaultChangesetDataSetEntry(type, primitive, earliestVersion); 224 231 } 225 232 233 @Override 226 234 public void remove() { 227 235 throw new UnsupportedOperationException(); -
applications/editors/josm/plugins/reverter/src/reverter/corehacks/OsmChangesetContentParser.java
r32685 r32905 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package reverter.corehacks; 3 3 … … 25 25 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 26 26 import org.openstreetmap.josm.tools.CheckParameterUtil; 27 import org.openstreetmap.josm.tools.XmlParsingException; 27 28 import org.openstreetmap.josm.tools.date.DateUtils; 28 import org.openstreetmap.josm.tools.XmlParsingException;29 29 import org.xml.sax.Attributes; 30 30 import org.xml.sax.InputSource; … … 79 79 try { 80 80 l = Long.parseLong(v); 81 } catch (NumberFormatException e) {81 } catch (NumberFormatException e) { 82 82 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long. Got ''{1}''.", name, v)); 83 83 } … … 104 104 } 105 105 */ 106 protected Double getAttributeDouble(Attributes attr, String name) throws SAXException{ 106 107 protected Double getAttributeDouble(Attributes attr, String name) throws SAXException { 107 108 String v = attr.getValue(name); 108 109 if (v == null) { … … 112 113 try { 113 114 d = Double.parseDouble(v); 114 } catch (NumberFormatException e) {115 } catch (NumberFormatException e) { 115 116 throwException(tr("Illegal value for attribute ''{0}'' of type double. Got ''{1}''.", name, v)); 116 117 } … … 118 119 } 119 120 120 protected String getMandatoryAttributeString(Attributes attr, String name) throws SAXException {121 protected String getMandatoryAttributeString(Attributes attr, String name) throws SAXException { 121 122 String v = attr.getValue(name); 122 123 if (v == null) { … … 133 134 } 134 135 */ 135 protected boolean getMandatoryAttributeBoolean(Attributes attr, String name) throws SAXException{ 136 137 protected boolean getMandatoryAttributeBoolean(Attributes attr, String name) throws SAXException { 136 138 String v = attr.getValue(name); 137 139 if (v == null) { … … 145 147 } 146 148 147 protected 148 long id = getMandatoryAttributeLong(atts, "id");149 long version = getMandatoryAttributeLong(atts, "version");150 long changesetId = getMandatoryAttributeLong(atts, "changeset");151 boolean visible = getMandatoryAttributeBoolean(atts, "visible");149 protected HistoryOsmPrimitive createPrimitive(Attributes atts, OsmPrimitiveType type) throws SAXException { 150 long id = getMandatoryAttributeLong(atts, "id"); 151 long version = getMandatoryAttributeLong(atts, "version"); 152 long changesetId = getMandatoryAttributeLong(atts, "changeset"); 153 boolean visible = getMandatoryAttributeBoolean(atts, "visible"); 152 154 String v = getMandatoryAttributeString(atts, "timestamp"); 153 155 Date timestamp = DateUtils.fromString(v); … … 158 160 Double lat = getAttributeDouble(atts, "lat"); 159 161 Double lon = getAttributeDouble(atts, "lon"); 160 LatLon coor = (lat != null && lon != null) ? new LatLon(lat, lon) : null;162 LatLon coor = (lat != null && lon != null) ? new LatLon(lat, lon) : null; 161 163 primitive = new HistoryNode( 162 id, version,visible,User.getAnonymous(),changesetId,timestamp, coor164 id, version, visible, User.getAnonymous(), changesetId, timestamp, coor 163 165 ); 164 166 165 167 } else if (type.equals(OsmPrimitiveType.WAY)) { 166 168 primitive = new HistoryWay( 167 id, version,visible,User.getAnonymous(),changesetId,timestamp169 id, version, visible, User.getAnonymous(), changesetId, timestamp 168 170 ); 169 } if (type.equals(OsmPrimitiveType.RELATION)) {171 } else if (type.equals(OsmPrimitiveType.RELATION)) { 170 172 primitive = new HistoryRelation( 171 id, version,visible,User.getAnonymous(),changesetId,timestamp173 id, version, visible, User.getAnonymous(), changesetId, timestamp 172 174 ); 173 175 } … … 176 178 177 179 protected void startNode(Attributes atts) throws SAXException { 178 currentPrimitive = createPrimitive(atts, OsmPrimitiveType.NODE);180 currentPrimitive = createPrimitive(atts, OsmPrimitiveType.NODE); 179 181 } 180 182 181 183 protected void startWay(Attributes atts) throws SAXException { 182 currentPrimitive= createPrimitive(atts, OsmPrimitiveType.WAY); 183 } 184 currentPrimitive = createPrimitive(atts, OsmPrimitiveType.WAY); 185 } 186 184 187 protected void startRelation(Attributes atts) throws SAXException { 185 currentPrimitive = createPrimitive(atts, OsmPrimitiveType.RELATION);188 currentPrimitive = createPrimitive(atts, OsmPrimitiveType.RELATION); 186 189 } 187 190 188 191 protected void handleTag(Attributes atts) throws SAXException { 189 String key = getMandatoryAttributeString(atts, "k");190 String value = getMandatoryAttributeString(atts, "v");191 currentPrimitive.put(key, value);192 String key = getMandatoryAttributeString(atts, "k"); 193 String value = getMandatoryAttributeString(atts, "v"); 194 currentPrimitive.put(key, value); 192 195 } 193 196 194 197 protected void handleNodeReference(Attributes atts) throws SAXException { 195 198 long ref = getMandatoryAttributeLong(atts, "ref"); 196 ((HistoryWay) currentPrimitive).addNode(ref);199 ((HistoryWay) currentPrimitive).addNode(ref); 197 200 } 198 201 … … 203 206 try { 204 207 type = OsmPrimitiveType.fromApiTypeName(v); 205 } catch (IllegalArgumentException e) {208 } catch (IllegalArgumentException e) { 206 209 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type OsmPrimitiveType. Got ''{1}''.", "type", v)); 207 210 } 208 211 String role = getMandatoryAttributeString(atts, "role"); 209 RelationMemberData member = new RelationMemberData(role, type, ref);210 ((HistoryRelation) currentPrimitive).addMember(member);212 RelationMemberData member = new RelationMemberData(role, type, ref); 213 ((HistoryRelation) currentPrimitive).addMember(member); 211 214 } 212 215 … … 233 236 currentModificationType = ChangesetModificationType.DELETED; 234 237 } else { 235 System.err.println(tr("Warning: unsupported start element ''{0}'' in changeset content at position ({1},{2}). Skipping.", qName, locator.getLineNumber(), locator.getColumnNumber())); 238 System.err.println(tr("Warning: unsupported start element ''{0}'' in changeset content at position ({1},{2}). Skipping.", 239 qName, locator.getLineNumber(), locator.getColumnNumber())); 236 240 } 237 241 } … … 243 247 || qName.equals("relation")) { 244 248 if (currentModificationType == null) { 245 throwException(tr("Illegal document structure. Found node, way, or relation outside of ''create'', ''modify'', or ''delete''.")); 249 throwException( 250 tr("Illegal document structure. Found node, way, or relation outside of ''create'', ''modify'', or ''delete''.")); 246 251 } 247 252 data.put(currentPrimitive, currentModificationType); … … 261 266 // do nothing 262 267 } else { 263 System.err.println(tr("Warning: unsupported end element ''{0}'' in changeset content at position ({1},{2}). Skipping.", qName, locator.getLineNumber(), locator.getColumnNumber())); 268 System.err.println(tr("Warning: unsupported end element ''{0}'' in changeset content at position ({1},{2}). Skipping.", 269 qName, locator.getLineNumber(), locator.getColumnNumber())); 264 270 } 265 271 } … … 310 316 progressMonitor.indeterminateSubTask(tr("Parsing changeset content ...")); 311 317 SAXParserFactory.newInstance().newSAXParser().parse(source, new Parser()); 312 } catch (XmlParsingException e){318 } catch (XmlParsingException e) { 313 319 throw e; 314 320 } catch (ParserConfigurationException e) { 315 321 throw new XmlParsingException(e); 316 } catch (SAXException e) {322 } catch (SAXException e) { 317 323 throw new XmlParsingException(e); 318 } catch (IOException e) {324 } catch (IOException e) { 319 325 throw new XmlParsingException(e); 320 326 } finally { -
applications/editors/josm/plugins/reverter/src/reverter/corehacks/OsmServerChangesetReader.java
r30737 r32905 36 36 * 37 37 */ 38 public OsmServerChangesetReader() {38 public OsmServerChangesetReader() { 39 39 setDoAuthenticate(false); 40 40 } … … 71 71 monitor.indeterminateSubTask(tr("Downloading changesets ...")); 72 72 return OsmChangesetParser.parse(in, monitor.createSubTaskMonitor(1, true)); 73 } catch (OsmTransferException e) {73 } catch (OsmTransferException e) { 74 74 throw e; 75 } catch (IllegalDataException e) {75 } catch (IllegalDataException e) { 76 76 throw new OsmTransferException(e); 77 77 } finally { … … 96 96 } 97 97 try { 98 monitor.beginTask(tr("Reading changeset {0} ...", id));98 monitor.beginTask(tr("Reading changeset {0} ...", id)); 99 99 StringBuffer sb = new StringBuffer(); 100 100 sb.append("changeset/").append(id); … … 107 107 return null; 108 108 return changesets.get(0); 109 } catch (OsmTransferException e) {109 } catch (OsmTransferException e) { 110 110 throw e; 111 } catch (IllegalDataException e) {111 } catch (IllegalDataException e) { 112 112 throw new OsmTransferException(e); 113 113 } finally { … … 132 132 } 133 133 try { 134 monitor.beginTask(trn("Downloading {0} changeset ...", "Downloading {0} changesets ...", ids.size(),ids.size()));134 monitor.beginTask(trn("Downloading {0} changeset ...", "Downloading {0} changesets ...", ids.size(), ids.size())); 135 135 monitor.setTicksCount(ids.size()); 136 136 List<Changeset> ret = new ArrayList<>(); 137 int i =0;138 for (Iterator<Integer> it = ids.iterator(); it.hasNext(); 137 int i = 0; 138 for (Iterator<Integer> it = ids.iterator(); it.hasNext();) { 139 139 int id = it.next(); 140 140 if (id <= 0) { … … 147 147 if (in == null) 148 148 return null; 149 monitor.indeterminateSubTask(tr("({0}/{1}) Downloading changeset {2} ...", i, ids.size(), id));149 monitor.indeterminateSubTask(tr("({0}/{1}) Downloading changeset {2} ...", i, ids.size(), id)); 150 150 List<Changeset> changesets = OsmChangesetParser.parse(in, monitor.createSubTaskMonitor(1, true)); 151 151 if (changesets == null || changesets.isEmpty()) { … … 156 156 } 157 157 return ret; 158 } catch (OsmTransferException e) {158 } catch (OsmTransferException e) { 159 159 throw e; 160 } catch (IllegalDataException e) {160 } catch (IllegalDataException e) { 161 161 throw new OsmTransferException(e); 162 162 } finally { … … 176 176 public ChangesetDataSet downloadChangeset(int id, ProgressMonitor monitor) throws IllegalArgumentException, OsmTransferException { 177 177 if (id <= 0) 178 throw new IllegalArgumentException(MessageFormat.format("Expected value of type integer > 0 for parameter ''{0}'', got {1}", "id", id)); 178 throw new IllegalArgumentException( 179 MessageFormat.format("Expected value of type integer > 0 for parameter ''{0}'', got {1}", "id", id)); 179 180 if (monitor == null) { 180 181 monitor = NullProgressMonitor.INSTANCE; … … 191 192 ChangesetDataSet ds = parser.parse(monitor.createSubTaskMonitor(1, true)); 192 193 return ds; 193 } catch (UnsupportedEncodingException e) {194 throw new OsmTransferException(e); 195 } catch (XmlParsingException e) {194 } catch (UnsupportedEncodingException e) { 195 throw new OsmTransferException(e); 196 } catch (XmlParsingException e) { 196 197 throw new OsmTransferException(e); 197 198 } finally {
Note:
See TracChangeset
for help on using the changeset viewer.