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;
009import java.util.Collection;
010
011import org.openstreetmap.josm.data.osm.OsmPrimitive;
012import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
013import org.openstreetmap.josm.tools.Shortcut;
014
015/**
016 * Action, to paste all tags from one primitive to another.
017 *
018 * It will take the primitive from the copy-paste buffer an apply all its tags
019 * to the selected primitive(s).
020 *
021 * @author David Earl
022 */
023public final class PasteTagsAction extends JosmAction {
024
025    private static final String HELP = ht("/Action/PasteTags");
026    private final OsmTransferHandler transferHandler = new OsmTransferHandler();
027
028    /**
029     * Constructs a new {@code PasteTagsAction}.
030     */
031    public PasteTagsAction() {
032        super(tr("Paste Tags"), "pastetags",
033                tr("Apply tags of contents of paste buffer to all selected items."),
034                Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")),
035                KeyEvent.VK_V, Shortcut.CTRL_SHIFT), true);
036        putValue("help", HELP);
037    }
038
039    @Override
040    public void actionPerformed(ActionEvent e) {
041        Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected();
042
043        if (selection.isEmpty())
044            return;
045
046        transferHandler.pasteTags(selection);
047    }
048
049    @Override
050    protected void updateEnabledState() {
051        updateEnabledStateOnCurrentSelection();
052    }
053
054    @Override
055    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
056        updateEnabledStateOnModifiableSelection(selection);
057    }
058}