Changeset 2856 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2010-01-14T16:31:41+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed #4365: "Do you want to update plugins" request shown behind Splashscreen

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r2839 r2856  
    101101    }
    102102
     103    private static Map<String, Collection<String>> buildCommandLineArgumentMap(String[] args) {
     104        Map<String, Collection<String>> argMap = new HashMap<String, Collection<String>>();
     105        for (String arg : args) {
     106            if ("-h".equals(arg) || "-?".equals(arg)) {
     107                arg = "--help";
     108            }
     109            // handle simple arguments like file names, URLs, bounds
     110            if (!arg.startsWith("--")) {
     111                arg = "--download="+arg;
     112            }
     113            int i = arg.indexOf('=');
     114            String key = i == -1 ? arg.substring(2) : arg.substring(2,i);
     115            String value = i == -1 ? "" : arg.substring(i+1);
     116            Collection<String> v = argMap.get(key);
     117            if (v == null) {
     118                v = new LinkedList<String>();
     119            }
     120            v.add(value);
     121            argMap.put(key, v);
     122        }
     123        return argMap;
     124    }
     125
    103126    /**
    104127     * Main application Startup
     
    115138
    116139        // construct argument table
    117         final Map<String, Collection<String>> args = new HashMap<String, Collection<String>>();
    118         for (String arg : argArray) {
    119             if ("-h".equals(arg) || "-?".equals(arg)) {
    120                 arg = "--help";
    121             }
    122             // handle simple arguments like file names, URLs, bounds
    123             if (!arg.startsWith("--")) {
    124                 arg = "--download="+arg;
    125             }
    126             int i = arg.indexOf('=');
    127             String key = i == -1 ? arg.substring(2) : arg.substring(2,i);
    128             String value = i == -1 ? "" : arg.substring(i+1);
    129             Collection<String> v = args.get(key);
    130             if (v == null) {
    131                 v = new LinkedList<String>();
    132             }
    133             v.add(value);
    134             args.put(key, v);
    135         }
     140        final Map<String, Collection<String>> args = buildCommandLineArgumentMap(argArray);
    136141
    137142        Main.pref.init(args.containsKey("reset-preferences"));
     
    162167        splash.setVisible(Main.pref.getBoolean("draw.splashscreen", true));
    163168
    164         List<PluginInformation> pluginsToLoad = PluginHandler.buildListOfPluginsToLoad(monitor.createSubTaskMonitor(1, false));
    165         if (!pluginsToLoad.isEmpty() && PluginHandler.checkAndConfirmPluginUpdate()) {
     169        List<PluginInformation> pluginsToLoad = PluginHandler.buildListOfPluginsToLoad(splash,monitor.createSubTaskMonitor(1, false));
     170        if (!pluginsToLoad.isEmpty() && PluginHandler.checkAndConfirmPluginUpdate(splash)) {
    166171            monitor.subTask(tr("Updating plugins..."));
    167             PluginHandler.updatePlugins(pluginsToLoad, monitor.createSubTaskMonitor(1, false));
     172            PluginHandler.updatePlugins(splash,pluginsToLoad, monitor.createSubTaskMonitor(1, false));
    168173        }
    169174        monitor.worked(1);
     
    174179
    175180        monitor.subTask(tr("Loading early plugins"));
    176         PluginHandler.loadEarlyPlugins(pluginsToLoad, monitor.createSubTaskMonitor(1, false));
     181        PluginHandler.loadEarlyPlugins(splash,pluginsToLoad, monitor.createSubTaskMonitor(1, false));
    177182        monitor.worked(1);
    178183
     
    189194
    190195        monitor.subTask(tr("Loading plugins"));
    191         PluginHandler.loadLatePlugins(pluginsToLoad,  monitor.createSubTaskMonitor(1, false));
     196        PluginHandler.loadLatePlugins(splash,pluginsToLoad,  monitor.createSubTaskMonitor(1, false));
    192197        monitor.worked(1);
    193198        toolbar.refreshToolbarControl();
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r2855 r2856  
    66
    77import java.awt.Font;
     8import java.awt.GridBagConstraints;
    89import java.awt.GridBagLayout;
     10import java.awt.Insets;
     11import java.awt.Window;
    912import java.awt.event.ActionEvent;
    1013import java.io.File;
     
    3437import javax.swing.Box;
    3538import javax.swing.JButton;
     39import javax.swing.JCheckBox;
    3640import javax.swing.JLabel;
    3741import javax.swing.JOptionPane;
     
    4347import org.openstreetmap.josm.Main;
    4448import org.openstreetmap.josm.data.Version;
    45 import org.openstreetmap.josm.gui.ExtendedDialog;
     49import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     50import org.openstreetmap.josm.gui.JMultilineLabel;
    4651import org.openstreetmap.josm.gui.MapFrame;
     52import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    4753import org.openstreetmap.josm.gui.download.DownloadSelection;
     54import org.openstreetmap.josm.gui.help.HelpUtil;
    4855import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
    4956import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
     
    8289     * @param plugins the collection of plugins
    8390     */
    84     private static void filterDeprecatedPlugins(Collection<String> plugins) {
     91    private static void filterDeprecatedPlugins(Window parent, Collection<String> plugins) {
    8592        Set<String> removedPlugins = new HashSet<String>();
    8693        for (String p : DEPRECATED_PLUGINS) {
     
    110117        sb.append("</html>");
    111118        JOptionPane.showMessageDialog(
    112                 Main.parent,
     119                parent,
    113120                sb.toString(),
    114121                tr("Warning"),
     
    126133     * @param plugins the collection of plugins
    127134     */
    128     private static void filterUnmaintainedPlugins(Collection<String> plugins) {
     135    private static void filterUnmaintainedPlugins(Window parent, Collection<String> plugins) {
    129136        for (String unmaintained : UNMAINTAINED_PLUGINS) {
    130137            if (!plugins.contains(unmaintained)) {
     
    134141                    + "<br>This plugin is no longer developed and very likely will produce errors."
    135142                    +"<br>It should be disabled.<br>Delete from preferences?</html>", unmaintained);
    136             if (confirmDisablePlugin(msg,unmaintained)) {
     143            if (confirmDisablePlugin(parent, msg,unmaintained)) {
    137144                Main.pref.removeFromCollection("plugins", unmaintained);
    138145                plugins.remove(unmaintained);
     
    147154     * if the plugins were last updated a long time ago.
    148155     *
     156     * @param parent the parent window relative to which the confirmation dialog
     157     * is to be displayed
    149158     * @return true if a plugin update should be run; false, otherwise
    150159     */
    151     public static boolean checkAndConfirmPluginUpdate() {
     160    public static boolean checkAndConfirmPluginUpdate(Window parent) {
    152161        String message = null;
    153162        String togglePreferenceKey = null;
    154163        int v = Version.getInstance().getVersion();
    155164        if (Main.pref.getInteger("pluginmanager.version", 0) < v) {
    156             message = tr("<html>You updated your JOSM software.<br>"
    157                     + "To prevent problems the plugins should be updated as well.<br><br>"
    158                     + "Update plugins now?"
    159                     + "</html>"
    160             );
     165            message =
     166                "<html>"
     167                + tr("You updated your JOSM software.<br>"
     168                        + "To prevent problems the plugins should be updated as well.<br><br>"
     169                        + "Update plugins now?"
     170                )
     171                + "</html>";
    161172            togglePreferenceKey = "pluginmanager.version";
    162173        }  else {
     
    168179                Main.pref.put("pluginmanager.lastupdate", Long.toString(tim));
    169180            } else if (d > maxTime) {
    170                 message = tr("Last plugin update more than {0} days ago.", d);
     181                message =
     182                    "<html>"
     183                    + tr("Last plugin update more than {0} days ago.", d)
     184                    + "</html>";
    171185                togglePreferenceKey = "pluginmanager.time";
    172186            }
     
    174188        if (message == null) return false;
    175189
    176         // ask whether update is fine
    177         //
    178         ExtendedDialog dialog = new ExtendedDialog(
    179                 Main.parent,
     190        ButtonSpec [] options = new ButtonSpec[] {
     191                new ButtonSpec(
     192                        tr("Update plugins"),
     193                        ImageProvider.get("dialogs", "refresh"),
     194                        tr("Click to update the activated plugins"),
     195                        null /* no specific help context */
     196                ),
     197                new ButtonSpec(
     198                        tr("Skip update"),
     199                        ImageProvider.get("cancel"),
     200                        tr("Click to skip updating the activated plugins"),
     201                        null /* no specific help context */
     202                )
     203        };
     204
     205        UpdatePluginsMessagePanel pnlMessage = new UpdatePluginsMessagePanel();
     206        pnlMessage.setMessage(message);
     207        pnlMessage.initDontShowAgain(togglePreferenceKey);
     208
     209        int ret = HelpAwareOptionPane.showOptionDialog(
     210                parent,
     211                pnlMessage,
    180212                tr("Update plugins"),
    181                 new String[] {
    182                     tr("Update plugins"), tr("Skip update")
    183                 }
     213                JOptionPane.WARNING_MESSAGE,
     214                null,
     215                options,
     216                options[0],
     217                ht("/Plugin/AutomaticUpdate")
    184218        );
    185         dialog.setContent(message);
    186         dialog.toggleEnable(togglePreferenceKey);
    187         dialog.setButtonIcons( new String[] {"dialogs/refresh.png", "cancel.png"});
    188         dialog.configureContextsensitiveHelp(ht("/Plugin/AutomaticUpdate"), true /* show help button */);
    189         dialog.showDialog();
    190         return dialog.getValue() == 1;
     219
     220        pnlMessage.rememberDontShowAgain(togglePreferenceKey);
     221        return ret == 0;
    191222    }
    192223
     
    197228     * @param missingRequiredPlugin the missing required plugin
    198229     */
    199     private static void alertMissingRequiredPlugin(String plugin, Set<String> missingRequiredPlugin) {
     230    private static void alertMissingRequiredPlugin(Window parent, String plugin, Set<String> missingRequiredPlugin) {
    200231        StringBuilder sb = new StringBuilder();
    201232        sb.append("<html>");
     
    212243        sb.append("</ul>").append("</html>");
    213244        JOptionPane.showMessageDialog(
    214                 Main.parent,
     245                parent,
    215246                sb.toString(),
    216247                tr("Error"),
     
    219250    }
    220251
     252    private static void alertJOSMUpdateRequired(Window parent, String plugin, int requiredVersion) {
     253        HelpAwareOptionPane.showOptionDialog(
     254                parent,
     255                tr("<html>Plugin {0} requires JOSM version {1}. The current JOSM version is {1}.<br>"
     256                        +"You have to update JOSM in order to use this plugin.</html>",
     257                        plugin, requiredVersion
     258                ),
     259                tr("Warning"),
     260                JOptionPane.WARNING_MESSAGE,
     261                HelpUtil.ht("/Plugin/Loading#JOSMUpdateRequired")
     262        );
     263    }
     264
    221265    /**
    222266     * Checks whether all preconditions for loading the plugin <code>plugin</code> are met. The
     
    228272     * @return true, if the preconditions are met; false otherwise
    229273     */
    230     public static boolean checkLoadPreconditions(Collection<PluginInformation> plugins, PluginInformation plugin) {
     274    public static boolean checkLoadPreconditions(Window parent, Collection<PluginInformation> plugins, PluginInformation plugin) {
    231275
    232276        // make sure the plugin is compatible with the current JOSM version
     
    234278        int josmVersion = Version.getInstance().getVersion();
    235279        if (plugin.mainversion > josmVersion && josmVersion != Version.JOSM_UNKNOWN_VERSION) {
    236             JOptionPane.showMessageDialog(
    237                     Main.parent,
    238                     tr("Plugin {0} requires JOSM update to version {1}.", plugin.name,
    239                             plugin.mainversion),
    240                             tr("Warning"),
    241                             JOptionPane.WARNING_MESSAGE
    242             );
     280            alertJOSMUpdateRequired(parent, plugin.name, plugin.mainversion);
    243281            return false;
    244282        }
     
    258296            }
    259297            if (!missingPlugins.isEmpty()) {
    260                 alertMissingRequiredPlugin(plugin.name, missingPlugins);
     298                alertMissingRequiredPlugin(parent, plugin.name, missingPlugins);
    261299                return false;
    262300            }
     
    300338     * @param pluginClassLoader the plugin class loader
    301339     */
    302     public static void loadPlugin(PluginInformation plugin, ClassLoader pluginClassLoader) {
     340    public static void loadPlugin(Window parent, PluginInformation plugin, ClassLoader pluginClassLoader) {
    303341        try {
    304342            Class<?> klass = plugin.loadClass(pluginClassLoader);
     
    310348            e.printStackTrace();
    311349            String msg = tr("Could not load plugin {0}. Delete from preferences?", plugin.name);
    312             if (confirmDisablePlugin(msg, plugin.name)) {
     350            if (confirmDisablePlugin(parent, msg, plugin.name)) {
    313351                Main.pref.removeFromCollection("plugins", plugin.name);
    314352            }
     
    323361     * @param monitor the progress monitor. Defaults to {@see NullProgressMonitor#INSTANCE} if null.
    324362     */
    325     public static void loadPlugins(Collection<PluginInformation> plugins, ProgressMonitor monitor) {
     363    public static void loadPlugins(Window parent,Collection<PluginInformation> plugins, ProgressMonitor monitor) {
    326364        if (monitor == null) {
    327365            monitor = NullProgressMonitor.INSTANCE;
     
    345383            monitor.subTask(tr("Checking plugin preconditions..."));
    346384            for (PluginInformation pi: plugins) {
    347                 if (checkLoadPreconditions(plugins, pi)) {
     385                if (checkLoadPreconditions(parent, plugins, pi)) {
    348386                    toLoad.add(pi);
    349387                }
     
    357395            for (PluginInformation info : toLoad) {
    358396                monitor.setExtraText(tr("Loading plugin ''{0}''...", info.name));
    359                 loadPlugin(info, pluginClassLoader);
     397                loadPlugin(parent, info, pluginClassLoader);
    360398                monitor.worked(1);
    361399            }
     
    372410     * @param monitor the progress monitor. Defaults to {@see NullProgressMonitor#INSTANCE} if null.
    373411     */
    374     public static void loadEarlyPlugins(Collection<PluginInformation> plugins, ProgressMonitor monitor) {
     412    public static void loadEarlyPlugins(Window parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) {
    375413        List<PluginInformation> earlyPlugins = new ArrayList<PluginInformation>(plugins.size());
    376414        for (PluginInformation pi: plugins) {
     
    379417            }
    380418        }
    381         loadPlugins(earlyPlugins, monitor);
     419        loadPlugins(parent, earlyPlugins, monitor);
    382420    }
    383421
     
    389427     * @param monitor the progress monitor. Defaults to {@see NullProgressMonitor#INSTANCE} if null.
    390428     */
    391     public static void loadLatePlugins(Collection<PluginInformation> plugins, ProgressMonitor monitor) {
     429    public static void loadLatePlugins(Window parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) {
    392430        List<PluginInformation> latePlugins = new ArrayList<PluginInformation>(plugins.size());
    393431        for (PluginInformation pi: plugins) {
     
    396434            }
    397435        }
    398         loadPlugins(latePlugins, monitor);
     436        loadPlugins(parent, latePlugins, monitor);
    399437    }
    400438
     
    434472    }
    435473
    436     private static void alertMissingPluginInformation(Collection<String> plugins) {
     474    private static void alertMissingPluginInformation(Window parent, Collection<String> plugins) {
    437475        StringBuilder sb = new StringBuilder();
    438476        sb.append("<html>");
     
    449487                plugins.size()));
    450488        sb.append("</html>");
    451         JOptionPane.showMessageDialog(
    452                 Main.parent,
     489        HelpAwareOptionPane.showOptionDialog(
     490                parent,
    453491                sb.toString(),
    454492                tr("Warning"),
    455                 JOptionPane.WARNING_MESSAGE
     493                JOptionPane.WARNING_MESSAGE,
     494                HelpUtil.ht("/Plugin/Loading#MissingPluginInfos")
    456495        );
    457496    }
     
    465504     * @return the set of plugins to load (as set of plugin names)
    466505     */
    467     public static List<PluginInformation> buildListOfPluginsToLoad(ProgressMonitor monitor) {
     506    public static List<PluginInformation> buildListOfPluginsToLoad(Window parent, ProgressMonitor monitor) {
    468507        if (monitor == null) {
    469508            monitor = NullProgressMonitor.INSTANCE;
     
    477516            }
    478517            monitor.subTask(tr("Removing deprecated plugins..."));
    479             filterDeprecatedPlugins(plugins);
     518            filterDeprecatedPlugins(parent, plugins);
    480519            monitor.subTask(tr("Removing umaintained plugins..."));
    481             filterUnmaintainedPlugins(plugins);
     520            filterUnmaintainedPlugins(parent, plugins);
    482521            Map<String, PluginInformation> infos = loadLocallyAvailablePluginInformation(monitor.createSubTaskMonitor(1,false));
    483522            List<PluginInformation> ret = new LinkedList<PluginInformation>();
     
    490529            }
    491530            if (!plugins.isEmpty()) {
    492                 alertMissingPluginInformation(plugins);
     531                alertMissingPluginInformation(parent, plugins);
    493532            }
    494533            return ret;
     
    498537    }
    499538
    500     private static void alertFailedPluginUpdate(Collection<PluginInformation> plugins) {
     539    private static void alertFailedPluginUpdate(Window parent, Collection<PluginInformation> plugins) {
    501540        StringBuffer sb = new StringBuffer();
    502541        sb.append("<html>");
     
    512551        }
    513552        sb.append("</ul>");
    514         sb.append(tr("Please open the Preference Dialog after JOSM has started and try to update them manually."));
     553        sb.append(trn(
     554                "Please open the Preference Dialog after JOSM has started and try to update it manually.",
     555                "Please open the Preference Dialog after JOSM has started and try to update them manually.",
     556                plugins.size()
     557        ));
    515558        sb.append("</html>");
    516         JOptionPane.showMessageDialog(
    517                 Main.parent,
     559        HelpAwareOptionPane.showOptionDialog(
     560                parent,
    518561                sb.toString(),
    519562                tr("Plugin update failed"),
    520                 JOptionPane.ERROR_MESSAGE
     563                JOptionPane.ERROR_MESSAGE,
     564                HelpUtil.ht("/Plugin/Loading#FailedPluginUpdated")
    521565        );
    522566    }
     
    529573     * @throws IllegalArgumentException thrown if plugins is null
    530574     */
    531     public static void updatePlugins(Collection<PluginInformation> plugins, ProgressMonitor monitor) throws IllegalArgumentException{
     575    public static void updatePlugins(Window parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) throws IllegalArgumentException{
    532576        CheckParameterUtil.ensureParameterNotNull(plugins, "plugins");
    533577        if (monitor == null) {
     
    550594            }
    551595            if (! task.getFailedPlugins().isEmpty()) {
    552                 alertFailedPluginUpdate(task.getFailedPlugins());
     596                alertFailedPluginUpdate(parent, task.getFailedPlugins());
    553597                return;
    554598            }
     
    569613     * @return true, if the plugin shall be disabled; false, otherwise
    570614     */
    571     public static boolean confirmDisablePlugin(String reason, String name) {
    572         ExtendedDialog dialog = new ExtendedDialog(
    573                 Main.parent,
     615    public static boolean confirmDisablePlugin(Window parent, String reason, String name) {
     616        ButtonSpec [] options = new ButtonSpec[] {
     617                new ButtonSpec(
     618                        tr("Disable plugin"),
     619                        ImageProvider.get("dialogs", "delete"),
     620                        tr("Click to delete the plugin ''{0}''", name),
     621                        null /* no specific help context */
     622                ),
     623                new ButtonSpec(
     624                        tr("Keep plugin"),
     625                        ImageProvider.get("cancel"),
     626                        tr("Click to keep the plugin ''{0}''", name),
     627                        null /* no specific help context */
     628                )
     629        };
     630        int ret = HelpAwareOptionPane.showOptionDialog(
     631                parent,
     632                reason,
    574633                tr("Disable plugin"),
    575                 new String[] {
    576                     tr("Disable plugin"), tr("Keep plugin")
    577                 }
     634                JOptionPane.WARNING_MESSAGE,
     635                null,
     636                options,
     637                options[0],
     638                null // FIXME: add help topic
    578639        );
    579         dialog.setContent(reason);
    580         dialog.setButtonIcons(new String[] { "dialogs/delete.png", "cancel.png" });
    581         dialog.showDialog();
    582         return dialog.getValue() == 1;
     640        return ret == 0;
    583641    }
    584642
     
    648706    }
    649707
    650     public static boolean checkException(Throwable e)
    651     {
     708    private static boolean confirmDisablingPluginAfterException(PluginProxy plugin) {
     709        ButtonSpec [] options = new ButtonSpec[] {
     710                new ButtonSpec(
     711                        tr("Disable plugin"),
     712                        ImageProvider.get("dialogs", "delete"),
     713                        tr("Click to disable the plugin ''{0}''", plugin.getPluginInformation().name),
     714                        null /* no specific help context */
     715                ),
     716                new ButtonSpec(
     717                        tr("Keep plugin"),
     718                        ImageProvider.get("cancel"),
     719                        tr("Click to keep the plugin ''{0}''",plugin.getPluginInformation().name),
     720                        null /* no specific help context */
     721                )
     722        };
     723
     724        StringBuffer msg = new StringBuffer();
     725        msg.append("<html>");
     726        msg.append(tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", plugin.getPluginInformation().name));
     727        msg.append("<br>");
     728        if(plugin.getPluginInformation().author != null) {
     729            msg.append(tr("According to the information within the plugin, the author is {0}.", plugin.getPluginInformation().author));
     730            msg.append("<br>");
     731        }
     732        msg.append(tr("Try updating to the newest version of this plugin before reporting a bug."));
     733        msg.append("<br>");
     734        msg.append(tr("Should the plugin be disabled?"));
     735        msg.append("</html>");
     736
     737        int ret = HelpAwareOptionPane.showOptionDialog(
     738                Main.parent,
     739                msg.toString(),
     740                tr("Update plugins"),
     741                JOptionPane.QUESTION_MESSAGE,
     742                null,
     743                options,
     744                options[0],
     745                ht("/ErrorMessages#ErrorInPlugin")
     746        );
     747        return ret == 0;
     748    }
     749
     750    private static PluginProxy getPluginCausingException(Throwable ex) {
     751        for (PluginProxy p : pluginList) {
     752            String baseClass = p.getPluginInformation().className;
     753            int i = baseClass.lastIndexOf(".");
     754            baseClass = baseClass.substring(0, i);
     755            for (StackTraceElement element : ex.getStackTrace()) {
     756                String c = element.getClassName();
     757                if (c.startsWith(baseClass))
     758                    return p;
     759            }
     760        }
     761        return null;
     762    }
     763
     764    public static boolean checkException(Throwable e) {
    652765        PluginProxy plugin = null;
    653766
    654767        // Check for an explicit problem when calling a plugin function
    655768        if (e instanceof PluginException) {
    656             plugin = ((PluginException)e).plugin;
     769            plugin = ((PluginException) e).plugin;
    657770        }
    658771
    659772        if (plugin == null) {
    660             /**
    661              * Analyze the stack of the argument and find a name of a plugin, if
    662              * some known problem pattern has been found.
    663              */
    664             for (PluginProxy p : pluginList) {
    665                 String baseClass = p.getPluginInformation().className;
    666                 int i = baseClass.lastIndexOf(".");
    667                 baseClass = baseClass.substring(0, i);
    668                 for (StackTraceElement element : e.getStackTrace()) {
    669                     String c = element.getClassName();
    670                     if (c.startsWith(baseClass)) {
    671                         plugin = p;
    672                         break;
    673                     }
     773            plugin = getPluginCausingException(e);
     774        }
     775
     776        if (plugin != null && confirmDisablingPluginAfterException(plugin)) {
     777            List<String> plugins = new ArrayList<String>(Main.pref.getCollection("plugins", Collections
     778                    .<String> emptyList()));
     779            if (plugins.contains(plugin.getPluginInformation().name)) {
     780                while (plugins.remove(plugin.getPluginInformation().name)) {
    674781                }
    675                 if (plugin != null) {
    676                     break;
    677                 }
    678             }
    679         }
    680 
    681         if (plugin != null) {
    682             ExtendedDialog dialog = new ExtendedDialog(
    683                     Main.parent,
    684                     tr("Disable plugin"),
    685                     new String[] {tr("Disable plugin"), tr("Cancel")}
    686             );
    687             dialog.setButtonIcons(new String[] {"dialogs/delete.png", "cancel.png"});
    688             dialog.setContent(
    689                     "<html>" +
    690                     tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", plugin.getPluginInformation().name)
    691                     + "<br>"
    692                     + (plugin.getPluginInformation().author != null
    693                             ? tr("According to the information within the plugin, the author is {0}.", plugin.getPluginInformation().author)
    694                                     : "")
    695                                     + "<br>"
    696                                     + tr("Try updating to the newest version of this plugin before reporting a bug.")
    697                                     + "<br>"
    698                                     + tr("Should the plugin be disabled?")
    699                                     + "</html>"
    700             );
    701             dialog.showDialog();
    702             int answer = dialog.getValue();
    703 
    704             if (answer == 1) {
    705                 List<String> plugins = new ArrayList<String>(Main.pref.getCollection("plugins", Collections.<String>emptyList()));
    706                 if (plugins.contains(plugin.getPluginInformation().name)) {
    707                     while (plugins.remove(plugin.getPluginInformation().name)) {}
    708                     Main.pref.putCollection("plugins", plugins);
    709                     JOptionPane.showMessageDialog(Main.parent,
    710                             tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."),
    711                             tr("Information"),
    712                             JOptionPane.INFORMATION_MESSAGE);
    713                 } else {
    714                     JOptionPane.showMessageDialog(
    715                             Main.parent,
    716                             tr("The plugin could not be removed. Probably it was already disabled"),
    717                             tr("Error"),
    718                             JOptionPane.ERROR_MESSAGE
    719                     );
    720                 }
    721                 return true;
    722             }
     782                Main.pref.putCollection("plugins", plugins);
     783                JOptionPane
     784                .showMessageDialog(
     785                        Main.parent,
     786                        tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."),
     787                        tr("Information"), JOptionPane.INFORMATION_MESSAGE);
     788            } else {
     789                JOptionPane.showMessageDialog(Main.parent,
     790                        tr("The plugin could not be removed. Probably it was already disabled"), tr("Error"),
     791                        JOptionPane.ERROR_MESSAGE);
     792            }
     793            return true;
    723794        }
    724795        return false;
     
    778849        return pluginTab;
    779850    }
     851
     852    static private class UpdatePluginsMessagePanel extends JPanel {
     853        private JMultilineLabel lblMessage;
     854        private JCheckBox cbDontShowAgain;
     855
     856        protected void build() {
     857            setLayout(new GridBagLayout());
     858            GridBagConstraints gc = new GridBagConstraints();
     859            gc.anchor = GridBagConstraints.NORTHWEST;
     860            gc.fill = GridBagConstraints.BOTH;
     861            gc.weightx = 1.0;
     862            gc.weighty = 1.0;
     863            gc.insets = new Insets(5,5,5,5);
     864            add(lblMessage = new JMultilineLabel(""), gc);
     865            lblMessage.setFont(lblMessage.getFont().deriveFont(Font.PLAIN));
     866
     867            gc.gridy = 1;
     868            gc.fill = GridBagConstraints.HORIZONTAL;
     869            gc.weighty = 0.0;
     870            add(cbDontShowAgain = new JCheckBox(tr("Do not show again (remembers choice)")), gc);
     871            cbDontShowAgain.setFont(cbDontShowAgain.getFont().deriveFont(Font.PLAIN));
     872        }
     873
     874        public UpdatePluginsMessagePanel() {
     875            build();
     876        }
     877
     878        public void setMessage(String message) {
     879            lblMessage.setText(message);
     880        }
     881
     882        public void initDontShowAgain(String preferencesKey) {
     883            cbDontShowAgain.setSelected(Main.pref.getBoolean(preferencesKey, false));
     884        }
     885
     886        public void rememberDontShowAgain(String preferenceKey) {
     887            Main.pref.put(preferenceKey, cbDontShowAgain.isSelected());
     888        }
     889    }
    780890}
Note: See TracChangeset for help on using the changeset viewer.