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

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

see #15310 - remove most of deprecated APIs

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