1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.Collection;
|
---|
7 |
|
---|
8 | import javax.swing.JLabel;
|
---|
9 | import javax.swing.JOptionPane;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
14 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
15 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
16 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
17 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
18 |
|
---|
19 | public 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 primitive<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 primitive ''{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 | }
|
---|