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.spi.preferences.Config;
009import org.openstreetmap.josm.tools.ImageProvider;
010
011/**
012 * Apply the updates and close the dialog.
013 */
014public class OKAction extends SavingAction {
015    private static final long serialVersionUID = 1L;
016
017    /**
018     * Constructs a new {@code OKAction}.
019     * @param editorAccess An interface to access the relation editor contents.
020     */
021    public OKAction(IRelationEditorActionAccess editorAccess) {
022        super(editorAccess);
023        putValue(SHORT_DESCRIPTION, tr("Apply the updates and close the dialog"));
024        new ImageProvider("ok").getResource().attachImageIcon(this);
025        putValue(NAME, tr("OK"));
026        setEnabled(true);
027    }
028
029    @Override
030    public void actionPerformed(ActionEvent e) {
031        Config.getPref().put("relation.editor.generic.lastrole", tfRole.getText());
032        editorAccess.getMemberTable().stopHighlighting();
033        if (!applyChanges())
034            return;
035        hideEditor();
036    }
037}