1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command.conflict;
|
---|
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 java.util.Objects;
|
---|
9 |
|
---|
10 | import javax.swing.Icon;
|
---|
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 the resolution of a conflict between the modified flag of two {@link OsmPrimitive}s.
|
---|
19 | * @since 2624
|
---|
20 | */
|
---|
21 | public class ModifiedConflictResolveCommand extends ConflictResolveCommand {
|
---|
22 |
|
---|
23 | /** the conflict to resolve */
|
---|
24 | private final Conflict<? extends OsmPrimitive> conflict;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * constructor
|
---|
28 | * @param conflict the conflict data set
|
---|
29 | */
|
---|
30 | public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
|
---|
31 | super(conflict.getMy().getDataSet());
|
---|
32 | this.conflict = conflict;
|
---|
33 | }
|
---|
34 |
|
---|
35 | @Override
|
---|
36 | public String getDescriptionText() {
|
---|
37 | String msg;
|
---|
38 | switch(OsmPrimitiveType.from(conflict.getMy())) {
|
---|
39 | case NODE: msg = marktr("Set the ''modified'' flag for node {0}"); break;
|
---|
40 | case WAY: msg = marktr("Set the ''modified'' flag for way {0}"); break;
|
---|
41 | case RELATION: msg = marktr("Set the ''modified'' flag for relation {0}"); break;
|
---|
42 | default: throw new AssertionError();
|
---|
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 | getAffectedDataSet().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 |
|
---|
69 | @Override
|
---|
70 | public int hashCode() {
|
---|
71 | return Objects.hash(super.hashCode(), conflict);
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Override
|
---|
75 | public boolean equals(Object obj) {
|
---|
76 | if (this == obj) return true;
|
---|
77 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
78 | if (!super.equals(obj)) return false;
|
---|
79 | ModifiedConflictResolveCommand that = (ModifiedConflictResolveCommand) obj;
|
---|
80 | return Objects.equals(conflict, that.conflict);
|
---|
81 | }
|
---|
82 | }
|
---|