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