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 | }
|
---|
72 | return "";
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public Icon getDescriptionIcon() {
|
---|
77 | return ImageProvider.get("data", "object");
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Override
|
---|
81 | public boolean executeCommand() {
|
---|
82 | // remember the current state of modified primitives, i.e. of
|
---|
83 | // OSM primitive 'my'
|
---|
84 | //
|
---|
85 | super.executeCommand();
|
---|
86 |
|
---|
87 | // apply the merge decisions to OSM primitive 'my'
|
---|
88 | //
|
---|
89 | for (TagMergeItem item: mergeItems) {
|
---|
90 | if (!item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
|
---|
91 | item.applyToMyPrimitive(conflict.getMy());
|
---|
92 | }
|
---|
93 | }
|
---|
94 | rememberConflict(conflict);
|
---|
95 | return true;
|
---|
96 | }
|
---|
97 |
|
---|
98 | @Override
|
---|
99 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
100 | Collection<OsmPrimitive> added) {
|
---|
101 | modified.add(conflict.getMy());
|
---|
102 | }
|
---|
103 |
|
---|
104 | @Override
|
---|
105 | public int hashCode() {
|
---|
106 | return Objects.hash(super.hashCode(), conflict, mergeItems);
|
---|
107 | }
|
---|
108 |
|
---|
109 | @Override
|
---|
110 | public boolean equals(Object obj) {
|
---|
111 | if (this == obj) return true;
|
---|
112 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
113 | if (!super.equals(obj)) return false;
|
---|
114 | TagConflictResolveCommand that = (TagConflictResolveCommand) obj;
|
---|
115 | return Objects.equals(conflict, that.conflict) &&
|
---|
116 | Objects.equals(mergeItems, that.mergeItems);
|
---|
117 | }
|
---|
118 | }
|
---|