Changeset 8471 in josm for trunk/src/org/openstreetmap/josm/plugins
- Timestamp:
- 2015-06-07T02:38:12+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.