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

Last change on this file since 1690 was 1670, checked in by Gubaer, 15 years ago

fixed: bug in OsmApi.getOsmApi()
cleanup: exception handling in interfacing with OSM API
new: new action for updating individual elements with the their current state on the server (including new menu item in the file menu)
new: improved user feedback in case of conflicts
new: handles 410 Gone conflicts when uploading a changeset
new: undoable command for "purging" a primitive from the current dataset (necessary if the primitive is already deleted on the server and the user wants to remove it from its local dataset)
new: undoable command for "undeleting" an already deleted primitive on the server (kind of "cloning")
new: after a full upload, checks whether there are primitives in the local dataset which might be deleted on the server.
new: data structures for history data
new: history download support in io package

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.tr;
5
6import java.util.Collection;
7import java.util.List;
8
9import javax.swing.JLabel;
10import javax.swing.tree.DefaultMutableTreeNode;
11import javax.swing.tree.MutableTreeNode;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.data.osm.Node;
15import org.openstreetmap.josm.data.osm.OsmPrimitive;
16import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
17import org.openstreetmap.josm.data.osm.Relation;
18import org.openstreetmap.josm.data.osm.Way;
19import org.openstreetmap.josm.gui.conflict.MergeDecisionType;
20import org.openstreetmap.josm.gui.conflict.tags.TagMergeItem;
21import org.openstreetmap.josm.tools.ImageProvider;
22
23/**
24 * Represents a the resolution of a tag conflict in an {@see OsmPrimitive}
25 *
26 */
27public 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}
Note: See TracBrowser for help on using the repository browser.