Changeset 6886 in josm


Ignore:
Timestamp:
2014-02-26T23:33:44+01:00 (11 years ago)
Author:
Don-vip
Message:

fix #6373 - proper conflict resolution after failed attempt to delete an object referenced by an unknown one

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

Legend:

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

    r6881 r6886  
    55
    66import java.util.Collection;
     7import java.util.Set;
    78
    89import javax.swing.Icon;
     
    1112import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1213import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
    13 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1414import org.openstreetmap.josm.tools.ImageProvider;
    1515
    1616/**
    1717 * Represents the resolution of a conflict between the deleted flag of two {@link OsmPrimitive}s.
    18  *
     18 * @since 1654
    1919 */
    2020public class DeletedStateConflictResolveCommand extends ConflictResolveCommand {
     
    2727
    2828    /**
    29      * constructor
     29     * Constructs a new {@code DeletedStateConflictResolveCommand}.
    3030     *
    3131     * @param conflict the conflict data set
     
    4949    @Override
    5050    public boolean executeCommand() {
    51         // remember the current state of modified primitives, i.e. of
    52         // OSM primitive 'my'
    53         //
     51        // remember the current state of modified primitives, i.e. of OSM primitive 'my'
    5452        super.executeCommand();
    55 
    56         OsmDataLayer layer = getLayer();
    5753
    5854        if (decision.equals(MergeDecisionType.KEEP_MINE)) {
     
    6056                // because my was involved in a conflict it my still be referred
    6157                // to from a way or a relation. Fix this now.
    62                 //
    63                 layer.data.unlinkReferencesToPrimitive(conflict.getMy());
    64                 conflict.getMy().setDeleted(true);
     58                deleteMy();
    6559            }
    6660        } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
    6761            if (conflict.getTheir().isDeleted()) {
    68                 layer.data.unlinkReferencesToPrimitive(conflict.getMy());
    69                 conflict.getMy().setDeleted(true);
     62                deleteMy();
    7063            } else {
    7164                conflict.getMy().setDeleted(false);
     
    7871        return true;
    7972    }
     73   
     74    private void deleteMy() {
     75        Set<OsmPrimitive> referrers = getLayer().data.unlinkReferencesToPrimitive(conflict.getMy());
     76        for (OsmPrimitive p : referrers) {
     77            if (!p.isNew() && !p.isDeleted()) {
     78                p.setModified(true);
     79            }
     80        }
     81        conflict.getMy().setDeleted(true);
     82    }
    8083
    8184    @Override
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r6830 r6886  
    1010import java.util.Collections;
    1111import java.util.HashMap;
     12import java.util.HashSet;
    1213import java.util.Iterator;
    1314import java.util.LinkedHashSet;
     
    814815
    815816    /**
    816      * removes all references from ways in this dataset to a particular node
     817     * Removes all references from ways in this dataset to a particular node.
    817818     *
    818819     * @param node the node
    819      */
    820     public void unlinkNodeFromWays(Node node) {
     820     * @return The set of ways that have been modified
     821     */
     822    public Set<Way> unlinkNodeFromWays(Node node) {
     823        Set<Way> result = new HashSet<Way>();
    821824        beginUpdate();
    822825        try {
     
    829832                        way.setNodes(wayNodes);
    830833                    }
     834                    result.add(way);
    831835                }
    832836            }
     
    834838            endUpdate();
    835839        }
     840        return result;
    836841    }
    837842
     
    840845     *
    841846     * @param primitive the primitive
    842      */
    843     public void unlinkPrimitiveFromRelations(OsmPrimitive primitive) {
     847     * @return The set of relations that have been modified
     848     */
     849    public Set<Relation> unlinkPrimitiveFromRelations(OsmPrimitive primitive) {
     850        Set<Relation> result = new HashSet<Relation>();
    844851        beginUpdate();
    845852        try {
     
    859866                if (removed) {
    860867                    relation.setMembers(members);
     868                    result.add(relation);
    861869                }
    862870            }
     
    864872            endUpdate();
    865873        }
    866     }
    867 
    868     /**
    869      * removes all references from other primitives to the
    870      * referenced primitive
     874        return result;
     875    }
     876
     877    /**
     878     * Removes all references from other primitives to the referenced primitive.
    871879     *
    872880     * @param referencedPrimitive the referenced primitive
    873      */
    874     public void unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive) {
     881     * @return The set of primitives that have been modified
     882     */
     883    public Set<OsmPrimitive> unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive) {
     884        Set<OsmPrimitive> result = new HashSet<OsmPrimitive>();
    875885        beginUpdate();
    876886        try {
    877887            if (referencedPrimitive instanceof Node) {
    878                 unlinkNodeFromWays((Node)referencedPrimitive);
    879                 unlinkPrimitiveFromRelations(referencedPrimitive);
    880             } else {
    881                 unlinkPrimitiveFromRelations(referencedPrimitive);
    882             }
     888                result.addAll(unlinkNodeFromWays((Node)referencedPrimitive));
     889            }
     890            result.addAll(unlinkPrimitiveFromRelations(referencedPrimitive));
    883891        } finally {
    884892            endUpdate();
    885893        }
     894        return result;
    886895    }
    887896
Note: See TracChangeset for help on using the changeset viewer.