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

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

remove extra whitespaces

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