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 | import java.util.logging.Logger;
|
---|
10 |
|
---|
11 | import javax.swing.JLabel;
|
---|
12 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
13 | import javax.swing.tree.MutableTreeNode;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
17 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
18 | import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
|
---|
19 | import org.openstreetmap.josm.gui.conflict.pair.tags.TagMergeItem;
|
---|
20 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Represents a the resolution of a tag conflict in an {@see OsmPrimitive}
|
---|
24 | *
|
---|
25 | */
|
---|
26 | public class TagConflictResolveCommand extends ConflictResolveCommand {
|
---|
27 | private static final Logger logger = Logger.getLogger(TagConflictResolveCommand.class.getName());
|
---|
28 |
|
---|
29 | /** the conflict to resolve */
|
---|
30 | private Conflict<OsmPrimitive> conflict;
|
---|
31 |
|
---|
32 | /** the list of merge decisions, represented as {@see TagMergeItem}s */
|
---|
33 | private final List<TagMergeItem> mergeItems;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * replies the number of decided conflicts
|
---|
37 | *
|
---|
38 | * @return the number of decided conflicts
|
---|
39 | */
|
---|
40 | public int getNumDecidedConflicts() {
|
---|
41 | int n = 0;
|
---|
42 | for (TagMergeItem item: mergeItems) {
|
---|
43 | if (!item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
|
---|
44 | n++;
|
---|
45 | }
|
---|
46 | }
|
---|
47 | return n;
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * constructor
|
---|
52 | *
|
---|
53 | * @param my my primitive
|
---|
54 | * @param their their primitive
|
---|
55 | * @param mergeItems the list of merge decisions, represented as {@see TagMergeItem}s
|
---|
56 | */
|
---|
57 | public TagConflictResolveCommand(OsmPrimitive my, OsmPrimitive their, List<TagMergeItem> mergeItems) {
|
---|
58 | this.conflict = new Conflict<OsmPrimitive>(my,their);
|
---|
59 | this.mergeItems = mergeItems;
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public MutableTreeNode description() {
|
---|
64 | String msg = "";
|
---|
65 | switch(OsmPrimitiveType.from(conflict.getMy())) {
|
---|
66 | case NODE: msg = marktr("Resolve {0} tag conflicts in node {1}"); break;
|
---|
67 | case WAY: msg = marktr("Resolve {0} tag conflicts in way {1}"); break;
|
---|
68 | case RELATION: msg = marktr("Resolve {0} tag conflicts in relation {1}"); break;
|
---|
69 | }
|
---|
70 | return new DefaultMutableTreeNode(
|
---|
71 | new JLabel(
|
---|
72 | tr(msg,getNumDecidedConflicts(), conflict.getMy().getId()),
|
---|
73 | ImageProvider.get("data", "object"),
|
---|
74 | JLabel.HORIZONTAL
|
---|
75 | )
|
---|
76 | );
|
---|
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 | }
|
---|