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