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

Last change on this file since 10953 was 10364, checked in by stoecker, 8 years ago

gsoc-core - patch by Michael Zangl - see #12953 - remove deprecation usage

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