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 |
|
---|
7 | import java.util.Collection;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import javax.swing.JLabel;
|
---|
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 a the resolution of a tag conflict in an {@see OsmPrimitive}
|
---|
21 | *
|
---|
22 | */
|
---|
23 | public class TagConflictResolveCommand extends ConflictResolveCommand {
|
---|
24 | /** the conflict to resolve */
|
---|
25 | private Conflict<? extends OsmPrimitive> conflict;
|
---|
26 |
|
---|
27 | /** the list of merge decisions, represented as {@see 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 my my primitive
|
---|
49 | * @param their their primitive
|
---|
50 | * @param mergeItems the list of merge decisions, represented as {@see 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 public JLabel getDescription() {
|
---|
58 | String msg = "";
|
---|
59 | switch(OsmPrimitiveType.from(conflict.getMy())) {
|
---|
60 | case NODE: msg = marktr("Resolve {0} tag conflicts in node {1}"); break;
|
---|
61 | case WAY: msg = marktr("Resolve {0} tag conflicts in way {1}"); break;
|
---|
62 | case RELATION: msg = marktr("Resolve {0} tag conflicts in relation {1}"); break;
|
---|
63 | }
|
---|
64 | return new JLabel(
|
---|
65 | tr(msg,getNumDecidedConflicts(), conflict.getMy().getId()),
|
---|
66 | ImageProvider.get("data", "object"),
|
---|
67 | JLabel.HORIZONTAL
|
---|
68 | );
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public boolean executeCommand() {
|
---|
73 | // remember the current state of modified primitives, i.e. of
|
---|
74 | // OSM primitive 'my'
|
---|
75 | //
|
---|
76 | super.executeCommand();
|
---|
77 |
|
---|
78 | // apply the merge decisions to OSM primitive 'my'
|
---|
79 | //
|
---|
80 | for (TagMergeItem item: mergeItems) {
|
---|
81 | if (! item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
|
---|
82 | item.applyToMyPrimitive(conflict.getMy());
|
---|
83 | }
|
---|
84 | }
|
---|
85 | rememberConflict(conflict);
|
---|
86 | return true;
|
---|
87 | }
|
---|
88 |
|
---|
89 | @Override
|
---|
90 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
91 | Collection<OsmPrimitive> added) {
|
---|
92 | modified.add(conflict.getMy());
|
---|
93 | }
|
---|
94 | }
|
---|