1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command;
|
---|
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 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}", getNumDecidedConflicts(), getNumDecidedConflicts(), conflict.getMy().getId());
|
---|
61 | case WAY:
|
---|
62 | /* for correct i18n of plural forms - see #9110 */
|
---|
63 | return trn("Resolve {0} tag conflict in way {1}", "Resolve {0} tag conflicts in way {1}", getNumDecidedConflicts(), getNumDecidedConflicts(), conflict.getMy().getId());
|
---|
64 | case RELATION:
|
---|
65 | /* for correct i18n of plural forms - see #9110 */
|
---|
66 | return trn("Resolve {0} tag conflict in relation {1}", "Resolve {0} tag conflicts in relation {1}", getNumDecidedConflicts(), getNumDecidedConflicts(), conflict.getMy().getId());
|
---|
67 | }
|
---|
68 | return "";
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public Icon getDescriptionIcon() {
|
---|
73 | return ImageProvider.get("data", "object");
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public boolean executeCommand() {
|
---|
78 | // remember the current state of modified primitives, i.e. of
|
---|
79 | // OSM primitive 'my'
|
---|
80 | //
|
---|
81 | super.executeCommand();
|
---|
82 |
|
---|
83 | // apply the merge decisions to OSM primitive 'my'
|
---|
84 | //
|
---|
85 | for (TagMergeItem item: mergeItems) {
|
---|
86 | if (! item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
|
---|
87 | item.applyToMyPrimitive(conflict.getMy());
|
---|
88 | }
|
---|
89 | }
|
---|
90 | rememberConflict(conflict);
|
---|
91 | return true;
|
---|
92 | }
|
---|
93 |
|
---|
94 | @Override
|
---|
95 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
96 | Collection<OsmPrimitive> added) {
|
---|
97 | modified.add(conflict.getMy());
|
---|
98 | }
|
---|
99 | }
|
---|