source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedBeforeSelection.java @ 14027

Last change on this file since 14027 was 14027, checked in by michael2402, 3 months ago

See #16388: New mechanism for plugins to register relation editor actions.

File size: 1.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7
8import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException;
9import org.openstreetmap.josm.tools.ImageProvider;
10import org.openstreetmap.josm.tools.Logging;
11
12/**
13 * Add all objects selected in the current dataset before the first selected member.
14 * @since 9496
15 */
16public class AddSelectedBeforeSelection extends AddFromSelectionAction {
17        private static final long serialVersionUID = 1L;
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     */
25    public AddSelectedBeforeSelection(IRelationEditorActionAccess editorAccess) {
26        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE);
27        putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset before the first selected member"));
28        new ImageProvider("dialogs/conflict", "copybeforecurrentright").getResource().attachImageIcon(this, true);
29        updateEnabledState();
30    }
31
32    @Override
33    protected void updateEnabledState() {
34                setEnabled(getSelectionTableModel().getRowCount() > 0
35                                && editorAccess.getMemberTableModel().getSelectionModel().getMinSelectionIndex() >= 0);
36    }
37
38    @Override
39    public void actionPerformed(ActionEvent e) {
40        try {
41                editorAccess.getMemberTableModel().addMembersBeforeIdx(filterConfirmedPrimitives(getSelectionTableModel().getSelection()),
42                                editorAccess.getMemberTableModel().getSelectionModel().getMinSelectionIndex());
43        } catch (AddAbortException ex) {
44            Logging.trace(ex);
45        }
46    }
47}
Note: See TracBrowser for help on using the repository browser.