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

Last change on this file since 2026 was 2017, checked in by Gubaer, 15 years ago

removed OptionPaneUtil
cleanup of deprecated Layer API
cleanup of deprecated APIs in OsmPrimitive and Way
cleanup of imports

File size: 2.9 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;
10import javax.swing.tree.DefaultMutableTreeNode;
11import javax.swing.tree.MutableTreeNode;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.data.conflict.Conflict;
15import org.openstreetmap.josm.data.osm.OsmPrimitive;
16import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
17import org.openstreetmap.josm.gui.DefaultNameFormatter;
18import org.openstreetmap.josm.gui.layer.OsmDataLayer;
19import org.openstreetmap.josm.tools.ImageProvider;
20
21public class ConflictAddCommand extends Command {
22 private Conflict<? extends OsmPrimitive> conflict;
23
24 public ConflictAddCommand(OsmDataLayer layer, Conflict<? extends OsmPrimitive> conflict) {
25 super(layer);
26 this.conflict = conflict;
27 }
28
29 protected void warnBecauseOfDoubleConflict() {
30 JOptionPane.showMessageDialog(
31 Main.parent,
32 tr("<html>Layer ''{0}'' already has a conflict for primitive<br>"
33 + "''{1}''.<br>"
34 + "This conflict can't be added.</html>",
35 getLayer().getName(),
36 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
37 ),
38 tr("Double conflict"),
39 JOptionPane.ERROR_MESSAGE
40 );
41 }
42 @Override public boolean executeCommand() {
43 try {
44 getLayer().getConflicts().add(conflict);
45 } catch(IllegalStateException e) {
46 e.printStackTrace();
47 warnBecauseOfDoubleConflict();
48 }
49 return true;
50 }
51
52 @Override public void undoCommand() {
53 if (! Main.map.mapView.hasLayer(getLayer())) {
54 System.out.println(tr("Warning: layer ''{0}'' doesn't exist anymore. Can't remove conflict for primitmive ''{1}''",
55 getLayer().getName(),
56 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
57 ));
58 return;
59 }
60 getLayer().getConflicts().remove(conflict);
61 }
62
63 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
64 // nothing to fill
65 }
66
67 @Override public MutableTreeNode description() {
68 return new DefaultMutableTreeNode(
69 new JLabel(
70 tr("Add conflict for ''{0}''",
71 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
72 ),
73 ImageProvider.get(OsmPrimitiveType.from(conflict.getMy())),
74 JLabel.HORIZONTAL
75 )
76 );
77 }
78}
Note: See TracBrowser for help on using the repository browser.