[2512] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.command;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.util.Collection;
|
---|
| 7 | import java.util.List;
|
---|
| 8 |
|
---|
[4918] | 9 | import javax.swing.Icon;
|
---|
[2512] | 10 |
|
---|
| 11 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
| 12 | import org.openstreetmap.josm.data.osm.Node;
|
---|
| 13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
| 14 | import org.openstreetmap.josm.data.osm.Way;
|
---|
| 15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
| 18 | * Represent a command for resolving conflicts in the node list of two
|
---|
[5266] | 19 | * {@link Way}s.
|
---|
[2512] | 20 | *
|
---|
| 21 | */
|
---|
| 22 | public class WayNodesConflictResolverCommand extends ConflictResolveCommand {
|
---|
| 23 | /** the conflict to resolve */
|
---|
| 24 | private Conflict<Way> conflict;
|
---|
| 25 |
|
---|
| 26 | /** the list of merged nodes. This becomes the list of news of my way after the
|
---|
| 27 | * command is executed
|
---|
| 28 | */
|
---|
| 29 | private final List<Node> mergedNodeList;
|
---|
| 30 |
|
---|
| 31 | /**
|
---|
| 32 | *
|
---|
| 33 | * @param my my may
|
---|
| 34 | * @param their their way
|
---|
| 35 | * @param mergedNodeList the list of merged nodes
|
---|
| 36 | */
|
---|
[3034] | 37 | @SuppressWarnings("unchecked")
|
---|
| 38 | public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
|
---|
| 39 | this.conflict = (Conflict<Way>) conflict;
|
---|
[2512] | 40 | this.mergedNodeList = mergedNodeList;
|
---|
| 41 | }
|
---|
[4918] | 42 | @Override
|
---|
| 43 | public String getDescriptionText() {
|
---|
| 44 | return tr("Resolve conflicts in node list of way {0}", conflict.getMy().getId());
|
---|
| 45 | }
|
---|
[2512] | 46 |
|
---|
[4918] | 47 | @Override
|
---|
| 48 | public Icon getDescriptionIcon() {
|
---|
| 49 | return ImageProvider.get("data", "object");
|
---|
[2512] | 50 | }
|
---|
| 51 |
|
---|
| 52 | @Override
|
---|
| 53 | public boolean executeCommand() {
|
---|
| 54 | // remember the current state of 'my' way
|
---|
| 55 | //
|
---|
| 56 | super.executeCommand();
|
---|
| 57 |
|
---|
| 58 | // replace the list of nodes of 'my' way by the list of merged
|
---|
| 59 | // nodes
|
---|
| 60 | //
|
---|
| 61 | for (Node n:mergedNodeList) {
|
---|
| 62 | if (! getLayer().data.getNodes().contains(n)) {
|
---|
[4191] | 63 | System.out.println(tr("Main dataset does not include node {0}", n.toString()));
|
---|
[2512] | 64 | }
|
---|
| 65 | }
|
---|
| 66 | conflict.getMy().setNodes(mergedNodeList);
|
---|
| 67 | rememberConflict(conflict);
|
---|
| 68 | return true;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | @Override
|
---|
| 72 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
| 73 | Collection<OsmPrimitive> added) {
|
---|
| 74 | modified.add(conflict.getMy());
|
---|
| 75 | }
|
---|
| 76 | }
|
---|