Changeset 8471 in josm
- Timestamp:
- 2015-06-07T02:38:12+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/RestartAction.java
r8459 r8471 21 21 * Restarts JOSM as it was launched. Comes from "restart" plugin, originally written by Upliner. 22 22 * <br><br> 23 * Mechanisms have been improved based on #8561 discussions and <a href="http://lewisleo.blogspot.jp/2012/08/programmatically-restart-java.html">this article</a>. 23 * Mechanisms have been improved based on #8561 discussions and 24 * <a href="http://lewisleo.blogspot.jp/2012/08/programmatically-restart-java.html">this article</a>. 24 25 * @since 5857 25 26 */ -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r8465 r8471 62 62 import org.openstreetmap.josm.data.preferences.ColorProperty; 63 63 import org.openstreetmap.josm.io.CachedFile; 64 import org.openstreetmap.josm.io.OfflineAccessException; 65 import org.openstreetmap.josm.io.OnlineResource; 64 66 import org.openstreetmap.josm.io.XmlWriter; 65 67 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 1449 1451 * Replies the collection of plugin site URLs from where plugin lists can be downloaded. 1450 1452 * @return the collection of plugin site URLs 1453 * @see #getOnlinePluginSites 1451 1454 */ 1452 1455 public Collection<String> getPluginSites() { 1453 1456 return getCollection("pluginmanager.sites", Collections.singleton(Main.getJOSMWebsite()+"/pluginicons%<?plugins=>")); 1457 } 1458 1459 /** 1460 * Returns the list of plugin sites available according to offline mode settings. 1461 * @return the list of available plugin sites 1462 * @since 8471 1463 */ 1464 public Collection<String> getOnlinePluginSites() { 1465 Collection<String> pluginSites = new ArrayList<>(getPluginSites()); 1466 for (Iterator<String> it = pluginSites.iterator(); it.hasNext();) { 1467 try { 1468 OnlineResource.JOSM_WEBSITE.checkOfflineAccess(it.next(), Main.getJOSMWebsite()); 1469 } catch (OfflineAccessException ex) { 1470 Main.warn(ex, false); 1471 it.remove(); 1472 } 1473 } 1474 return pluginSites; 1454 1475 } 1455 1476 -
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
r8444 r8471 50 50 import org.openstreetmap.josm.gui.widgets.JosmTextField; 51 51 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 52 import org.openstreetmap.josm.io.OfflineAccessException;53 import org.openstreetmap.josm.io.OnlineResource;54 52 import org.openstreetmap.josm.plugins.PluginDownloadTask; 55 53 import org.openstreetmap.josm.plugins.PluginInformation; … … 121 119 * @param parent The parent component 122 120 * @param task The finished plugin download task 121 * @param restartRequired true if a restart is required 123 122 * @since 6797 124 123 */ … … 321 320 } 322 321 323 private static Collection<String> getOnlinePluginSites() {324 Collection<String> pluginSites = new ArrayList<>(Main.pref.getPluginSites());325 for (Iterator<String> it = pluginSites.iterator(); it.hasNext();) {326 try {327 OnlineResource.JOSM_WEBSITE.checkOfflineAccess(it.next(), Main.getJOSMWebsite());328 } catch (OfflineAccessException ex) {329 Main.warn(ex.getMessage());330 it.remove();331 }332 }333 return pluginSites;334 }335 336 322 /** 337 323 * The action for downloading the list of available plugins … … 339 325 class DownloadAvailablePluginsAction extends AbstractAction { 340 326 327 /** 328 * Constructs a new {@code DownloadAvailablePluginsAction}. 329 */ 341 330 public DownloadAvailablePluginsAction() { 342 331 putValue(NAME,tr("Download list")); … … 347 336 @Override 348 337 public void actionPerformed(ActionEvent e) { 349 Collection<String> pluginSites = getOnlinePluginSites();338 Collection<String> pluginSites = Main.pref.getOnlinePluginSites(); 350 339 if (pluginSites.isEmpty()) { 351 340 return; … … 369 358 Main.worker.submit(continuation); 370 359 } 371 372 360 } 373 361 … … 411 399 ); 412 400 // the async task for downloading plugin information 413 final ReadRemotePluginInformationTask pluginInfoDownloadTask = new ReadRemotePluginInformationTask(getOnlinePluginSites()); 401 final ReadRemotePluginInformationTask pluginInfoDownloadTask = new ReadRemotePluginInformationTask( 402 Main.pref.getOnlinePluginSites()); 414 403 415 404 // to be run asynchronously after the plugin download -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r8465 r8471 53 53 54 54 import org.openstreetmap.josm.Main; 55 import org.openstreetmap.josm.actions.RestartAction; 55 56 import org.openstreetmap.josm.data.Version; 56 57 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 464 465 465 466 /** 466 * Alerts the user if a plugin required by another plugin is missing 467 * Alerts the user if a plugin required by another plugin is missing, and offer to download them & restart JOSM 467 468 * 468 469 * @param parent The parent Component used to display error popup … … 471 472 */ 472 473 private static void alertMissingRequiredPlugin(Component parent, String plugin, Set<String> missingRequiredPlugin) { 473 StringBuilder sb = new StringBuilder( );474 StringBuilder sb = new StringBuilder(48); 474 475 sb.append("<html>") 475 476 .append(trn("Plugin {0} requires a plugin which was not found. The missing plugin is:", … … 480 481 .append(Utils.joinAsHtmlUnorderedList(missingRequiredPlugin)) 481 482 .append("</html>"); 482 JOptionPane.showMessageDialog( 483 ButtonSpec[] specs = new ButtonSpec[] { 484 new ButtonSpec( 485 tr("Download and restart"), 486 ImageProvider.get("restart"), 487 trn("Click to download missing plugin and restart JOSM", 488 "Click to download missing plugins and restart JOSM", 489 missingRequiredPlugin.size()), 490 null /* no specific help text */ 491 ), 492 new ButtonSpec( 493 tr("Continue"), 494 ImageProvider.get("ok"), 495 trn("Click to continue without this plugin", 496 "Click to continue without these plugins", 497 missingRequiredPlugin.size()), 498 null /* no specific help text */ 499 ) 500 }; 501 if (0 == HelpAwareOptionPane.showOptionDialog( 483 502 parent, 484 503 sb.toString(), 485 504 tr("Error"), 486 JOptionPane.ERROR_MESSAGE 487 ); 505 JOptionPane.ERROR_MESSAGE, 506 null, /* no special icon */ 507 specs, 508 specs[0], 509 HelpUtil.ht("/Plugin/Loading#MissingRequiredPlugin"))) { 510 downloadRequiredPluginsAndRestart(parent, missingRequiredPlugin); 511 } 512 } 513 514 private static void downloadRequiredPluginsAndRestart(final Component parent, final Set<String> missingRequiredPlugin) { 515 // Update plugin list 516 final ReadRemotePluginInformationTask pluginInfoDownloadTask = new ReadRemotePluginInformationTask( 517 Main.pref.getOnlinePluginSites()); 518 Main.worker.submit(pluginInfoDownloadTask); 519 520 // Continuation 521 Main.worker.submit(new Runnable() { 522 @Override 523 public void run() { 524 // Build list of plugins to download 525 Set<PluginInformation> toDownload = new HashSet<>(pluginInfoDownloadTask.getAvailablePlugins()); 526 for (Iterator<PluginInformation> it = toDownload.iterator(); it.hasNext();) { 527 PluginInformation info = it.next(); 528 if (!missingRequiredPlugin.contains(info.getName())) { 529 it.remove(); 530 } 531 } 532 // Check if something has still to be downloaded 533 if (!toDownload.isEmpty()) { 534 // download plugins 535 final PluginDownloadTask task = new PluginDownloadTask(parent, toDownload, tr("Download plugins")); 536 Main.worker.submit(task); 537 Main.worker.submit(new Runnable() { 538 @Override 539 public void run() { 540 // restart if some plugins have been downloaded 541 if (!task.getDownloadedPlugins().isEmpty()) { 542 // update plugin list in preferences 543 Set<String> plugins = new HashSet<>(Main.pref.getCollection("plugins")); 544 for (PluginInformation plugin : task.getDownloadedPlugins()) { 545 plugins.add(plugin.name); 546 } 547 Main.pref.putCollection("plugins", plugins); 548 // restart 549 new RestartAction().actionPerformed(null); 550 } else { 551 Main.warn("No plugin downloaded, restart canceled"); 552 } 553 } 554 }); 555 } else { 556 Main.warn("No plugin to download, operation canceled"); 557 } 558 } 559 }); 488 560 } 489 561 … … 645 717 646 718 /** 647 * Loads the plugin in <code>plugins</code> from locally available jar files into 648 * memory. 719 * Loads the plugin in <code>plugins</code> from locally available jar files into memory. 649 720 * 650 721 * @param parent The parent component to be used for the displayed dialog … … 905 976 ReadRemotePluginInformationTask task1 = new ReadRemotePluginInformationTask( 906 977 monitor.createSubTaskMonitor(1, false), 907 Main.pref.get PluginSites(), displayErrMsg978 Main.pref.getOnlinePluginSites(), displayErrMsg 908 979 ); 909 980 Future<?> future = service.submit(task1); … … 1246 1317 PluginProxy err = null; 1247 1318 StackTraceElement[] stack = ex.getStackTrace(); 1248 /* remember the error position, as multiple plugins may be involved, 1249 we search the topmost one */ 1319 // remember the error position, as multiple plugins may be involved, we search the topmost one 1250 1320 int pos = stack.length; 1251 1321 for (PluginProxy p : pluginList) {
Note:
See TracChangeset
for help on using the changeset viewer.