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