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 | /**
|
---|
12 | * This is the common base class for {@see Command}s which manipulate {@see Conflict}s in
|
---|
13 | * addition to {@see OsmPrimitive}s.
|
---|
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
|
---|
46 | * set of conflicts of the {@see OsmDataLayer} this command was applied to.
|
---|
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())) {
|
---|
63 | System.out.println(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
|
---|
64 | this.toString(),
|
---|
65 | getLayer().toString()
|
---|
66 | ));
|
---|
67 | return;
|
---|
68 | }
|
---|
69 |
|
---|
70 | Main.map.mapView.setActiveLayer(getLayer());
|
---|
71 | reconstituteConflicts();
|
---|
72 | }
|
---|
73 | }
|
---|