001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.dialogs.relation.actions;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.event.ActionEvent;
007import java.beans.PropertyChangeEvent;
008
009import org.openstreetmap.josm.actions.mapmode.DeleteAction;
010import org.openstreetmap.josm.data.osm.Relation;
011import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
012import org.openstreetmap.josm.tools.ImageProvider;
013
014/**
015 * Delete the currently edited relation.
016 * @since 9496
017 */
018public class DeleteCurrentRelationAction extends AbstractRelationEditorAction {
019    private static final long serialVersionUID = 1L;
020
021    /**
022     * Constructs a new {@code DeleteCurrentRelationAction}.
023     * @param editorAccess An interface to access the relation editor contents.
024     */
025    public DeleteCurrentRelationAction(IRelationEditorActionAccess editorAccess) {
026        super(editorAccess);
027        putValue(SHORT_DESCRIPTION, tr("Delete the currently edited relation"));
028        new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true);
029        putValue(NAME, tr("Delete"));
030        updateEnabledState();
031    }
032
033    @Override
034    public void actionPerformed(ActionEvent e) {
035        Relation toDelete = getEditor().getRelation();
036        if (toDelete == null)
037            return;
038        DeleteAction.deleteRelation(getLayer(), toDelete);
039    }
040
041    @Override
042    protected void updateEnabledState() {
043        setEnabled(getEditor().getRelationSnapshot() != null);
044    }
045
046    @Override
047    public void propertyChange(PropertyChangeEvent evt) {
048        // Do not call super.
049        if (GenericRelationEditor.RELATION_SNAPSHOT_PROP.equals(evt.getPropertyName())) {
050            updateEnabledState();
051        }
052    }
053}