source: josm/trunk/src/org/openstreetmap/josm/command/VersionConflictResolveCommand.java@ 4067

Last change on this file since 4067 was 3362, checked in by stoecker, 14 years ago

fix #5182 - Conflict system simplification - patch by Upliner

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.util.Collection;
8
9import javax.swing.JLabel;
10
11import org.openstreetmap.josm.data.conflict.Conflict;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
14import org.openstreetmap.josm.tools.ImageProvider;
15
16/**
17 * Represents a command for resolving a version conflict between two {@see OsmPrimitive}
18 *
19 *
20 */
21public 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}
Note: See TracBrowser for help on using the repository browser.