Ignore:
Timestamp:
2016-01-24T15:06:37+01:00 (8 years ago)
Author:
Don-vip
Message:

update unit tests

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

Legend:

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

    r8846 r9611  
    7474    }
    7575
     76    private JosmTextField tfFilter;
     77    private PluginListPanel pnlPluginPreferences;
     78    private PluginPreferencesModel model;
     79    private JScrollPane spPluginPreferences;
     80    private PluginUpdatePolicyPanel pnlPluginUpdatePolicy;
     81
     82    /**
     83     * is set to true if this preference pane has been selected by the user
     84     */
     85    private boolean pluginPreferencesActivated;
     86
    7687    private PluginPreference() {
    7788        super(/* ICON(preferences/) */ "plugin", tr("Plugins"), tr("Configure available plugins."), false, new JTabbedPane());
     
    146157    }
    147158
    148     private JosmTextField tfFilter;
    149     private PluginListPanel pnlPluginPreferences;
    150     private PluginPreferencesModel model;
    151     private JScrollPane spPluginPreferences;
    152     private PluginUpdatePolicyPanel pnlPluginUpdatePolicy;
    153 
    154     /**
    155      * is set to true if this preference pane has been selected
    156      * by the user
    157      */
    158     private boolean pluginPreferencesActivated;
    159 
    160159    protected JPanel buildSearchFieldPanel() {
    161         JPanel pnl  = new JPanel(new GridBagLayout());
     160        JPanel pnl = new JPanel(new GridBagLayout());
    162161        pnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    163162        GridBagConstraints gc = new GridBagConstraints();
     
    268267
    269268    /**
    270      * Replies the list of plugins waiting for update or download
     269     * Replies the set of plugins waiting for update or download
    271270     *
    272      * @return the list of plugins waiting for update or download
     271     * @return the set of plugins waiting for update or download
    273272     */
    274273    public Set<PluginInformation> getPluginsScheduledForUpdateOrDownload() {
     
    276275    }
    277276
     277    /**
     278     * Replies the list of plugins which have been added by the user to the set of activated plugins
     279     *
     280     * @return the list of newly activated plugins
     281     */
    278282    public List<PluginInformation> getNewlyActivatedPlugins() {
    279283        return model != null ? model.getNewlyActivatedPlugins() : null;
     
    289293            Collections.sort(l);
    290294            Main.pref.putCollection("plugins", l);
    291             if (!model.getNewlyDeactivatedPlugins().isEmpty()) return true;
     295            if (!model.getNewlyDeactivatedPlugins().isEmpty())
     296                return true;
    292297            for (PluginInformation pi : model.getNewlyActivatedPlugins()) {
    293                 if (!pi.canloadatruntime) return true;
     298                if (!pi.canloadatruntime)
     299                    return true;
    294300            }
    295301        }
     
    308314            @Override
    309315            public void run() {
    310                 if (task.isCanceled()) return;
    311                 SwingUtilities.invokeLater(new Runnable() {
    312                     @Override
    313                     public void run() {
    314                         model.setAvailablePlugins(task.getAvailablePlugins());
    315                         pnlPluginPreferences.refreshView();
    316                     }
    317                 });
     316                if (!task.isCanceled()) {
     317                    SwingUtilities.invokeLater(new Runnable() {
     318                        @Override
     319                        public void run() {
     320                            model.setAvailablePlugins(task.getAvailablePlugins());
     321                            pnlPluginPreferences.refreshView();
     322                        }
     323                    });
     324                }
    318325            }
    319326        };
     
    346353                @Override
    347354                public void run() {
    348                     if (task.isCanceled()) return;
    349                     SwingUtilities.invokeLater(new Runnable() {
    350                         @Override
    351                         public void run() {
    352                             model.updateAvailablePlugins(task.getAvailablePlugins());
    353                             pnlPluginPreferences.refreshView();
    354                             Main.pref.putInteger("pluginmanager.version", Version.getInstance().getVersion()); // fix #7030
    355                         }
    356                     });
     355                    if (!task.isCanceled()) {
     356                        SwingUtilities.invokeLater(new Runnable() {
     357                            @Override
     358                            public void run() {
     359                                model.updateAvailablePlugins(task.getAvailablePlugins());
     360                                pnlPluginPreferences.refreshView();
     361                                Main.pref.putInteger("pluginmanager.version", Version.getInstance().getVersion()); // fix #7030
     362                            }
     363                        });
     364                    }
    357365                }
    358366            };
     
    512520    private static class PluginConfigurationSitesPanel extends JPanel {
    513521
    514         private DefaultListModel<String> model;
    515 
    516         protected final void build() {
    517             setLayout(new GridBagLayout());
     522        private final DefaultListModel<String> model = new DefaultListModel<>();
     523
     524        PluginConfigurationSitesPanel() {
     525            super(new GridBagLayout());
    518526            add(new JLabel(tr("Add JOSM Plugin description URL.")), GBC.eol());
    519             model = new DefaultListModel<>();
    520527            for (String s : Main.pref.getPluginSites()) {
    521528                model.addElement(s);
     
    582589        }
    583590
    584         PluginConfigurationSitesPanel() {
    585             build();
    586         }
    587 
    588591        public List<String> getUpdateSites() {
    589             if (model.getSize() == 0) return Collections.emptyList();
     592            if (model.getSize() == 0)
     593                return Collections.emptyList();
    590594            List<String> ret = new ArrayList<>(model.getSize());
    591595            for (int i = 0; i < model.getSize(); i++) {
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesModel.java

    r9078 r9611  
    8383        activePlugins.addAll(Main.pref.getCollection("plugins", activePlugins));
    8484        for (PluginInformation pi: availablePlugins) {
    85             if (selectedPluginsMap.get(pi) == null) {
    86                 if (activePlugins.contains(pi.name)) {
    87                     selectedPluginsMap.put(pi, Boolean.TRUE);
    88                 }
     85            if (selectedPluginsMap.get(pi) == null && activePlugins.contains(pi.name)) {
     86                selectedPluginsMap.put(pi, Boolean.TRUE);
    8987            }
    9088        }
     
    9492
    9593    protected void updateAvailablePlugin(PluginInformation other) {
    96         if (other == null) return;
    97         PluginInformation pi = getPluginInformation(other.name);
    98         if (pi == null) {
    99             availablePlugins.add(other);
    100             return;
    101         }
    102         pi.updateFromPluginSite(other);
     94        if (other != null) {
     95            PluginInformation pi = getPluginInformation(other.name);
     96            if (pi == null) {
     97                availablePlugins.add(other);
     98                return;
     99            }
     100            pi.updateFromPluginSite(other);
     101        }
    103102    }
    104103
     
    216215     */
    217216    public void clearPendingPlugins(Collection<PluginInformation> plugins) {
    218         if (plugins == null || plugins.isEmpty()) return;
    219         for (PluginInformation pi: plugins) {
    220             pendingDownloads.remove(pi.name);
     217        if (plugins != null) {
     218            for (PluginInformation pi: plugins) {
     219                pendingDownloads.remove(pi.name);
     220            }
    221221        }
    222222    }
     
    264264    public boolean isSelectedPlugin(String name) {
    265265        PluginInformation pi = getPluginInformation(name);
    266         if (pi == null) return false;
    267         if (selectedPluginsMap.get(pi) == null) return false;
     266        if (pi == null || selectedPluginsMap.get(pi) == null)
     267            return false;
    268268        return selectedPluginsMap.get(pi);
    269269    }
     
    273273     * the set of activated plugins.
    274274     *
    275      * @return the set of newly deactivated plugins
     275     * @return the set of newly activated plugins
    276276     */
    277277    public List<PluginInformation> getNewlyActivatedPlugins() {
     
    289289    /**
    290290     * Replies the set of plugins which have been removed by the user from
    291      * the set of activated plugins.
     291     * the set of deactivated plugins.
    292292     *
    293293     * @return the set of newly deactivated plugins
     
    349349     */
    350350    public void refreshLocalPluginVersion(Collection<PluginInformation> plugins) {
    351         if (plugins == null) return;
    352         for (PluginInformation pi : plugins) {
    353             File downloadedPluginFile = PluginHandler.findUpdatedJar(pi.name);
    354             if (downloadedPluginFile == null) {
    355                 continue;
    356             }
    357             try {
    358                 PluginInformation newinfo = new PluginInformation(downloadedPluginFile, pi.name);
    359                 PluginInformation oldinfo = getPluginInformation(pi.name);
    360                 if (oldinfo == null) {
    361                     // should not happen
     351        if (plugins != null) {
     352            for (PluginInformation pi : plugins) {
     353                File downloadedPluginFile = PluginHandler.findUpdatedJar(pi.name);
     354                if (downloadedPluginFile == null) {
    362355                    continue;
    363356                }
    364                 oldinfo.updateLocalInfo(newinfo);
    365             } catch (PluginException e) {
    366                 Main.error(e);
     357                try {
     358                    PluginInformation newinfo = new PluginInformation(downloadedPluginFile, pi.name);
     359                    PluginInformation oldinfo = getPluginInformation(pi.name);
     360                    if (oldinfo != null) {
     361                        oldinfo.updateLocalInfo(newinfo);
     362                    }
     363                } catch (PluginException e) {
     364                    Main.error(e);
     365                }
    367366            }
    368367        }
Note: See TracChangeset for help on using the changeset viewer.