source: josm/trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java@ 9917

Last change on this file since 9917 was 9371, checked in by simon04, 8 years ago

Java 7: use Objects.equals and Objects.hash

  • Property svn:eol-style set to native
File size: 3.3 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.Collection;
7import java.util.Objects;
8
9import javax.swing.Icon;
10import javax.swing.JOptionPane;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.command.Command;
14import org.openstreetmap.josm.data.conflict.Conflict;
15import org.openstreetmap.josm.data.osm.OsmPrimitive;
16import org.openstreetmap.josm.gui.DefaultNameFormatter;
17import org.openstreetmap.josm.gui.layer.OsmDataLayer;
18import org.openstreetmap.josm.tools.ImageProvider;
19
20/**
21 * Command used to add a new conflict.
22 * @since 1857
23 */
24public class ConflictAddCommand extends Command {
25 private final Conflict<? extends OsmPrimitive> conflict;
26
27 /**
28 * Constructs a new {@code ConflictAddCommand}.
29 * @param layer the data layer. Must not be null.
30 * @param conflict the conflict to add
31 */
32 public ConflictAddCommand(OsmDataLayer layer, Conflict<? extends OsmPrimitive> conflict) {
33 super(layer);
34 this.conflict = conflict;
35 }
36
37 protected void warnBecauseOfDoubleConflict() {
38 JOptionPane.showMessageDialog(
39 Main.parent,
40 tr("<html>Layer ''{0}'' already has a conflict for object<br>"
41 + "''{1}''.<br>"
42 + "This conflict cannot be added.</html>",
43 getLayer().getName(),
44 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
45 ),
46 tr("Double conflict"),
47 JOptionPane.ERROR_MESSAGE
48 );
49 }
50
51 @Override
52 public boolean executeCommand() {
53 try {
54 getLayer().getConflicts().add(conflict);
55 } catch (IllegalStateException e) {
56 Main.error(e);
57 warnBecauseOfDoubleConflict();
58 }
59 return true;
60 }
61
62 @Override
63 public void undoCommand() {
64 if (Main.isDisplayingMapView() && !Main.map.mapView.hasLayer(getLayer())) {
65 Main.warn(tr("Layer ''{0}'' does not exist any more. Cannot remove conflict for object ''{1}''.",
66 getLayer().getName(),
67 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
68 ));
69 return;
70 }
71 getLayer().getConflicts().remove(conflict);
72 }
73
74 @Override
75 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
76 // nothing to fill
77 }
78
79 @Override
80 public String getDescriptionText() {
81 return tr("Add conflict for ''{0}''",
82 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance()));
83 }
84
85 @Override
86 public Icon getDescriptionIcon() {
87 return ImageProvider.get(conflict.getMy().getDisplayType());
88 }
89
90 @Override
91 public int hashCode() {
92 return Objects.hash(super.hashCode(), conflict);
93 }
94
95 @Override
96 public boolean equals(Object obj) {
97 if (this == obj) return true;
98 if (obj == null || getClass() != obj.getClass()) return false;
99 if (!super.equals(obj)) return false;
100 ConflictAddCommand that = (ConflictAddCommand) obj;
101 return Objects.equals(conflict, that.conflict);
102 }
103}
Note: See TracBrowser for help on using the repository browser.