source: josm/trunk/src/org/openstreetmap/josm/command/CoordinateConflictResolveCommand.java@ 1656

Last change on this file since 1656 was 1654, checked in by Gubaer, 15 years ago

added merge support for coordinate conflicts
added merge support for conflicts due to different deleted states

File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collection;
7
8import javax.swing.JLabel;
9import javax.swing.tree.DefaultMutableTreeNode;
10import javax.swing.tree.MutableTreeNode;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.data.osm.Node;
14import org.openstreetmap.josm.data.osm.OsmPrimitive;
15import org.openstreetmap.josm.data.osm.Relation;
16import org.openstreetmap.josm.data.osm.Way;
17import org.openstreetmap.josm.gui.conflict.MergeDecisionType;
18import org.openstreetmap.josm.tools.ImageProvider;
19
20/**
21 * Represents a the resolution of a conflict between the coordinates of two {@see Node}s
22 *
23 */
24public class CoordinateConflictResolveCommand extends Command {
25
26 /** my node (in the local dataset). merge decisions are applied to this
27 * node
28 */
29 private final Node my;
30 /** their node (in the server dataset) */
31 private final Node their;
32
33 /** the merge decision */
34 private final MergeDecisionType decision;
35
36
37 /**
38 * replies a (localized) display name for the type of an OSM primitive
39 *
40 * @param primitive the primitive
41 * @return a localized display name
42 */
43 protected String getPrimitiveTypeAsString(OsmPrimitive primitive) {
44 if (primitive instanceof Node) return tr("node");
45 if (primitive instanceof Way) return tr("way");
46 if (primitive instanceof Relation) return tr("relation");
47 return "";
48 }
49
50 /**
51 * constructor
52 *
53 * @param my my node
54 * @param their their node
55 * @param decision the merge decision
56 */
57 public CoordinateConflictResolveCommand(Node my, Node their, MergeDecisionType decision) {
58 this.my = my;
59 this.their = their;
60 this.decision = decision;
61 }
62
63
64 @Override
65 public MutableTreeNode description() {
66 return new DefaultMutableTreeNode(
67 new JLabel(
68 tr("Resolve conflicts in coordinates in {0}",my.id),
69 ImageProvider.get("data", "object"),
70 JLabel.HORIZONTAL
71 )
72 );
73 }
74
75 @Override
76 public boolean executeCommand() {
77 // remember the current state of modified primitives, i.e. of
78 // OSM primitive 'my'
79 //
80 super.executeCommand();
81
82 if (decision.equals(MergeDecisionType.KEEP_MINE)) {
83 // do nothing
84 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
85 my.setCoor(their.getCoor());
86 } else
87 // should not happen
88 throw new IllegalStateException(tr("cannot resolve undecided conflict"));
89
90 return true;
91 }
92
93 @Override
94 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
95 Collection<OsmPrimitive> added) {
96 modified.add(my);
97 }
98
99 @Override
100 public void undoCommand() {
101 // restore former state of modified primitives
102 //
103 super.undoCommand();
104
105 // restore a conflict if necessary
106 //
107 if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
108 Main.map.conflictDialog.addConflict(my, their);
109 }
110 }
111}
Note: See TracBrowser for help on using the repository browser.