[2512] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.command;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import org.openstreetmap.josm.Main;
|
---|
| 7 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
| 8 | import org.openstreetmap.josm.data.conflict.ConflictCollection;
|
---|
| 9 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
[5266] | 12 | * This is the common base class for {@link Command}s which manipulate {@link Conflict}s in
|
---|
[5816] | 13 | * addition to {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s.
|
---|
[2512] | 14 | *
|
---|
| 15 | * A ConflictResolverCommand can remember a collection of conflicts it resolves. Upon undoing
|
---|
| 16 | * it reconstitutes them.
|
---|
| 17 | *
|
---|
| 18 | */
|
---|
| 19 | public abstract class ConflictResolveCommand extends Command {
|
---|
| 20 | /** the list of resolved conflicts */
|
---|
| 21 | private ConflictCollection resolvedConflicts;
|
---|
| 22 |
|
---|
| 23 | public ConflictResolveCommand() {
|
---|
| 24 | super();
|
---|
| 25 | resolvedConflicts = new ConflictCollection();
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | public ConflictResolveCommand(OsmDataLayer layer) {
|
---|
| 29 | super(layer);
|
---|
| 30 | resolvedConflicts = new ConflictCollection();
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * remembers a conflict in the internal list of remembered conflicts
|
---|
| 35 | *
|
---|
| 36 | * @param c the remembered conflict
|
---|
| 37 | */
|
---|
| 38 | protected void rememberConflict(Conflict<?> c) {
|
---|
| 39 | if (! resolvedConflicts.hasConflictForMy(c.getMy())) {
|
---|
| 40 | resolvedConflicts.add(c);
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * reconstitutes all remembered conflicts. Add the remembered conflicts to the
|
---|
[5266] | 46 | * set of conflicts of the {@link OsmDataLayer} this command was applied to.
|
---|
[2512] | 47 | *
|
---|
| 48 | */
|
---|
| 49 | protected void reconstituteConflicts() {
|
---|
| 50 | OsmDataLayer editLayer = getLayer();
|
---|
| 51 | for(Conflict<?> c : resolvedConflicts) {
|
---|
| 52 | if (!editLayer.getConflicts().hasConflictForMy(c.getMy())) {
|
---|
| 53 | editLayer.getConflicts().add(c);
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | @Override
|
---|
| 59 | public void undoCommand() {
|
---|
| 60 | super.undoCommand();
|
---|
| 61 |
|
---|
| 62 | if (! Main.map.mapView.hasLayer(getLayer())) {
|
---|
[4191] | 63 | System.out.println(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
|
---|
[2512] | 64 | this.toString(),
|
---|
| 65 | getLayer().toString()
|
---|
| 66 | ));
|
---|
| 67 | return;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | Main.map.mapView.setActiveLayer(getLayer());
|
---|
| 71 | reconstituteConflicts();
|
---|
| 72 | }
|
---|
| 73 | }
|
---|