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