Changeset 21691 in osm for applications/editors/josm/plugins
- Timestamp:
- 2010-06-14T00:43:16+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/reverter/src/reverter
- Files:
-
- 2 added
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java
r21675 r21691 43 43 */ 44 44 public class ChangesetReverter { 45 46 public static enum RevertType { 47 FULL, 48 SELECTION, 49 SELECTION_WITH_UNDELETE 50 } 51 45 52 public final int changesetId; 46 53 public final Changeset changeset; … … 120 127 121 128 // Build our own lists of created/updated/modified objects for better performance 122 Iterator<ChangesetDataSetEntry> iterator = cds.iterator(); 123 while (iterator.hasNext()) { 124 ChangesetDataSetEntry entry = iterator.next(); 129 for (Iterator<ChangesetDataSetEntry> it = cds.iterator();it.hasNext();) { 130 ChangesetDataSetEntry entry = it.next(); 125 131 if (entry.getModificationType() == ChangesetModificationType.CREATED) { 126 132 created.add(entry.getPrimitive()); … … 191 197 p.setDeleted(true); 192 198 p.setModified(false); 199 ReverterPlugin.undeletedObjects.addPrimitive(ds, 200 new PrimitiveIdVersion(p.getPrimitiveId(),(int)p.getVersion())); 193 201 } 194 202 } … … 280 288 281 289 // Check objects versions 282 Iterator<ChangesetDataSetEntry> iterator = cds.iterator(); 283 while (iterator.hasNext()) { 284 ChangesetDataSetEntry entry = iterator.next(); 290 for (Iterator<ChangesetDataSetEntry> it = cds.iterator();it.hasNext();) { 291 ChangesetDataSetEntry entry = it.next(); 285 292 HistoryOsmPrimitive hp = entry.getPrimitive(); 286 293 OsmPrimitive dp = ds.getPrimitiveById(hp.getPrimitiveId()); … … 306 313 * isn't going to be deleted or modified, create a conflict. 307 314 */ 308 for (OsmPrimitive p : toDelete.toArray(new OsmPrimitive[0])) { 315 for (Iterator<OsmPrimitive> it = toDelete.iterator(); it.hasNext();) { 316 OsmPrimitive p = it.next(); 309 317 if (p.isDeleted()) { 310 toDelete.remove(p);318 it.remove(); 311 319 continue; 312 320 } … … 321 329 conflicted.add(p); 322 330 } 323 toDelete.remove(p);331 it.remove(); 324 332 break; 325 333 } -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java
r21675 r21691 75 75 rev.checkMissingDeleted(); 76 76 // Don't ask user to download primitives going to be undeleted 77 rev.downloadMissingPrimitives(NullProgressMonitor.INSTANCE); 77 rev.downloadMissingPrimitives(progressMonitor.createSubTaskMonitor(0, false)); 78 if (progressMonitor.isCancelled()) return; 78 79 rev.checkMissingCreated(); 79 80 rev.checkMissingUpdated(); -
applications/editors/josm/plugins/reverter/src/reverter/ReverterPlugin.java
r21634 r21691 11 11 import org.openstreetmap.josm.actions.UploadAction; 12 12 import org.openstreetmap.josm.gui.MainMenu; 13 import org.openstreetmap.josm.gui.MapView; 13 14 import org.openstreetmap.josm.plugins.Plugin; 14 15 import org.openstreetmap.josm.plugins.PluginInformation; 15 16 16 17 public class ReverterPlugin extends Plugin { 18 static UndeletedObjectsStorage undeletedObjects = new UndeletedObjectsStorage(); 17 19 public ReverterPlugin(PluginInformation info) { 18 20 super(info); 19 JMenu historyMenu = Main.main.menu.addMenu(marktr("History"), KeyEvent.VK_R, Main.main.menu.defaultMenuPos,ht("/Plugin/Reverter")); 21 JMenu historyMenu = Main.main.menu.addMenu(marktr("History"), KeyEvent.VK_R, 22 Main.main.menu.defaultMenuPos,ht("/Plugin/Reverter")); 20 23 //MainMenu.add(historyMenu, new ObjectsHistoryAction()); 21 24 MainMenu.add(historyMenu, new RevertChangesetAction()); 22 UploadAction.registerUploadHook(new ModifiyUploadOrderHook()); 23 24 //TODO: Download deleted objects 25 MapView.addLayerChangeListener(undeletedObjects); 26 UploadAction.registerUploadHook(new ReverterUploadHook(undeletedObjects)); 25 27 } 26 28 } -
applications/editors/josm/plugins/reverter/src/reverter/ReverterUploadHook.java
r21657 r21691 2 2 package reverter; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import java.util.Collections; 5 7 import java.util.Comparator; 8 import java.util.HashMap; 9 import java.util.HashSet; 10 import java.util.LinkedList; 11 import java.util.List; 12 import java.util.Map.Entry; 6 13 14 import javax.swing.JOptionPane; 15 16 import org.openstreetmap.josm.Main; 7 17 import org.openstreetmap.josm.data.APIDataSet; 18 import org.openstreetmap.josm.data.osm.DataSet; 8 19 import org.openstreetmap.josm.data.osm.Node; 9 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 13 24 import org.openstreetmap.josm.actions.upload.UploadHook; 14 25 15 /** 16 * Sort modified objects before uploading in order: nodes, ways, relations 17 * It is needed because objects undeleted by reverter is marked as "modified", 18 * but in fact they're re-added to JOSM. Without this the "precondition failed" 19 * error appears when trying to upload objects undeleted by reverter. 20 * 21 */ 22 public class ModifiyUploadOrderHook implements UploadHook { 26 public class ReverterUploadHook implements UploadHook { 27 private UndeletedObjectsStorage undeletedStorage; 28 29 public ReverterUploadHook(UndeletedObjectsStorage undeletedStorage) { 30 this.undeletedStorage = undeletedStorage; 31 } 32 33 public boolean checkUpload(APIDataSet apiDataSet) { 34 // Determine DataSet associated with APIDataSet 35 DataSet ds = null; 36 if (!apiDataSet.getPrimitivesToAdd().isEmpty()) { 37 ds = apiDataSet.getPrimitivesToAdd().get(0).getDataSet(); 38 } else if (!apiDataSet.getPrimitivesToUpdate().isEmpty()) { 39 ds = apiDataSet.getPrimitivesToUpdate().get(0).getDataSet(); 40 } else if (!apiDataSet.getPrimitivesToDelete().isEmpty()) { 41 ds = apiDataSet.getPrimitivesToDelete().get(0).getDataSet(); 42 } 43 if (ds == null) return true; 44 45 /* Sort modified objects before uploading in order: nodes, ways, relations. 46 * It is needed because objects undeleted by reverter is marked as "modified", but they 47 * cannot be referenced as well as deleted objects. Without this the "precondition failed" 48 * error appears when trying to upload objects undeleted by reverter. 49 */ 50 if (undeletedStorage.haveUndeletedObjects(ds)) { 51 Collections.sort( 52 apiDataSet.getPrimitivesToUpdate(), 53 new Comparator<OsmPrimitive>() { 54 public int compare(OsmPrimitive o1, OsmPrimitive o2) { 55 if (o1 instanceof Node && o2 instanceof Node) 56 return 0; 57 else if (o1 instanceof Node) 58 return -1; 59 else if (o2 instanceof Node) 60 return 1; 61 62 if (o1 instanceof Way && o2 instanceof Way) 63 return 0; 64 else if (o1 instanceof Way && o2 instanceof Relation) 65 return -1; 66 else if (o2 instanceof Way && o1 instanceof Relation) 67 return 1; 68 69 return 0; 70 } 71 } 72 ); 73 } 74 /* Remove primitives that was undeleted and deleted again from list of primitives 75 * to be deleted. 76 */ 77 apiDataSet.getPrimitivesToDelete().removeAll(undeletedStorage.getUndeletedObjects(ds)); 23 78 24 public boolean checkUpload(APIDataSet apiDataSet) { 25 Collections.sort( 26 apiDataSet.getPrimitivesToUpdate(), 27 new Comparator<OsmPrimitive>() { 28 public int compare(OsmPrimitive o1, OsmPrimitive o2) { 29 if (o1 instanceof Node && o2 instanceof Node) 30 return 0; 31 else if (o1 instanceof Node) 32 return -1; 33 else if (o2 instanceof Node) 34 return 1; 35 36 if (o1 instanceof Way && o2 instanceof Way) 37 return 0; 38 else if (o1 instanceof Way && o2 instanceof Relation) 39 return -1; 40 else if (o2 instanceof Way && o1 instanceof Relation) 41 return 1; 42 43 return 0; 44 } 45 } 46 ); 79 if (apiDataSet.isEmpty()) { 80 JOptionPane.showMessageDialog( 81 Main.parent, 82 tr("No changes to upload."), 83 tr("Warning"), 84 JOptionPane.INFORMATION_MESSAGE 85 ); 86 return false; 87 } 47 88 return true; 48 89 }
Note:
See TracChangeset
for help on using the changeset viewer.