[2512] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.command;
|
---|
| 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.List;
|
---|
| 9 | import java.util.logging.Logger;
|
---|
| 10 |
|
---|
| 11 | import javax.swing.JLabel;
|
---|
| 12 |
|
---|
| 13 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
| 14 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
| 15 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
| 16 | import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
|
---|
| 17 | import org.openstreetmap.josm.gui.conflict.pair.tags.TagMergeItem;
|
---|
| 18 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
| 19 |
|
---|
| 20 | /**
|
---|
| 21 | * Represents a the resolution of a tag conflict in an {@see OsmPrimitive}
|
---|
| 22 | *
|
---|
| 23 | */
|
---|
| 24 | public class TagConflictResolveCommand extends ConflictResolveCommand {
|
---|
[2990] | 25 | @SuppressWarnings("unused")
|
---|
[2512] | 26 | private static final Logger logger = Logger.getLogger(TagConflictResolveCommand.class.getName());
|
---|
| 27 |
|
---|
| 28 | /** the conflict to resolve */
|
---|
[3034] | 29 | private Conflict<? extends OsmPrimitive> conflict;
|
---|
[2512] | 30 |
|
---|
| 31 | /** the list of merge decisions, represented as {@see TagMergeItem}s */
|
---|
| 32 | private final List<TagMergeItem> mergeItems;
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * replies the number of decided conflicts
|
---|
| 36 | *
|
---|
| 37 | * @return the number of decided conflicts
|
---|
| 38 | */
|
---|
| 39 | public int getNumDecidedConflicts() {
|
---|
| 40 | int n = 0;
|
---|
| 41 | for (TagMergeItem item: mergeItems) {
|
---|
| 42 | if (!item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
|
---|
| 43 | n++;
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | return n;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | /**
|
---|
| 50 | * constructor
|
---|
| 51 | *
|
---|
| 52 | * @param my my primitive
|
---|
| 53 | * @param their their primitive
|
---|
| 54 | * @param mergeItems the list of merge decisions, represented as {@see TagMergeItem}s
|
---|
| 55 | */
|
---|
[3034] | 56 | public TagConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, List<TagMergeItem> mergeItems) {
|
---|
| 57 | this.conflict = conflict;
|
---|
[2512] | 58 | this.mergeItems = mergeItems;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[3262] | 61 | @Override public JLabel getDescription() {
|
---|
[2512] | 62 | String msg = "";
|
---|
| 63 | switch(OsmPrimitiveType.from(conflict.getMy())) {
|
---|
[2990] | 64 | case NODE: msg = marktr("Resolve {0} tag conflicts in node {1}"); break;
|
---|
| 65 | case WAY: msg = marktr("Resolve {0} tag conflicts in way {1}"); break;
|
---|
| 66 | case RELATION: msg = marktr("Resolve {0} tag conflicts in relation {1}"); break;
|
---|
[2512] | 67 | }
|
---|
[3262] | 68 | return new JLabel(
|
---|
[2512] | 69 | tr(msg,getNumDecidedConflicts(), conflict.getMy().getId()),
|
---|
| 70 | ImageProvider.get("data", "object"),
|
---|
| 71 | JLabel.HORIZONTAL
|
---|
| 72 | );
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | @Override
|
---|
| 76 | public boolean executeCommand() {
|
---|
| 77 | // remember the current state of modified primitives, i.e. of
|
---|
| 78 | // OSM primitive 'my'
|
---|
| 79 | //
|
---|
| 80 | super.executeCommand();
|
---|
| 81 |
|
---|
| 82 | // apply the merge decisions to OSM primitive 'my'
|
---|
| 83 | //
|
---|
| 84 | for (TagMergeItem item: mergeItems) {
|
---|
| 85 | if (! item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
|
---|
| 86 | item.applyToMyPrimitive(conflict.getMy());
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | rememberConflict(conflict);
|
---|
| 90 | return true;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | @Override
|
---|
| 94 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
| 95 | Collection<OsmPrimitive> added) {
|
---|
| 96 | modified.add(conflict.getMy());
|
---|
| 97 | }
|
---|
| 98 | }
|
---|