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