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

Last change on this file since 3034 was 3034, checked in by jttt, 14 years ago

Fix #4467 Don't silently drop locally deleted member primitives from downloaded ways and relation (fix the issue when deleted primitive is referenced)

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;
8
9import javax.swing.JLabel;
10import javax.swing.tree.DefaultMutableTreeNode;
11import javax.swing.tree.MutableTreeNode;
12
13import org.openstreetmap.josm.data.conflict.Conflict;
14import org.openstreetmap.josm.data.osm.OsmPrimitive;
15import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
16import org.openstreetmap.josm.tools.ImageProvider;
17
18/**
19 * Represents a command for resolving a version conflict between two {@see OsmPrimitive}
20 *
21 *
22 */
23public class VersionConflictResolveCommand extends ConflictResolveCommand {
24
25 /** the conflict to resolve */
26 private Conflict<? extends 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(Conflict<? extends OsmPrimitive> conflict) {
34 this.conflict = conflict;
35 }
36
37 @Override
38 public MutableTreeNode description() {
39 String msg = "";
40 switch(OsmPrimitiveType.from(conflict.getMy())) {
41 case NODE: msg = marktr("Resolve version conflict for node {0}"); break;
42 case WAY: msg = marktr("Resolve version conflict for way {0}"); break;
43 case RELATION: msg = marktr("Resolve version conflict 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}
Note: See TracBrowser for help on using the repository browser.