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 java.util.logging.Logger;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
10 | import org.openstreetmap.josm.data.conflict.ConflictCollection;
|
---|
11 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * This is the common basse class for {@see Command}s which manipulate {@see Conflict}s in
|
---|
15 | * addition to {@see OsmPrimitive}s.
|
---|
16 | *
|
---|
17 | * A ConflictResolverCommand can remember a collection of conflicts it resolves. Upon undoing
|
---|
18 | * it reconstitutes these conflicts.
|
---|
19 | *
|
---|
20 | */
|
---|
21 | public abstract class ConflictResolveCommand extends Command {
|
---|
22 | private static final Logger logger = Logger.getLogger(ConflictResolveCommand.class.getName());
|
---|
23 |
|
---|
24 | /** the list of resolved conflicts */
|
---|
25 | private ConflictCollection resolvedConflicts;
|
---|
26 |
|
---|
27 | public ConflictResolveCommand() {
|
---|
28 | super();
|
---|
29 | resolvedConflicts = new ConflictCollection();
|
---|
30 | }
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * remembers a conflict in the internal list of remembered conflicts
|
---|
34 | *
|
---|
35 | * @param c the remembered conflict
|
---|
36 | */
|
---|
37 | protected void rememberConflict(Conflict c) {
|
---|
38 | if (! resolvedConflicts.hasConflictForMy(c.getMy())) {
|
---|
39 | resolvedConflicts.add(c);
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * reconstitutes all remembered conflicts. Add the remembered conflicts to the
|
---|
45 | * set of conflicts of the {@see OsmDataLayer} this command was applied to.
|
---|
46 | *
|
---|
47 | */
|
---|
48 | protected void reconstituteConflicts() {
|
---|
49 | OsmDataLayer editLayer = getLayer();
|
---|
50 | for(Conflict c : resolvedConflicts) {
|
---|
51 | if (!editLayer.getConflicts().hasConflictForMy(c.getMy())) {
|
---|
52 | editLayer.getConflicts().add(c);
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public void undoCommand() {
|
---|
59 | super.undoCommand();
|
---|
60 |
|
---|
61 | if (! Main.map.mapView.hasLayer(getLayer())) {
|
---|
62 | logger.warning(tr("Can't undo command ''{0}'' because layer ''{1}'' is not present anymore",
|
---|
63 | this.toString(),
|
---|
64 | getLayer().toString()
|
---|
65 | ));
|
---|
66 | return;
|
---|
67 | }
|
---|
68 |
|
---|
69 | Main.map.mapView.setActiveLayer(getLayer());
|
---|
70 | reconstituteConflicts();
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 | }
|
---|