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