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

Last change on this file since 12620 was 12620, checked in by Don-vip, 7 years ago

see #15182 - deprecate all Main logging methods and introduce suitable replacements in Logging for most of them

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command.conflict;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Objects;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.command.Command;
10import org.openstreetmap.josm.data.conflict.Conflict;
11import org.openstreetmap.josm.data.conflict.ConflictCollection;
12import org.openstreetmap.josm.gui.layer.OsmDataLayer;
13import org.openstreetmap.josm.tools.Logging;
14
15/**
16 * This is the common base class for {@link Command}s which manipulate {@link Conflict}s in
17 * addition to {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s.
18 *
19 * A ConflictResolverCommand can remember a collection of conflicts it resolves. Upon undoing
20 * it reconstitutes them.
21 *
22 */
23public abstract class ConflictResolveCommand extends Command {
24 /** the list of resolved conflicts */
25 private final ConflictCollection resolvedConflicts;
26
27 /**
28 * Constructs a new {@code ConflictResolveCommand} in the context of the current edit layer, if any.
29 */
30 public ConflictResolveCommand() {
31 super();
32 resolvedConflicts = new ConflictCollection();
33 }
34
35 /**
36 * Constructs a new {@code ConflictResolveCommand} in the context of a given data layer.
37 * @param layer the data layer. Must not be null.
38 */
39 public ConflictResolveCommand(OsmDataLayer layer) {
40 super(layer);
41 resolvedConflicts = new ConflictCollection();
42 }
43
44 /**
45 * remembers a conflict in the internal list of remembered conflicts
46 *
47 * @param c the remembered conflict
48 */
49 protected void rememberConflict(Conflict<?> c) {
50 if (!resolvedConflicts.hasConflictForMy(c.getMy())) {
51 resolvedConflicts.add(c);
52 }
53 }
54
55 /**
56 * reconstitutes all remembered conflicts. Add the remembered conflicts to the
57 * set of conflicts of the {@link OsmDataLayer} this command was applied to.
58 *
59 */
60 protected void reconstituteConflicts() {
61 OsmDataLayer editLayer = getLayer();
62 for (Conflict<?> c : resolvedConflicts) {
63 if (!editLayer.getConflicts().hasConflictForMy(c.getMy())) {
64 editLayer.getConflicts().add(c);
65 }
66 }
67 }
68
69 @Override
70 public void undoCommand() {
71 super.undoCommand();
72
73 if (Main.isDisplayingMapView()) {
74 if (!Main.getLayerManager().containsLayer(getLayer())) {
75 Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
76 this.toString(),
77 getLayer().toString()
78 ));
79 return;
80 }
81
82 Main.getLayerManager().setActiveLayer(getLayer());
83 }
84 reconstituteConflicts();
85 }
86
87 @Override
88 public int hashCode() {
89 return Objects.hash(super.hashCode(), resolvedConflicts);
90 }
91
92 @Override
93 public boolean equals(Object obj) {
94 if (this == obj) return true;
95 if (obj == null || getClass() != obj.getClass()) return false;
96 if (!super.equals(obj)) return false;
97 ConflictResolveCommand that = (ConflictResolveCommand) obj;
98 return Objects.equals(resolvedConflicts, that.resolvedConflicts);
99 }
100}
Note: See TracBrowser for help on using the repository browser.