source: josm/trunk/src/org/openstreetmap/josm/actions/UpdateModifiedAction.java@ 13745

Last change on this file since 13745 was 13559, checked in by Don-vip, 6 years ago

extract DownloadPolicy / UploadPolicy to separate classes

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