Ignore:
Timestamp:
2010-03-06T12:37:34+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed #4443: Plugins with known update site: Don't download unless a new version is available
fixed #4565: local version differs from local version of updated plugin (was: local version number lost, after update plugin list.)

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

Legend:

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

    r3088 r3090  
    1717import java.util.Collection;
    1818import java.util.Collections;
     19import java.util.Iterator;
    1920import java.util.LinkedList;
    2021import java.util.List;
     
    7778            sb.append("<ul>");
    7879            for(PluginInformation pi: downloaded) {
    79                 sb.append("<li>").append(pi.name).append("</li>");
     80                sb.append("<li>").append(pi.name).append(" (").append(pi.version).append(")").append("</li>");
    8081            }
    8182            sb.append("</ul>");
     
    283284                    SwingUtilities.invokeLater(new Runnable() {
    284285                        public void run() {
    285                             model.setAvailablePlugins(task.getAvailabePlugins());
     286                            model.updateAvailablePlugins(task.getAvailabePlugins());
    286287                            pnlPluginPreferences.refreshView();
    287 
    288288                        }
    289289                    });
     
    320320                    sb.toString(),
    321321                    tr("Update plugins"),
    322                     failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE,
     322                    !failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE,
    323323                            // FIXME: check help topic
    324324                            HelpUtil.ht("/Preferences/Plugin")
     
    326326        }
    327327
     328        protected void alertNothingToUpdate() {
     329            HelpAwareOptionPane.showOptionDialog(
     330                    pnlPluginPreferences,
     331                    tr("All installed plugins are up to date. JOSM does not have to download newer versions."),
     332                    tr("Plugins up to date"),
     333                    JOptionPane.INFORMATION_MESSAGE,
     334                    null // FIXME: provide help context
     335            );
     336        }
     337
    328338        public void actionPerformed(ActionEvent e) {
    329             List<PluginInformation> toUpdate = model.getSelectedPlugins();
     339            final List<PluginInformation> toUpdate = model.getSelectedPlugins();
    330340            // the async task for downloading plugins
    331341            final PluginDownloadTask pluginDownloadTask = new PluginDownloadTask(
     
    345355                    notifyDownloadResults(pluginDownloadTask);
    346356                    model.refreshLocalPluginVersion(pluginDownloadTask.getDownloadedPlugins());
     357                    model.clearPendingPlugins(pluginDownloadTask.getDownloadedPlugins());
    347358                    pnlPluginPreferences.refreshView();
    348359                }
     
    355366                    if (pluginInfoDownloadTask.isCanceled())
    356367                        return;
     368                    model.updateAvailablePlugins(pluginInfoDownloadTask.getAvailabePlugins());
     369                    // select plugins which actually have to be updated
     370                    //
     371                    Iterator<PluginInformation> it = toUpdate.iterator();
     372                    while(it.hasNext()) {
     373                        PluginInformation pi = it.next();
     374                        if (!pi.isUpdateRequired()) {
     375                            it.remove();
     376                        }
     377                    }
     378                    if (toUpdate.isEmpty()) {
     379                        alertNothingToUpdate();
     380                        return;
     381                    }
     382                    pluginDownloadTask.setPluginsToDownload(toUpdate);
    357383                    Main.worker.submit(pluginDownloadTask);
    358384                    Main.worker.submit(pluginDownloadContinuation);
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesModel.java

    r3083 r3090  
    7474    }
    7575
     76    protected  void updateAvailablePlugin(PluginInformation other) {
     77        if (other == null) return;
     78        PluginInformation pi = getPluginInformation(other.name);
     79        if (pi == null) {
     80            availablePlugins.add(other);
     81            return;
     82        }
     83        pi.updateFromPluginSite(other);
     84    }
     85
     86    /**
     87     * Updates the list of plugin information objects with new information from
     88     * plugin update sites.
     89     *
     90     * @param fromPluginSite plugin information read from plugin update sites
     91     */
     92    public void updateAvailablePlugins(Collection<PluginInformation> fromPluginSite) {
     93        for (PluginInformation other: fromPluginSite) {
     94            updateAvailablePlugin(other);
     95        }
     96        sort();
     97        filterDisplayedPlugins(filterExpression);
     98        Set<String> activePlugins = new HashSet<String>();
     99        activePlugins.addAll(Main.pref.getCollection("plugins", activePlugins));
     100        for (PluginInformation pi: availablePlugins) {
     101            if (selectedPluginsMap.get(pi) == null) {
     102                if (activePlugins.contains(pi.name)) {
     103                    selectedPluginsMap.put(pi, true);
     104                }
     105            }
     106        }
     107        clearChanged();
     108        notifyObservers();
     109    }
     110
    76111    /**
    77112     * Replies the list of selected plugin information objects
     
    113148                new Comparator<PluginInformation>() {
    114149                    public int compare(PluginInformation o1, PluginInformation o2) {
    115                         String n1 = o1.getName() == null ? "" : o1.getName();
    116                         String n2 = o2.getName() == null ? "" : o2.getName();
     150                        String n1 = o1.getName() == null ? "" : o1.getName().toLowerCase();
     151                        String n2 = o2.getName() == null ? "" : o2.getName().toLowerCase();
    117152                        return n1.compareTo(n2);
    118153                    }
     
    164199        if (!selected) {
    165200            pendingDownloads.remove(name);
     201        }
     202    }
     203
     204    /**
     205     * Removes all the plugin in {@code plugins} from the list of plugins
     206     * with a pending download
     207     *
     208     * @param plugins the list of plugins to clear for a pending download
     209     */
     210    public void clearPendingPlugins(Collection<PluginInformation> plugins){
     211        if (plugins == null || plugins.isEmpty()) return;
     212        for(PluginInformation pi: plugins) {
     213            pendingDownloads.remove(pi.name);
    166214        }
    167215    }
Note: See TracChangeset for help on using the changeset viewer.