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 | import java.beans.PropertyChangeListener;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.actions.mapmode.DeleteAction;
|
---|
11 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
12 | import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
|
---|
13 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Delete the currently edited relation.
|
---|
17 | * @since 9496
|
---|
18 | */
|
---|
19 | public class DeleteCurrentRelationAction extends AbstractRelationEditorAction implements PropertyChangeListener {
|
---|
20 | private static final long serialVersionUID = 1L;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Constructs a new {@code DeleteCurrentRelationAction}.
|
---|
24 | * @param layer OSM data layer
|
---|
25 | * @param editor relation editor
|
---|
26 | */
|
---|
27 | public DeleteCurrentRelationAction(IRelationEditorActionAccess editorAccess) {
|
---|
28 | super(editorAccess);
|
---|
29 | putValue(SHORT_DESCRIPTION, tr("Delete the currently edited relation"));
|
---|
30 | new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true);
|
---|
31 | putValue(NAME, tr("Delete"));
|
---|
32 | updateEnabledState();
|
---|
33 | }
|
---|
34 |
|
---|
35 | @Override
|
---|
36 | public void actionPerformed(ActionEvent e) {
|
---|
37 | Relation toDelete = getEditor().getRelation();
|
---|
38 | if (toDelete == null)
|
---|
39 | return;
|
---|
40 | DeleteAction.deleteRelation(getLayer(), toDelete);
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | protected void updateEnabledState() {
|
---|
45 | setEnabled(getEditor().getRelationSnapshot() != null);
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
50 | if (GenericRelationEditor.RELATION_SNAPSHOT_PROP.equals(evt.getPropertyName())) {
|
---|
51 | updateEnabledState();
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|