1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-01 21:52:12 +01:00

LibraryManager: correctly apply "type" and "category" filters together

Previously changing "Category" would filter libraries by the selected
category but without applying the "Type" previously selected.
For instance selecting Type="Installed" and Category="Communication"
will display *all* the libraries belonging to "communication" instead of
the installed only.

This commit fix this behavior.
This commit is contained in:
Cristian Maglie 2020-06-29 17:27:11 +02:00
parent 3263967893
commit b66ed5e5d7
2 changed files with 6 additions and 8 deletions

View File

@ -41,7 +41,6 @@ import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.function.Predicate;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.JComboBox; import javax.swing.JComboBox;
@ -67,7 +66,6 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
private final JComboBox typeChooser; private final JComboBox typeChooser;
private final LibraryInstaller installer; private final LibraryInstaller installer;
private Predicate<ContributedLibraryReleases> typeFilter;
@Override @Override
protected FilteredAbstractTableModel createContribModel() { protected FilteredAbstractTableModel createContribModel() {
@ -116,17 +114,16 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
} }
protected final ActionListener typeChooserActionListener = new ActionListener() { protected final ActionListener typeChooserActionListener = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
DropdownItem<ContributedLibraryReleases> selected = (DropdownItem<ContributedLibraryReleases>) typeChooser.getSelectedItem(); DropdownItem<ContributedLibraryReleases> selected = (DropdownItem<ContributedLibraryReleases>) typeChooser.getSelectedItem();
previousRowAtPoint = -1; previousRowAtPoint = -1;
if (selected != null && typeFilter != selected.getFilterPredicate()) { if (selected != null && extraFilter != selected.getFilterPredicate()) {
typeFilter = selected.getFilterPredicate(); extraFilter = selected.getFilterPredicate();
if (contribTable.getCellEditor() != null) { if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing(); contribTable.getCellEditor().stopCellEditing();
} }
updateIndexFilter(filters, categoryFilter.and(typeFilter)); updateIndexFilter(filters, categoryFilter.and(extraFilter));
} }
} }
}; };
@ -159,7 +156,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
categoryChooser.setSelectedIndex(0); categoryChooser.setSelectedIndex(0);
// Load types // Load types
typeFilter = x -> true; extraFilter = x -> true;
typeChooser.removeActionListener(typeChooserActionListener); typeChooser.removeActionListener(typeChooserActionListener);
typeChooser.removeAllItems(); typeChooser.removeAllItems();
typeChooser.addItem(new DropdownAllLibraries()); typeChooser.addItem(new DropdownAllLibraries());

View File

@ -81,6 +81,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
protected final FilterJTextField filterField; protected final FilterJTextField filterField;
protected final JPanel filtersContainer; protected final JPanel filtersContainer;
// Currently selected category and filters // Currently selected category and filters
protected Predicate<T> extraFilter = x -> true;
protected Predicate<T> categoryFilter; protected Predicate<T> categoryFilter;
protected String[] filters; protected String[] filters;
protected final String noConnectionErrorMessage; protected final String noConnectionErrorMessage;
@ -337,7 +338,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
if (contribTable.getCellEditor() != null) { if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing(); contribTable.getCellEditor().stopCellEditing();
} }
updateIndexFilter(filters, categoryFilter); updateIndexFilter(filters, categoryFilter.and(extraFilter));
} }
} }
}; };