source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RemoveSelectedAction.java @ 14027

Last change on this file since 14027 was 14027, checked in by michael2402, 3 months ago

See #16388: New mechanism for plugins to register relation editor actions.

File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7
8import org.openstreetmap.josm.data.osm.DataSet;
9import org.openstreetmap.josm.tools.ImageProvider;
10
11/**
12 * Remove all members referring to one of the selected objects.
13 * @since 9496
14 */
15public class RemoveSelectedAction extends AddFromSelectionAction {
16        private static final long serialVersionUID = 1L;
17
18    /**
19     * Constructs a new {@code RemoveSelectedAction}.
20     * @param memberTableModel member table model
21     * @param selectionTableModel selection table model
22     * @param layer OSM data layer
23     */
24    public RemoveSelectedAction(IRelationEditorActionAccess editorAccess) {
25        super(editorAccess, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE);
26        putValue(SHORT_DESCRIPTION, tr("Remove all members referring to one of the selected objects"));
27        new ImageProvider("dialogs/relation", "deletemembers").getResource().attachImageIcon(this, true);
28        updateEnabledState();
29    }
30
31    @Override
32    protected void updateEnabledState() {
33        DataSet ds = getLayer().data;
34        if (ds == null || ds.selectionEmpty()) {
35            setEnabled(false);
36            return;
37        }
38        // only enable the action if we have members referring to the selected primitives
39        setEnabled(editorAccess.getMemberTableModel().hasMembersReferringTo(ds.getSelected()));
40    }
41
42    @Override
43    public void actionPerformed(ActionEvent e) {
44        editorAccess.getMemberTableModel().removeMembersReferringTo(getSelectionTableModel().getSelection());
45    }
46}
Note: See TracBrowser for help on using the repository browser.