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