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