001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.command.conflict; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.util.Collection; 007import java.util.List; 008 009import javax.swing.Icon; 010 011import org.openstreetmap.josm.Main; 012import org.openstreetmap.josm.data.conflict.Conflict; 013import org.openstreetmap.josm.data.osm.Node; 014import org.openstreetmap.josm.data.osm.OsmPrimitive; 015import org.openstreetmap.josm.data.osm.Way; 016import org.openstreetmap.josm.tools.ImageProvider; 017 018/** 019 * Represents the resolution of conflicts in the node list of two {@link Way}s. 020 * 021 */ 022public class WayNodesConflictResolverCommand extends ConflictResolveCommand { 023 /** the conflict to resolve */ 024 private Conflict<Way> conflict; 025 026 /** the list of merged nodes. This becomes the list of news of my way after the 027 * command is executed 028 */ 029 private final List<Node> mergedNodeList; 030 031 /** 032 * @param conflict the conflict data set 033 * @param mergedNodeList the list of merged nodes 034 */ 035 @SuppressWarnings("unchecked") 036 public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) { 037 this.conflict = (Conflict<Way>) conflict; 038 this.mergedNodeList = mergedNodeList; 039 } 040 041 @Override 042 public String getDescriptionText() { 043 return tr("Resolve conflicts in node list of way {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 'my' way 054 // 055 super.executeCommand(); 056 057 // replace the list of nodes of 'my' way by the list of merged nodes 058 // 059 for (Node n:mergedNodeList) { 060 if (! getLayer().data.getNodes().contains(n)) { 061 Main.warn(tr("Main dataset does not include node {0}", n.toString())); 062 } 063 } 064 conflict.getMy().setNodes(mergedNodeList); 065 rememberConflict(conflict); 066 return true; 067 } 068 069 @Override 070 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 071 Collection<OsmPrimitive> added) { 072 modified.add(conflict.getMy()); 073 } 074}