source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DeleteCurrentRelationAction.java @ 14027

Last change on this file since 14027 was 14027, checked in by michael2402, 5 weeks ago

See #16388: New mechanism for plugins to register relation editor actions.

File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.beans.PropertyChangeEvent;
8import java.beans.PropertyChangeListener;
9
10import org.openstreetmap.josm.actions.mapmode.DeleteAction;
11import org.openstreetmap.josm.data.osm.Relation;
12import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
13import org.openstreetmap.josm.tools.ImageProvider;
14
15/**
16 * Delete the currently edited relation.
17 * @since 9496
18 */
19public 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}
Note: See TracBrowser for help on using the repository browser.