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

Last change on this file since 6886 was 6881, checked in by Don-vip, 10 years ago

javadoc/code style/minor refactorization

  • Property svn:eol-style set to native
File size: 2.5 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 org.openstreetmap.josm.Main;
7import org.openstreetmap.josm.data.conflict.Conflict;
8import org.openstreetmap.josm.data.conflict.ConflictCollection;
9import org.openstreetmap.josm.gui.layer.OsmDataLayer;
10
11/**
12 * This is the common base class for {@link Command}s which manipulate {@link Conflict}s in
13 * addition to {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s.
14 *
15 * A ConflictResolverCommand can remember a collection of conflicts it resolves. Upon undoing
16 * it reconstitutes them.
17 *
18 */
19public abstract class ConflictResolveCommand extends Command {
20 /** the list of resolved conflicts */
21 private ConflictCollection resolvedConflicts;
22
23 /**
24 * Constructs a new {@code ConflictResolveCommand} in the context of the current edit layer, if any.
25 */
26 public ConflictResolveCommand() {
27 super();
28 resolvedConflicts = new ConflictCollection();
29 }
30
31 /**
32 * Constructs a new {@code ConflictResolveCommand} in the context of a given data layer.
33 * @param layer the data layer. Must not be null.
34 */
35 public ConflictResolveCommand(OsmDataLayer layer) {
36 super(layer);
37 resolvedConflicts = new ConflictCollection();
38 }
39
40 /**
41 * remembers a conflict in the internal list of remembered conflicts
42 *
43 * @param c the remembered conflict
44 */
45 protected void rememberConflict(Conflict<?> c) {
46 if (! resolvedConflicts.hasConflictForMy(c.getMy())) {
47 resolvedConflicts.add(c);
48 }
49 }
50
51 /**
52 * reconstitutes all remembered conflicts. Add the remembered conflicts to the
53 * set of conflicts of the {@link OsmDataLayer} this command was applied to.
54 *
55 */
56 protected void reconstituteConflicts() {
57 OsmDataLayer editLayer = getLayer();
58 for(Conflict<?> c : resolvedConflicts) {
59 if (!editLayer.getConflicts().hasConflictForMy(c.getMy())) {
60 editLayer.getConflicts().add(c);
61 }
62 }
63 }
64
65 @Override
66 public void undoCommand() {
67 super.undoCommand();
68
69 if (! Main.map.mapView.hasLayer(getLayer())) {
70 Main.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
71 this.toString(),
72 getLayer().toString()
73 ));
74 return;
75 }
76
77 Main.map.mapView.setActiveLayer(getLayer());
78 reconstituteConflicts();
79 }
80}
Note: See TracBrowser for help on using the repository browser.