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

Last change on this file since 4908 was 3995, checked in by mjulius, 13 years ago

fix #3590 - Primitives or objects: Pick one

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collection;
7
8import javax.swing.JLabel;
9import javax.swing.JOptionPane;
10
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.conflict.Conflict;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
15import org.openstreetmap.josm.gui.DefaultNameFormatter;
16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
17import org.openstreetmap.josm.tools.ImageProvider;
18
19public class ConflictAddCommand extends Command {
20 private Conflict<? extends OsmPrimitive> conflict;
21
22 public ConflictAddCommand(OsmDataLayer layer, Conflict<? extends OsmPrimitive> conflict) {
23 super(layer);
24 this.conflict = conflict;
25 }
26
27 protected void warnBecauseOfDoubleConflict() {
28 JOptionPane.showMessageDialog(
29 Main.parent,
30 tr("<html>Layer ''{0}'' already has a conflict for object<br>"
31 + "''{1}''.<br>"
32 + "This conflict cannot be added.</html>",
33 getLayer().getName(),
34 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
35 ),
36 tr("Double conflict"),
37 JOptionPane.ERROR_MESSAGE
38 );
39 }
40 @Override public boolean executeCommand() {
41 try {
42 getLayer().getConflicts().add(conflict);
43 } catch(IllegalStateException e) {
44 e.printStackTrace();
45 warnBecauseOfDoubleConflict();
46 }
47 return true;
48 }
49
50 @Override public void undoCommand() {
51 if (! Main.map.mapView.hasLayer(getLayer())) {
52 System.out.println(tr("Warning: Layer ''{0}'' does not exist any more. Cannot remove conflict for object ''{1}''.",
53 getLayer().getName(),
54 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
55 ));
56 return;
57 }
58 getLayer().getConflicts().remove(conflict);
59 }
60
61 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
62 // nothing to fill
63 }
64
65 @Override public JLabel getDescription() {
66 return new JLabel(
67 tr("Add conflict for ''{0}''",
68 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
69 ),
70 ImageProvider.get(OsmPrimitiveType.from(conflict.getMy())),
71 JLabel.HORIZONTAL
72 );
73 }
74}
Note: See TracBrowser for help on using the repository browser.