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

Revision 4918, 2.2 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 javax.swing.JLabel;
11
12import org.openstreetmap.josm.data.conflict.Conflict;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
15import org.openstreetmap.josm.tools.ImageProvider;
16
17/**
18 * Represents a command for to set the modified flag {@see OsmPrimitive}
19 *
20 *
21 */
22public class ModifiedConflictResolveCommand extends ConflictResolveCommand {
23
24    /** the conflict to resolve */
25    private Conflict<? extends OsmPrimitive> conflict;
26
27    /**
28     * constructor
29     * @param my  my primitive (i.e. the primitive from the local dataset)
30     * @param their their primitive (i.e. the primitive from the server)
31     */
32    public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
33        this.conflict = conflict;
34    }
35
36    @Override
37    public String getDescriptionText() {
38        String msg = "";
39        switch(OsmPrimitiveType.from(conflict.getMy())) {
40        case NODE: msg = marktr("Set the ''modified'' flag for node {0}"); break;
41        case WAY: msg = marktr("Set the ''modified'' flag for way {0}"); break;
42        case RELATION: msg = marktr("Set the ''modified'' flag for relation {0}"); break;
43        }
44        return tr(msg,conflict.getMy().getId());
45    }
46
47    @Override
48    public Icon getDescriptionIcon() {
49        return ImageProvider.get("data", "object");
50    }
51
52    @Override
53    public boolean executeCommand() {
54        super.executeCommand();
55        if (!conflict.getMy().isNew() && conflict.getMy().hasEqualSemanticAttributes(conflict.getTheir())) {
56            conflict.getMy().setModified(conflict.getTheir().isModified());
57        }
58        getLayer().getConflicts().remove(conflict);
59        rememberConflict(conflict);
60        return true;
61    }
62
63    @Override
64    public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
65            Collection<OsmPrimitive> added) {
66        modified.add(conflict.getMy());
67    }
68}
Note: See TracBrowser for help on using the repository browser.