| 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 javax.swing.Icon; |
|---|
| 8 | |
|---|
| 9 | import org.openstreetmap.josm.data.conflict.Conflict; |
|---|
| 10 | import org.openstreetmap.josm.data.osm.Node; |
|---|
| 11 | import org.openstreetmap.josm.data.osm.OsmPrimitive; |
|---|
| 12 | import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType; |
|---|
| 13 | import org.openstreetmap.josm.tools.ImageProvider; |
|---|
| 14 | |
|---|
| 15 | /** |
|---|
| 16 | * Represents a the resolution of a conflict between the coordinates of two {@see Node}s |
|---|
| 17 | * |
|---|
| 18 | */ |
|---|
| 19 | public class CoordinateConflictResolveCommand extends ConflictResolveCommand { |
|---|
| 20 | |
|---|
| 21 | /** the conflict to resolve */ |
|---|
| 22 | private Conflict<? extends OsmPrimitive> conflict; |
|---|
| 23 | |
|---|
| 24 | /** the merge decision */ |
|---|
| 25 | private final MergeDecisionType decision; |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * constructor |
|---|
| 29 | * |
|---|
| 30 | * @param my my node |
|---|
| 31 | * @param their their node |
|---|
| 32 | * @param decision the merge decision |
|---|
| 33 | */ |
|---|
| 34 | public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) { |
|---|
| 35 | this.conflict = conflict; |
|---|
| 36 | this.decision = decision; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | @Override |
|---|
| 40 | public String getDescriptionText() { |
|---|
| 41 | return tr("Resolve conflicts in coordinates in {0}", conflict.getMy().getId()); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | @Override |
|---|
| 45 | public Icon getDescriptionIcon() { |
|---|
| 46 | return ImageProvider.get("data", "object"); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | @Override |
|---|
| 50 | public boolean executeCommand() { |
|---|
| 51 | // remember the current state of modified primitives, i.e. of |
|---|
| 52 | // OSM primitive 'my' |
|---|
| 53 | // |
|---|
| 54 | super.executeCommand(); |
|---|
| 55 | |
|---|
| 56 | if (decision.equals(MergeDecisionType.KEEP_MINE)) { |
|---|
| 57 | // do nothing |
|---|
| 58 | } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) { |
|---|
| 59 | Node my = (Node)conflict.getMy(); |
|---|
| 60 | Node their = (Node)conflict.getTheir(); |
|---|
| 61 | my.setCoor(their.getCoor()); |
|---|
| 62 | } else |
|---|
| 63 | // should not happen |
|---|
| 64 | throw new IllegalStateException(tr("Cannot resolve undecided conflict.")); |
|---|
| 65 | |
|---|
| 66 | // remember the layer this command was applied to |
|---|
| 67 | // |
|---|
| 68 | rememberConflict(conflict); |
|---|
| 69 | |
|---|
| 70 | return true; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | @Override |
|---|
| 74 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, |
|---|
| 75 | Collection<OsmPrimitive> added) { |
|---|
| 76 | modified.add(conflict.getMy()); |
|---|
| 77 | } |
|---|
| 78 | } |
|---|