1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command.conflict;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
5 |
|
---|
6 | import java.util.Collection;
|
---|
7 | import java.util.List;
|
---|
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.gui.conflict.pair.MergeDecisionType;
|
---|
16 | import org.openstreetmap.josm.gui.conflict.pair.tags.TagMergeItem;
|
---|
17 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Represents the resolution of a tag conflict in an {@link OsmPrimitive}.
|
---|
21 | *
|
---|
22 | */
|
---|
23 | public class TagConflictResolveCommand extends ConflictResolveCommand {
|
---|
24 | /** the conflict to resolve */
|
---|
25 | private final Conflict<? extends OsmPrimitive> conflict;
|
---|
26 |
|
---|
27 | /** the list of merge decisions, represented as {@link TagMergeItem}s */
|
---|
28 | private final List<TagMergeItem> mergeItems;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * replies the number of decided conflicts
|
---|
32 | *
|
---|
33 | * @return the number of decided conflicts
|
---|
34 | */
|
---|
35 | public int getNumDecidedConflicts() {
|
---|
36 | int n = 0;
|
---|
37 | for (TagMergeItem item: mergeItems) {
|
---|
38 | if (!item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
|
---|
39 | n++;
|
---|
40 | }
|
---|
41 | }
|
---|
42 | return n;
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * constructor
|
---|
47 | *
|
---|
48 | * @param conflict the conflict data set
|
---|
49 | * @param mergeItems the list of merge decisions, represented as {@link TagMergeItem}s
|
---|
50 | */
|
---|
51 | public TagConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, List<TagMergeItem> mergeItems) {
|
---|
52 | this.conflict = conflict;
|
---|
53 | this.mergeItems = mergeItems;
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public String getDescriptionText() {
|
---|
58 | switch (OsmPrimitiveType.from(conflict.getMy())) {
|
---|
59 | case NODE:
|
---|
60 | /* for correct i18n of plural forms - see #9110 */
|
---|
61 | return trn("Resolve {0} tag conflict in node {1}", "Resolve {0} tag conflicts in node {1}",
|
---|
62 | getNumDecidedConflicts(), getNumDecidedConflicts(), conflict.getMy().getId());
|
---|
63 | case WAY:
|
---|
64 | /* for correct i18n of plural forms - see #9110 */
|
---|
65 | return trn("Resolve {0} tag conflict in way {1}", "Resolve {0} tag conflicts in way {1}",
|
---|
66 | getNumDecidedConflicts(), getNumDecidedConflicts(), conflict.getMy().getId());
|
---|
67 | case RELATION:
|
---|
68 | /* for correct i18n of plural forms - see #9110 */
|
---|
69 | return trn("Resolve {0} tag conflict in relation {1}", "Resolve {0} tag conflicts in relation {1}",
|
---|
70 | getNumDecidedConflicts(), getNumDecidedConflicts(), conflict.getMy().getId());
|
---|
71 | default:
|
---|
72 | return "";
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public Icon getDescriptionIcon() {
|
---|
78 | return ImageProvider.get("data", "object");
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Override
|
---|
82 | public boolean executeCommand() {
|
---|
83 | // remember the current state of modified primitives, i.e. of
|
---|
84 | // OSM primitive 'my'
|
---|
85 | //
|
---|
86 | super.executeCommand();
|
---|
87 |
|
---|
88 | // apply the merge decisions to OSM primitive 'my'
|
---|
89 | //
|
---|
90 | for (TagMergeItem item: mergeItems) {
|
---|
91 | if (!item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
|
---|
92 | item.applyToMyPrimitive(conflict.getMy());
|
---|
93 | }
|
---|
94 | }
|
---|
95 | rememberConflict(conflict);
|
---|
96 | return true;
|
---|
97 | }
|
---|
98 |
|
---|
99 | @Override
|
---|
100 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
101 | Collection<OsmPrimitive> added) {
|
---|
102 | modified.add(conflict.getMy());
|
---|
103 | }
|
---|
104 |
|
---|
105 | @Override
|
---|
106 | public int hashCode() {
|
---|
107 | return Objects.hash(super.hashCode(), conflict, mergeItems);
|
---|
108 | }
|
---|
109 |
|
---|
110 | @Override
|
---|
111 | public boolean equals(Object obj) {
|
---|
112 | if (this == obj) return true;
|
---|
113 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
114 | if (!super.equals(obj)) return false;
|
---|
115 | TagConflictResolveCommand that = (TagConflictResolveCommand) obj;
|
---|
116 | return Objects.equals(conflict, that.conflict) &&
|
---|
117 | Objects.equals(mergeItems, that.mergeItems);
|
---|
118 | }
|
---|
119 | }
|
---|