mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-25 06:22:11 +03:00
LibraryManager: better type filtering
This commit is contained in:
@ -0,0 +1,39 @@
|
||||
package cc.arduino.contributions.libraries.filters;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndex;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class InstalledLibraryPredicate implements Predicate<ContributedLibrary> {
|
||||
|
||||
private final LibrariesIndex index;
|
||||
|
||||
public InstalledLibraryPredicate(LibrariesIndex index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary input) {
|
||||
if (input.isInstalled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Collection<ContributedLibrary> installed = Collections2.filter(index.find(input.getName()), new Predicate<ContributedLibrary>() {
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary input) {
|
||||
return input.isInstalled();
|
||||
}
|
||||
});
|
||||
|
||||
return !installed.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof InstalledLibraryPredicate;
|
||||
}
|
||||
|
||||
}
|
@ -33,6 +33,7 @@ import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.ContributedLibraryComparator;
|
||||
import cc.arduino.contributions.libraries.filters.BuiltInPredicate;
|
||||
import cc.arduino.contributions.libraries.filters.InstalledLibraryPredicate;
|
||||
import cc.arduino.contributions.libraries.filters.OnlyUpstreamReleasePredicate;
|
||||
import cc.arduino.contributions.ui.InstallerTableCell;
|
||||
import cc.arduino.contributions.ui.listeners.DelegatingKeyListener;
|
||||
@ -65,6 +66,7 @@ import static processing.app.I18n.format;
|
||||
@SuppressWarnings("serial")
|
||||
public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
|
||||
private final LibraryManagerUI indexer;
|
||||
private JPanel panel;
|
||||
private JButton installButton;
|
||||
private Component installButtonPlaceholder;
|
||||
@ -75,7 +77,9 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
private JPanel inactiveButtonsPanel;
|
||||
private JLabel statusLabel;
|
||||
|
||||
public ContributedLibraryTableCell() {
|
||||
public ContributedLibraryTableCell(LibraryManagerUI indexer) {
|
||||
this.indexer = indexer;
|
||||
|
||||
{
|
||||
installButton = new JButton(_("Install"));
|
||||
installButton.addActionListener(new ActionListener() {
|
||||
|
@ -0,0 +1,27 @@
|
||||
package cc.arduino.contributions.libraries.ui;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndex;
|
||||
import cc.arduino.contributions.libraries.filters.InstalledLibraryPredicate;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
public class DropdownInstalledLibraryItem implements DropdownItem<ContributedLibrary> {
|
||||
|
||||
private final LibrariesIndex index;
|
||||
|
||||
public DropdownInstalledLibraryItem(LibrariesIndex index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return _("Installed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<ContributedLibrary> getFilterPredicate() {
|
||||
return new InstalledLibraryPredicate(index);
|
||||
}
|
||||
}
|
@ -39,7 +39,6 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
@ -62,12 +61,12 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
|
||||
@Override
|
||||
protected InstallerTableCell createCellRenderer() {
|
||||
return new ContributedLibraryTableCell();
|
||||
return new ContributedLibraryTableCell(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstallerTableCell createCellEditor() {
|
||||
return new ContributedLibraryTableCell() {
|
||||
return new ContributedLibraryTableCell(this) {
|
||||
@Override
|
||||
protected void onInstall(ContributedLibrary selectedLibrary, ContributedLibrary installedLibrary) {
|
||||
if (selectedLibrary.isReadOnly()) {
|
||||
@ -150,7 +149,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
typeFilter = null;
|
||||
typeChooser.removeAllItems();
|
||||
typeChooser.addItem(new DropdownAllItem());
|
||||
typeChooser.addItem(new DropdownInstalledContributionItem());
|
||||
typeChooser.addItem(new DropdownInstalledLibraryItem(indexer.getIndex()));
|
||||
Collection<String> types = indexer.getIndex().getTypes();
|
||||
for (String type : types) {
|
||||
typeChooser.addItem(new DropdownLibraryOfTypeItem(type));
|
||||
@ -169,6 +168,10 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
};
|
||||
}
|
||||
|
||||
public LibrariesIndexer getIndexer() {
|
||||
return indexer;
|
||||
}
|
||||
|
||||
public void setProgress(Progress progress) {
|
||||
progressBar.setValue(progress);
|
||||
}
|
||||
|
@ -1,20 +0,0 @@
|
||||
package cc.arduino.contributions.ui;
|
||||
|
||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
public class DropdownInstalledContributionItem implements DropdownItem<DownloadableContribution> {
|
||||
|
||||
public String toString() {
|
||||
return _("Installed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<DownloadableContribution> getFilterPredicate() {
|
||||
return new InstalledPredicate();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user