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

Last change on this file since 6248 was 5816, checked in by stoecker, 11 years ago

javadoc fixes

  • Property svn:eol-style set to native
File size: 2.4 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;
8import javax.swing.Icon;
9
10import org.openstreetmap.josm.data.conflict.Conflict;
11import org.openstreetmap.josm.data.osm.OsmPrimitive;
12import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
13import org.openstreetmap.josm.tools.ImageProvider;
14
15/**
16 * Represents a command for resolving a version conflict between two {@link OsmPrimitive}
17 *
18 *
19 */
20public class VersionConflictResolveCommand extends ConflictResolveCommand {
21
22 /** the conflict to resolve */
23 private Conflict<? extends OsmPrimitive> conflict;
24
25 /**
26 * constructor
27 * @param conflict the conflict data set
28 */
29 public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
30 this.conflict = conflict;
31 }
32
33 @Override
34 public String getDescriptionText() {
35 String msg = "";
36 switch(OsmPrimitiveType.from(conflict.getMy())) {
37 case NODE: msg = marktr("Resolve version conflict for node {0}"); break;
38 case WAY: msg = marktr("Resolve version conflict for way {0}"); break;
39 case RELATION: msg = marktr("Resolve version conflict for relation {0}"); break;
40 }
41 return tr(msg, conflict.getMy().getId());
42 }
43
44 @Override
45 public Icon getDescriptionIcon() {
46 return ImageProvider.get("data", "object");
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.