source: josm/trunk/src/org/openstreetmap/josm/command/DeletedStateConflictResolveCommand.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: 2.8 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.OsmPrimitive;
14import org.openstreetmap.josm.gui.conflict.MergeDecisionType;
15import org.openstreetmap.josm.tools.ImageProvider;
16
17/**
18 * Represents a the resolution of a conflict between the coordinates of two {@see Node}s
19 *
20 */
21public class DeletedStateConflictResolveCommand extends Command {
22
23 /** my primitive (in the local dataset). merge decisions are applied to this
24 * node
25 */
26 private final OsmPrimitive my;
27 /** their primitive (in the server dataset) */
28 private final OsmPrimitive their;
29
30 /** the merge decision */
31 private final MergeDecisionType decision;
32
33
34
35 /**
36 * constructor
37 *
38 * @param my my node
39 * @param their their node
40 * @param decision the merge decision
41 */
42 public DeletedStateConflictResolveCommand(OsmPrimitive my, OsmPrimitive their, MergeDecisionType decision) {
43 this.my = my;
44 this.their = their;
45 this.decision = decision;
46 }
47
48
49 @Override
50 public MutableTreeNode description() {
51 return new DefaultMutableTreeNode(
52 new JLabel(
53 tr("Resolve conflicts in deleted state in {0}",my.id),
54 ImageProvider.get("data", "object"),
55 JLabel.HORIZONTAL
56 )
57 );
58 }
59
60 @Override
61 public boolean executeCommand() {
62 // remember the current state of modified primitives, i.e. of
63 // OSM primitive 'my'
64 //
65 super.executeCommand();
66
67 if (decision.equals(MergeDecisionType.KEEP_MINE)) {
68 // do nothing
69 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
70 my.deleted = their.deleted;
71 } else
72 // should not happen
73 throw new IllegalStateException(tr("cannot resolve undecided conflict"));
74
75 return true;
76 }
77
78 @Override
79 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
80 Collection<OsmPrimitive> added) {
81 modified.add(my);
82 }
83
84 @Override
85 public void undoCommand() {
86 // restore former state of modified primitives
87 //
88 super.undoCommand();
89
90 // restore a conflict if necessary
91 //
92 if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
93 Main.map.conflictDialog.addConflict(my, their);
94 }
95 }
96}
Note: See TracBrowser for help on using the repository browser.