Changeset 3034 in josm for trunk/src


Ignore:
Timestamp:
2010-02-23T08:58:12+01:00 (10 years ago)
Author:
jttt
Message:

Fix #4467 Don't silently drop locally deleted member primitives from downloaded ways and relation (fix the issue when deleted primitive is referenced)

Location:
trunk/src/org/openstreetmap/josm
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r2932 r3034  
    22package org.openstreetmap.josm.command;
    33
     4import java.util.ArrayList;
    45import java.util.Collection;
    56import java.util.HashMap;
    6 import java.util.HashSet;
     7import java.util.LinkedHashMap;
    78import java.util.Map;
    89import java.util.Map.Entry;
     
    3233
    3334    private static final class CloneVisitor extends AbstractVisitor {
    34         public Map<OsmPrimitive, PrimitiveData> orig = new HashMap<OsmPrimitive, PrimitiveData>();
     35        public final Map<OsmPrimitive, PrimitiveData> orig = new LinkedHashMap<OsmPrimitive, PrimitiveData>();
    3536
    3637        public void visit(Node n) {
     
    7273    public boolean executeCommand() {
    7374        CloneVisitor visitor = new CloneVisitor();
    74         Collection<OsmPrimitive> all = new HashSet<OsmPrimitive>();
     75        Collection<OsmPrimitive> all = new ArrayList<OsmPrimitive>();
    7576        fillModifiedData(all, all, all);
    7677        for (OsmPrimitive osm : all) {
  • trunk/src/org/openstreetmap/josm/command/CoordinateConflictResolveCommand.java

    r2512 r3034  
    2323
    2424    /** the conflict to resolve */
    25     private Conflict<Node> conflict;
     25    private Conflict<? extends OsmPrimitive> conflict;
    2626
    2727    /** the merge decision */
     
    3535     * @param decision the merge decision
    3636     */
    37     public CoordinateConflictResolveCommand(Node my, Node their, MergeDecisionType decision) {
    38         this.conflict = new Conflict<Node>(my,their);
     37    public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
     38        this.conflict = conflict;
    3939        this.decision = decision;
    4040    }
     
    6161            // do nothing
    6262        } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
    63             Node my = conflict.getMy();
    64             Node their = conflict.getTheir();
     63            Node my = (Node)conflict.getMy();
     64            Node their = (Node)conflict.getTheir();
    6565            my.setCoor(their.getCoor());
    6666        } else
  • trunk/src/org/openstreetmap/josm/command/DeletedStateConflictResolveCommand.java

    r2945 r3034  
    2323
    2424    /** the conflict to resolve */
    25     private Conflict<OsmPrimitive> conflict;
     25    private Conflict<? extends OsmPrimitive> conflict;
    2626
    2727    /** the merge decision */
     
    3535     * @param decision the merge decision
    3636     */
    37     public DeletedStateConflictResolveCommand(OsmPrimitive my, OsmPrimitive their, MergeDecisionType decision) {
    38         this.conflict = new Conflict<OsmPrimitive>(my, their);
     37    public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
     38        this.conflict = conflict;
    3939        this.decision = decision;
    4040    }
     
    6161
    6262        if (decision.equals(MergeDecisionType.KEEP_MINE)) {
    63             if (conflict.getMy().isDeleted()) {
     63            if (conflict.getMy().isDeleted() || conflict.isMyDeleted()) {
    6464                // because my was involved in a conflict it my still be referred
    6565                // to from a way or a relation. Fix this now.
    6666                //
    6767                layer.data.unlinkReferencesToPrimitive(conflict.getMy());
     68                conflict.getMy().setDeleted(true);
    6869            }
    6970        } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
     
    8687            Collection<OsmPrimitive> added) {
    8788        modified.add(conflict.getMy());
     89        modified.addAll(conflict.getMy().getReferrers());
    8890    }
    8991}
  • trunk/src/org/openstreetmap/josm/command/ModifiedConflictResolveCommand.java

    r2844 r3034  
    2424
    2525    /** the conflict to resolve */
    26     private Conflict<OsmPrimitive> conflict;
     26    private Conflict<? extends OsmPrimitive> conflict;
    2727
    2828    /**
     
    3131     * @param their their primitive (i.e. the primitive from the server)
    3232     */
    33     public ModifiedConflictResolveCommand(OsmPrimitive my, OsmPrimitive their) {
    34         conflict = new Conflict<OsmPrimitive>(my, their);
     33    public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
     34        this.conflict = conflict;
    3535    }
    3636
  • trunk/src/org/openstreetmap/josm/command/TagConflictResolveCommand.java

    r2990 r3034  
    2929
    3030    /** the conflict to resolve */
    31     private Conflict<OsmPrimitive> conflict;
     31    private Conflict<? extends OsmPrimitive> conflict;
    3232
    3333    /** the list of merge decisions, represented as {@see TagMergeItem}s */
     
    5656     * @param mergeItems the list of merge decisions, represented as {@see TagMergeItem}s
    5757     */
    58     public TagConflictResolveCommand(OsmPrimitive my, OsmPrimitive their, List<TagMergeItem> mergeItems) {
    59         this.conflict = new Conflict<OsmPrimitive>(my,their);
     58    public TagConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, List<TagMergeItem> mergeItems) {
     59        this.conflict = conflict;
    6060        this.mergeItems = mergeItems;
    6161    }
  • trunk/src/org/openstreetmap/josm/command/VersionConflictResolveCommand.java

    r2844 r3034  
    2424
    2525    /** the conflict to resolve */
    26     private Conflict<OsmPrimitive> conflict;
     26    private Conflict<? extends OsmPrimitive> conflict;
    2727
    2828    /**
     
    3131     * @param their their primitive (i.e. the primitive from the server)
    3232     */
    33     public VersionConflictResolveCommand(OsmPrimitive my, OsmPrimitive their) {
    34         conflict = new Conflict<OsmPrimitive>(my, their);
     33    public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
     34        this.conflict = conflict;
    3535    }
    3636
     
    3939        String msg = "";
    4040        switch(OsmPrimitiveType.from(conflict.getMy())) {
    41             case NODE: msg = marktr("Resolve version conflict for node {0}"); break;
    42             case WAY: msg = marktr("Resolve version conflict for way {0}"); break;
    43             case RELATION: msg = marktr("Resolve version conflict for relation {0}"); break;
     41        case NODE: msg = marktr("Resolve version conflict for node {0}"); break;
     42        case WAY: msg = marktr("Resolve version conflict for way {0}"); break;
     43        case RELATION: msg = marktr("Resolve version conflict for relation {0}"); break;
    4444        }
    4545        return new DefaultMutableTreeNode(
  • trunk/src/org/openstreetmap/josm/command/WayNodesConflictResolverCommand.java

    r2512 r3034  
    4141     * @param mergedNodeList  the list of merged nodes
    4242     */
    43     public WayNodesConflictResolverCommand(Way my, Way their, List<Node> mergedNodeList) {
    44         conflict = new Conflict<Way>(my,their);
     43    @SuppressWarnings("unchecked")
     44    public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
     45        this.conflict = (Conflict<Way>) conflict;
    4546        this.mergedNodeList = mergedNodeList;
    4647    }
  • trunk/src/org/openstreetmap/josm/data/conflict/Conflict.java

    r2979 r3034  
    2121    private final T my;
    2222    private final T their;
     23    private final boolean isMyDeleted;
    2324
    2425    public Conflict(T my, T their) {
     26        this(my, their, false);
     27    }
     28
     29    public Conflict(T my, T their, boolean isMyDeleted) {
    2530        this.my = my;
    2631        this.their = their;
     32        this.isMyDeleted = isMyDeleted;
    2733    }
    2834
     
    96102        return true;
    97103    }
     104
     105    /**
     106     *
     107     * @return True if my primitive was deleted but it has set non deleted status because it's referred by another
     108     * primitive and references to deleted primitives are not allowed.
     109     */
     110    public boolean isMyDeleted() {
     111        return isMyDeleted;
     112    }
    98113}
  • trunk/src/org/openstreetmap/josm/data/conflict/ConflictCollection.java

    r2949 r3034  
    3333 * </ul>
    3434 */
    35 public class ConflictCollection implements Iterable<Conflict<?>>{
    36     private final List<Conflict<?>> conflicts;
     35public class ConflictCollection implements Iterable<Conflict<? extends OsmPrimitive>>{
     36    private final List<Conflict<? extends OsmPrimitive>> conflicts;
    3737    private CopyOnWriteArrayList<IConflictListener> listeners;
    3838
  • trunk/src/org/openstreetmap/josm/data/osm/DataSetMerger.java

    r3033 r3034  
    1313import java.util.logging.Logger;
    1414
     15import org.openstreetmap.josm.data.conflict.Conflict;
    1516import org.openstreetmap.josm.data.conflict.ConflictCollection;
    1617import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    160161     * @param other
    161162     */
     163    //TODO This method is probably useless
    162164    protected void fixIncompleteParentWays(Node other) {
    163165        Node myNode = (Node)getMergeTarget(other);
     
    224226                    newNodes.add(targetNode);
    225227                    if (targetNode.isDeleted() && !conflicts.hasConflictForMy(targetNode)) {
    226                         conflicts.add(targetNode, sourceNode);
     228                        conflicts.add(new Conflict<OsmPrimitive>(targetNode, sourceNode, true));
     229                        targetNode.setDeleted(false);
    227230                    }
    228231                } else {
     
    255258                newMembers.add(newMember);
    256259                if (targetMember.isDeleted() && !conflicts.hasConflictForMy(targetMember)) {
    257                     conflicts.add(targetMember, sourceMember.getMember());
     260                    conflicts.add(new Conflict<OsmPrimitive>(targetMember, sourceMember.getMember(), true));
     261                    targetMember.setDeleted(false);
    258262                }
    259263            } else {
     
    319323            for (OsmPrimitive referrer: source.getReferrers()) {
    320324                if (targetDataSet.getPrimitiveById(referrer.getPrimitiveId()) == null) {
    321                     conflicts.add(target, source);
     325                    conflicts.add(new Conflict<OsmPrimitive>(target, source, true));
     326                    target.setDeleted(false);
    322327                    break;
    323328                }
  • trunk/src/org/openstreetmap/josm/data/osm/User.java

    r2863 r3034  
    2727
    2828    private static long getNextLocalUid() {
    29         synchronized(User.class) {
    30             return uidCounter.decrementAndGet();
    31         }
     29        return uidCounter.decrementAndGet();
    3230    }
    3331
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ConflictResolver.java

    r2945 r3034  
    1919import org.openstreetmap.josm.command.SequenceCommand;
    2020import org.openstreetmap.josm.command.VersionConflictResolveCommand;
     21import org.openstreetmap.josm.data.conflict.Conflict;
    2122import org.openstreetmap.josm.data.osm.Node;
    2223import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    7778    private OsmPrimitive my;
    7879    private OsmPrimitive their;
     80    private Conflict<? extends OsmPrimitive> conflict;
    7981
    8082    private ImageIcon mergeComplete;
     
    228230     *
    229231     */
    230     public void populate(OsmPrimitive my, OsmPrimitive their) {
    231         setMy(my);
    232         setTheir(their);
    233         propertiesMerger.populate(my, their);
     232    public void populate(Conflict<? extends OsmPrimitive> conflict) {
     233        setMy(conflict.getMy());
     234        setTheir(conflict.getTheir());
     235        this.conflict = conflict;
     236        propertiesMerger.populate(conflict);
    234237        if (propertiesMerger.getModel().hasVisibleStateConflict()) {
    235238            tabbedPane.setEnabledAt(1, false);
     
    239242        }
    240243        tabbedPane.setEnabledAt(0, true);
    241         tagMerger.populate(my, their);
     244        tagMerger.populate(conflict);
    242245        tabbedPane.setEnabledAt(1, true);
    243246
     
    246249            tabbedPane.setEnabledAt(3,false);
    247250        } else if (my instanceof Way) {
    248             nodeListMerger.populate(my, their);
     251            nodeListMerger.populate(conflict);
    249252            tabbedPane.setEnabledAt(2, true);
    250253            tabbedPane.setEnabledAt(3, false);
     
    252255            tabbedPane.setIconAt(3, null);
    253256        } else if (my instanceof Relation) {
    254             relationMemberMerger.populate(my, their);
     257            relationMemberMerger.populate(conflict);
    255258            tabbedPane.setEnabledAt(2, false);
    256259            tabbedPane.setTitleAt(2,tr("Nodes"));
     
    271274        if (propertiesMerger.getModel().hasVisibleStateConflict()) {
    272275            if (propertiesMerger.getModel().isDecidedVisibleState()) {
    273                 commands.addAll(propertiesMerger.getModel().buildResolveCommand(my, their));
     276                commands.addAll(propertiesMerger.getModel().buildResolveCommand(conflict));
    274277            }
    275278        } else {
    276279            if (tagMerger.getModel().getNumResolvedConflicts() > 0) {
    277                 commands.add(tagMerger.getModel().buildResolveCommand(my, their));
    278             }
    279             commands.addAll(propertiesMerger.getModel().buildResolveCommand(my, their));
     280                commands.add(tagMerger.getModel().buildResolveCommand(conflict));
     281            }
     282            commands.addAll(propertiesMerger.getModel().buildResolveCommand(conflict));
    280283            if (my instanceof Way && nodeListMerger.getModel().isFrozen()) {
    281284                NodeListMergeModel model  =(NodeListMergeModel)nodeListMerger.getModel();
    282                 commands.add(model.buildResolveCommand((Way)my, (Way)their));
     285                commands.add(model.buildResolveCommand(conflict));
    283286            } else if (my instanceof Relation && relationMemberMerger.getModel().isFrozen()) {
    284287                RelationMemberListMergeModel model  =(RelationMemberListMergeModel)relationMemberMerger.getModel();
     
    286289            }
    287290            if (isResolvedCompletely()) {
    288                 commands.add(new VersionConflictResolveCommand(my, their));
    289                 commands.add(new ModifiedConflictResolveCommand(my, their));
     291                commands.add(new VersionConflictResolveCommand(conflict));
     292                commands.add(new ModifiedConflictResolveCommand(conflict));
    290293            }
    291294        }
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/IConflictResolver.java

    r2945 r3034  
    22package org.openstreetmap.josm.gui.conflict.pair;
    33
     4import org.openstreetmap.josm.data.conflict.Conflict;
    45import org.openstreetmap.josm.data.osm.OsmPrimitive;
    56
     
    78
    89    void deletePrimitive(boolean deleted);
    9     void populate(OsmPrimitive my, OsmPrimitive their);
     10    void populate(Conflict<? extends OsmPrimitive> conflict);
    1011
    1112}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListMergeModel.java

    r2949 r3034  
    99
    1010import org.openstreetmap.josm.command.WayNodesConflictResolverCommand;
     11import org.openstreetmap.josm.data.conflict.Conflict;
    1112import org.openstreetmap.josm.data.osm.DataSet;
    1213import org.openstreetmap.josm.data.osm.Node;
     
    6162     * @param their  their way. Must not be null
    6263     * @return the command
    63      * @exception IllegalArgumentException thrown, if my is null or not a {@see Way}
    64      * @exception IllegalArgumentException thrown, if their is null or not a {@see Way}
    6564     * @exception IllegalStateException thrown, if the merge is not yet frozen
    6665     */
    67     public WayNodesConflictResolverCommand buildResolveCommand(Way my, Way their) {
    68         CheckParameterUtil.ensureParameterNotNull(my, "my");
    69         CheckParameterUtil.ensureParameterNotNull(their, "their");
     66    public WayNodesConflictResolverCommand buildResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
    7067        if (! isFrozen())
    7168            throw new IllegalArgumentException(tr("Merged nodes not frozen yet. Cannot build resolution command."));
    72         return new WayNodesConflictResolverCommand(my, their, getMergedEntries());
     69        return new WayNodesConflictResolverCommand(conflict, getMergedEntries());
    7370    }
    7471
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListMerger.java

    r2945 r3034  
    44import javax.swing.JTable;
    55
     6import org.openstreetmap.josm.data.conflict.Conflict;
    67import org.openstreetmap.josm.data.osm.Node;
    78import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    6364    }
    6465
    65     public void populate(OsmPrimitive my, OsmPrimitive their) {
    66         ((NodeListMergeModel)model).populate((Way)my, (Way)their);
     66    public void populate(Conflict<? extends OsmPrimitive> conflict) {
     67        ((NodeListMergeModel)model).populate((Way)conflict.getMy(), (Way)conflict.getTheir());
    6768    }
    6869
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/properties/PropertiesMergeModel.java

    r2940 r3034  
    2121import org.openstreetmap.josm.command.PurgePrimitivesCommand;
    2222import org.openstreetmap.josm.command.UndeletePrimitivesCommand;
     23import org.openstreetmap.josm.data.conflict.Conflict;
    2324import org.openstreetmap.josm.data.coor.LatLon;
    2425import org.openstreetmap.josm.data.osm.DataSet;
     
    161162     * @param their their version of the primitive
    162163     */
    163     public void populate(OsmPrimitive my, OsmPrimitive their) {
    164         this.my = my;
     164    public void populate(Conflict<? extends OsmPrimitive> conflict) {
     165        this.my = conflict.getMy();
     166        OsmPrimitive their = conflict.getTheir();
    165167        if (my instanceof Node) {
    166168            myCoords = ((Node)my).getCoor();
     
    171173        }
    172174
    173         myDeletedState = my.isDeleted();
     175        myDeletedState =  conflict.isMyDeleted() || my.isDeleted();
    174176        theirDeletedState = their.isDeleted();
    175177
     
    418420     * @return the list of commands
    419421     */
    420     public List<Command> buildResolveCommand(OsmPrimitive my, OsmPrimitive their) throws OperationCancelledException{
    421         ArrayList<Command> cmds = new ArrayList<Command>();
     422    public List<Command> buildResolveCommand(Conflict<? extends OsmPrimitive> conflict) throws OperationCancelledException{
     423        OsmPrimitive my = conflict.getMy();
     424        List<Command> cmds = new ArrayList<Command>();
    422425        if (hasVisibleStateConflict() && isDecidedVisibleState()) {
    423426            if (isVisibleStateDecision(MergeDecisionType.KEEP_MINE)) {
     
    436439        }
    437440        if (hasCoordConflict() && isDecidedCoord()) {
    438             cmds.add(new CoordinateConflictResolveCommand((Node)my, (Node)their, coordMergeDecision));
     441            cmds.add(new CoordinateConflictResolveCommand(conflict, coordMergeDecision));
    439442        }
    440443        if (hasDeletedStateConflict() && isDecidedDeletedState()) {
    441             cmds.add(new DeletedStateConflictResolveCommand(my, their, deletedMergeDecision));
     444            cmds.add(new DeletedStateConflictResolveCommand(conflict, deletedMergeDecision));
    442445        }
    443446        return cmds;
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/properties/PropertiesMerger.java

    r2945 r3034  
    2222import javax.swing.JPanel;
    2323
     24import org.openstreetmap.josm.data.conflict.Conflict;
    2425import org.openstreetmap.josm.data.coor.LatLon;
    2526import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    718719    }
    719720
    720     public void populate(OsmPrimitive my, OsmPrimitive their) {
    721         model.populate(my, their);
     721    public void populate(Conflict<? extends OsmPrimitive> conflict) {
     722        model.populate(conflict);
    722723    }
    723724}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberMerger.java

    r2945 r3034  
    55import javax.swing.JTable;
    66
     7import org.openstreetmap.josm.data.conflict.Conflict;
    78import org.openstreetmap.josm.data.osm.OsmPrimitive;
    89import org.openstreetmap.josm.data.osm.Relation;
     
    5455    }
    5556
    56     public void populate(OsmPrimitive my, OsmPrimitive their) {
     57    public void populate(Conflict<? extends OsmPrimitive> conflict) {
    5758        RelationMemberListMergeModel model = (RelationMemberListMergeModel)getModel();
    58         model.populate((Relation)my, (Relation)their);
     59        model.populate((Relation)conflict.getMy(), (Relation)conflict.getTheir());
    5960    }
    6061
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/tags/TagMergeModel.java

    r2945 r3034  
    1212
    1313import org.openstreetmap.josm.command.TagConflictResolveCommand;
     14import org.openstreetmap.josm.data.conflict.Conflict;
    1415import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1516import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
     
    189190    }
    190191
    191     public TagConflictResolveCommand buildResolveCommand(OsmPrimitive my, OsmPrimitive their) {
    192         return new TagConflictResolveCommand(my,  their, tagMergeItems);
     192    public TagConflictResolveCommand buildResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
     193        return new TagConflictResolveCommand(conflict, tagMergeItems);
    193194    }
    194195
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/tags/TagMerger.java

    r2945 r3034  
    2626import javax.swing.event.ListSelectionListener;
    2727
     28import org.openstreetmap.josm.data.conflict.Conflict;
    2829import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2930import org.openstreetmap.josm.gui.conflict.pair.IConflictResolver;
     
    421422    }
    422423
    423     public void populate(OsmPrimitive my, OsmPrimitive their) {
    424         model.populate(my, their);
     424    public void populate(Conflict<? extends OsmPrimitive> conflict) {
     425        model.populate(conflict.getMy(), conflict.getTheir());
    425426        mineTable.getSelectionModel().setSelectionInterval(0, 0);
    426427        theirTable.getSelectionModel().setSelectionInterval(0, 0);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r2945 r3034  
    144144        }
    145145
    146         Conflict<?> c = conflicts.get(index);
    147         OsmPrimitive my = c.getMy();
    148         OsmPrimitive their = c.getTheir();
     146        Conflict<? extends OsmPrimitive> c = conflicts.get(index);
    149147        ConflictResolutionDialog dialog = new ConflictResolutionDialog(Main.parent);
    150         dialog.getConflictResolver().populate(my, their);
     148        dialog.getConflictResolver().populate(c);
    151149        dialog.setVisible(true);
    152150
Note: See TracChangeset for help on using the changeset viewer.