[2624] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[6887] | 2 | package org.openstreetmap.josm.command.conflict;
|
---|
[2624] | 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;
|
---|
[5926] | 9 |
|
---|
[4918] | 10 | import javax.swing.Icon;
|
---|
[2624] | 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 conflict between the modified flag of two {@link OsmPrimitive}s.
|
---|
[2624] | 19 | *
|
---|
| 20 | *
|
---|
| 21 | */
|
---|
| 22 | public class ModifiedConflictResolveCommand extends ConflictResolveCommand {
|
---|
| 23 |
|
---|
| 24 | /** the conflict to resolve */
|
---|
[8910] | 25 | private final Conflict<? extends OsmPrimitive> conflict;
|
---|
[2624] | 26 |
|
---|
| 27 | /**
|
---|
| 28 | * constructor
|
---|
[5816] | 29 | * @param conflict the conflict data set
|
---|
[2624] | 30 | */
|
---|
[3034] | 31 | public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
|
---|
| 32 | this.conflict = conflict;
|
---|
[2624] | 33 | }
|
---|
| 34 |
|
---|
[4918] | 35 | @Override
|
---|
| 36 | public String getDescriptionText() {
|
---|
[2624] | 37 | String msg = "";
|
---|
| 38 | switch(OsmPrimitiveType.from(conflict.getMy())) {
|
---|
[2844] | 39 | case NODE: msg = marktr("Set the ''modified'' flag for node {0}"); break;
|
---|
| 40 | case WAY: msg = marktr("Set the ''modified'' flag for way {0}"); break;
|
---|
| 41 | case RELATION: msg = marktr("Set the ''modified'' flag for relation {0}"); break;
|
---|
[2624] | 42 | }
|
---|
[8510] | 43 | return tr(msg, conflict.getMy().getId());
|
---|
[2624] | 44 | }
|
---|
| 45 |
|
---|
| 46 | @Override
|
---|
[4918] | 47 | public Icon getDescriptionIcon() {
|
---|
| 48 | return ImageProvider.get("data", "object");
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | @Override
|
---|
[2624] | 52 | public boolean executeCommand() {
|
---|
| 53 | super.executeCommand();
|
---|
| 54 | if (!conflict.getMy().isNew() && conflict.getMy().hasEqualSemanticAttributes(conflict.getTheir())) {
|
---|
| 55 | conflict.getMy().setModified(conflict.getTheir().isModified());
|
---|
| 56 | }
|
---|
| 57 | getLayer().getConflicts().remove(conflict);
|
---|
| 58 | rememberConflict(conflict);
|
---|
| 59 | return true;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | @Override
|
---|
| 63 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
| 64 | Collection<OsmPrimitive> added) {
|
---|
| 65 | modified.add(conflict.getMy());
|
---|
| 66 | }
|
---|
[8456] | 67 |
|
---|
| 68 | @Override
|
---|
| 69 | public int hashCode() {
|
---|
[9371] | 70 | return Objects.hash(super.hashCode(), conflict);
|
---|
[8456] | 71 | }
|
---|
| 72 |
|
---|
| 73 | @Override
|
---|
| 74 | public boolean equals(Object obj) {
|
---|
[9371] | 75 | if (this == obj) return true;
|
---|
| 76 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
| 77 | if (!super.equals(obj)) return false;
|
---|
| 78 | ModifiedConflictResolveCommand that = (ModifiedConflictResolveCommand) obj;
|
---|
| 79 | return Objects.equals(conflict, that.conflict);
|
---|
[8456] | 80 | }
|
---|
[2624] | 81 | }
|
---|