mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-21 10:52:14 +01:00
Merge branch 'lib_manager_filters_fix' of https://github.com/cmaglie/Arduino (#10440)
This commit is contained in:
commit
bf24880d7c
@ -35,12 +35,12 @@ import java.awt.Dialog;
|
|||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
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;
|
||||||
@ -66,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() {
|
||||||
@ -115,63 +114,60 @@ 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public void updateUI() {
|
private Collection<String> oldCategories = new ArrayList<>();
|
||||||
DropdownItem<ContributedLibraryReleases> previouslySelectedCategory = (DropdownItem<ContributedLibraryReleases>) categoryChooser.getSelectedItem();
|
private Collection<String> oldTypes = new ArrayList<>();
|
||||||
DropdownItem<ContributedLibraryReleases> previouslySelectedType = (DropdownItem<ContributedLibraryReleases>) typeChooser.getSelectedItem();
|
|
||||||
|
|
||||||
categoryChooser.removeActionListener(categoryChooserActionListener);
|
public void updateUI() {
|
||||||
typeChooser.removeActionListener(typeChooserActionListener);
|
// Check if categories or types have changed
|
||||||
|
Collection<String> categories = BaseNoGui.librariesIndexer.getIndex().getCategories();
|
||||||
|
List<String> types = new LinkedList<>(BaseNoGui.librariesIndexer.getIndex().getTypes());
|
||||||
|
Collections.sort(types, new LibraryTypeComparator());
|
||||||
|
|
||||||
|
if (categories.equals(oldCategories) && types.equals(oldTypes)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
oldCategories = categories;
|
||||||
|
oldTypes = types;
|
||||||
|
|
||||||
// Load categories
|
// Load categories
|
||||||
categoryFilter = x -> true;
|
categoryFilter = x -> true;
|
||||||
|
categoryChooser.removeActionListener(categoryChooserActionListener);
|
||||||
categoryChooser.removeAllItems();
|
categoryChooser.removeAllItems();
|
||||||
categoryChooser.addItem(new DropdownAllLibraries());
|
categoryChooser.addItem(new DropdownAllLibraries());
|
||||||
Collection<String> categories = BaseNoGui.librariesIndexer.getIndex().getCategories();
|
|
||||||
for (String category : categories) {
|
for (String category : categories) {
|
||||||
categoryChooser.addItem(new DropdownLibraryOfCategoryItem(category));
|
categoryChooser.addItem(new DropdownLibraryOfCategoryItem(category));
|
||||||
}
|
}
|
||||||
|
|
||||||
categoryChooser.setEnabled(categoryChooser.getItemCount() > 1);
|
categoryChooser.setEnabled(categoryChooser.getItemCount() > 1);
|
||||||
|
|
||||||
categoryChooser.addActionListener(categoryChooserActionListener);
|
categoryChooser.addActionListener(categoryChooserActionListener);
|
||||||
if (previouslySelectedCategory != null) {
|
|
||||||
categoryChooser.setSelectedItem(previouslySelectedCategory);
|
|
||||||
} else {
|
|
||||||
categoryChooser.setSelectedIndex(0);
|
categoryChooser.setSelectedIndex(0);
|
||||||
}
|
|
||||||
|
|
||||||
typeFilter = x -> true;
|
// Load types
|
||||||
|
extraFilter = x -> true;
|
||||||
|
typeChooser.removeActionListener(typeChooserActionListener);
|
||||||
typeChooser.removeAllItems();
|
typeChooser.removeAllItems();
|
||||||
typeChooser.addItem(new DropdownAllLibraries());
|
typeChooser.addItem(new DropdownAllLibraries());
|
||||||
typeChooser.addItem(new DropdownUpdatableLibrariesItem());
|
typeChooser.addItem(new DropdownUpdatableLibrariesItem());
|
||||||
typeChooser.addItem(new DropdownInstalledLibraryItem());
|
typeChooser.addItem(new DropdownInstalledLibraryItem());
|
||||||
List<String> types = new LinkedList<>(BaseNoGui.librariesIndexer.getIndex().getTypes());
|
|
||||||
Collections.sort(types, new LibraryTypeComparator());
|
|
||||||
for (String type : types) {
|
for (String type : types) {
|
||||||
typeChooser.addItem(new DropdownLibraryOfTypeItem(type));
|
typeChooser.addItem(new DropdownLibraryOfTypeItem(type));
|
||||||
}
|
}
|
||||||
typeChooser.setEnabled(typeChooser.getItemCount() > 1);
|
typeChooser.setEnabled(typeChooser.getItemCount() > 1);
|
||||||
typeChooser.addActionListener(typeChooserActionListener);
|
typeChooser.addActionListener(typeChooserActionListener);
|
||||||
if (previouslySelectedType != null) {
|
|
||||||
typeChooser.setSelectedItem(previouslySelectedType);
|
|
||||||
} else {
|
|
||||||
typeChooser.setSelectedIndex(0);
|
typeChooser.setSelectedIndex(0);
|
||||||
}
|
|
||||||
|
|
||||||
filterField.setEnabled(contribModel.getRowCount() > 0);
|
filterField.setEnabled(contribModel.getRowCount() > 0);
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,6 @@ import javax.swing.text.DefaultEditorKit;
|
|||||||
|
|
||||||
import cc.arduino.contributions.ui.listeners.AbstractKeyListener;
|
import cc.arduino.contributions.ui.listeners.AbstractKeyListener;
|
||||||
import processing.app.Base;
|
import processing.app.Base;
|
||||||
import processing.app.Theme;
|
|
||||||
|
|
||||||
public abstract class InstallerJDialog<T> extends JDialog {
|
public abstract class InstallerJDialog<T> extends JDialog {
|
||||||
|
|
||||||
@ -82,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;
|
||||||
@ -329,7 +329,6 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected final ActionListener categoryChooserActionListener = new ActionListener() {
|
protected final ActionListener categoryChooserActionListener = new ActionListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
DropdownItem<T> selected = (DropdownItem<T>) categoryChooser.getSelectedItem();
|
DropdownItem<T> selected = (DropdownItem<T>) categoryChooser.getSelectedItem();
|
||||||
@ -339,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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user