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