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