| 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 {@see 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 my my node |
|---|
| 33 | * @param their their node |
|---|
| 34 | * @param decision the merge decision |
|---|
| 35 | */ |
|---|
| 36 | public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) { |
|---|
| 37 | this.conflict = conflict; |
|---|
| 38 | this.decision = decision; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | @Override |
|---|
| 42 | public String getDescriptionText() { |
|---|
| 43 | return tr("Resolve conflicts in deleted state in {0}", conflict.getMy().getId()); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | @Override |
|---|
| 47 | public Icon getDescriptionIcon() { |
|---|
| 48 | return ImageProvider.get("data", "object"); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | @Override |
|---|
| 52 | public boolean executeCommand() { |
|---|
| 53 | // remember the current state of modified primitives, i.e. of |
|---|
| 54 | // OSM primitive 'my' |
|---|
| 55 | // |
|---|
| 56 | super.executeCommand(); |
|---|
| 57 | |
|---|
| 58 | OsmDataLayer layer = getLayer(); |
|---|
| 59 | |
|---|
| 60 | if (decision.equals(MergeDecisionType.KEEP_MINE)) { |
|---|
| 61 | if (conflict.getMy().isDeleted() || conflict.isMyDeleted()) { |
|---|
| 62 | // because my was involved in a conflict it my still be referred |
|---|
| 63 | // to from a way or a relation. Fix this now. |
|---|
| 64 | // |
|---|
| 65 | layer.data.unlinkReferencesToPrimitive(conflict.getMy()); |
|---|
| 66 | conflict.getMy().setDeleted(true); |
|---|
| 67 | } |
|---|
| 68 | } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) { |
|---|
| 69 | if (conflict.getTheir().isDeleted()) { |
|---|
| 70 | layer.data.unlinkReferencesToPrimitive(conflict.getMy()); |
|---|
| 71 | conflict.getMy().setDeleted(true); |
|---|
| 72 | } else { |
|---|
| 73 | conflict.getMy().setDeleted(false); |
|---|
| 74 | } |
|---|
| 75 | } else |
|---|
| 76 | // should not happen |
|---|
| 77 | throw new IllegalStateException(tr("Cannot resolve undecided conflict.")); |
|---|
| 78 | |
|---|
| 79 | rememberConflict(conflict); |
|---|
| 80 | return true; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | @Override |
|---|
| 84 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, |
|---|
| 85 | Collection<OsmPrimitive> added) { |
|---|
| 86 | modified.add(conflict.getMy()); |
|---|
| 87 | modified.addAll(conflict.getMy().getReferrers()); |
|---|
| 88 | } |
|---|
| 89 | } |
|---|