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

Last change on this file since 14027 was 14027, checked in by michael2402, 5 weeks ago

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

File size: 2.0 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.tools.ImageProvider;
9
10/**
11 * Selects  members in the relation editor which refer to primitives in the current selection of the context layer.
12 * @since 9496
13 */
14public class SelectedMembersForSelectionAction extends AddFromSelectionAction {
15        private static final long serialVersionUID = 1L;
16
17    /**
18     * Constructs a new {@code SelectedMembersForSelectionAction}.
19     * @param memberTableModel member table model
20     * @param selectionTableModel selection table model
21     * @param layer OSM data layer
22     */
23    public SelectedMembersForSelectionAction(IRelationEditorActionAccess editorAccess) {
24        super(editorAccess, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE);
25        putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to objects in the current selection"));
26        new ImageProvider("dialogs/relation", "selectmembers").getResource().attachImageIcon(this, true);
27        updateEnabledState();
28    }
29
30    @Override
31    protected void updateEnabledState() {
32        boolean enabled = getSelectionTableModel().getRowCount() > 0
33        && !editorAccess.getMemberTableModel().getChildPrimitives(getLayer().data.getSelected()).isEmpty();
34
35        if (enabled) {
36            putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to {0} objects in the current selection",
37                        editorAccess.getMemberTableModel().getChildPrimitives(getLayer().data.getSelected()).size()));
38        } else {
39            putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to objects in the current selection"));
40        }
41        setEnabled(enabled);
42    }
43
44    @Override
45    public void actionPerformed(ActionEvent e) {
46        editorAccess.getMemberTableModel().selectMembersReferringTo(getLayer().data.getSelected());
47    }
48}
Note: See TracBrowser for help on using the repository browser.