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