1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.beans.PropertyChangeEvent;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.actions.mapmode.DeleteAction;
|
---|
10 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
11 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
12 | import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
|
---|
13 | import org.openstreetmap.josm.gui.dialogs.relation.RelationDialogManager;
|
---|
14 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Delete the currently edited relation.
|
---|
19 | * @since 9496
|
---|
20 | */
|
---|
21 | public class DeleteCurrentRelationAction extends AbstractRelationEditorAction {
|
---|
22 | private static final long serialVersionUID = 1L;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Constructs a new {@code DeleteCurrentRelationAction}.
|
---|
26 | * @param editorAccess An interface to access the relation editor contents.
|
---|
27 | */
|
---|
28 | public DeleteCurrentRelationAction(IRelationEditorActionAccess editorAccess) {
|
---|
29 | super(editorAccess);
|
---|
30 | putValue(SHORT_DESCRIPTION, tr("Delete the currently edited relation"));
|
---|
31 | new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true);
|
---|
32 | putValue(NAME, tr("Delete"));
|
---|
33 | updateEnabledState();
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void actionPerformed(ActionEvent e) {
|
---|
38 | Relation toDelete = getEditor().getRelation();
|
---|
39 | if (toDelete == null)
|
---|
40 | return;
|
---|
41 | if (toDelete.isDeleted()) {
|
---|
42 | // see #23447
|
---|
43 | OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
|
---|
44 | if (layer != null) {
|
---|
45 | RelationDialogManager.getRelationDialogManager().close(layer, toDelete);
|
---|
46 | }
|
---|
47 | return;
|
---|
48 | }
|
---|
49 | DeleteAction.deleteRelation(getLayer(), toDelete);
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | protected void updateEnabledState() {
|
---|
54 | setEnabled(getEditor().getRelationSnapshot() != null);
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
59 | // Do not call super.
|
---|
60 | if (GenericRelationEditor.RELATION_SNAPSHOT_PROP.equals(evt.getPropertyName())) {
|
---|
61 | updateEnabledState();
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|