[7937] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.actions.relation;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.awt.event.ActionEvent;
|
---|
[9472] | 7 | import java.util.Collection;
|
---|
[7937] | 8 |
|
---|
[9472] | 9 | import org.openstreetmap.josm.actions.mapmode.DeleteAction;
|
---|
[13434] | 10 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
[7937] | 11 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
[12630] | 12 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
| 13 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
[10453] | 14 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
[7937] | 15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
| 18 | * Action that delete relations
|
---|
| 19 | * @since 5799
|
---|
| 20 | */
|
---|
| 21 | public class DeleteRelationsAction extends AbstractRelationAction {
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | * Constructs a new <code>DeleteRelationsAction</code>.
|
---|
| 25 | */
|
---|
| 26 | public DeleteRelationsAction() {
|
---|
[8510] | 27 | putValue(SHORT_DESCRIPTION, tr("Delete the selected relation"));
|
---|
[7937] | 28 | putValue(NAME, tr("Delete"));
|
---|
[10428] | 29 | new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true);
|
---|
[7937] | 30 | }
|
---|
| 31 |
|
---|
[9472] | 32 | protected void deleteRelation(Collection<Relation> toDelete) {
|
---|
[12636] | 33 | OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
|
---|
[10453] | 34 | if (toDelete == null || layer == null)
|
---|
[7937] | 35 | return;
|
---|
[10453] | 36 |
|
---|
| 37 | DeleteAction.deleteRelations(layer, toDelete);
|
---|
[7937] | 38 | // clear selection after deletion
|
---|
[12630] | 39 | MapFrame map = MainApplication.getMap();
|
---|
| 40 | if (map.relationListDialog != null)
|
---|
| 41 | map.relationListDialog.selectRelations(null);
|
---|
[7937] | 42 | }
|
---|
| 43 |
|
---|
| 44 | @Override
|
---|
| 45 | public void actionPerformed(ActionEvent e) {
|
---|
[10453] | 46 | if (!isEnabled())
|
---|
[7937] | 47 | return;
|
---|
[9472] | 48 | deleteRelation(relations);
|
---|
[7937] | 49 | }
|
---|
[13434] | 50 |
|
---|
| 51 | @Override
|
---|
| 52 | protected void updateEnabledState() {
|
---|
| 53 | setEnabled(!relations.isEmpty() && relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isReadOnly));
|
---|
| 54 | }
|
---|
[7937] | 55 | }
|
---|