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.Icon;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
13 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
14 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
15 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
16 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Represent a command for resolving conflicts in the member lists of two
|
---|
20 | * {@link Relation}s.
|
---|
21 | *
|
---|
22 | */
|
---|
23 | public class RelationMemberConflictResolverCommand extends Command {
|
---|
24 | /** my relation */
|
---|
25 | private final Relation my;
|
---|
26 | /** their relation */
|
---|
27 | private final Relation their;
|
---|
28 | /** the list of merged nodes. This becomes the list of news of my way after the
|
---|
29 | * command is executed
|
---|
30 | */
|
---|
31 | private final List<RelationMember> mergedMembers;
|
---|
32 |
|
---|
33 | /** the layer this conflict is resolved in */
|
---|
34 | private OsmDataLayer layer;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | *
|
---|
38 | * @param my my relation
|
---|
39 | * @param their their relation
|
---|
40 | * @param mergedMembers the list of merged relation members
|
---|
41 | */
|
---|
42 | public RelationMemberConflictResolverCommand(Relation my, Relation their, List<RelationMember> mergedMembers) {
|
---|
43 | this.my = my;
|
---|
44 | this.their = their;
|
---|
45 | this.mergedMembers = mergedMembers;
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public String getDescriptionText() {
|
---|
50 | return tr("Resolve conflicts in member list of relation {0}", my.getId());
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public Icon getDescriptionIcon() {
|
---|
55 | return ImageProvider.get("data", "object");
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public boolean executeCommand() {
|
---|
60 | // remember the current state of 'my' way
|
---|
61 | //
|
---|
62 | super.executeCommand();
|
---|
63 |
|
---|
64 | // replace the list of members of 'my' relation by the list of merged
|
---|
65 | // members
|
---|
66 | //
|
---|
67 | my.setMembers(mergedMembers);
|
---|
68 |
|
---|
69 | // remember the layer
|
---|
70 | layer = Main.map.mapView.getEditLayer();
|
---|
71 | return true;
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Override
|
---|
75 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
76 | Collection<OsmPrimitive> added) {
|
---|
77 | modified.add(my);
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Override
|
---|
81 | public void undoCommand() {
|
---|
82 | if (! Main.map.mapView.hasLayer(layer)) {
|
---|
83 | Main.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
|
---|
84 | this.toString(),
|
---|
85 | layer.toString()
|
---|
86 | ));
|
---|
87 | return;
|
---|
88 | }
|
---|
89 |
|
---|
90 | Main.map.mapView.setActiveLayer(layer);
|
---|
91 | OsmDataLayer editLayer = Main.map.mapView.getEditLayer();
|
---|
92 |
|
---|
93 | // restore the former state
|
---|
94 | //
|
---|
95 | super.undoCommand();
|
---|
96 |
|
---|
97 | // restore a conflict if necessary
|
---|
98 | //
|
---|
99 | if (!editLayer.getConflicts().hasConflictForMy(my)) {
|
---|
100 | editLayer.getConflicts().add(my,their);
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|