Changeset 21634 in osm for applications/editors/josm/plugins
- Timestamp:
- 2010-06-10T17:30:56+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/reverter/src/reverter
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reverter/src/reverter/ChangesetIdQuery.java
r21225 r21634 19 19 private JFormattedTextField tcid = new JFormattedTextField(NumberFormat.getInstance()); 20 20 21 public int ChangesetId() 22 { 21 public int ChangesetId() { 23 22 try { 24 23 return NumberFormat.getInstance().parse(tcid.getText()).intValue(); -
applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java
r21625 r21634 1 1 package reverter; 2 2 3 import java.util.HashMap; 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.util.HashSet; 5 6 import java.util.Iterator; 6 7 import java.util.LinkedList; 7 8 import java.util.List; 8 import java.util.Map;9 import java.util.Set;10 9 11 10 import org.openstreetmap.josm.Main; 12 11 import org.openstreetmap.josm.command.Command; 12 import org.openstreetmap.josm.command.ConflictAddCommand; 13 13 import org.openstreetmap.josm.command.DeleteCommand; 14 import org.openstreetmap.josm.data.conflict.Conflict; 14 15 import org.openstreetmap.josm.data.osm.Changeset; 15 16 import org.openstreetmap.josm.data.osm.ChangesetDataSet; … … 28 29 import org.openstreetmap.josm.data.osm.history.HistoryWay; 29 30 import org.openstreetmap.josm.data.osm.history.RelationMember; 30 import org.openstreetmap.josm.gui. progress.NullProgressMonitor;31 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 31 32 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 32 33 import org.openstreetmap.josm.io.MultiFetchServerObjectReader; … … 34 35 import org.openstreetmap.josm.io.OsmTransferException; 35 36 37 /** 38 * Fetches and stores data for reverting of specific changeset. 39 * @author Upliner 40 * 41 */ 36 42 public class ChangesetReverter { 37 43 public final int changesetId; 38 44 public final Changeset changeset; 39 45 40 private final DataSet ds; 41 private final ChangesetDataSet osmchange; 46 private final OsmDataLayer layer; // data layer associated with reverter 47 private final DataSet ds; // DataSet associated with reverter 48 private final ChangesetDataSet cds; // Current changeset data 49 private DataSet nds; // Dataset that contains new objects downloaded by reverter 42 50 43 51 private final HashSet<PrimitiveId> missing = new HashSet<PrimitiveId>(); 44 private LinkedList<Command> cmds; 45 46 static class MyCsDataset { 47 public HashMap<PrimitiveId,Integer> created = new HashMap<PrimitiveId,Integer>(); 48 public HashMap<PrimitiveId,Integer> updated = new HashMap<PrimitiveId,Integer>(); 49 public HashMap<PrimitiveId,Integer> deleted = new HashMap<PrimitiveId,Integer>(); 50 51 private static void put(HashMap<PrimitiveId,Integer> map,PrimitiveId id,int version) { 52 if (map.containsKey(id)) { 53 if (version < map.get(id)) 54 map.put(id, version); 55 } else { 56 map.put(id, version); 57 } 58 } 59 60 private void addEntry(ChangesetDataSetEntry entry) { 61 HistoryOsmPrimitive t = entry.getPrimitive(); 62 if (entry.getModificationType() == ChangesetModificationType.CREATED) { 63 put(created, new SimplePrimitiveId(t.getId(),t.getType()), (int)t.getVersion()); 64 } else if (entry.getModificationType() == ChangesetModificationType.UPDATED) { 65 put(updated, new SimplePrimitiveId(t.getId(),t.getType()), (int)t.getVersion()); 66 } else if (entry.getModificationType() == ChangesetModificationType.DELETED) { 67 put(deleted, new SimplePrimitiveId(t.getId(),t.getType()), (int)t.getVersion()); 68 } else throw new AssertionError(); 69 } 70 71 public MyCsDataset(ChangesetDataSet ds) { 72 Iterator<ChangesetDataSetEntry> iterator = ds.iterator(); 73 while (iterator.hasNext()) { 74 addEntry(iterator.next()); 75 } 76 } 77 } 78 79 private void AddIfMissing(PrimitiveId id) { 80 if (ds.getPrimitiveById(id) == null) { 52 53 private final HashSet<HistoryOsmPrimitive> created = new HashSet<HistoryOsmPrimitive>(); 54 private final HashSet<HistoryOsmPrimitive> updated = new HashSet<HistoryOsmPrimitive>(); 55 private final HashSet<HistoryOsmPrimitive> deleted = new HashSet<HistoryOsmPrimitive>(); 56 57 //// Handling missing objects 58 //////////////////////////////////////// 59 private void addIfMissing(PrimitiveId id) { 60 OsmPrimitive p = ds.getPrimitiveById(id); 61 if (p == null || p.isIncomplete()) { 81 62 missing.add(id); 82 63 } 83 64 } 84 private void AddMissingIds(Set<HistoryOsmPrimitive> primitives) {65 private void addMissingHistoryIds(Iterable<HistoryOsmPrimitive> primitives) { 85 66 for (HistoryOsmPrimitive p : primitives) { 86 AddIfMissing(new SimplePrimitiveId(p.getId(),p.getType()));67 addIfMissing(p.getPrimitiveId()); 87 68 if (p.getType() == OsmPrimitiveType.WAY) { 88 69 for (long nd : ((HistoryWay)p).getNodes()) { 89 AddIfMissing(new SimplePrimitiveId(nd,OsmPrimitiveType.NODE));70 addIfMissing(new SimplePrimitiveId(nd,OsmPrimitiveType.NODE)); 90 71 } 91 72 } 92 73 if (p.getType() == OsmPrimitiveType.RELATION) { 93 74 for (RelationMember member : ((HistoryRelation)p).getMembers()) { 94 AddIfMissing(new SimplePrimitiveId(member.getPrimitiveId(),75 addIfMissing(new SimplePrimitiveId(member.getPrimitiveId(), 95 76 member.getPrimitiveType())); 96 77 } … … 98 79 } 99 80 } 100 private void CheckMissing() { 81 82 private void addMissingIds(Iterable<OsmPrimitive> primitives) { 83 for (OsmPrimitive p : primitives) { 84 addIfMissing(p); 85 if (p.getType() == OsmPrimitiveType.WAY) { 86 for (Node nd : ((Way)p).getNodes()) { 87 addIfMissing(nd); 88 } 89 } 90 if (p.getType() == OsmPrimitiveType.RELATION) { 91 for (org.openstreetmap.josm.data.osm.RelationMember member 92 : ((Relation)p).getMembers()) { 93 addIfMissing(member.getMember()); 94 } 95 } 96 } 97 } 98 99 /** 100 * creates a reverter for specific changeset and fetches initial data 101 * @param changesetId 102 * @param monitor 103 * @throws OsmTransferException 104 */ 105 public ChangesetReverter(int changesetId, ProgressMonitor monitor) throws OsmTransferException { 106 this.changesetId = changesetId; 107 this.layer = Main.main.getEditLayer(); 108 this.ds = layer.data; 109 110 OsmServerChangesetReader csr = new OsmServerChangesetReader(); 111 monitor.beginTask("", 2); 112 try { 113 changeset = csr.readChangeset(changesetId, monitor.createSubTaskMonitor(1, false)); 114 cds = csr.downloadChangeset(changesetId, monitor.createSubTaskMonitor(1, false)); 115 } finally { 116 monitor.finishTask(); 117 } 118 119 // Build our own lists of created/updated/modified objects for better performance 120 Iterator<ChangesetDataSetEntry> iterator = cds.iterator(); 121 while (iterator.hasNext()) { 122 ChangesetDataSetEntry entry = iterator.next(); 123 if (entry.getModificationType() == ChangesetModificationType.CREATED) { 124 created.add(entry.getPrimitive()); 125 } else if (entry.getModificationType() == ChangesetModificationType.UPDATED) { 126 updated.add(entry.getPrimitive()); 127 } else if (entry.getModificationType() == ChangesetModificationType.DELETED) { 128 deleted.add(entry.getPrimitive()); 129 } else throw new AssertionError(); 130 } 131 101 132 /* Create list of objects that created or modified my the changeset but 102 133 * doesn't present in the current dataset. 103 134 */ 104 135 missing.clear(); 105 AddMissingIds(osmchange. 106 getPrimitivesByModificationType(ChangesetModificationType.CREATED)); 107 AddMissingIds(osmchange. 108 getPrimitivesByModificationType(ChangesetModificationType.UPDATED)); 109 } 110 111 public ChangesetReverter(int changesetId) throws OsmTransferException { 112 this.changesetId = changesetId; 113 this.ds = Main.main.getCurrentDataSet(); 114 115 OsmServerChangesetReader csr = new OsmServerChangesetReader(); 116 changeset = csr.readChangeset(changesetId, NullProgressMonitor.INSTANCE); 117 osmchange = csr.downloadChangeset(changesetId, NullProgressMonitor.INSTANCE); 118 CheckMissing(); 119 } 120 121 public void RevertChangeset(ProgressMonitor progressMonitor) throws OsmTransferException { 122 final MyCsDataset cds = new MyCsDataset(osmchange); 136 addMissingHistoryIds(created); 137 addMissingHistoryIds(updated); 138 } 139 140 /** 141 * fetch objects that was updated or deleted by changeset 142 * @param progressMonitor 143 * @throws OsmTransferException 144 */ 145 public void downloadObjectsHistory(ProgressMonitor progressMonitor) throws OsmTransferException { 123 146 final OsmServerMultiObjectReader rdr = new OsmServerMultiObjectReader(); 124 147 125 progressMonitor.beginTask("",cds.updated.size()+cds.deleted.size()+2); 126 progressMonitor.worked(1); 148 progressMonitor.beginTask("Downloading objects history",updated.size()+deleted.size()+1); 127 149 try { 128 // Fetch objects that was updated or deleted by changeset 129 for (Map.Entry<PrimitiveId,Integer> entry : cds.updated.entrySet()) { 130 rdr.ReadObject(entry.getKey().getUniqueId(), entry.getValue()-1, entry.getKey().getType(), 150 for (HistoryOsmPrimitive entry : updated) { 151 rdr.ReadObject(entry.getPrimitiveId(), (int)entry.getVersion()-1, 131 152 progressMonitor.createSubTaskMonitor(1, true)); 132 153 if (progressMonitor.isCancelled()) return; 133 154 } 134 for ( Map.Entry<PrimitiveId,Integer> entry : cds.deleted.entrySet()) {135 rdr.ReadObject(entry.get Key().getUniqueId(), entry.getValue()-1, entry.getKey().getType(),155 for (HistoryOsmPrimitive entry : deleted) { 156 rdr.ReadObject(entry.getPrimitiveId(), (int)entry.getVersion()-1, 136 157 progressMonitor.createSubTaskMonitor(1, true)); 137 158 if (progressMonitor.isCancelled()) return; 138 159 } 139 final DataSet nds = rdr.parseOsm(progressMonitor.createSubTaskMonitor(1, true)); 140 141 // Mark objects that have visible=false to be deleted 142 LinkedList<OsmPrimitive> toDelete = new LinkedList<OsmPrimitive>(); 143 for (OsmPrimitive p : nds.allPrimitives()) { 144 if (!p.isVisible()) { 145 OsmPrimitive dp = ds.getPrimitiveById(p); 146 if (dp != null) toDelete.add(dp); 147 } 148 } 149 150 // Create commands to restore/update all affected objects 151 this.cmds = new DataSetToCmd(nds,ds).getCommandList(); 152 153 // Mark all created objects to be deleted 154 for (PrimitiveId id : cds.created.keySet()) { 155 OsmPrimitive p = ds.getPrimitiveById(id); 156 if (p != null) toDelete.add(p); 157 } 158 // Create a Command to delete all marked objects 159 List<? extends OsmPrimitive> list; 160 list = OsmPrimitive.getFilteredList(toDelete, Relation.class); 161 if (!list.isEmpty()) cmds.add(new DeleteCommand(list)); 162 list = OsmPrimitive.getFilteredList(toDelete, Way.class); 163 if (!list.isEmpty()) cmds.add(new DeleteCommand(list)); 164 list = OsmPrimitive.getFilteredList(toDelete, Node.class); 165 if (!list.isEmpty()) cmds.add(new DeleteCommand(list)); 160 nds = rdr.parseOsm(progressMonitor.createSubTaskMonitor(1, true)); 161 addMissingIds(nds.allPrimitives()); 166 162 } finally { 167 163 progressMonitor.finishTask(); … … 169 165 } 170 166 171 public void DownloadMissingPrimitives(ProgressMonitor monitor) throws OsmTransferException {167 public void downloadMissingPrimitives(ProgressMonitor monitor) throws OsmTransferException { 172 168 MultiFetchServerObjectReader rdr = new MultiFetchServerObjectReader(); 173 169 for (PrimitiveId id : missing) { … … 185 181 } 186 182 } 187 DataSet from = rdr.parseOsm(monitor); 188 for (Node n : from.getNodes()) { 189 if (ds.getPrimitiveById(n) == null) { 190 ds.addPrimitive(new Node(n)); 191 } 192 } 193 for (Way w : from.getWays()) { 194 if (ds.getPrimitiveById(w) == null) { 195 Way nw = new Way(w.getId()); 196 ds.addPrimitive(nw); 197 nw.load(w.save()); 198 } 199 } 200 final LinkedList<Relation> rels = new LinkedList<Relation>(); 201 for (Relation r : from.getRelations()) { 202 if (ds.getPrimitiveById(r) == null) { 203 ds.addPrimitive(new Relation(r.getId())); 204 rels.add(r); 205 } 206 } 207 for (Relation r : rels) { 208 ((Relation)ds.getPrimitiveById(r)).load(r.save()); 209 } 183 layer.mergeFrom(rdr.parseOsm(monitor)); 210 184 missing.clear(); 211 185 } 212 186 187 /** 188 * Builds a list of commands that will revert the changeset 189 * 190 */ 213 191 public List<Command> getCommands() { 192 if (this.nds == null) return null; 193 LinkedList<OsmPrimitive> toDelete = new LinkedList<OsmPrimitive>(); 194 LinkedList<Command> cmds = new LinkedList<Command>(); 195 for (OsmPrimitive p : nds.allPrimitives()) { 196 if (p.isIncomplete()) continue; 197 OsmPrimitive dp = ds.getPrimitiveById(p); 198 if (dp == null) 199 throw new IllegalStateException(tr("Missing merge target for {0} with id {1}", 200 p.getType(), p.getUniqueId())); 201 // Mark objects that have visible=false to be deleted 202 if (!p.isVisible()) { 203 toDelete.add(dp); 204 } 205 // Check object version 206 if (p.getVersion() != dp.getVersion() 207 && (p.isVisible() || dp.isVisible())) { 208 Conflict<? extends OsmPrimitive> c; 209 switch (dp.getType()) { 210 case NODE: 211 c = new Conflict<Node>((Node)p,new Node((Node)dp),!p.isVisible()); 212 break; 213 case WAY: 214 c = new Conflict<Way>((Way)p,new Way((Way)dp),!p.isVisible()); 215 break; 216 case RELATION: 217 c = new Conflict<Relation>((Relation)p,new Relation((Relation)dp),!p.isVisible()); 218 break; 219 default: throw new AssertionError(); 220 } 221 cmds.add(new ConflictAddCommand(layer,c)); 222 } 223 } 224 225 // Create commands to restore/update all affected objects 226 cmds.addAll(new DataSetToCmd(nds,ds).getCommandList()); 227 228 // Mark all created objects to be deleted 229 for (HistoryOsmPrimitive id : created) { 230 OsmPrimitive p = ds.getPrimitiveById(id.getPrimitiveId()); 231 if (p != null) toDelete.add(p); 232 } 233 // Create a Command to delete all marked objects 234 List<? extends OsmPrimitive> list; 235 list = OsmPrimitive.getFilteredList(toDelete, Relation.class); 236 if (!list.isEmpty()) cmds.add(new DeleteCommand(list)); 237 list = OsmPrimitive.getFilteredList(toDelete, Way.class); 238 if (!list.isEmpty()) cmds.add(new DeleteCommand(list)); 239 list = OsmPrimitive.getFilteredList(toDelete, Node.class); 240 if (!list.isEmpty()) cmds.add(new DeleteCommand(list)); 214 241 return cmds; 215 242 } 216 public Set<PrimitiveId> getMissingObjects() {217 return missing;243 public boolean haveMissingObjects() { 244 return !missing.isEmpty(); 218 245 } 219 246 } -
applications/editors/josm/plugins/reverter/src/reverter/DataSetToCmd.java
r21210 r21634 9 9 import java.util.Map; 10 10 11 import org.openstreetmap.josm.command.AddCommand;12 11 import org.openstreetmap.josm.command.ChangeCommand; 13 12 import org.openstreetmap.josm.command.ChangeNodesCommand; … … 15 14 import org.openstreetmap.josm.data.osm.*; 16 15 16 /** 17 * Modified {@see org.openstreetmap.josm.data.osm.DataSetMerger} that 18 * produces list of commands instead of directly merging layers. 19 * 20 */ 17 21 final class DataSetToCmd { 18 22 … … 21 25 private final DataSet targetDataSet; 22 26 23 /**24 * A map of all primitives that got replaced with other primitives.25 * Key is the PrimitiveId in their dataset, the value is the PrimitiveId in my dataset26 */27 private final Map<OsmPrimitive, OsmPrimitive> mergedMap = new HashMap<OsmPrimitive, OsmPrimitive>();28 29 27 private final LinkedList<Command> cmds = new LinkedList<Command>(); 30 28 … … 47 45 if (source.isIncomplete()) return; 48 46 if (!source.isVisible()) return; 49 OsmPrimitive target = targetDataSet.getPrimitiveById(source.getId(), source.getType()); 50 if (target == null) { 51 switch(source.getType()) { 52 case NODE: target = new Node(source.getId()); break; 53 case WAY: target = new Way(source.getId()); break; 54 case RELATION: target = new Relation(source.getId()); break; 55 default: throw new AssertionError(); 56 } 57 target.mergeFrom(source); 58 target.setOsmId(target.getId(), (int)source.getVersion()+1); 59 target.setModified(true); 60 cmds.add(new AddCommand(target)); 61 } else { 62 OsmPrimitive newTarget = null; 63 switch(target.getType()) { 64 case NODE: newTarget = new Node((Node)target); break; 65 case WAY: newTarget = new Way((Way)target); break; 66 case RELATION: newTarget = new Relation((Relation)target); break; 67 default: throw new AssertionError(); 68 } 69 newTarget.mergeFrom(source); 70 newTarget.setOsmId(target.getId(), (int)source.getVersion()+1); 71 newTarget.setDeleted(false); 72 cmds.add(new ChangeCommand(target,newTarget)); 47 OsmPrimitive target = getMergeTarget(source); 48 if (target.getVersion() == 0) 49 throw new IllegalStateException(tr("Target of type {0} with id {1} have invalid version", 50 target.getType(), target.getUniqueId())); 51 OsmPrimitive newTarget; 52 switch(target.getType()) { 53 case NODE: newTarget = new Node((Node)target); break; 54 case WAY: newTarget = new Way((Way)target); break; 55 case RELATION: newTarget = new Relation((Relation)target); break; 56 default: throw new AssertionError(); 73 57 } 74 mergedMap.put(source, target); 58 newTarget.mergeFrom(source); 59 newTarget.setOsmId(target.getId(), (int)target.getVersion()); 60 newTarget.setDeleted(false); 61 cmds.add(new ChangeCommand(target,newTarget)); 75 62 } 76 63 77 64 private OsmPrimitive getMergeTarget(OsmPrimitive mergeSource) { 78 OsmPrimitive p = mergedMap.get(mergeSource); 79 if (p == null) p = targetDataSet.getPrimitiveById(mergeSource.getId(), mergeSource.getType()); 65 OsmPrimitive p = targetDataSet.getPrimitiveById(mergeSource.getId(), mergeSource.getType()); 66 if (p == null) 67 throw new IllegalStateException(tr("Missing merge target of type {0} with id {1}", 68 mergeSource.getType(), mergeSource.getUniqueId())); 80 69 return p; 81 70 } … … 106 95 if (!source.isVisible()) return; 107 96 Way target = (Way)getMergeTarget(source); 108 if (target == null)109 throw new IllegalStateException(tr("Missing merge target for way with id {0}", source.getUniqueId()));110 97 111 98 List<Node> newNodes = new ArrayList<Node>(source.getNodesCount()); 112 99 for (Node sourceNode : source.getNodes()) { 113 100 Node targetNode = (Node)getMergeTarget(sourceNode); 114 if (targetNode == null)115 throw new IllegalStateException(tr("Missing merge target for node with id {0}", sourceNode.getUniqueId()));116 117 101 newNodes.add(targetNode); 118 102 } … … 131 115 if (!source.isVisible()) return; 132 116 Relation target = (Relation) getMergeTarget(source); 133 if (target == null)134 throw new IllegalStateException(tr("Missing merge target for relation with id {0}", source.getUniqueId()));135 117 LinkedList<RelationMember> newMembers = new LinkedList<RelationMember>(); 136 118 for (RelationMember sourceMember : source.getMembers()) { 137 119 OsmPrimitive targetMember = getMergeTarget(sourceMember.getMember()); 138 if (targetMember == null)139 throw new IllegalStateException(tr("Missing merge target of type {0} with id {1}", sourceMember.getType(), sourceMember.getUniqueId()));140 120 newMembers.add(new RelationMember(sourceMember.getRole(), targetMember)); 141 121 } … … 144 124 cmds.add(new ChangeCommand(target,newRelation)); 145 125 } 146 private void merge() 147 { 126 private void merge() { 148 127 for (Node node: sourceDataSet.getNodes()) { 149 128 mergePrimitive(node); -
applications/editors/josm/plugins/reverter/src/reverter/MultiOsmReader.java
r21201 r21634 48 48 49 49 /** 50 * Parser for the Osm Api. Read from an input stream and construct a dataset out of it.50 * Modified {@see org.openstreetmap.josm.io.OsmReader} that can handle multiple XML streams. 51 51 * 52 52 */ … … 426 426 * @throws IllegalDataException thrown if a data integrity problem is detected 427 427 */ 428 protected void processWaysAfterParsing() throws IllegalDataException {428 protected void processWaysAfterParsing() throws IllegalDataException { 429 429 for (Long externalWayId: ways.keySet()) { 430 430 Way w = (Way)externalIdMap.get(new SimplePrimitiveId(externalWayId, OsmPrimitiveType.WAY)); … … 556 556 } 557 557 } 558 public void ProcessData() throws IllegalDataException 559 { 558 public void ProcessData() throws IllegalDataException { 560 559 processNodesAfterParsing(); 561 560 processWaysAfterParsing(); -
applications/editors/josm/plugins/reverter/src/reverter/ObjectsHistoryAction.java
r21225 r21634 12 12 public class ObjectsHistoryAction extends JosmAction { 13 13 14 public ObjectsHistoryAction() 15 { 14 public ObjectsHistoryAction() { 16 15 super(tr("Objects history"),null,tr("History reverter"), 17 16 Shortcut.registerShortcut("tool:history", -
applications/editors/josm/plugins/reverter/src/reverter/OsmServerMultiObjectReader.java
r21201 r21634 8 8 import org.openstreetmap.josm.data.osm.DataSet; 9 9 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 10 import org.openstreetmap.josm.data.osm.PrimitiveId; 10 11 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 11 12 import org.openstreetmap.josm.io.OsmServerReader; … … 15 16 public class OsmServerMultiObjectReader extends OsmServerReader { 16 17 private MultiOsmReader rdr = new MultiOsmReader(); 17 public void ReadObject(long id,int version,OsmPrimitiveType type,ProgressMonitor progressMonitor) throws OsmTransferException 18 { 18 public void ReadObject(PrimitiveId id, int version, ProgressMonitor progressMonitor) throws OsmTransferException { 19 ReadObject(id.getUniqueId(), version, id.getType(), progressMonitor); 20 } 21 public void ReadObject(long id,int version,OsmPrimitiveType type,ProgressMonitor progressMonitor) throws OsmTransferException { 19 22 StringBuffer sb = new StringBuffer(); 20 23 sb.append(type.getAPIName()); … … 53 56 } catch (Exception e) { 54 57 throw new OsmTransferException(e); 55 } finally 56 { 58 } finally { 57 59 progressMonitor.finishTask(); 58 60 activeConnection = null; 59 61 } 60 62 } 61 62 63 } -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java
r21625 r21634 14 14 import org.openstreetmap.josm.command.SequenceCommand; 15 15 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 16 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 16 17 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 17 18 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 22 23 public class RevertChangesetAction extends JosmAction { 23 24 24 public RevertChangesetAction() 25 { 25 public RevertChangesetAction() { 26 26 super(tr("Revert changeset"),null,tr("Revert changeset"), 27 27 Shortcut.registerShortcut("tool:revert", … … 37 37 } 38 38 39 public void actionPerformed(ActionEvent arg0) {39 public void actionPerformed(ActionEvent arg0) { 40 40 if (getCurrentDataSet() == null) 41 41 return; … … 46 46 if (changesetId == 0) return; 47 47 Main.worker.submit(new PleaseWaitRunnable(tr("Reverting...")) { 48 private ChangesetReverter rev; 49 private boolean downloadConfirmed = false; 50 51 private boolean checkMissing() throws OsmTransferException { 52 if (!rev.haveMissingObjects()) return true; 53 if (!downloadConfirmed) { 54 downloadConfirmed = JOptionPane.showConfirmDialog(Main.parent, 55 tr("This changeset have objects that doesn't present in current dataset.\n" + 56 "It is needed to download them before reverting. Do you want to continue?"), 57 tr("Confirm"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; 58 if (!downloadConfirmed) return false; 59 } 60 final PleaseWaitProgressMonitor monitor = 61 new PleaseWaitProgressMonitor(tr("Fetching missing primitives")); 62 try { 63 rev.downloadMissingPrimitives(monitor); 64 } finally { 65 monitor.close(); 66 } 67 return true; 68 } 69 48 70 @Override 49 71 protected void realRun() throws OsmTransferException { 50 ChangesetReverter rev = new ChangesetReverter(changesetId); 51 if (!rev.getMissingObjects().isEmpty()) 52 { 53 if (JOptionPane.showConfirmDialog(Main.parent, 54 tr("This changeset have objects outside the downloaded area.\n" + 55 "It is needed to download them before reverting. Do you want to continue?"), 56 tr("Confirm"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { 57 final PleaseWaitProgressMonitor monitor = 58 new PleaseWaitProgressMonitor(tr("Fetching missing primitives")); 59 try { 60 rev.DownloadMissingPrimitives(monitor); 61 } finally { 62 monitor.close(); 63 } 64 } else { 65 return; 66 } 67 } 68 rev.RevertChangeset(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, true)); 72 rev = new ChangesetReverter(changesetId, NullProgressMonitor.INSTANCE); 73 progressMonitor.indeterminateSubTask("Downloading changeset"); 74 if (!checkMissing()) return; 75 rev.downloadObjectsHistory(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 69 76 if (progressMonitor.isCancelled()) return; 77 if (!checkMissing()) return; 70 78 List<Command> cmds = rev.getCommands(); 71 79 Command cmd = new SequenceCommand(tr("Revert changeset #{0}",changesetId),cmds); … … 82 90 }); 83 91 } 84 85 92 } -
applications/editors/josm/plugins/reverter/src/reverter/ReverterPlugin.java
r21225 r21634 15 15 16 16 public class ReverterPlugin extends Plugin { 17 public ReverterPlugin(PluginInformation info) 18 { 17 public ReverterPlugin(PluginInformation info) { 19 18 super(info); 20 19 JMenu historyMenu = Main.main.menu.addMenu(marktr("History"), KeyEvent.VK_R, Main.main.menu.defaultMenuPos,ht("/Plugin/Reverter"));
Note:
See TracChangeset
for help on using the changeset viewer.