001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.command.conflict; 003 004import static org.openstreetmap.josm.tools.I18n.marktr; 005import static org.openstreetmap.josm.tools.I18n.tr; 006 007import java.util.Collection; 008import java.util.Objects; 009 010import javax.swing.Icon; 011 012import org.openstreetmap.josm.data.conflict.Conflict; 013import org.openstreetmap.josm.data.osm.OsmPrimitive; 014import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 015import org.openstreetmap.josm.tools.ImageProvider; 016 017/** 018 * Represents the resolution of a conflict between the modified flag of two {@link OsmPrimitive}s. 019 * 020 * 021 */ 022public class ModifiedConflictResolveCommand extends ConflictResolveCommand { 023 024 /** the conflict to resolve */ 025 private final Conflict<? extends OsmPrimitive> conflict; 026 027 /** 028 * constructor 029 * @param conflict the conflict data set 030 */ 031 public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) { 032 this.conflict = conflict; 033 } 034 035 @Override 036 public String getDescriptionText() { 037 String msg = ""; 038 switch(OsmPrimitiveType.from(conflict.getMy())) { 039 case NODE: msg = marktr("Set the ''modified'' flag for node {0}"); break; 040 case WAY: msg = marktr("Set the ''modified'' flag for way {0}"); break; 041 case RELATION: msg = marktr("Set the ''modified'' flag for relation {0}"); break; 042 } 043 return tr(msg, 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 super.executeCommand(); 054 if (!conflict.getMy().isNew() && conflict.getMy().hasEqualSemanticAttributes(conflict.getTheir())) { 055 conflict.getMy().setModified(conflict.getTheir().isModified()); 056 } 057 getLayer().getConflicts().remove(conflict); 058 rememberConflict(conflict); 059 return true; 060 } 061 062 @Override 063 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 064 Collection<OsmPrimitive> added) { 065 modified.add(conflict.getMy()); 066 } 067 068 @Override 069 public int hashCode() { 070 return Objects.hash(super.hashCode(), conflict); 071 } 072 073 @Override 074 public boolean equals(Object obj) { 075 if (this == obj) return true; 076 if (obj == null || getClass() != obj.getClass()) return false; 077 if (!super.equals(obj)) return false; 078 ModifiedConflictResolveCommand that = (ModifiedConflictResolveCommand) obj; 079 return Objects.equals(conflict, that.conflict); 080 } 081}