source: osm/applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/actions/GetMissingDataAction.java

Last change on this file was 34565, checked in by donvip, 6 years ago

update to JOSM 14153

File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins.trustosm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.util.Collection;
9import java.util.HashSet;
10import java.util.Map;
11
12import javax.swing.JOptionPane;
13
14import org.openstreetmap.josm.actions.JosmAction;
15import org.openstreetmap.josm.data.osm.OsmPrimitive;
16import org.openstreetmap.josm.gui.MainApplication;
17import org.openstreetmap.josm.plugins.trustosm.TrustOSMplugin;
18import org.openstreetmap.josm.plugins.trustosm.data.TrustOsmPrimitive;
19import org.openstreetmap.josm.plugins.trustosm.gui.DownloadSignedOsmDataTask;
20import org.openstreetmap.josm.tools.Shortcut;
21
22public class GetMissingDataAction extends JosmAction {
23
24 public GetMissingDataAction() {
25 super(tr("Download OSM"), "getmissing", tr("Get all referenced but not actually present OSM objects from OSM server."),
26 Shortcut.registerShortcut("gpg:download", tr("Download referenced osm objects..."), KeyEvent.VK_T, Shortcut.CTRL), true);
27 }
28
29 @Override
30 public void actionPerformed(ActionEvent arg0) {
31 if (!isEnabled())
32 return;
33 downloadMissing();
34 }
35
36 public boolean downloadMissing() {
37 Collection<OsmPrimitive> missingData = new HashSet<>();
38 Map<String, TrustOsmPrimitive> trustitems = TrustOSMplugin.signedItems;
39 getMissing(trustitems, missingData);
40
41 int missingCount = missingData.size();
42 int itemCount = trustitems.size();
43 if (missingCount == 0) {
44 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("{0} Signatures loaded. All referenced OSM objects found.", itemCount));
45 } else {
46 int n = JOptionPane.showOptionDialog(MainApplication.getMainFrame(),
47 tr("{0} of {1} OSM objects are referenced but not there.\nDo you want to load them from OSM-Server?",
48 missingCount, itemCount),
49 tr("Load objects from server"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
50
51 if (n == JOptionPane.YES_OPTION) {
52 MainApplication.worker.submit(new DownloadSignedOsmDataTask(missingData, getLayerManager().getEditLayer()));
53 return true;
54 }
55 }
56
57 return false;
58 }
59
60 public void getMissing(Map<String, TrustOsmPrimitive> trustitems, Collection<OsmPrimitive> missingData) {
61 Collection<OsmPrimitive> presentData = getLayerManager().getEditDataSet().allPrimitives();
62 for (TrustOsmPrimitive t : trustitems.values()) {
63 OsmPrimitive osm = t.getOsmPrimitive();
64 if (!presentData.contains(osm))
65 missingData.add(osm);
66 }
67 }
68}
Note: See TracBrowser for help on using the repository browser.