1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.Collection;
|
---|
7 |
|
---|
8 | import javax.swing.JLabel;
|
---|
9 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
10 | import javax.swing.tree.MutableTreeNode;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
13 | import org.openstreetmap.josm.data.osm.Node;
|
---|
14 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
15 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
16 | import org.openstreetmap.josm.data.osm.Way;
|
---|
17 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Represents a command for resolving a version conflict between two {@see OsmPrimitive}
|
---|
21 | *
|
---|
22 | *
|
---|
23 | */
|
---|
24 | public 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 | }
|
---|