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.tools.CheckParameterUtil; 012 013/** 014 * Downloads/Updates the content of the changeset. 015 * @since 9493 016 */ 017public class DownloadChangesetContentAction extends AbstractAction { 018 private final transient ChangesetAware component; 019 020 /** 021 * Constructs a new {@code DownloadChangesetContentAction}. 022 * @param component changeset-aware component 023 */ 024 public DownloadChangesetContentAction(ChangesetAware component) { 025 CheckParameterUtil.ensureParameterNotNull(component, "component"); 026 putValue(NAME, tr("Download content")); 027 putValue(SMALL_ICON, ChangesetCacheManager.DOWNLOAD_CONTENT_ICON); 028 putValue(SHORT_DESCRIPTION, tr("Download the changeset content from the OSM server")); 029 this.component = component; 030 } 031 032 @Override 033 public void actionPerformed(ActionEvent evt) { 034 if (component.getCurrentChangeset() != null) { 035 ChangesetCacheManager.getInstance().runDownloadTask(new ChangesetContentDownloadTask( 036 (Component) component, component.getCurrentChangeset().getId())); 037 } 038 } 039 040 /** 041 * Init properties. 042 */ 043 public void initProperties() { 044 if (component.getCurrentChangeset() == null) { 045 setEnabled(false); 046 return; 047 } else { 048 setEnabled(true); 049 } 050 if (component.getCurrentChangeset().getContent() == null) { 051 putValue(NAME, tr("Download content")); 052 putValue(SMALL_ICON, ChangesetCacheManager.DOWNLOAD_CONTENT_ICON); 053 putValue(SHORT_DESCRIPTION, tr("Download the changeset content from the OSM server")); 054 } else { 055 putValue(NAME, tr("Update content")); 056 putValue(SMALL_ICON, ChangesetCacheManager.UPDATE_CONTENT_ICON); 057 putValue(SHORT_DESCRIPTION, tr("Update the changeset content from the OSM server")); 058 } 059 } 060}