1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Simplified overly complex filtering of InstallerJDialog

- we ensure that there is always a filter selected, no more need
  to check for non-nullness
- the filters are always the same, no need to pass a
  Stream<Predicate<T>> around where Predicate<T> suffices
This commit is contained in:
Cristian Maglie 2017-12-17 20:30:35 +01:00
parent f111905da6
commit 212825eb55
5 changed files with 9 additions and 24 deletions

View File

@ -38,7 +38,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;
@SuppressWarnings("serial")
public class LibrariesIndexTableModel
@ -54,8 +53,8 @@ public class LibrariesIndexTableModel
String selectedFilters[] = null;
public void updateIndexFilter(String filters[],
Stream<Predicate<ContributedLibrary>> additionalFilters) {
selectedCategoryFilter = additionalFilters.reduce(Predicate::and).get();
Predicate<ContributedLibrary> additionalFilter) {
selectedCategoryFilter = additionalFilter;
selectedFilters = filters;
update();
}

View File

@ -118,24 +118,16 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
public void actionPerformed(ActionEvent event) {
DropdownItem<ContributedLibrary> selected = (DropdownItem<ContributedLibrary>) typeChooser.getSelectedItem();
previousRowAtPoint = -1;
if (typeFilter == null || typeFilter != selected.getFilterPredicate()) {
if (selected != null && typeFilter != selected.getFilterPredicate()) {
typeFilter = selected.getFilterPredicate();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
updateIndexFilter(filters, categoryFilter, typeFilter);
updateIndexFilter(filters, categoryFilter.and(typeFilter));
}
}
};
@Override
public void updateIndexFilter(String[] filters, Predicate<ContributedLibrary>... additionalFilters) {
if (additionalFilters.length == 1) {
additionalFilters = new Predicate[]{additionalFilters[0], typeFilter};
}
super.updateIndexFilter(filters, additionalFilters);
}
public void updateUI() {
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser.getSelectedItem();
DropdownItem<DownloadableContribution> previouslySelectedType = (DropdownItem<DownloadableContribution>) typeChooser.getSelectedItem();

View File

@ -39,7 +39,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@SuppressWarnings("serial")
public class ContributionIndexTableModel
@ -50,10 +49,8 @@ public class ContributionIndexTableModel
private final Class<?>[] columnTypes = { ContributedPlatform.class };
public void updateIndexFilter(String[] filters,
Stream<Predicate<ContributedPlatform>> additionalFilters) {
Predicate<ContributedPlatform> filter) {
contributions.clear();
Predicate<ContributedPlatform> filter = additionalFilters
.reduce(Predicate::and).get();
for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) {
for (ContributedPlatform platform : pack.getPlatforms()) {
String compoundTargetSearchText = platform.getName() + "\n"

View File

@ -37,11 +37,10 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;
public abstract class FilteredAbstractTableModel<T> extends AbstractTableModel {
abstract public void updateIndexFilter(String[] filters, Stream<Predicate<T>> additionalFilters);
abstract public void updateIndexFilter(String[] filters, Predicate<T> additionalFilter);
public static <T extends DownloadableContribution> T getLatestOf(List<T> contribs) {
contribs = new LinkedList<>(contribs);

View File

@ -46,7 +46,6 @@ import java.awt.event.WindowEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.function.Predicate;
import java.util.stream.Stream;
import javax.swing.Box;
import javax.swing.BoxLayout;
@ -265,9 +264,8 @@ public abstract class InstallerJDialog<T> extends JDialog {
SwingUtilities.invokeLater(InstallerJDialog.this::onUpdatePressed);
}
public void updateIndexFilter(String[] filters, Predicate<T>... additionalFilters) {
Stream<Predicate<T>> notNullAdditionalFilters = Stream.of(additionalFilters).filter(filter -> filter != null);
contribModel.updateIndexFilter(filters, notNullAdditionalFilters);
public void updateIndexFilter(String[] filters, Predicate<T> additionalFilter) {
contribModel.updateIndexFilter(filters, additionalFilter);
}
public void setErrorMessage(String message) {
@ -311,7 +309,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
public void actionPerformed(ActionEvent event) {
DropdownItem<T> selected = (DropdownItem<T>) categoryChooser.getSelectedItem();
previousRowAtPoint = -1;
if (categoryFilter == null || categoryFilter != selected.getFilterPredicate()) {
if (selected != null && categoryFilter != selected.getFilterPredicate()) {
categoryFilter = selected.getFilterPredicate();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();