001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.dialogs.relation.actions;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.event.ActionEvent;
007
008import org.openstreetmap.josm.tools.ImageProvider;
009
010/**
011 * Selects primitives in the layer this editor belongs to. The selected primitives are
012 * equal to the set of primitives the currently selected relation members refer to.
013 * @since 9496
014 */
015public class SelectPrimitivesForSelectedMembersAction extends AbstractRelationEditorAction {
016    private static final long serialVersionUID = 1L;
017
018    /**
019     * Select objects for selected relation members.
020     * @param editorAccess An interface to access the relation editor contents.
021     */
022    public SelectPrimitivesForSelectedMembersAction(IRelationEditorActionAccess editorAccess) {
023        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION);
024        putValue(SHORT_DESCRIPTION, tr("Select objects for selected relation members"));
025        new ImageProvider("dialogs/relation", "selectprimitives").getResource().attachImageIcon(this, true);
026        updateEnabledState();
027    }
028
029    @Override
030    protected void updateEnabledState() {
031        setEnabled(editorAccess.getMemberTable().getSelectedRowCount() > 0);
032    }
033
034    @Override
035    public void actionPerformed(ActionEvent e) {
036        getLayer().data.setSelected(editorAccess.getMemberTableModel().getSelectedChildPrimitives());
037    }
038}