[2512] | 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 |
|
---|
[4918] | 8 | import javax.swing.Icon;
|
---|
[2512] | 9 |
|
---|
| 10 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
[4918] | 11 | import org.openstreetmap.josm.data.osm.Node;
|
---|
[2512] | 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 | /**
|
---|
[5266] | 18 | * Represents a the resolution of a conflict between the coordinates of two {@link Node}s
|
---|
[2512] | 19 | *
|
---|
| 20 | */
|
---|
| 21 | public class DeletedStateConflictResolveCommand extends ConflictResolveCommand {
|
---|
| 22 |
|
---|
| 23 | /** the conflict to resolve */
|
---|
[3034] | 24 | private Conflict<? extends OsmPrimitive> conflict;
|
---|
[2512] | 25 |
|
---|
| 26 | /** the merge decision */
|
---|
| 27 | private final MergeDecisionType decision;
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * constructor
|
---|
| 31 | *
|
---|
[5816] | 32 | * @param conflict the conflict data set
|
---|
[2512] | 33 | * @param decision the merge decision
|
---|
| 34 | */
|
---|
[3034] | 35 | public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
|
---|
| 36 | this.conflict = conflict;
|
---|
[2512] | 37 | this.decision = decision;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[4918] | 40 | @Override
|
---|
| 41 | public String getDescriptionText() {
|
---|
| 42 | return tr("Resolve conflicts in deleted state in {0}", conflict.getMy().getId());
|
---|
[2512] | 43 | }
|
---|
| 44 |
|
---|
| 45 | @Override
|
---|
[4918] | 46 | public Icon getDescriptionIcon() {
|
---|
| 47 | return ImageProvider.get("data", "object");
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | @Override
|
---|
[2512] | 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)) {
|
---|
[3034] | 60 | if (conflict.getMy().isDeleted() || conflict.isMyDeleted()) {
|
---|
[2512] | 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());
|
---|
[3034] | 65 | conflict.getMy().setDeleted(true);
|
---|
[2512] | 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 {
|
---|
[2945] | 72 | conflict.getMy().setDeleted(false);
|
---|
[2512] | 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());
|
---|
[3034] | 86 | modified.addAll(conflict.getMy().getReferrers());
|
---|
[2512] | 87 | }
|
---|
| 88 | }
|
---|