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

Revision 4918, 2.5 KB checked in by simon04, 3 months ago (diff)

fix #7370 - Refactor Command.getDescription

  • Property svn:eol-style set to native
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 {@see 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 my  my primitive (i.e. the primitive from the local dataset)
28     * @param their their primitive (i.e. the primitive from the server)
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.