Changeset 17785 in josm


Ignore:
Timestamp:
2021-04-14T21:21:33+02:00 (3 years ago)
Author:
simon04
Message:

see #20720 - Filtering in plugins list in preferences is slow (simplify)

File:
1 edited

Legend:

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

    r17784 r17785  
    1010import java.awt.event.MouseAdapter;
    1111import java.awt.event.MouseEvent;
    12 import java.util.ArrayList;
     12import java.util.Collections;
    1313import java.util.HashSet;
    1414import java.util.List;
     
    113113        );
    114114        hint.putClientProperty("plugin", "empty");
     115        hint.setVisible(false);
    115116        add(hint, gbc);
    116117    }
     
    170171            add(description, gbc);
    171172        }
    172 
    173173        pluginListInitialized = true;
    174174    }
     
    182182    public void refreshView() {
    183183        final Rectangle visibleRect = getVisibleRect();
    184         List<PluginInformation> displayedPlugins = model.getDisplayedPlugins();
    185 
    186         if (displayedPlugins.isEmpty()) {
    187             hidePluginsNotInList(new ArrayList<>());
     184        if (!pluginListInitialized) {
     185            removeAll();
    188186            displayEmptyPluginListInformation();
    189         } else if (!pluginListInitialized) {
    190             removeAll();
    191             displayPluginList(displayedPlugins);
     187            displayPluginList(model.getAvailablePlugins());
    192188        } else {
    193             hidePluginsNotInList(displayedPlugins);
     189            hidePluginsNotInList(new HashSet<>(model.getDisplayedPlugins()));
    194190        }
    195191        revalidate();
     
    205201     * those that shouldn't be visible.
    206202     *
    207      * @param displayedPlugins A collection of plugins that are currently visible.
    208      */
    209     private void hidePluginsNotInList(List<PluginInformation> displayedPlugins) {
    210         // Remove the empty plugin list warning if it's there
    211         synchronized (getTreeLock()) {
    212             for (int i = 0; i < getComponentCount(); i++) {
    213                 JComponent component = (JComponent) getComponent(i);
    214                 if ("empty".equals(component.getClientProperty("plugin"))) {
    215                     remove(component);
    216                 }
    217             }
    218         }
    219 
    220         Set<PluginInformation> displayedPluginsSet = new HashSet<>(displayedPlugins);
     203     * @param displayedPlugins A set of plugins that are currently visible.
     204     */
     205    private void hidePluginsNotInList(Set<PluginInformation> displayedPlugins) {
    221206        synchronized (getTreeLock()) {
    222207            for (int i = 0; i < getComponentCount(); i++) {
    223208                JComponent component = (JComponent) getComponent(i);
    224209                Object plugin = component.getClientProperty("plugin");
    225                 component.setVisible(displayedPluginsSet.contains(plugin));
     210                if ("empty".equals(plugin)) {
     211                    // Hide the empty plugin list warning if it's there
     212                    component.setVisible(displayedPlugins.isEmpty());
     213                } else {
     214                    component.setVisible(displayedPlugins.contains(plugin));
     215                }
    226216            }
    227217        }
Note: See TracChangeset for help on using the changeset viewer.