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

Last change on this file since 6887 was 6887, checked in by Don-vip, 10 years ago

package refactoring of conflict commands => move all of them to new package command.conflict (some plugins have to be updated)

  • 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.conflict;
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.Icon;
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 the resolution of a version conflict between two {@link OsmPrimitive}s.
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 conflict the conflict data set
29 */
30 public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
31 this.conflict = conflict;
32 }
33
34 @Override
35 public String getDescriptionText() {
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 tr(msg, conflict.getMy().getId());
43 }
44
45 @Override
46 public Icon getDescriptionIcon() {
47 return ImageProvider.get("data", "object");
48 }
49
50 @Override
51 public boolean executeCommand() {
52 super.executeCommand();
53 if (!conflict.getMy().isNew()) {
54 long myVersion = conflict.getMy().getVersion();
55 long theirVersion = conflict.getTheir().getVersion();
56 conflict.getMy().setOsmId(
57 conflict.getMy().getId(),
58 (int)Math.max(myVersion, theirVersion)
59 );
60 // update visiblity state
61 if (theirVersion >= myVersion) {
62 conflict.getMy().setVisible(conflict.getTheir().isVisible());
63 }
64 }
65 getLayer().getConflicts().remove(conflict);
66 rememberConflict(conflict);
67 return true;
68 }
69
70 @Override
71 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
72 Collection<OsmPrimitive> added) {
73 modified.add(conflict.getMy());
74 }
75}
Note: See TracBrowser for help on using the repository browser.