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 |
|
---|
8 | import javax.swing.Icon;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
11 | import org.openstreetmap.josm.data.osm.Node;
|
---|
12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
13 | import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
|
---|
14 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Represents a the resolution of a conflict between the coordinates of two {@link Node}s
|
---|
19 | *
|
---|
20 | */
|
---|
21 | public class DeletedStateConflictResolveCommand extends ConflictResolveCommand {
|
---|
22 |
|
---|
23 | /** the conflict to resolve */
|
---|
24 | private Conflict<? extends OsmPrimitive> conflict;
|
---|
25 |
|
---|
26 | /** the merge decision */
|
---|
27 | private final MergeDecisionType decision;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * constructor
|
---|
31 | *
|
---|
32 | * @param conflict the conflict data set
|
---|
33 | * @param decision the merge decision
|
---|
34 | */
|
---|
35 | public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
|
---|
36 | this.conflict = conflict;
|
---|
37 | this.decision = decision;
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public String getDescriptionText() {
|
---|
42 | return tr("Resolve conflicts in deleted state in {0}", conflict.getMy().getId());
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public Icon getDescriptionIcon() {
|
---|
47 | return ImageProvider.get("data", "object");
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public boolean executeCommand() {
|
---|
52 | // remember the current state of modified primitives, i.e. of
|
---|
53 | // OSM primitive 'my'
|
---|
54 | //
|
---|
55 | super.executeCommand();
|
---|
56 |
|
---|
57 | OsmDataLayer layer = getLayer();
|
---|
58 |
|
---|
59 | if (decision.equals(MergeDecisionType.KEEP_MINE)) {
|
---|
60 | if (conflict.getMy().isDeleted() || conflict.isMyDeleted()) {
|
---|
61 | // because my was involved in a conflict it my still be referred
|
---|
62 | // to from a way or a relation. Fix this now.
|
---|
63 | //
|
---|
64 | layer.data.unlinkReferencesToPrimitive(conflict.getMy());
|
---|
65 | conflict.getMy().setDeleted(true);
|
---|
66 | }
|
---|
67 | } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
|
---|
68 | if (conflict.getTheir().isDeleted()) {
|
---|
69 | layer.data.unlinkReferencesToPrimitive(conflict.getMy());
|
---|
70 | conflict.getMy().setDeleted(true);
|
---|
71 | } else {
|
---|
72 | conflict.getMy().setDeleted(false);
|
---|
73 | }
|
---|
74 | } else
|
---|
75 | // should not happen
|
---|
76 | throw new IllegalStateException(tr("Cannot resolve undecided conflict."));
|
---|
77 |
|
---|
78 | rememberConflict(conflict);
|
---|
79 | return true;
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
84 | Collection<OsmPrimitive> added) {
|
---|
85 | modified.add(conflict.getMy());
|
---|
86 | modified.addAll(conflict.getMy().getReferrers());
|
---|
87 | }
|
---|
88 | }
|
---|