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 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
11 | import javax.swing.tree.MutableTreeNode;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
15 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
17 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
18 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
19 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
20 |
|
---|
21 | public 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 any more. Can't remove conflict for primitive ''{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 | }
|
---|