source: josm/trunk/src/org/openstreetmap/josm/actions/DownloadNotesInViewAction.java@ 16509

Last change on this file since 16509 was 16509, checked in by GerdP, 4 years ago

see #19296: Actions should avoid to install listeners which are not needed

  • either don't call installAdapters() or overwrite listenToSelectionChange()
  • partly reverts previous changes so that installAdapters() is not overwritten

One has to be careful because installAdapters() also calls initEnabledState()

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.util.concurrent.Future;
8
9import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
10import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
11import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
12import org.openstreetmap.josm.data.Bounds;
13import org.openstreetmap.josm.gui.MainApplication;
14import org.openstreetmap.josm.io.NetworkManager;
15import org.openstreetmap.josm.io.OnlineResource;
16
17/**
18 * Action that downloads the notes within the current view from the server.
19 *
20 * No interaction is required.
21 */
22public final class DownloadNotesInViewAction extends JosmAction {
23
24 private DownloadNotesInViewAction(String iconName) {
25 super(tr("Download notes in current view"), iconName, tr("Download notes in current view"), null, false,
26 "dialogs/notes/download_in_view", true);
27 }
28
29 /**
30 * Constructs a new {@code DownloadNotesInViewAction} with note icon.
31 * @return a new {@code DownloadNotesInViewAction} with note icon
32 */
33 public static DownloadNotesInViewAction newActionWithNoteIcon() {
34 return new DownloadNotesInViewAction("dialogs/notes/note_open");
35 }
36
37 /**
38 * Constructs a new {@code DownloadNotesInViewAction} with download icon.
39 * @return a new {@code DownloadNotesInViewAction} with download icon
40 */
41 public static DownloadNotesInViewAction newActionWithDownloadIcon() {
42 return new DownloadNotesInViewAction("download");
43 }
44
45 @Override
46 public void actionPerformed(ActionEvent e) {
47 final Bounds bounds = MainApplication.getMap().mapView.getRealBounds();
48 DownloadNotesTask task = new DownloadNotesTask();
49 task.setZoomAfterDownload(false);
50 Future<?> future = task.download(new DownloadParams(), bounds, null);
51 MainApplication.worker.submit(new PostDownloadHandler(task, future));
52 }
53
54 @Override
55 protected boolean listenToSelectionChange() {
56 return false;
57 }
58
59 @Override
60 protected void updateEnabledState() {
61 setEnabled(getLayerManager().getActiveLayer() != null
62 && !NetworkManager.isOffline(OnlineResource.OSM_API));
63 }
64}
Note: See TracBrowser for help on using the repository browser.