001 // License: GPL. For details, see LICENSE file.
002 package org.openstreetmap.josm.command;
003
004 import static org.openstreetmap.josm.tools.I18n.marktr;
005 import static org.openstreetmap.josm.tools.I18n.tr;
006
007 import java.util.Collection;
008 import javax.swing.Icon;
009
010 import org.openstreetmap.josm.data.conflict.Conflict;
011 import org.openstreetmap.josm.data.osm.OsmPrimitive;
012 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
013 import org.openstreetmap.josm.tools.ImageProvider;
014
015 /**
016 * Represents a command for resolving a version conflict between two {@link OsmPrimitive}
017 *
018 *
019 */
020 public class VersionConflictResolveCommand extends ConflictResolveCommand {
021
022 /** the conflict to resolve */
023 private Conflict<? extends OsmPrimitive> conflict;
024
025 /**
026 * constructor
027 * @param my my primitive (i.e. the primitive from the local dataset)
028 * @param their their primitive (i.e. the primitive from the server)
029 */
030 public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
031 this.conflict = conflict;
032 }
033
034 @Override
035 public String getDescriptionText() {
036 String msg = "";
037 switch(OsmPrimitiveType.from(conflict.getMy())) {
038 case NODE: msg = marktr("Resolve version conflict for node {0}"); break;
039 case WAY: msg = marktr("Resolve version conflict for way {0}"); break;
040 case RELATION: msg = marktr("Resolve version conflict for relation {0}"); break;
041 }
042 return tr(msg, 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 super.executeCommand();
053 if (!conflict.getMy().isNew()) {
054 long myVersion = conflict.getMy().getVersion();
055 long theirVersion = conflict.getTheir().getVersion();
056 conflict.getMy().setOsmId(
057 conflict.getMy().getId(),
058 (int)Math.max(myVersion, theirVersion)
059 );
060 // update visiblity state
061 if (theirVersion >= myVersion) {
062 conflict.getMy().setVisible(conflict.getTheir().isVisible());
063 }
064 }
065 getLayer().getConflicts().remove(conflict);
066 rememberConflict(conflict);
067 return true;
068 }
069
070 @Override
071 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
072 Collection<OsmPrimitive> added) {
073 modified.add(conflict.getMy());
074 }
075 }