1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.marktr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.util.Collection;
|
---|
8 | import javax.swing.Icon;
|
---|
9 |
|
---|
10 | import javax.swing.JLabel;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
14 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Represents a command for to set the modified flag {@link OsmPrimitive}
|
---|
19 | *
|
---|
20 | *
|
---|
21 | */
|
---|
22 | public 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 | }
|
---|