1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.marktr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.util.Collection;
|
---|
8 |
|
---|
9 | import javax.swing.JLabel;
|
---|
10 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
11 | import javax.swing.tree.MutableTreeNode;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
14 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
15 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
16 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Represents a command for resolving a version conflict between two {@see OsmPrimitive}
|
---|
20 | *
|
---|
21 | *
|
---|
22 | */
|
---|
23 | public class VersionConflictResolveCommand extends ConflictResolveCommand {
|
---|
24 |
|
---|
25 | /** the conflict to resolve */
|
---|
26 | private Conflict<OsmPrimitive> conflict;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * constructor
|
---|
30 | * @param my my primitive (i.e. the primitive from the local dataset)
|
---|
31 | * @param their their primitive (i.e. the primitive from the server)
|
---|
32 | */
|
---|
33 | public VersionConflictResolveCommand(OsmPrimitive my, OsmPrimitive their) {
|
---|
34 | conflict = new Conflict<OsmPrimitive>(my, their);
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public MutableTreeNode description() {
|
---|
39 | String msg = "";
|
---|
40 | switch(OsmPrimitiveType.from(conflict.getMy())) {
|
---|
41 | case NODE: msg = marktr("Resolve version conflicts for node {0}"); break;
|
---|
42 | case WAY: msg = marktr("Resolve version conflicts for way {0}"); break;
|
---|
43 | case RELATION: msg = marktr("Resolve version conflicts for relation {0}"); break;
|
---|
44 | }
|
---|
45 | return new DefaultMutableTreeNode(
|
---|
46 | new JLabel(
|
---|
47 | tr(msg,conflict.getMy().getId()),
|
---|
48 | ImageProvider.get("data", "object"),
|
---|
49 | JLabel.HORIZONTAL
|
---|
50 | )
|
---|
51 | );
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public boolean executeCommand() {
|
---|
56 | super.executeCommand();
|
---|
57 | if (!conflict.getMy().isNew()) {
|
---|
58 | conflict.getMy().setOsmId(
|
---|
59 | conflict.getMy().getId(),
|
---|
60 | (int)Math.max(conflict.getMy().getVersion(), conflict.getTheir().getVersion())
|
---|
61 | );
|
---|
62 | }
|
---|
63 | getLayer().getConflicts().remove(conflict);
|
---|
64 | rememberConflict(conflict);
|
---|
65 | return true;
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
70 | Collection<OsmPrimitive> added) {
|
---|
71 | modified.add(conflict.getMy());
|
---|
72 | }
|
---|
73 | }
|
---|