[9665] | 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 |
|
---|
| 8 | import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException;
|
---|
| 9 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
[12620] | 10 | import org.openstreetmap.josm.tools.Logging;
|
---|
[9665] | 11 |
|
---|
| 12 | /**
|
---|
| 13 | * Add all objects selected in the current dataset before the first selected member.
|
---|
| 14 | * @since 9496
|
---|
| 15 | */
|
---|
| 16 | public class AddSelectedBeforeSelection extends AddFromSelectionAction {
|
---|
[14027] | 17 | private static final long serialVersionUID = 1L;
|
---|
[9665] | 18 |
|
---|
| 19 | /**
|
---|
| 20 | * Constructs a new {@code AddSelectedBeforeSelection}.
|
---|
| 21 | * @param memberTableModel member table model
|
---|
| 22 | * @param selectionTableModel selection table model
|
---|
| 23 | * @param editor relation editor
|
---|
| 24 | */
|
---|
[14027] | 25 | public AddSelectedBeforeSelection(IRelationEditorActionAccess editorAccess) {
|
---|
| 26 | super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE);
|
---|
[9665] | 27 | putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset before the first selected member"));
|
---|
[13130] | 28 | new ImageProvider("dialogs/conflict", "copybeforecurrentright").getResource().attachImageIcon(this, true);
|
---|
[9665] | 29 | updateEnabledState();
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | @Override
|
---|
| 33 | protected void updateEnabledState() {
|
---|
[14027] | 34 | setEnabled(getSelectionTableModel().getRowCount() > 0
|
---|
| 35 | && editorAccess.getMemberTableModel().getSelectionModel().getMinSelectionIndex() >= 0);
|
---|
[9665] | 36 | }
|
---|
| 37 |
|
---|
| 38 | @Override
|
---|
| 39 | public void actionPerformed(ActionEvent e) {
|
---|
| 40 | try {
|
---|
[14027] | 41 | editorAccess.getMemberTableModel().addMembersBeforeIdx(filterConfirmedPrimitives(getSelectionTableModel().getSelection()),
|
---|
| 42 | editorAccess.getMemberTableModel().getSelectionModel().getMinSelectionIndex());
|
---|
[9665] | 43 | } catch (AddAbortException ex) {
|
---|
[12620] | 44 | Logging.trace(ex);
|
---|
[9665] | 45 | }
|
---|
| 46 | }
|
---|
| 47 | }
|
---|