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.Main; 012import org.openstreetmap.josm.data.osm.OsmPrimitive; 013import org.openstreetmap.josm.io.OnlineResource; 014import org.openstreetmap.josm.tools.Shortcut; 015 016/** 017 * This action synchronizes a set of primitives with their state on the server. 018 * @since 2682 019 */ 020public class UpdateModifiedAction extends UpdateSelectionAction { 021 022 /** 023 * Constructs a new {@code UpdateModifiedAction}. 024 */ 025 public UpdateModifiedAction() { 026 super(tr("Update modified"), "updatedata", 027 tr("Updates the currently modified objects from the server (re-downloads data)"), 028 Shortcut.registerShortcut("file:updatemodified", 029 tr("File: {0}", tr("Update modified")), KeyEvent.VK_M, 030 Shortcut.ALT_CTRL), 031 true, "updatemodified"); 032 putValue("help", ht("/Action/UpdateModified")); 033 } 034 035 // FIXME: overrides the behaviour of UpdateSelectionAction. Doesn't update 036 // the enabled state based on the current selection because 037 // it doesn't depend on it. 038 // The action should be enabled/disabled based on whether there is a least 039 // one modified object in the current dataset. Unfortunately, there is no 040 // efficient way to find out here. getDataSet().allModifiedPrimitives() is 041 // too heavy weight because it loops over the whole dataset. 042 // Perhaps this action should be a DataSetListener? Or it could listen to the 043 // REQUIRES_SAVE_TO_DISK_PROP and REQUIRES_UPLOAD_TO_SERVER_PROP properties 044 // in the OsmLayer? 045 // 046 @Override 047 protected void updateEnabledState() { 048 setEnabled(getCurrentDataSet() != null && !Main.isOffline(OnlineResource.OSM_API)); 049 } 050 051 @Override 052 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 053 } 054 055 @Override 056 public Collection<OsmPrimitive> getData() { 057 if (getCurrentDataSet() == null) return Collections.emptyList(); 058 return getCurrentDataSet().allModifiedPrimitives(); 059 } 060}