source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/PasteMembersAction.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: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation.actions;
3
4import java.awt.datatransfer.FlavorEvent;
5import java.awt.datatransfer.FlavorListener;
6import java.awt.event.ActionEvent;
7import java.util.Optional;
8
9import javax.swing.TransferHandler.TransferSupport;
10
11import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
12import org.openstreetmap.josm.gui.dialogs.relation.MemberTransferHandler;
13import org.openstreetmap.josm.tools.Logging;
14
15/**
16 * Paste members.
17 * @since 9496
18 */
19public class PasteMembersAction extends AddFromSelectionAction implements FlavorListener {
20        private static final long serialVersionUID = 1L;
21
22    /**
23     * Constructs a new {@code PasteMembersAction}.
24     * @param memberTable member table
25     * @param layer OSM data layer
26     * @param editor relation editor
27     */
28    public PasteMembersAction(IRelationEditorActionAccess editorAccess) {
29        super(editorAccess);
30        updateEnabledState();
31    }
32
33    @Override
34    public void actionPerformed(ActionEvent e) {
35        try {
36            new MemberTransferHandler().importData(getSupport());
37        } catch (IllegalStateException ex) {
38            Logging.error(ex);
39        }
40    }
41
42    private TransferSupport getSupport() {
43        return new TransferSupport(editorAccess.getMemberTable(), Optional.ofNullable(ClipboardUtils.getClipboardContent())
44                .orElseThrow(() -> new IllegalStateException("Failed to retrieve clipboard content")));
45    }
46
47    @Override
48    protected void updateEnabledState() {
49        try {
50            setEnabled(new MemberTransferHandler().canImport(getSupport()));
51        } catch (IllegalStateException ex) {
52            Logging.error(ex);
53        }
54    }
55
56    @Override
57    public void flavorsChanged(FlavorEvent e) {
58        updateEnabledState();
59    }
60}
Note: See TracBrowser for help on using the repository browser.