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;
007import java.awt.event.KeyEvent;
008
009import org.openstreetmap.josm.Main;
010import org.openstreetmap.josm.tools.ImageProvider;
011import org.openstreetmap.josm.tools.Shortcut;
012
013/**
014 * Sort the relation members
015 * @since 9496
016 */
017public class SortAction extends AbstractRelationEditorAction {
018    private static final long serialVersionUID = 1L;
019
020    /**
021     * Constructs a new {@code SortAction}.
022     * @param editorAccess An interface to access the relation editor contents.
023     */
024    public SortAction(IRelationEditorActionAccess editorAccess) {
025        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE);
026        new ImageProvider("dialogs", "sort").getResource().attachImageIcon(this, true);
027        putValue(NAME, tr("Sort"));
028        Shortcut sc = Shortcut.registerShortcut("relationeditor:sort", tr("Relation Editor: Sort"), KeyEvent.VK_END, Shortcut.ALT);
029        sc.setAccelerator(this);
030        putValue(SHORT_DESCRIPTION, Main.platform.makeTooltip(tr("Sort the relation members"), sc));
031        updateEnabledState();
032    }
033
034    @Override
035    public void actionPerformed(ActionEvent e) {
036        editorAccess.getMemberTableModel().sort();
037    }
038
039    @Override
040    protected void updateEnabledState() {
041        setEnabled(editorAccess.getMemberTableModel().getRowCount() > 0);
042    }
043}