[2682] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
| 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 6 |
|
---|
| 7 | import java.awt.event.KeyEvent;
|
---|
| 8 | import java.util.Collection;
|
---|
[3093] | 9 | import java.util.Collections;
|
---|
[2682] | 10 |
|
---|
[7434] | 11 | import org.openstreetmap.josm.Main;
|
---|
[2682] | 12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
[7434] | 13 | import org.openstreetmap.josm.io.OnlineResource;
|
---|
[2682] | 14 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * This action synchronizes a set of primitives with their state on the server.
|
---|
[6814] | 18 | * @since 2682
|
---|
[2682] | 19 | */
|
---|
| 20 | public class UpdateModifiedAction extends UpdateSelectionAction {
|
---|
| 21 |
|
---|
| 22 | /**
|
---|
[6814] | 23 | * Constructs a new {@code UpdateModifiedAction}.
|
---|
[2682] | 24 | */
|
---|
| 25 | public UpdateModifiedAction() {
|
---|
[6814] | 26 | super(tr("Update modified"), "updatedata",
|
---|
[2682] | 27 | tr("Updates the currently modified objects from the server (re-downloads data)"),
|
---|
| 28 | Shortcut.registerShortcut("file:updatemodified",
|
---|
[4927] | 29 | tr("File: {0}", tr("Update modified")), KeyEvent.VK_M,
|
---|
[4982] | 30 | Shortcut.ALT_CTRL),
|
---|
[6814] | 31 | true, "updatemodified");
|
---|
[2684] | 32 | putValue("help", ht("/Action/UpdateModified"));
|
---|
[2682] | 33 | }
|
---|
| 34 |
|
---|
[3092] | 35 | // FIXME: overrides the behaviour of UpdateSelectionAction. Doesn't update
|
---|
| 36 | // the enabled state based on the current selection because
|
---|
| 37 | // it doesn't depend on it.
|
---|
| 38 | // The action should be enabled/disabled based on whether there is a least
|
---|
| 39 | // one modified object in the current dataset. Unfortunately, there is no
|
---|
| 40 | // efficient way to find out here. getDataSet().allModifiedPrimitives() is
|
---|
| 41 | // too heavy weight because it loops over the whole dataset.
|
---|
| 42 | // Perhaps this action should be a DataSetListener? Or it could listen to the
|
---|
| 43 | // REQUIRES_SAVE_TO_DISK_PROP and REQUIRES_UPLOAD_TO_SERVER_PROP properties
|
---|
| 44 | // in the OsmLayer?
|
---|
| 45 | //
|
---|
[2682] | 46 | @Override
|
---|
[3092] | 47 | protected void updateEnabledState() {
|
---|
[7434] | 48 | setEnabled(getCurrentDataSet() != null && !Main.isOffline(OnlineResource.OSM_API));
|
---|
[2682] | 49 | }
|
---|
| 50 |
|
---|
| 51 | @Override
|
---|
[3092] | 52 | protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
|
---|
[2682] | 53 | }
|
---|
[3093] | 54 |
|
---|
| 55 | @Override
|
---|
| 56 | public Collection<OsmPrimitive> getData() {
|
---|
| 57 | if (getCurrentDataSet() == null) return Collections.emptyList();
|
---|
| 58 | return getCurrentDataSet().allModifiedPrimitives();
|
---|
| 59 | }
|
---|
[2682] | 60 | }
|
---|