| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.command.conflict;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.marktr;
|
|---|
| 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 6 |
|
|---|
| 7 | import java.util.Collection;
|
|---|
| 8 | import java.util.Objects;
|
|---|
| 9 |
|
|---|
| 10 | import javax.swing.Icon;
|
|---|
| 11 |
|
|---|
| 12 | import org.openstreetmap.josm.data.conflict.Conflict;
|
|---|
| 13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 14 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
|---|
| 15 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 16 |
|
|---|
| 17 | /**
|
|---|
| 18 | * Represents the resolution of a version conflict between two {@link OsmPrimitive}s.
|
|---|
| 19 | * @since 1622
|
|---|
| 20 | */
|
|---|
| 21 | public class VersionConflictResolveCommand extends ConflictResolveCommand {
|
|---|
| 22 |
|
|---|
| 23 | /** the conflict to resolve */
|
|---|
| 24 | private final Conflict<? extends OsmPrimitive> conflict;
|
|---|
| 25 |
|
|---|
| 26 | /**
|
|---|
| 27 | * constructor
|
|---|
| 28 | * @param conflict the conflict data set
|
|---|
| 29 | */
|
|---|
| 30 | public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
|
|---|
| 31 | this.conflict = conflict;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | @Override
|
|---|
| 35 | public String getDescriptionText() {
|
|---|
| 36 | String msg;
|
|---|
| 37 | switch(OsmPrimitiveType.from(conflict.getMy())) {
|
|---|
| 38 | case NODE: msg = marktr("Resolve version conflict for node {0}"); break;
|
|---|
| 39 | case WAY: msg = marktr("Resolve version conflict for way {0}"); break;
|
|---|
| 40 | case RELATION: msg = marktr("Resolve version conflict for relation {0}"); break;
|
|---|
| 41 | default: throw new AssertionError();
|
|---|
| 42 | }
|
|---|
| 43 | return tr(msg, 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 | super.executeCommand();
|
|---|
| 54 | if (!conflict.getMy().isNew()) {
|
|---|
| 55 | long myVersion = conflict.getMy().getVersion();
|
|---|
| 56 | long theirVersion = conflict.getTheir().getVersion();
|
|---|
| 57 | conflict.getMy().setOsmId(
|
|---|
| 58 | conflict.getMy().getId(),
|
|---|
| 59 | (int) Math.max(myVersion, theirVersion)
|
|---|
| 60 | );
|
|---|
| 61 | // update visiblity state
|
|---|
| 62 | if (theirVersion >= myVersion) {
|
|---|
| 63 | conflict.getMy().setVisible(conflict.getTheir().isVisible());
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 | getLayer().getConflicts().remove(conflict);
|
|---|
| 67 | rememberConflict(conflict);
|
|---|
| 68 | return true;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | @Override
|
|---|
| 72 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
|---|
| 73 | Collection<OsmPrimitive> added) {
|
|---|
| 74 | modified.add(conflict.getMy());
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | @Override
|
|---|
| 78 | public int hashCode() {
|
|---|
| 79 | return Objects.hash(super.hashCode(), conflict);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | @Override
|
|---|
| 83 | public boolean equals(Object obj) {
|
|---|
| 84 | if (this == obj) return true;
|
|---|
| 85 | if (obj == null || getClass() != obj.getClass()) return false;
|
|---|
| 86 | if (!super.equals(obj)) return false;
|
|---|
| 87 | VersionConflictResolveCommand that = (VersionConflictResolveCommand) obj;
|
|---|
| 88 | return Objects.equals(conflict, that.conflict);
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|