source: josm/trunk/src/org/openstreetmap/josm/command/ConflictResolveCommand.java@ 2932

Last change on this file since 2932 was 2844, checked in by mjulius, 14 years ago

fix messages for commands

File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.logging.Logger;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.data.conflict.Conflict;
10import org.openstreetmap.josm.data.conflict.ConflictCollection;
11import org.openstreetmap.josm.gui.layer.OsmDataLayer;
12
13/**
14 * This is the common base 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 them.
19 *
20 */
21public 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 public ConflictResolveCommand(OsmDataLayer layer) {
33 super(layer);
34 resolvedConflicts = new ConflictCollection();
35 }
36
37 /**
38 * remembers a conflict in the internal list of remembered conflicts
39 *
40 * @param c the remembered conflict
41 */
42 protected void rememberConflict(Conflict<?> c) {
43 if (! resolvedConflicts.hasConflictForMy(c.getMy())) {
44 resolvedConflicts.add(c);
45 }
46 }
47
48 /**
49 * reconstitutes all remembered conflicts. Add the remembered conflicts to the
50 * set of conflicts of the {@see OsmDataLayer} this command was applied to.
51 *
52 */
53 protected void reconstituteConflicts() {
54 OsmDataLayer editLayer = getLayer();
55 for(Conflict<?> c : resolvedConflicts) {
56 if (!editLayer.getConflicts().hasConflictForMy(c.getMy())) {
57 editLayer.getConflicts().add(c);
58 }
59 }
60 }
61
62 @Override
63 public void undoCommand() {
64 super.undoCommand();
65
66 if (! Main.map.mapView.hasLayer(getLayer())) {
67 logger.warning(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
68 this.toString(),
69 getLayer().toString()
70 ));
71 return;
72 }
73
74 Main.map.mapView.setActiveLayer(getLayer());
75 reconstituteConflicts();
76 }
77}
Note: See TracBrowser for help on using the repository browser.