001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.command; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.util.Collection; 007 008import javax.swing.Icon; 009 010import org.openstreetmap.josm.data.conflict.Conflict; 011import org.openstreetmap.josm.data.osm.Node; 012import org.openstreetmap.josm.data.osm.OsmPrimitive; 013import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType; 014import org.openstreetmap.josm.gui.layer.OsmDataLayer; 015import org.openstreetmap.josm.tools.ImageProvider; 016 017/** 018 * Represents a the resolution of a conflict between the coordinates of two {@link Node}s 019 * 020 */ 021public class DeletedStateConflictResolveCommand extends ConflictResolveCommand { 022 023 /** the conflict to resolve */ 024 private Conflict<? extends OsmPrimitive> conflict; 025 026 /** the merge decision */ 027 private final MergeDecisionType decision; 028 029 /** 030 * constructor 031 * 032 * @param conflict the conflict data set 033 * @param decision the merge decision 034 */ 035 public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) { 036 this.conflict = conflict; 037 this.decision = decision; 038 } 039 040 @Override 041 public String getDescriptionText() { 042 return tr("Resolve conflicts in deleted state in {0}", conflict.getMy().getId()); 043 } 044 045 @Override 046 public Icon getDescriptionIcon() { 047 return ImageProvider.get("data", "object"); 048 } 049 050 @Override 051 public boolean executeCommand() { 052 // remember the current state of modified primitives, i.e. of 053 // OSM primitive 'my' 054 // 055 super.executeCommand(); 056 057 OsmDataLayer layer = getLayer(); 058 059 if (decision.equals(MergeDecisionType.KEEP_MINE)) { 060 if (conflict.getMy().isDeleted() || conflict.isMyDeleted()) { 061 // because my was involved in a conflict it my still be referred 062 // to from a way or a relation. Fix this now. 063 // 064 layer.data.unlinkReferencesToPrimitive(conflict.getMy()); 065 conflict.getMy().setDeleted(true); 066 } 067 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) { 068 if (conflict.getTheir().isDeleted()) { 069 layer.data.unlinkReferencesToPrimitive(conflict.getMy()); 070 conflict.getMy().setDeleted(true); 071 } else { 072 conflict.getMy().setDeleted(false); 073 } 074 } else 075 // should not happen 076 throw new IllegalStateException(tr("Cannot resolve undecided conflict.")); 077 078 rememberConflict(conflict); 079 return true; 080 } 081 082 @Override 083 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 084 Collection<OsmPrimitive> added) { 085 modified.add(conflict.getMy()); 086 modified.addAll(conflict.getMy().getReferrers()); 087 } 088}