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