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 import java.util.List;
008
009 import javax.swing.Icon;
010
011 import org.openstreetmap.josm.data.conflict.Conflict;
012 import org.openstreetmap.josm.data.osm.Node;
013 import org.openstreetmap.josm.data.osm.OsmPrimitive;
014 import org.openstreetmap.josm.data.osm.Way;
015 import org.openstreetmap.josm.tools.ImageProvider;
016
017 /**
018 * Represent a command for resolving conflicts in the node list of two
019 * {@link Way}s.
020 *
021 */
022 public 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 *
033 * @param my my may
034 * @param their their way
035 * @param mergedNodeList the list of merged nodes
036 */
037 @SuppressWarnings("unchecked")
038 public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
039 this.conflict = (Conflict<Way>) conflict;
040 this.mergedNodeList = mergedNodeList;
041 }
042 @Override
043 public String getDescriptionText() {
044 return tr("Resolve conflicts in node list of way {0}", conflict.getMy().getId());
045 }
046
047 @Override
048 public Icon getDescriptionIcon() {
049 return ImageProvider.get("data", "object");
050 }
051
052 @Override
053 public boolean executeCommand() {
054 // remember the current state of 'my' way
055 //
056 super.executeCommand();
057
058 // replace the list of nodes of 'my' way by the list of merged
059 // nodes
060 //
061 for (Node n:mergedNodeList) {
062 if (! getLayer().data.getNodes().contains(n)) {
063 System.out.println(tr("Main dataset does not include node {0}", n.toString()));
064 }
065 }
066 conflict.getMy().setNodes(mergedNodeList);
067 rememberConflict(conflict);
068 return true;
069 }
070
071 @Override
072 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
073 Collection<OsmPrimitive> added) {
074 modified.add(conflict.getMy());
075 }
076 }