source: josm/trunk/src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java @ 13434

Last change on this file since 13434 was 13434, checked in by Don-vip, 5 months ago

see #8039, see #10456 - support read-only data layers

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