source: josm/trunk/src/org/openstreetmap/josm/command/VersionConflictResolveCommand.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.7 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.tools.ImageProvider;
18
19/**
20 * Represents a command for resolving a version conflict between two {@see OsmPrimitive}
21 *
22 *
23 */
24public class VersionConflictResolveCommand extends Command {
25
26 private final OsmPrimitive my;
27 private final OsmPrimitive their;
28
29 /**
30 * constructor
31 * @param my my primitive (i.e. the primitive from the local dataset)
32 * @param their their primitive (i.e. the primitive from the server)
33 */
34 public VersionConflictResolveCommand(OsmPrimitive my, OsmPrimitive their) {
35 this.my = my;
36 this.their = their;
37 }
38
39 //FIXME copied from TagConflictResolveCommand -> refactor
40 /**
41 * replies a (localized) display name for the type of an OSM primitive
42 *
43 * @param primitive the primitive
44 * @return a localized display name
45 */
46 protected String getPrimitiveTypeAsString(OsmPrimitive primitive) {
47 if (primitive instanceof Node) return tr("node");
48 if (primitive instanceof Way) return tr("way");
49 if (primitive instanceof Relation) return tr("relation");
50 return "";
51 }
52
53 @Override
54 public MutableTreeNode description() {
55 return new DefaultMutableTreeNode(
56 new JLabel(
57 tr("Resolve version conflicts for {0} {1}",getPrimitiveTypeAsString(my), my.id),
58 ImageProvider.get("data", "object"),
59 JLabel.HORIZONTAL
60 )
61 );
62 }
63
64 @Override
65 public boolean executeCommand() {
66 super.executeCommand();
67 my.version = Math.max(my.version, their.version);
68 Main.map.conflictDialog.removeConflictForPrimitive(my);
69 return true;
70 }
71
72 @Override
73 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
74 Collection<OsmPrimitive> added) {
75 modified.add(my);
76 }
77
78 @Override
79 public void undoCommand() {
80 super.undoCommand();
81
82 // restore a conflict if necessary
83 //
84 if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
85 Main.map.conflictDialog.addConflict(my, their);
86 }
87 }
88}
Note: See TracBrowser for help on using the repository browser.