source: josm/trunk/src/org/openstreetmap/josm/command/TagConflictResolveCommand.java@ 2284

Last change on this file since 2284 was 2070, checked in by Gubaer, 15 years ago

new: rewrite of CombineWay action
new: conflict resolution dialog for CombineWay, including conflicts for different relation memberships
cleanup: cleanup in OsmReader, reduces memory footprint and reduces parsing time
cleanup: made most of the public fields in OsmPrimitive @deprecated, added accessors and changed the code
cleanup: replaced usages of @deprecated constructors for ExtendedDialog
fixed #3208: Combine ways brokes relation order

WARNING: this changeset touches a lot of code all over the code base. "latest" might become slightly unstable in the next days. Also experience incompatibility issues with plugins in the next few days.

File size: 3.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.util.Collection;
8import java.util.List;
9import java.util.logging.Logger;
10
11import javax.swing.JLabel;
12import javax.swing.tree.DefaultMutableTreeNode;
13import javax.swing.tree.MutableTreeNode;
14
15import org.openstreetmap.josm.data.conflict.Conflict;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
18import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
19import org.openstreetmap.josm.gui.conflict.pair.tags.TagMergeItem;
20import org.openstreetmap.josm.tools.ImageProvider;
21
22/**
23 * Represents a the resolution of a tag conflict in an {@see OsmPrimitive}
24 *
25 */
26public 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}
Note: See TracBrowser for help on using the repository browser.