1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.Collection;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import javax.swing.JLabel;
|
---|
10 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
11 | import javax.swing.tree.MutableTreeNode;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.data.osm.Node;
|
---|
15 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
17 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
18 | import org.openstreetmap.josm.data.osm.Way;
|
---|
19 | import org.openstreetmap.josm.gui.conflict.MergeDecisionType;
|
---|
20 | import org.openstreetmap.josm.gui.conflict.tags.TagMergeItem;
|
---|
21 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Represents a the resolution of a tag conflict in an {@see OsmPrimitive}
|
---|
25 | *
|
---|
26 | */
|
---|
27 | public class TagConflictResolveCommand extends Command {
|
---|
28 |
|
---|
29 | /** my primitive (in the local dataset). merge decisions are applied to this
|
---|
30 | * primitive
|
---|
31 | */
|
---|
32 | private final OsmPrimitive my;
|
---|
33 | /** their primitive (in the server dataset) */
|
---|
34 | private final OsmPrimitive their;
|
---|
35 |
|
---|
36 | /** the list of merge decisions, represented as {@see TagMergeItem}s */
|
---|
37 | private final List<TagMergeItem> mergeItems;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * replies the number of decided conflicts
|
---|
41 | *
|
---|
42 | * @return the number of decided conflicts
|
---|
43 | */
|
---|
44 | public int getNumDecidedConflicts() {
|
---|
45 | int n = 0;
|
---|
46 | for (TagMergeItem item: mergeItems) {
|
---|
47 | if (!item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
|
---|
48 | n++;
|
---|
49 | }
|
---|
50 | }
|
---|
51 | return n;
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * constructor
|
---|
56 | *
|
---|
57 | * @param my my primitive
|
---|
58 | * @param their their primitive
|
---|
59 | * @param mergeItems the list of merge decisions, represented as {@see TagMergeItem}s
|
---|
60 | */
|
---|
61 | public TagConflictResolveCommand(OsmPrimitive my, OsmPrimitive their, List<TagMergeItem> mergeItems) {
|
---|
62 | this.my = my;
|
---|
63 | this.their = their;
|
---|
64 | this.mergeItems = mergeItems;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | public MutableTreeNode description() {
|
---|
70 | return new DefaultMutableTreeNode(
|
---|
71 | new JLabel(
|
---|
72 | tr("Resolve {0} tag conflicts in {1} {2}",getNumDecidedConflicts(), OsmPrimitiveType.from(my).getLocalizedDisplayNameSingular(), my.id),
|
---|
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(my);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | return true;
|
---|
94 | }
|
---|
95 |
|
---|
96 | @Override
|
---|
97 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
98 | Collection<OsmPrimitive> added) {
|
---|
99 | modified.add(my);
|
---|
100 | }
|
---|
101 |
|
---|
102 | @Override
|
---|
103 | public void undoCommand() {
|
---|
104 | // restore former state of modified primitives
|
---|
105 | //
|
---|
106 | super.undoCommand();
|
---|
107 |
|
---|
108 | // restore a conflict if necessary
|
---|
109 | //
|
---|
110 | if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
|
---|
111 | Main.map.conflictDialog.addConflict(my, their);
|
---|
112 | }
|
---|
113 | }
|
---|
114 | }
|
---|