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

Last change on this file since 1728 was 1670, checked in by Gubaer, 15 years ago

fixed: bug in OsmApi.getOsmApi()
cleanup: exception handling in interfacing with OSM API
new: new action for updating individual elements with the their current state on the server (including new menu item in the file menu)
new: improved user feedback in case of conflicts
new: handles 410 Gone conflicts when uploading a changeset
new: undoable command for "purging" a primitive from the current dataset (necessary if the primitive is already deleted on the server and the user wants to remove it from its local dataset)
new: undoable command for "undeleting" an already deleted primitive on the server (kind of "cloning")
new: after a full upload, checks whether there are primitives in the local dataset which might be deleted on the server.
new: data structures for history data
new: history download support in io package

File size: 2.9 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 * constructor
38 *
39 * @param my my node
40 * @param their their node
41 * @param decision the merge decision
42 */
43 public CoordinateConflictResolveCommand(Node my, Node their, MergeDecisionType decision) {
44 this.my = my;
45 this.their = their;
46 this.decision = decision;
47 }
48
49
50 @Override
51 public MutableTreeNode description() {
52 return new DefaultMutableTreeNode(
53 new JLabel(
54 tr("Resolve conflicts in coordinates in {0}",my.id),
55 ImageProvider.get("data", "object"),
56 JLabel.HORIZONTAL
57 )
58 );
59 }
60
61 @Override
62 public boolean executeCommand() {
63 // remember the current state of modified primitives, i.e. of
64 // OSM primitive 'my'
65 //
66 super.executeCommand();
67
68 if (decision.equals(MergeDecisionType.KEEP_MINE)) {
69 // do nothing
70 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
71 my.setCoor(their.getCoor());
72 } else
73 // should not happen
74 throw new IllegalStateException(tr("cannot resolve undecided conflict"));
75
76 return true;
77 }
78
79 @Override
80 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
81 Collection<OsmPrimitive> added) {
82 modified.add(my);
83 }
84
85 @Override
86 public void undoCommand() {
87 // restore former state of modified primitives
88 //
89 super.undoCommand();
90
91 // restore a conflict if necessary
92 //
93 if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
94 Main.map.conflictDialog.addConflict(my, their);
95 }
96 }
97}
Note: See TracBrowser for help on using the repository browser.