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 |
|
---|
30 | /** the conflict to resolve */
|
---|
31 | private Conflict<OsmPrimitive> conflict;
|
---|
32 |
|
---|
33 | /** the list of merge decisions, represented as {@see TagMergeItem}s */
|
---|
34 | private final List<TagMergeItem> mergeItems;
|
---|
35 |
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * replies the number of decided conflicts
|
---|
39 | *
|
---|
40 | * @return the number of decided conflicts
|
---|
41 | */
|
---|
42 | public int getNumDecidedConflicts() {
|
---|
43 | int n = 0;
|
---|
44 | for (TagMergeItem item: mergeItems) {
|
---|
45 | if (!item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
|
---|
46 | n++;
|
---|
47 | }
|
---|
48 | }
|
---|
49 | return n;
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * constructor
|
---|
54 | *
|
---|
55 | * @param my my primitive
|
---|
56 | * @param their their primitive
|
---|
57 | * @param mergeItems the list of merge decisions, represented as {@see TagMergeItem}s
|
---|
58 | */
|
---|
59 | public TagConflictResolveCommand(OsmPrimitive my, OsmPrimitive their, List<TagMergeItem> mergeItems) {
|
---|
60 | this.conflict = new Conflict<OsmPrimitive>(my,their);
|
---|
61 | this.mergeItems = mergeItems;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | @Override
|
---|
66 | public MutableTreeNode description() {
|
---|
67 | String msg = "";
|
---|
68 | switch(OsmPrimitiveType.from(conflict.getMy())) {
|
---|
69 | case NODE: msg = marktr("Resolve {0} tag conflicts in node {1}"); break;
|
---|
70 | case WAY: msg = marktr("Resolve {0} tag conflicts in way {1}"); break;
|
---|
71 | case RELATION: msg = marktr("Resolve {0} tag conflicts in relation {1}"); break;
|
---|
72 | }
|
---|
73 | return new DefaultMutableTreeNode(
|
---|
74 | new JLabel(
|
---|
75 | tr(msg,getNumDecidedConflicts(), conflict.getMy().getId()),
|
---|
76 | ImageProvider.get("data", "object"),
|
---|
77 | JLabel.HORIZONTAL
|
---|
78 | )
|
---|
79 | );
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | public boolean executeCommand() {
|
---|
84 | // remember the current state of modified primitives, i.e. of
|
---|
85 | // OSM primitive 'my'
|
---|
86 | //
|
---|
87 | super.executeCommand();
|
---|
88 |
|
---|
89 | // apply the merge decisions to OSM primitive 'my'
|
---|
90 | //
|
---|
91 | for (TagMergeItem item: mergeItems) {
|
---|
92 | if (! item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
|
---|
93 | item.applyToMyPrimitive(conflict.getMy());
|
---|
94 | }
|
---|
95 | }
|
---|
96 | rememberConflict(conflict);
|
---|
97 | return true;
|
---|
98 | }
|
---|
99 |
|
---|
100 | @Override
|
---|
101 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
102 | Collection<OsmPrimitive> added) {
|
---|
103 | modified.add(conflict.getMy());
|
---|
104 | }
|
---|
105 | }
|
---|