Changeset 8195 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2015-04-15T20:42:45+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java
r8061 r8195 7 7 import java.awt.GridBagConstraints; 8 8 import java.awt.GridBagLayout; 9 import java.awt.GridLayout; 9 10 import java.awt.event.ActionEvent; 10 11 import java.awt.event.KeyEvent; … … 18 19 import javax.swing.JCheckBox; 19 20 import javax.swing.JLabel; 21 import javax.swing.JList; 20 22 import javax.swing.JOptionPane; 21 23 import javax.swing.JPanel; … … 24 26 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 25 27 import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask; 28 import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesUrlBoundsTask; 29 import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesUrlIdTask; 26 30 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeCompressedTask; 27 31 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeTask; … … 67 71 addDownloadTaskClass(DownloadOsmChangeCompressedTask.class); 68 72 addDownloadTaskClass(DownloadSessionTask.class); 73 addDownloadTaskClass(DownloadNotesUrlBoundsTask.class); 74 addDownloadTaskClass(DownloadNotesUrlIdTask.class); 69 75 } 70 76 … … 183 189 PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download Data")); 184 190 Collection<DownloadTask> tasks = findDownloadTasks(url, false); 185 DownloadTask task = null; 186 Future<?> future = null; 187 if (!tasks.isEmpty()) { 188 // TODO: handle multiple suitable tasks ? 191 192 if (tasks.size() > 1) { 193 tasks = askWhichTasksToLoad(tasks); 194 } else if (tasks.isEmpty()) { 195 warnNoSuitableTasks(url); 196 return; 197 } 198 199 for (final DownloadTask task : tasks) { 189 200 try { 190 task = tasks.iterator().next();191 future = task.loadUrl(newLayer, url, monitor);201 Future<?> future = task.loadUrl(newLayer, url, monitor); 202 Main.worker.submit(new PostDownloadHandler(task, future)); 192 203 } catch (IllegalArgumentException e) { 193 204 Main.error(e); 194 205 } 195 206 } 196 if (future != null) { 197 Main.worker.submit(new PostDownloadHandler(task, future)); 198 } else { 199 final String details = findSummaryDocumentation(); // Explain what patterns are supported 200 HelpAwareOptionPane.showMessageDialogInEDT(Main.parent, "<html><p>" + tr( 201 "Cannot open URL ''{0}''<br>The following download tasks accept the URL patterns shown:<br>{1}", 202 url, details) + "</p></html>", tr("Download Location"), JOptionPane.ERROR_MESSAGE, HelpUtil.ht("/Action/OpenLocation")); 203 } 207 208 } 209 210 /** 211 * Asks the user which of the possible tasks to perform. 212 * @param tasks a list of possible tasks 213 * @return the selected tasks from the user or an empty list if the dialog has been canceled 214 */ 215 Collection<DownloadTask> askWhichTasksToLoad(final Collection<DownloadTask> tasks) { 216 final JList<DownloadTask> list = new JList<>(tasks.toArray(new DownloadTask[tasks.size()])); 217 list.addSelectionInterval(0, tasks.size() - 1); 218 final ExtendedDialog dialog = new ExtendedDialog(Main.parent, tr("Which tasks to perform?"), new String[]{tr("Ok"), tr("Cancel")}, true) {{ 219 final JPanel pane = new JPanel(new GridLayout(2, 1)); 220 pane.add(new JLabel(tr("Which tasks to perform?"))); 221 pane.add(list); 222 setContent(pane); 223 }}; 224 dialog.showDialog(); 225 return dialog.getValue() == 1 ? list.getSelectedValuesList() : Collections.<DownloadTask>emptyList(); 226 } 227 228 /** 229 * Displays an error message dialog that no suitable tasks have been found for the given url. 230 * @param url the given url 231 */ 232 void warnNoSuitableTasks(final String url) { 233 final String details = findSummaryDocumentation(); // Explain what patterns are supported 234 HelpAwareOptionPane.showMessageDialogInEDT(Main.parent, "<html><p>" + tr( 235 "Cannot open URL ''{0}''<br>The following download tasks accept the URL patterns shown:<br>{1}", 236 url, details) + "</p></html>", tr("Download Location"), JOptionPane.ERROR_MESSAGE, HelpUtil.ht("/Action/OpenLocation")); 204 237 } 205 238 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTask.java
r7749 r8195 108 108 } 109 109 110 @Override 111 public String toString() { 112 return this.getTitle(); 113 } 114 110 115 // Default pattern to keep old plugins compatible 111 116 @Override -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java
r8115 r8195 16 16 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 17 17 import org.openstreetmap.josm.io.BoundingBoxDownloader; 18 import org.openstreetmap.josm.io.OsmApi; 18 19 import org.openstreetmap.josm.io.OsmServerLocationReader; 19 20 import org.openstreetmap.josm.io.OsmServerReader; … … 28 29 29 30 private DownloadTask downloadTask; 31 32 public Future<?> download(boolean newLayer, long id, ProgressMonitor progressMonitor) { 33 final String url = OsmApi.getOsmApi().getBaseUrl() + "notes/" + id; 34 downloadTask = new DownloadRawUrlTask(new OsmServerLocationReader(url), progressMonitor); 35 return Main.worker.submit(downloadTask); 36 } 30 37 31 38 @Override
Note:
See TracChangeset
for help on using the changeset viewer.