Ignore:
Timestamp:
2010-01-11T21:06:49+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed #3063: Downloading a plugin yields 3 dialogs at the same time: Downloading plugin / You should restart JOSM / Plugin downloaded
fixed #3628: JOSM blocking itself updating broken plugin
fixed #4187: JOSM deleted random files from disk after start (data loss)
fixed #4199: new version - plugins update vs josm start [should be fixed. Be careful if you have two JOSM instances running. Auto-update of plugins in the second instance will fail because plugin files are locked by the first instance]
fixed #4034: JOSM should auto-download plugin list when it hasn't been downloaded before [JOSM now displays a hint]

fixed: splash screen showing again even if plugins are auto-updated
new: progress indication integrated in splash screen
new: cancelable, asynchronous download of plugins from preferences
new: cancelable, asynchronous download of plugin list from plugin download sites
new: asynchronous loading of plugin information, launch of preferences dialog accelerated
refactored: clean up, documentation of plugin management code (PluginHandler)

File:
1 edited

Legend:

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

    r2745 r2817  
    2323import javax.swing.JScrollPane;
    2424import javax.swing.JTabbedPane;
     25import javax.swing.SwingUtilities;
    2526
    2627import org.openstreetmap.josm.Main;
     28import org.openstreetmap.josm.plugins.PluginDownloadTask;
    2729import org.openstreetmap.josm.plugins.PluginHandler;
     30import org.openstreetmap.josm.plugins.PluginInformation;
    2831import org.openstreetmap.josm.tools.BugReportExceptionHandler;
    2932import org.openstreetmap.josm.tools.GBC;
     
    4750    public final JPanel map = createPreferenceTab("map", I18n.tr("Map Settings"), I18n.tr("Settings for the map projection and data interpretation."));
    4851    public final JPanel audio = createPreferenceTab("audio", I18n.tr("Audio Settings"), I18n.tr("Settings for the audio player and audio markers."));
     52    public final JPanel plugins = createPreferenceTab("plugin", tr("Plugins"), tr("Configure available plugins."), false);
    4953
    5054    public final javax.swing.JTabbedPane displaycontent = new javax.swing.JTabbedPane();
     
    9599    }
    96100
     101    protected PluginPreference getPluginPreference() {
     102        for (PreferenceSetting setting: settings) {
     103            if (setting instanceof PluginPreference)
     104                return (PluginPreference) setting;
     105        }
     106        return null;
     107    }
     108
    97109    public void savePreferences() {
    98         boolean requiresRestart = false;
    99         for (PreferenceSetting setting : settings)
    100         {
    101             if(setting.ok()) {
    102                 requiresRestart = true;
     110
     111        // create a task for downloading plugins if the user has activated, yet not downloaded,
     112        // new plugins
     113        //
     114        final PluginPreference preference = getPluginPreference();
     115        final List<PluginInformation> toDownload = preference.getPluginsScheduledForUpdateOrDownload();
     116        final PluginDownloadTask task;
     117        if (! toDownload.isEmpty()) {
     118            task = new PluginDownloadTask(this, toDownload, tr("Download plugins"));
     119        } else {
     120            task = null;
     121        }
     122
     123        // this is the task which will run *after* the plugins are downloaded
     124        //
     125        final Runnable continuation = new Runnable() {
     126            public void run() {
     127                boolean requiresRestart = false;
     128                if (task != null && !task.isCanceled()) {
     129                    if (!task.getDownloadedPlugins().isEmpty()) {
     130                        requiresRestart = true;
     131                    }
     132                }
     133
     134                for (PreferenceSetting setting : settings) {
     135                    if (setting.ok()) {
     136                        requiresRestart = true;
     137                    }
     138                }
     139
     140                // build the messages. We only display one message, including the status
     141                // information from the plugin download task and - if necessary - a hint
     142                // to restart JOSM
     143                //
     144                StringBuffer sb = new StringBuffer();
     145                sb.append("<html>");
     146                if (task != null && !task.isCanceled()) {
     147                    sb.append(PluginPreference.buildDownloadSummary(task));
     148                }
     149                if (requiresRestart) {
     150                    sb.append(tr("You have to restart JOSM for some settings to take effect."));
     151                }
     152                sb.append("</html>");
     153
     154                // display the message, if necessary
     155                //
     156                if ((task != null && !task.isCanceled()) || requiresRestart) {
     157                    JOptionPane.showMessageDialog(
     158                            Main.parent,
     159                            sb.toString(),
     160                            tr("Warning"),
     161                            JOptionPane.WARNING_MESSAGE
     162                    );
     163                }
     164                Main.parent.repaint();
    103165            }
    104         }
    105         if (requiresRestart) {
    106             JOptionPane.showMessageDialog(
    107                     Main.parent,
    108                     tr("You have to restart JOSM for some settings to take effect."),
    109                     tr("Warning"),
    110                     JOptionPane.WARNING_MESSAGE
     166        };
     167
     168        if (task != null) {
     169            // if we have to launch a plugin download task we do it asynchronously, followed
     170            // by the remaining "save preferences" activites run on the Swing EDT.
     171            //
     172            Main.worker.submit(task);
     173            Main.worker.submit(
     174                    new Runnable() {
     175                        public void run() {
     176                            SwingUtilities.invokeLater(continuation);
     177                        }
     178                    }
    111179            );
    112         }
    113         Main.parent.repaint();
     180        } else {
     181            // no need for asynchronous activities. Simply run the remaining "save preference"
     182            // activities on this thread (we are already on the Swing EDT
     183            //
     184            continuation.run();
     185        }
    114186    }
    115187
Note: See TracChangeset for help on using the changeset viewer.