Ignore:
Timestamp:
2010-06-10T17:30:56+02:00 (14 years ago)
Author:
upliner
Message:

reverter: fully fix #5005 and add conflicts handling

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  
    1919    private JFormattedTextField tcid = new JFormattedTextField(NumberFormat.getInstance());
    2020
    21     public int ChangesetId()
    22     {
     21    public int ChangesetId() {
    2322        try {
    2423          return NumberFormat.getInstance().parse(tcid.getText()).intValue();
  • applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java

    r21625 r21634  
    11package reverter;
    22
    3 import java.util.HashMap;
     3import static org.openstreetmap.josm.tools.I18n.tr;
     4
    45import java.util.HashSet;
    56import java.util.Iterator;
    67import java.util.LinkedList;
    78import java.util.List;
    8 import java.util.Map;
    9 import java.util.Set;
    109
    1110import org.openstreetmap.josm.Main;
    1211import org.openstreetmap.josm.command.Command;
     12import org.openstreetmap.josm.command.ConflictAddCommand;
    1313import org.openstreetmap.josm.command.DeleteCommand;
     14import org.openstreetmap.josm.data.conflict.Conflict;
    1415import org.openstreetmap.josm.data.osm.Changeset;
    1516import org.openstreetmap.josm.data.osm.ChangesetDataSet;
     
    2829import org.openstreetmap.josm.data.osm.history.HistoryWay;
    2930import org.openstreetmap.josm.data.osm.history.RelationMember;
    30 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
     31import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3132import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    3233import org.openstreetmap.josm.io.MultiFetchServerObjectReader;
     
    3435import org.openstreetmap.josm.io.OsmTransferException;
    3536
     37/**
     38 * Fetches and stores data for reverting of specific changeset.
     39 * @author Upliner
     40 *
     41 */
    3642public class ChangesetReverter {
    3743    public final int changesetId;
    3844    public final Changeset changeset;
    3945
    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
    4250
    4351    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()) {
    8162            missing.add(id);
    8263        }
    8364    }
    84     private void AddMissingIds(Set<HistoryOsmPrimitive> primitives) {
     65    private void addMissingHistoryIds(Iterable<HistoryOsmPrimitive> primitives) {
    8566        for (HistoryOsmPrimitive p : primitives) {
    86             AddIfMissing(new SimplePrimitiveId(p.getId(),p.getType()));
     67            addIfMissing(p.getPrimitiveId());
    8768            if (p.getType() == OsmPrimitiveType.WAY) {
    8869                for (long nd : ((HistoryWay)p).getNodes()) {
    89                     AddIfMissing(new SimplePrimitiveId(nd,OsmPrimitiveType.NODE));
     70                    addIfMissing(new SimplePrimitiveId(nd,OsmPrimitiveType.NODE));
    9071                }
    9172            }
    9273            if (p.getType() == OsmPrimitiveType.RELATION) {
    9374                for (RelationMember member : ((HistoryRelation)p).getMembers()) {
    94                     AddIfMissing(new SimplePrimitiveId(member.getPrimitiveId(),
     75                    addIfMissing(new SimplePrimitiveId(member.getPrimitiveId(),
    9576                            member.getPrimitiveType()));
    9677                }
     
    9879        }
    9980    }
    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       
    101132        /* Create list of objects that created or modified my the changeset but
    102133         * doesn't present in the current dataset.
    103134         */
    104135        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 {
    123146        final OsmServerMultiObjectReader rdr = new OsmServerMultiObjectReader();
    124147       
    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);
    127149        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,
    131152                        progressMonitor.createSubTaskMonitor(1, true));
    132153                if (progressMonitor.isCancelled()) return;
    133154            }
    134             for (Map.Entry<PrimitiveId,Integer> entry : cds.deleted.entrySet()) {
    135                 rdr.ReadObject(entry.getKey().getUniqueId(), entry.getValue()-1, entry.getKey().getType(),
     155            for (HistoryOsmPrimitive entry : deleted) {
     156                rdr.ReadObject(entry.getPrimitiveId(), (int)entry.getVersion()-1,
    136157                        progressMonitor.createSubTaskMonitor(1, true));
    137158                if (progressMonitor.isCancelled()) return;
    138159            }
    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());
    166162        } finally {
    167163            progressMonitor.finishTask();
     
    169165    }
    170166   
    171     public void DownloadMissingPrimitives(ProgressMonitor monitor) throws OsmTransferException {
     167    public void downloadMissingPrimitives(ProgressMonitor monitor) throws OsmTransferException {
    172168        MultiFetchServerObjectReader rdr = new MultiFetchServerObjectReader();
    173169        for (PrimitiveId id : missing) {
     
    185181            }
    186182        }
    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));
    210184        missing.clear();
    211185    }
    212186   
     187    /**
     188     * Builds a list of commands that will revert the changeset
     189     *
     190     */
    213191    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));
    214241        return cmds;
    215242    }
    216     public Set<PrimitiveId> getMissingObjects() {
    217         return missing;
     243    public boolean haveMissingObjects() {
     244        return !missing.isEmpty();
    218245    }
    219246}
  • applications/editors/josm/plugins/reverter/src/reverter/DataSetToCmd.java

    r21210 r21634  
    99import java.util.Map;
    1010
    11 import org.openstreetmap.josm.command.AddCommand;
    1211import org.openstreetmap.josm.command.ChangeCommand;
    1312import org.openstreetmap.josm.command.ChangeNodesCommand;
     
    1514import org.openstreetmap.josm.data.osm.*;
    1615
     16/**
     17 * Modified {@see org.openstreetmap.josm.data.osm.DataSetMerger} that
     18 * produces list of commands instead of directly merging layers.
     19 *
     20 */
    1721final class DataSetToCmd {
    1822
     
    2125    private final DataSet targetDataSet;
    2226
    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 dataset
    26      */
    27     private final Map<OsmPrimitive, OsmPrimitive> mergedMap = new HashMap<OsmPrimitive, OsmPrimitive>();
    28    
    2927    private final LinkedList<Command> cmds = new LinkedList<Command>();
    3028
     
    4745        if (source.isIncomplete()) return;
    4846        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();
    7357        }
    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));
    7562    }
    7663
    7764    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()));
    8069        return p;
    8170    }
     
    10695        if (!source.isVisible()) return;
    10796        Way target = (Way)getMergeTarget(source);
    108         if (target == null)
    109             throw new IllegalStateException(tr("Missing merge target for way with id {0}", source.getUniqueId()));
    11097
    11198        List<Node> newNodes = new ArrayList<Node>(source.getNodesCount());
    11299        for (Node sourceNode : source.getNodes()) {
    113100            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 
    117101            newNodes.add(targetNode);
    118102        }
     
    131115        if (!source.isVisible()) return;
    132116        Relation target = (Relation) getMergeTarget(source);
    133         if (target == null)
    134             throw new IllegalStateException(tr("Missing merge target for relation with id {0}", source.getUniqueId()));
    135117        LinkedList<RelationMember> newMembers = new LinkedList<RelationMember>();
    136118        for (RelationMember sourceMember : source.getMembers()) {
    137119            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()));
    140120            newMembers.add(new RelationMember(sourceMember.getRole(), targetMember));
    141121        }
     
    144124        cmds.add(new ChangeCommand(target,newRelation));
    145125    }
    146     private void merge()
    147     {
     126    private void merge() {
    148127        for (Node node: sourceDataSet.getNodes()) {
    149128            mergePrimitive(node);
  • applications/editors/josm/plugins/reverter/src/reverter/MultiOsmReader.java

    r21201 r21634  
    4848
    4949/**
    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.
    5151 *
    5252 */
     
    426426     * @throws IllegalDataException thrown if a data integrity problem is detected
    427427     */
    428     protected void processWaysAfterParsing() throws IllegalDataException{
     428    protected void processWaysAfterParsing() throws IllegalDataException {
    429429        for (Long externalWayId: ways.keySet()) {
    430430            Way w = (Way)externalIdMap.get(new SimplePrimitiveId(externalWayId, OsmPrimitiveType.WAY));
     
    556556        }
    557557    }
    558     public void ProcessData() throws IllegalDataException
    559     {
     558    public void ProcessData() throws IllegalDataException {
    560559        processNodesAfterParsing();
    561560        processWaysAfterParsing();
  • applications/editors/josm/plugins/reverter/src/reverter/ObjectsHistoryAction.java

    r21225 r21634  
    1212public class ObjectsHistoryAction extends JosmAction {
    1313
    14     public ObjectsHistoryAction()
    15     {
     14    public ObjectsHistoryAction() {
    1615        super(tr("Objects history"),null,tr("History reverter"),
    1716                Shortcut.registerShortcut("tool:history",
  • applications/editors/josm/plugins/reverter/src/reverter/OsmServerMultiObjectReader.java

    r21201 r21634  
    88import org.openstreetmap.josm.data.osm.DataSet;
    99import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     10import org.openstreetmap.josm.data.osm.PrimitiveId;
    1011import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1112import org.openstreetmap.josm.io.OsmServerReader;
     
    1516public class OsmServerMultiObjectReader extends OsmServerReader {
    1617    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 {
    1922        StringBuffer sb = new StringBuffer();
    2023        sb.append(type.getAPIName());
     
    5356        } catch (Exception e) {
    5457            throw new OsmTransferException(e);
    55         } finally
    56         {
     58        } finally {
    5759            progressMonitor.finishTask();
    5860            activeConnection = null;
    5961        }
    6062    }
    61 
    6263}
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java

    r21625 r21634  
    1414import org.openstreetmap.josm.command.SequenceCommand;
    1515import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     16import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1617import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
    1718import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    2223public class RevertChangesetAction extends JosmAction {
    2324
    24     public RevertChangesetAction()
    25     {
     25    public RevertChangesetAction() {
    2626        super(tr("Revert changeset"),null,tr("Revert changeset"),
    2727                Shortcut.registerShortcut("tool:revert",
     
    3737    }
    3838
    39     public void actionPerformed(ActionEvent arg0) {
     39    public void actionPerformed(ActionEvent arg0)  {
    4040        if (getCurrentDataSet() == null)
    4141            return;
     
    4646        if (changesetId == 0) return;
    4747        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           
    4870            @Override
    4971            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));
    6976                if (progressMonitor.isCancelled()) return;
     77                if (!checkMissing()) return;
    7078                List<Command> cmds = rev.getCommands();
    7179                Command cmd = new SequenceCommand(tr("Revert changeset #{0}",changesetId),cmds);
     
    8290        });
    8391    }
    84 
    8592}
  • applications/editors/josm/plugins/reverter/src/reverter/ReverterPlugin.java

    r21225 r21634  
    1515
    1616public class ReverterPlugin extends Plugin {
    17     public ReverterPlugin(PluginInformation info)
    18     {
     17    public ReverterPlugin(PluginInformation info) {
    1918        super(info);
    2019        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.