001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.actions; 003 004import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 005import static org.openstreetmap.josm.tools.I18n.tr; 006 007import java.awt.event.KeyEvent; 008import java.util.Collection; 009import java.util.Collections; 010 011import org.openstreetmap.josm.data.osm.DataSet; 012import org.openstreetmap.josm.data.osm.DownloadPolicy; 013import org.openstreetmap.josm.data.osm.OsmPrimitive; 014import org.openstreetmap.josm.io.NetworkManager; 015import org.openstreetmap.josm.io.OnlineResource; 016import org.openstreetmap.josm.tools.Shortcut; 017 018/** 019 * This action synchronizes a set of primitives with their state on the server. 020 * @since 2682 021 */ 022public class UpdateModifiedAction extends UpdateSelectionAction { 023 024 /** 025 * Constructs a new {@code UpdateModifiedAction}. 026 */ 027 public UpdateModifiedAction() { 028 super(tr("Update modified"), "updatedata", 029 tr("Updates the currently modified objects from the server (re-downloads data)"), 030 Shortcut.registerShortcut("file:updatemodified", 031 tr("File: {0}", tr("Update modified")), KeyEvent.VK_M, 032 Shortcut.ALT_CTRL), 033 true, "updatemodified"); 034 setHelpId(ht("/Action/UpdateModified")); 035 } 036 037 // FIXME: overrides the behaviour of UpdateSelectionAction. Doesn't update 038 // the enabled state based on the current selection because it doesn't depend on it. 039 // The action should be enabled/disabled based on whether there is a least 040 // one modified object in the current dataset. Unfortunately, there is no 041 // efficient way to find out here. getDataSet().allModifiedPrimitives() is 042 // too heavy weight because it loops over the whole dataset. 043 // Perhaps this action should be a DataSetListener? Or it could listen to the 044 // REQUIRES_SAVE_TO_DISK_PROP and REQUIRES_UPLOAD_TO_SERVER_PROP properties 045 // in the OsmLayer? 046 // 047 @Override 048 protected void updateEnabledState() { 049 DataSet ds = getLayerManager().getEditDataSet(); 050 setEnabled(ds != null && DownloadPolicy.BLOCKED != ds.getDownloadPolicy() 051 && !NetworkManager.isOffline(OnlineResource.OSM_API)); 052 } 053 054 @Override 055 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 056 // Do nothing 057 } 058 059 @Override 060 public Collection<OsmPrimitive> getData() { 061 DataSet ds = getLayerManager().getEditDataSet(); 062 return ds == null ? Collections.<OsmPrimitive>emptyList() : ds.allModifiedPrimitives(); 063 } 064}