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