source: josm/trunk/src/org/openstreetmap/josm/command/DeletedStateConflictResolveCommand.java@ 1706

Last change on this file since 1706 was 1690, checked in by Gubaer, 15 years ago

new: MultiFetchServerObjectReader using APIs Multi Fetch method
update: now uses Multi Fetch to check for deleted primitives on the server
update: now uses Multi Fetch to update the selected primitives with the state from the server
fixed: cleaned up merging in MergeVisitor
new: conflict resolution dialog; now resolves conflicts due to different visibilities
new: replacement for realEqual() on OsmPrimitive and derived classes; realEqual now @deprecated
fixed: cleaning up OsmReader
fixed: progress indication in OsmApi

File size: 3.2 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 if (my.deleted) {
69 // because my was involved in a conflict it my still be referred
70 // to from a way or a relation. Fix this now.
71 //
72 Main.main.editLayer().data.unlinkReferencesToPrimitive(my);
73 }
74 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
75 if (their.deleted) {
76 Main.main.editLayer().data.unlinkReferencesToPrimitive(my);
77 my.delete(true);
78 } else {
79 my.deleted = their.deleted;
80 }
81 } else
82 // should not happen
83 throw new IllegalStateException(tr("cannot resolve undecided conflict"));
84
85 return true;
86 }
87
88 @Override
89 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
90 Collection<OsmPrimitive> added) {
91 modified.add(my);
92 }
93
94 @Override
95 public void undoCommand() {
96 // restore former state of modified primitives
97 //
98 super.undoCommand();
99
100 // restore a conflict if necessary
101 //
102 if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
103 Main.map.conflictDialog.addConflict(my, their);
104 }
105 }
106}
Note: See TracBrowser for help on using the repository browser.