[9665] | 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 {
|
---|
[14027] | 20 | private static final long serialVersionUID = 1L;
|
---|
[9665] | 21 |
|
---|
| 22 | /**
|
---|
| 23 | * Constructs a new {@code DeleteCurrentRelationAction}.
|
---|
| 24 | * @param layer OSM data layer
|
---|
| 25 | * @param editor relation editor
|
---|
| 26 | */
|
---|
[14027] | 27 | public DeleteCurrentRelationAction(IRelationEditorActionAccess editorAccess) {
|
---|
| 28 | super(editorAccess);
|
---|
[9665] | 29 | putValue(SHORT_DESCRIPTION, tr("Delete the currently edited relation"));
|
---|
[13130] | 30 | new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true);
|
---|
[9665] | 31 | putValue(NAME, tr("Delete"));
|
---|
| 32 | updateEnabledState();
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | @Override
|
---|
| 36 | public void actionPerformed(ActionEvent e) {
|
---|
[14027] | 37 | Relation toDelete = getEditor().getRelation();
|
---|
[9665] | 38 | if (toDelete == null)
|
---|
| 39 | return;
|
---|
[14027] | 40 | DeleteAction.deleteRelation(getLayer(), toDelete);
|
---|
[9665] | 41 | }
|
---|
| 42 |
|
---|
| 43 | @Override
|
---|
| 44 | protected void updateEnabledState() {
|
---|
[14027] | 45 | setEnabled(getEditor().getRelationSnapshot() != null);
|
---|
[9665] | 46 | }
|
---|
| 47 |
|
---|
| 48 | @Override
|
---|
| 49 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
| 50 | if (GenericRelationEditor.RELATION_SNAPSHOT_PROP.equals(evt.getPropertyName())) {
|
---|
| 51 | updateEnabledState();
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | }
|
---|