001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.dialogs.relation.actions;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.event.ActionEvent;
007
008import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException;
009import org.openstreetmap.josm.tools.ImageProvider;
010import org.openstreetmap.josm.tools.Logging;
011
012/**
013 * Add all objects selected in the current dataset after the last member.
014 * @since 9496
015 */
016public class AddSelectedAtEndAction extends AddFromSelectionAction {
017    private static final long serialVersionUID = 1L;
018
019    /**
020     * Constructs a new {@code AddSelectedAtEndAction}.
021     * @param editorAccess An interface to access the relation editor contents.
022     */
023    public AddSelectedAtEndAction(IRelationEditorActionAccess editorAccess) {
024        super(editorAccess, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE);
025        putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset after the last member"));
026        new ImageProvider("dialogs/conflict", "copyendright").getResource().attachImageIcon(this, true);
027        updateEnabledState();
028    }
029
030    @Override
031    protected void updateEnabledState() {
032        setEnabled(getSelectionTableModel().getRowCount() > 0);
033    }
034
035    @Override
036    public void actionPerformed(ActionEvent e) {
037        try {
038            getMemberTableModel().addMembersAtEnd(filterConfirmedPrimitives(getSelectionTableModel().getSelection()));
039        } catch (AddAbortException ex) {
040            Logging.trace(ex);
041        }
042    }
043}