001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.dialogs.changeset;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.Component;
007import java.awt.event.ActionEvent;
008
009import javax.swing.AbstractAction;
010
011import org.openstreetmap.josm.actions.downloadtasks.ChangesetContentDownloadTask;
012import org.openstreetmap.josm.tools.CheckParameterUtil;
013
014/**
015 * Downloads/Updates the content of the changeset.
016 * @since 9493
017 */
018public class DownloadChangesetContentAction extends AbstractAction {
019    private final transient ChangesetAware component;
020
021    /**
022     * Constructs a new {@code DownloadChangesetContentAction}.
023     * @param component changeset-aware component
024     */
025    public DownloadChangesetContentAction(ChangesetAware component) {
026        CheckParameterUtil.ensureParameterNotNull(component, "component");
027        putValue(NAME, tr("Download content"));
028        putValue(SMALL_ICON, ChangesetCacheManager.DOWNLOAD_CONTENT_ICON);
029        putValue(SHORT_DESCRIPTION, tr("Download the changeset content from the OSM server"));
030        this.component = component;
031    }
032
033    @Override
034    public void actionPerformed(ActionEvent evt) {
035        if (component.getCurrentChangeset() != null) {
036            ChangesetCacheManager.getInstance().runDownloadTask(new ChangesetContentDownloadTask(
037                    (Component) component, component.getCurrentChangeset().getId()));
038        }
039    }
040
041    /**
042     * Init properties.
043     */
044    public void initProperties() {
045        if (component.getCurrentChangeset() == null) {
046            setEnabled(false);
047            return;
048        } else {
049            setEnabled(true);
050        }
051        if (component.getCurrentChangeset().getContent() == null) {
052            putValue(NAME, tr("Download content"));
053            putValue(SMALL_ICON, ChangesetCacheManager.DOWNLOAD_CONTENT_ICON);
054            putValue(SHORT_DESCRIPTION, tr("Download the changeset content from the OSM server"));
055        } else {
056            putValue(NAME, tr("Update content"));
057            putValue(SMALL_ICON, ChangesetCacheManager.UPDATE_CONTENT_ICON);
058            putValue(SHORT_DESCRIPTION, tr("Update the changeset content from the OSM server"));
059        }
060    }
061}