mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-26 20:54:22 +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:
parent
f111905da6
commit
212825eb55
@ -38,7 +38,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class LibrariesIndexTableModel
|
public class LibrariesIndexTableModel
|
||||||
@ -54,8 +53,8 @@ public class LibrariesIndexTableModel
|
|||||||
String selectedFilters[] = null;
|
String selectedFilters[] = null;
|
||||||
|
|
||||||
public void updateIndexFilter(String filters[],
|
public void updateIndexFilter(String filters[],
|
||||||
Stream<Predicate<ContributedLibrary>> additionalFilters) {
|
Predicate<ContributedLibrary> additionalFilter) {
|
||||||
selectedCategoryFilter = additionalFilters.reduce(Predicate::and).get();
|
selectedCategoryFilter = additionalFilter;
|
||||||
selectedFilters = filters;
|
selectedFilters = filters;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -118,24 +118,16 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
|||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
DropdownItem<ContributedLibrary> selected = (DropdownItem<ContributedLibrary>) typeChooser.getSelectedItem();
|
DropdownItem<ContributedLibrary> selected = (DropdownItem<ContributedLibrary>) typeChooser.getSelectedItem();
|
||||||
previousRowAtPoint = -1;
|
previousRowAtPoint = -1;
|
||||||
if (typeFilter == null || typeFilter != selected.getFilterPredicate()) {
|
if (selected != null && typeFilter != selected.getFilterPredicate()) {
|
||||||
typeFilter = selected.getFilterPredicate();
|
typeFilter = selected.getFilterPredicate();
|
||||||
if (contribTable.getCellEditor() != null) {
|
if (contribTable.getCellEditor() != null) {
|
||||||
contribTable.getCellEditor().stopCellEditing();
|
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() {
|
public void updateUI() {
|
||||||
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser.getSelectedItem();
|
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser.getSelectedItem();
|
||||||
DropdownItem<DownloadableContribution> previouslySelectedType = (DropdownItem<DownloadableContribution>) typeChooser.getSelectedItem();
|
DropdownItem<DownloadableContribution> previouslySelectedType = (DropdownItem<DownloadableContribution>) typeChooser.getSelectedItem();
|
||||||
|
@ -39,7 +39,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ContributionIndexTableModel
|
public class ContributionIndexTableModel
|
||||||
@ -50,10 +49,8 @@ public class ContributionIndexTableModel
|
|||||||
private final Class<?>[] columnTypes = { ContributedPlatform.class };
|
private final Class<?>[] columnTypes = { ContributedPlatform.class };
|
||||||
|
|
||||||
public void updateIndexFilter(String[] filters,
|
public void updateIndexFilter(String[] filters,
|
||||||
Stream<Predicate<ContributedPlatform>> additionalFilters) {
|
Predicate<ContributedPlatform> filter) {
|
||||||
contributions.clear();
|
contributions.clear();
|
||||||
Predicate<ContributedPlatform> filter = additionalFilters
|
|
||||||
.reduce(Predicate::and).get();
|
|
||||||
for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) {
|
for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) {
|
||||||
for (ContributedPlatform platform : pack.getPlatforms()) {
|
for (ContributedPlatform platform : pack.getPlatforms()) {
|
||||||
String compoundTargetSearchText = platform.getName() + "\n"
|
String compoundTargetSearchText = platform.getName() + "\n"
|
||||||
|
@ -37,11 +37,10 @@ import java.util.Collections;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public abstract class FilteredAbstractTableModel<T> extends AbstractTableModel {
|
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) {
|
public static <T extends DownloadableContribution> T getLatestOf(List<T> contribs) {
|
||||||
contribs = new LinkedList<>(contribs);
|
contribs = new LinkedList<>(contribs);
|
||||||
|
@ -46,7 +46,6 @@ import java.awt.event.WindowEvent;
|
|||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseMotionListener;
|
import java.awt.event.MouseMotionListener;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
@ -265,9 +264,8 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
|||||||
SwingUtilities.invokeLater(InstallerJDialog.this::onUpdatePressed);
|
SwingUtilities.invokeLater(InstallerJDialog.this::onUpdatePressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateIndexFilter(String[] filters, Predicate<T>... additionalFilters) {
|
public void updateIndexFilter(String[] filters, Predicate<T> additionalFilter) {
|
||||||
Stream<Predicate<T>> notNullAdditionalFilters = Stream.of(additionalFilters).filter(filter -> filter != null);
|
contribModel.updateIndexFilter(filters, additionalFilter);
|
||||||
contribModel.updateIndexFilter(filters, notNullAdditionalFilters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setErrorMessage(String message) {
|
public void setErrorMessage(String message) {
|
||||||
@ -311,7 +309,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
|||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
DropdownItem<T> selected = (DropdownItem<T>) categoryChooser.getSelectedItem();
|
DropdownItem<T> selected = (DropdownItem<T>) categoryChooser.getSelectedItem();
|
||||||
previousRowAtPoint = -1;
|
previousRowAtPoint = -1;
|
||||||
if (categoryFilter == null || categoryFilter != selected.getFilterPredicate()) {
|
if (selected != null && categoryFilter != selected.getFilterPredicate()) {
|
||||||
categoryFilter = selected.getFilterPredicate();
|
categoryFilter = selected.getFilterPredicate();
|
||||||
if (contribTable.getCellEditor() != null) {
|
if (contribTable.getCellEditor() != null) {
|
||||||
contribTable.getCellEditor().stopCellEditing();
|
contribTable.getCellEditor().stopCellEditing();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user