| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.gui.dialogs.relation.actions;
|
|---|
| 3 |
|
|---|
| 4 | import java.awt.event.ActionEvent;
|
|---|
| 5 | import java.util.Collection;
|
|---|
| 6 |
|
|---|
| 7 | import org.openstreetmap.josm.data.osm.RelationMember;
|
|---|
| 8 | import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
|
|---|
| 9 | import org.openstreetmap.josm.gui.datatransfer.RelationMemberTransferable;
|
|---|
| 10 |
|
|---|
| 11 | /**
|
|---|
| 12 | * Copy members.
|
|---|
| 13 | * @since 9496
|
|---|
| 14 | */
|
|---|
| 15 | public class CopyMembersAction extends AddFromSelectionAction {
|
|---|
| 16 | private static final long serialVersionUID = 1L;
|
|---|
| 17 | private boolean keepCopiedMembers = true;
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * Constructs a new {@code CopyMembersAction}.
|
|---|
| 21 | * @param editorAccess An interface to access the relation editor contents.
|
|---|
| 22 | * @param keepCopiedMembers if true, copied members are kept in the table; otherwise they are removed (cut)
|
|---|
| 23 | */
|
|---|
| 24 | public CopyMembersAction(IRelationEditorActionAccess editorAccess, boolean keepCopiedMembers) {
|
|---|
| 25 | super(editorAccess);
|
|---|
| 26 | this.keepCopiedMembers = keepCopiedMembers;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | @Override
|
|---|
| 30 | public void actionPerformed(ActionEvent e) {
|
|---|
| 31 | final Collection<RelationMember> members = getMemberTableModel().getSelectedMembers();
|
|---|
| 32 |
|
|---|
| 33 | if (!members.isEmpty()) {
|
|---|
| 34 | ClipboardUtils.copy(new RelationMemberTransferable(members));
|
|---|
| 35 | if (!this.keepCopiedMembers) {
|
|---|
| 36 | getMemberTableModel().remove(getMemberTableModel().getSelectedIndices());
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | @Override
|
|---|
| 42 | protected void updateEnabledState() {
|
|---|
| 43 | // Do nothing
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|