| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.gui.dialogs.relation.actions;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 5 |
|
|---|
| 6 | import java.awt.event.ActionEvent;
|
|---|
| 7 | import java.awt.event.KeyEvent;
|
|---|
| 8 |
|
|---|
| 9 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 10 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 11 |
|
|---|
| 12 | /**
|
|---|
| 13 | * Remove the currently selected members from this relation.
|
|---|
| 14 | * @since 9496
|
|---|
| 15 | */
|
|---|
| 16 | public class RemoveAction extends AbstractRelationEditorAction {
|
|---|
| 17 | private static final long serialVersionUID = 1L;
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * Constructs a new {@code RemoveAction}.
|
|---|
| 21 | * @param editorAccess An interface to access the relation editor contents.
|
|---|
| 22 | * @param actionMapKey action map key
|
|---|
| 23 | */
|
|---|
| 24 | public RemoveAction(IRelationEditorActionAccess editorAccess, String actionMapKey) {
|
|---|
| 25 | super(editorAccess, actionMapKey, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION);
|
|---|
| 26 | new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true);
|
|---|
| 27 | putValue(NAME, tr("Remove"));
|
|---|
| 28 | Shortcut sc = Shortcut.registerShortcut("relationeditor:remove", tr("Relation Editor: Remove"), KeyEvent.VK_DELETE, Shortcut.ALT);
|
|---|
| 29 | sc.setAccelerator(this);
|
|---|
| 30 | sc.setTooltip(this, tr("Remove the currently selected members from this relation"));
|
|---|
| 31 | setEnabled(false);
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | @Override
|
|---|
| 35 | public void actionPerformed(ActionEvent e) {
|
|---|
| 36 | int[] selectedRows = editorAccess.getMemberTable().getSelectedRows();
|
|---|
| 37 | editorAccess.getMemberTableModel().remove(selectedRows);
|
|---|
| 38 | if (selectedRows.length > 0 && editorAccess.getMemberTableModel().getRowCount() > selectedRows[0]) {
|
|---|
| 39 | // make first row of former selection visible, see #17952
|
|---|
| 40 | editorAccess.getMemberTable().makeMemberVisible(selectedRows[0]);
|
|---|
| 41 | }
|
|---|
| 42 | editorAccess.stopMemberCellEditing();
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | @Override
|
|---|
| 46 | protected void updateEnabledState() {
|
|---|
| 47 | setEnabled(editorAccess.getMemberTableModel().canRemove(editorAccess.getMemberTable().getSelectedRows()));
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|