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 * Apply the current updates.
012 * @since 9496
013 */
014public class ApplyAction extends SavingAction {
015    private static final long serialVersionUID = 1L;
016
017    /**
018     * Constructs a new {@code ApplyAction}.
019     * @param editorAccess An interface to access the relation editor contents.
020     */
021    public ApplyAction(IRelationEditorActionAccess editorAccess) {
022        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE, IRelationEditorUpdateOn.TAG_CHANGE);
023        putValue(SHORT_DESCRIPTION, tr("Apply the current updates"));
024        new ImageProvider("save").getResource().attachImageIcon(this, true);
025        putValue(NAME, tr("Apply"));
026        updateEnabledState();
027    }
028
029    @Override
030    public void actionPerformed(ActionEvent e) {
031        if (applyChanges()) {
032            editorAccess.getEditor().reloadDataFromRelation();
033        }
034    }
035
036    @Override
037    protected void updateEnabledState() {
038        setEnabled(isEditorDirty());
039    }
040}