Changeset 13799 in josm


Ignore:
Timestamp:
2018-05-21T00:57:38+02:00 (4 weeks ago)
Author:
Don-vip
Message:

fix #16220 - filter plugins by installation state

Location:
trunk/src/org/openstreetmap/josm/gui/preferences/plugin
Files:
1 added
3 edited

Legend:

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

    r13111 r13799  
    100100        hint.setText(
    101101                "<html>"
    102                 + tr("Please click on <strong>Download list</strong> to download and display a list of available plugins.")
     102                + (model.getAvailablePlugins().isEmpty() ?
     103                        tr("Please click on <strong>Download list</strong> to download and display a list of available plugins.") :
     104                        tr("The filter returned no results."))
    103105                + "</html>"
    104106        );
     
    107109
    108110    /**
    109      * Refreshes the list.
     111     * Displays a list of plugins.
     112     * @param displayedPlugins list of plugins
     113     * @since 13799
    110114     */
    111     public void refreshView() {
    112         final Rectangle visibleRect = getVisibleRect();
    113         List<PluginInformation> displayedPlugins = model.getDisplayedPlugins();
    114         removeAll();
    115 
     115    public void displayPluginList(List<PluginInformation> displayedPlugins) {
    116116        GridBagConstraints gbc = new GridBagConstraints();
    117117        gbc.gridx = 0;
     
    119119        gbc.fill = GridBagConstraints.HORIZONTAL;
    120120        gbc.weightx = 1.0;
    121 
    122         if (displayedPlugins.isEmpty()) {
    123             displayEmptyPluginListInformation();
    124             return;
    125         }
    126121
    127122        int row = -1;
     
    164159            add(description, gbc);
    165160        }
     161    }
     162
     163    /**
     164     * Refreshes the list.
     165     */
     166    public void refreshView() {
     167        final Rectangle visibleRect = getVisibleRect();
     168        List<PluginInformation> displayedPlugins = model.getDisplayedPlugins();
     169        removeAll();
     170
     171        if (displayedPlugins.isEmpty()) {
     172            displayEmptyPluginListInformation();
     173        } else {
     174            displayPluginList(displayedPlugins);
     175        }
    166176        revalidate();
    167177        repaint();
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java

    r13431 r13799  
    2727import javax.swing.AbstractAction;
    2828import javax.swing.BorderFactory;
     29import javax.swing.ButtonGroup;
    2930import javax.swing.DefaultListModel;
    3031import javax.swing.JButton;
     
    3435import javax.swing.JOptionPane;
    3536import javax.swing.JPanel;
     37import javax.swing.JRadioButton;
    3638import javax.swing.JScrollPane;
    3739import javax.swing.JTabbedPane;
     
    177179        gc.weightx = 0.0;
    178180        gc.insets = new Insets(0, 0, 0, 3);
     181        pnl.add(GBC.glue(0, 0));
     182
     183        gc.weightx = 1.0;
     184        ButtonGroup bg = new ButtonGroup();
     185        JPanel radios = new JPanel();
     186        addRadioButton(bg, radios, new JRadioButton(tr("All"), true), gc, PluginInstallation.ALL);
     187        addRadioButton(bg, radios, new JRadioButton(tr("Installed")), gc, PluginInstallation.INSTALLED);
     188        addRadioButton(bg, radios, new JRadioButton(tr("Available")), gc, PluginInstallation.AVAILABLE);
     189        pnl.add(radios, gc);
     190
     191        gc.gridx = 0;
     192        gc.weightx = 0.0;
    179193        pnl.add(new JLabel(tr("Search:")), gc);
    180194
     
    187201        tfFilter.getDocument().addDocumentListener(new SearchFieldAdapter());
    188202        return pnl;
     203    }
     204
     205    private void addRadioButton(ButtonGroup bg, JPanel pnl, JRadioButton rb, GridBagConstraints gc, PluginInstallation value) {
     206        bg.add(rb);
     207        pnl.add(rb, gc);
     208        rb.addActionListener(e -> {
     209            model.filterDisplayedPlugins(value);
     210            pnlPluginPreferences.refreshView();
     211        });
    189212    }
    190213
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesModel.java

    r12846 r13799  
    2929    private final Set<String> currentActivePlugins;
    3030    private final List<PluginInformation> availablePlugins = new ArrayList<>();
     31    private PluginInstallation filterStatus;
    3132    private String filterExpression;
    3233    private final List<PluginInformation> displayedPlugins = new ArrayList<>();
     
    4445
    4546    /**
    46      * Filters the list of displayed plugins.
     47     * Filters the list of displayed plugins by installation status.
     48     * @param status The filter used against installation status
     49     * @since 13799
     50     */
     51    public void filterDisplayedPlugins(PluginInstallation status) {
     52        if (status == null) {
     53            displayedPlugins.clear();
     54            displayedPlugins.addAll(availablePlugins);
     55            this.filterStatus = null;
     56            return;
     57        }
     58        displayedPlugins.clear();
     59        for (PluginInformation pi: availablePlugins) {
     60            boolean installed = currentActivePlugins.contains(pi.getName());
     61            if (PluginInstallation.ALL == status
     62            || (PluginInstallation.INSTALLED == status && installed)
     63            || (PluginInstallation.AVAILABLE == status && !installed)) {
     64                displayedPlugins.add(pi);
     65            }
     66        }
     67        filterStatus = status;
     68        fireStateChanged();
     69    }
     70
     71    /**
     72     * Filters the list of displayed plugins by text.
    4773     * @param filter The filter used against plugin name, description or version
    4874     */
     
    78104    protected final void availablePluginsModified() {
    79105        sort();
     106        filterDisplayedPlugins(filterStatus);
    80107        filterDisplayedPlugins(filterExpression);
    81108        Set<String> activePlugins = new HashSet<>();
Note: See TracChangeset for help on using the changeset viewer.