001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.actions;
003
004import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
005import static org.openstreetmap.josm.tools.I18n.tr;
006
007import java.awt.event.ActionEvent;
008import java.awt.event.KeyEvent;
009
010import org.openstreetmap.josm.data.osm.IPrimitive;
011import org.openstreetmap.josm.data.osm.OsmData;
012import org.openstreetmap.josm.tools.Shortcut;
013
014/**
015 * User action to select all primitives in the current dataset.
016 */
017public class SelectAllAction extends JosmAction {
018
019    /**
020     * Constructs a new {@code SelectAllAction}.
021     */
022    public SelectAllAction() {
023        super(tr("Select All"), "selectall", tr("Select all undeleted objects in the data layer. This selects incomplete objects too."),
024                Shortcut.registerShortcut("system:selectall", tr("Selection: {0}", tr("Select All")), KeyEvent.VK_A, Shortcut.CTRL), true);
025        setHelpId(ht("/Action/SelectAll"));
026    }
027
028    @Override
029    public void actionPerformed(ActionEvent e) {
030        if (!isEnabled())
031            return;
032        OsmData<?, ?, ?, ?> ds = getLayerManager().getActiveData();
033        ds.setSelected(ds.getPrimitives(IPrimitive::isSelectable));
034    }
035
036    @Override
037    protected boolean listenToSelectionChange() {
038        return false;
039    }
040
041    /**
042     * Refreshes the enabled state
043     */
044    @Override
045    protected void updateEnabledState() {
046        setEnabled(getLayerManager().getActiveData() != null);
047    }
048}