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.tools.ImageProvider;
009
010/**
011 * Reverse the order of the relation members.
012 * @since 9496
013 */
014public class ReverseAction extends AbstractRelationEditorAction {
015    private static final long serialVersionUID = 1L;
016
017    /**
018     * Constructs a new {@code ReverseAction}.
019     * @param editorAccess An interface to access the relation editor contents.
020     */
021    public ReverseAction(IRelationEditorActionAccess editorAccess) {
022        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE);
023
024        putValue(SHORT_DESCRIPTION, tr("Reverse the order of the relation members"));
025        new ImageProvider("dialogs/", "reverse").getResource().attachImageIcon(this, true);
026        putValue(NAME, tr("Reverse"));
027        updateEnabledState();
028    }
029
030    @Override
031    public void actionPerformed(ActionEvent e) {
032        editorAccess.getMemberTableModel().reverse();
033    }
034
035    @Override
036    protected void updateEnabledState() {
037        setEnabled(editorAccess.getMemberTableModel().getRowCount() > 0);
038    }
039}