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.OsmPrimitiveType;
|
---|
16 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
17 | import org.openstreetmap.josm.data.osm.Way;
|
---|
18 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Represents a command for resolving a version conflict between two {@see OsmPrimitive}
|
---|
22 | *
|
---|
23 | *
|
---|
24 | */
|
---|
25 | public class VersionConflictResolveCommand extends Command {
|
---|
26 |
|
---|
27 | private final OsmPrimitive my;
|
---|
28 | private final OsmPrimitive their;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * constructor
|
---|
32 | * @param my my primitive (i.e. the primitive from the local dataset)
|
---|
33 | * @param their their primitive (i.e. the primitive from the server)
|
---|
34 | */
|
---|
35 | public VersionConflictResolveCommand(OsmPrimitive my, OsmPrimitive their) {
|
---|
36 | this.my = my;
|
---|
37 | this.their = their;
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public MutableTreeNode description() {
|
---|
42 | return new DefaultMutableTreeNode(
|
---|
43 | new JLabel(
|
---|
44 | tr("Resolve version conflicts for {0} {1}",OsmPrimitiveType.from(my).getLocalizedDisplayNameSingular(), my.id),
|
---|
45 | ImageProvider.get("data", "object"),
|
---|
46 | JLabel.HORIZONTAL
|
---|
47 | )
|
---|
48 | );
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public boolean executeCommand() {
|
---|
53 | super.executeCommand();
|
---|
54 | my.version = Math.max(my.version, their.version);
|
---|
55 | Main.map.conflictDialog.removeConflictForPrimitive(my);
|
---|
56 | return true;
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
61 | Collection<OsmPrimitive> added) {
|
---|
62 | modified.add(my);
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Override
|
---|
66 | public void undoCommand() {
|
---|
67 | super.undoCommand();
|
---|
68 |
|
---|
69 | // restore a conflict if necessary
|
---|
70 | //
|
---|
71 | if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
|
---|
72 | Main.map.conflictDialog.addConflict(my, their);
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|