Skip to content

Commit b66ed5e

Browse files
committed
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.
1 parent 3263967 commit b66ed5e

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.util.LinkedList;
4242
import java.util.List;
4343
import java.util.Optional;
44-
import java.util.function.Predicate;
4544

4645
import javax.swing.Box;
4746
import javax.swing.JComboBox;
@@ -67,7 +66,6 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
6766

6867
private final JComboBox typeChooser;
6968
private final LibraryInstaller installer;
70-
private Predicate<ContributedLibraryReleases> typeFilter;
7169

7270
@Override
7371
protected FilteredAbstractTableModel createContribModel() {
@@ -116,17 +114,16 @@ public LibraryManagerUI(Frame parent, LibraryInstaller installer) {
116114
}
117115

118116
protected final ActionListener typeChooserActionListener = new ActionListener() {
119-
120117
@Override
121118
public void actionPerformed(ActionEvent event) {
122119
DropdownItem<ContributedLibraryReleases> selected = (DropdownItem<ContributedLibraryReleases>) typeChooser.getSelectedItem();
123120
previousRowAtPoint = -1;
124-
if (selected != null && typeFilter != selected.getFilterPredicate()) {
125-
typeFilter = selected.getFilterPredicate();
121+
if (selected != null && extraFilter != selected.getFilterPredicate()) {
122+
extraFilter = selected.getFilterPredicate();
126123
if (contribTable.getCellEditor() != null) {
127124
contribTable.getCellEditor().stopCellEditing();
128125
}
129-
updateIndexFilter(filters, categoryFilter.and(typeFilter));
126+
updateIndexFilter(filters, categoryFilter.and(extraFilter));
130127
}
131128
}
132129
};
@@ -159,7 +156,7 @@ public void updateUI() {
159156
categoryChooser.setSelectedIndex(0);
160157

161158
// Load types
162-
typeFilter = x -> true;
159+
extraFilter = x -> true;
163160
typeChooser.removeActionListener(typeChooserActionListener);
164161
typeChooser.removeAllItems();
165162
typeChooser.addItem(new DropdownAllLibraries());

app/src/cc/arduino/contributions/ui/InstallerJDialog.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
8181
protected final FilterJTextField filterField;
8282
protected final JPanel filtersContainer;
8383
// Currently selected category and filters
84+
protected Predicate<T> extraFilter = x -> true;
8485
protected Predicate<T> categoryFilter;
8586
protected String[] filters;
8687
protected final String noConnectionErrorMessage;
@@ -337,7 +338,7 @@ public void actionPerformed(ActionEvent event) {
337338
if (contribTable.getCellEditor() != null) {
338339
contribTable.getCellEditor().stopCellEditing();
339340
}
340-
updateIndexFilter(filters, categoryFilter);
341+
updateIndexFilter(filters, categoryFilter.and(extraFilter));
341342
}
342343
}
343344
};

0 commit comments

Comments
 (0)