mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Lib manager Predicates must act on ContributedLibraryReleases
Previously the filtering was made on ContributedLibrary, but the objects that is actually displayed is a ContributeLibraryReleases, so it comens natural to filter on this class of objects. Apparently the functionality is not affected by this commit, but there may be some side-effect that may probably fix some visualization bug.
This commit is contained in:
parent
482b905a62
commit
3ec6748dc4
@ -27,22 +27,22 @@
|
|||||||
* the GNU General Public License.
|
* the GNU General Public License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cc.arduino.contributions.ui;
|
package cc.arduino.contributions.libraries.ui;
|
||||||
|
|
||||||
import cc.arduino.contributions.DownloadableContribution;
|
import cc.arduino.contributions.ui.DropdownItem;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static processing.app.I18n.tr;
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
public class DropdownAllItem implements DropdownItem<DownloadableContribution> {
|
public class DropdownAllLibraries implements DropdownItem<ContributedLibraryReleases> {
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return tr("All");
|
return tr("All");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<DownloadableContribution> getFilterPredicate() {
|
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
|
||||||
return x -> true;
|
return x -> true;
|
||||||
}
|
}
|
||||||
|
|
@ -29,23 +29,26 @@
|
|||||||
|
|
||||||
package cc.arduino.contributions.libraries.ui;
|
package cc.arduino.contributions.libraries.ui;
|
||||||
|
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import static processing.app.I18n.tr;
|
||||||
import cc.arduino.contributions.libraries.filters.InstalledLibraryPredicate;
|
|
||||||
import cc.arduino.contributions.ui.DropdownItem;
|
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static processing.app.I18n.tr;
|
import cc.arduino.contributions.ui.DropdownItem;
|
||||||
|
|
||||||
public class DropdownInstalledLibraryItem implements DropdownItem<ContributedLibrary> {
|
public class DropdownInstalledLibraryItem implements DropdownItem<ContributedLibraryReleases> {
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return tr("Installed");
|
return tr("Installed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<ContributedLibrary> getFilterPredicate() {
|
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
|
||||||
return new InstalledLibraryPredicate();
|
return new Predicate<ContributedLibraryReleases>() {
|
||||||
|
@Override
|
||||||
|
public boolean test(ContributedLibraryReleases t) {
|
||||||
|
return t.getInstalled().isPresent();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,13 @@
|
|||||||
package cc.arduino.contributions.libraries.ui;
|
package cc.arduino.contributions.libraries.ui;
|
||||||
|
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.libraries.filters.CategoryPredicate;
|
|
||||||
import cc.arduino.contributions.ui.DropdownItem;
|
import cc.arduino.contributions.ui.DropdownItem;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static processing.app.I18n.tr;
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
public class DropdownLibraryOfCategoryItem implements DropdownItem<ContributedLibrary> {
|
public class DropdownLibraryOfCategoryItem implements DropdownItem<ContributedLibraryReleases> {
|
||||||
|
|
||||||
private final String category;
|
private final String category;
|
||||||
|
|
||||||
@ -50,8 +49,14 @@ public class DropdownLibraryOfCategoryItem implements DropdownItem<ContributedLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<ContributedLibrary> getFilterPredicate() {
|
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
|
||||||
return new CategoryPredicate(category);
|
return new Predicate<ContributedLibraryReleases>() {
|
||||||
|
@Override
|
||||||
|
public boolean test(ContributedLibraryReleases rel) {
|
||||||
|
ContributedLibrary lib = rel.getLatest();
|
||||||
|
return category.equals(lib.getCategory());
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,15 +29,14 @@
|
|||||||
|
|
||||||
package cc.arduino.contributions.libraries.ui;
|
package cc.arduino.contributions.libraries.ui;
|
||||||
|
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
|
||||||
import cc.arduino.contributions.libraries.filters.TypePredicate;
|
|
||||||
import cc.arduino.contributions.ui.DropdownItem;
|
import cc.arduino.contributions.ui.DropdownItem;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static processing.app.I18n.tr;
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
public class DropdownLibraryOfTypeItem implements DropdownItem<ContributedLibrary> {
|
public class DropdownLibraryOfTypeItem implements DropdownItem<ContributedLibraryReleases> {
|
||||||
|
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
@ -50,8 +49,14 @@ public class DropdownLibraryOfTypeItem implements DropdownItem<ContributedLibrar
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<ContributedLibrary> getFilterPredicate() {
|
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
|
||||||
return new TypePredicate(type);
|
return new Predicate<ContributedLibraryReleases>() {
|
||||||
|
@Override
|
||||||
|
public boolean test(ContributedLibraryReleases lib) {
|
||||||
|
List<String> types = lib.getLatest().getTypes();
|
||||||
|
return types != null && types.contains(type);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,18 +30,27 @@
|
|||||||
package cc.arduino.contributions.libraries.ui;
|
package cc.arduino.contributions.libraries.ui;
|
||||||
|
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.libraries.filters.UpdatableLibraryPredicate;
|
|
||||||
import cc.arduino.contributions.ui.DropdownItem;
|
import cc.arduino.contributions.ui.DropdownItem;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static processing.app.I18n.tr;
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
public class DropdownUpdatableLibrariesItem implements DropdownItem<ContributedLibrary> {
|
public class DropdownUpdatableLibrariesItem implements DropdownItem<ContributedLibraryReleases> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<ContributedLibrary> getFilterPredicate() {
|
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
|
||||||
return new UpdatableLibraryPredicate();
|
return new Predicate<ContributedLibraryReleases>() {
|
||||||
|
@Override
|
||||||
|
public boolean test(ContributedLibraryReleases lib) {
|
||||||
|
Optional<ContributedLibrary> mayInstalled = lib.getInstalled();
|
||||||
|
if (!mayInstalled.isPresent()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !lib.getLatest().equals(mayInstalled.get());
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,7 +41,7 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class LibrariesIndexTableModel
|
public class LibrariesIndexTableModel
|
||||||
extends FilteredAbstractTableModel<ContributedLibrary> {
|
extends FilteredAbstractTableModel<ContributedLibraryReleases> {
|
||||||
|
|
||||||
private final List<ContributedLibraryReleases> contributions = new ArrayList<>();
|
private final List<ContributedLibraryReleases> contributions = new ArrayList<>();
|
||||||
|
|
||||||
@ -49,11 +49,11 @@ public class LibrariesIndexTableModel
|
|||||||
|
|
||||||
private final Class<?>[] columnTypes = { ContributedPlatform.class };
|
private final Class<?>[] columnTypes = { ContributedPlatform.class };
|
||||||
|
|
||||||
Predicate<ContributedLibrary> selectedCategoryFilter = null;
|
Predicate<ContributedLibraryReleases> selectedCategoryFilter = null;
|
||||||
String selectedFilters[] = null;
|
String selectedFilters[] = null;
|
||||||
|
|
||||||
public void updateIndexFilter(String filters[],
|
public void updateIndexFilter(String filters[],
|
||||||
Predicate<ContributedLibrary> additionalFilter) {
|
Predicate<ContributedLibraryReleases> additionalFilter) {
|
||||||
selectedCategoryFilter = additionalFilter;
|
selectedCategoryFilter = additionalFilter;
|
||||||
selectedFilters = filters;
|
selectedFilters = filters;
|
||||||
update();
|
update();
|
||||||
@ -86,17 +86,6 @@ public class LibrariesIndexTableModel
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addContribution(ContributedLibrary lib) {
|
|
||||||
for (ContributedLibraryReleases contribution : contributions) {
|
|
||||||
if (!contribution.shouldContain(lib))
|
|
||||||
continue;
|
|
||||||
contribution.add(lib);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
contributions.add(new ContributedLibraryReleases(lib));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
return columnNames.length;
|
return columnNames.length;
|
||||||
@ -149,17 +138,19 @@ public class LibrariesIndexTableModel
|
|||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyFilterToLibrary(ContributedLibrary lib) {
|
private boolean filterCondition(ContributedLibraryReleases lib) {
|
||||||
if (selectedCategoryFilter != null && !selectedCategoryFilter.test(lib)) {
|
if (selectedCategoryFilter != null && !selectedCategoryFilter.test(lib)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String compoundTargetSearchText = lib.getName() + "\n" + lib.getParagraph()
|
ContributedLibrary latest = lib.getLatest();
|
||||||
+ "\n" + lib.getSentence();
|
String compoundTargetSearchText = latest.getName() + "\n" + latest.getParagraph()
|
||||||
|
+ "\n" + latest.getSentence();
|
||||||
if (!stringContainsAll(compoundTargetSearchText, selectedFilters)) {
|
if (!stringContainsAll(compoundTargetSearchText, selectedFilters)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
addContribution(lib);
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLibrary(ContributedLibrary lib) {
|
public void updateLibrary(ContributedLibrary lib) {
|
||||||
@ -189,12 +180,26 @@ public class LibrariesIndexTableModel
|
|||||||
fireTableRowsDeleted(row, row);
|
fireTableRowsDeleted(row, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<ContributedLibraryReleases> rebuildContributionsFromIndex() {
|
||||||
|
List<ContributedLibraryReleases> res = new ArrayList<>();
|
||||||
|
BaseNoGui.librariesIndexer.getIndex().getLibraries(). //
|
||||||
|
forEach(lib -> {
|
||||||
|
for (ContributedLibraryReleases contribution : res) {
|
||||||
|
if (!contribution.shouldContain(lib))
|
||||||
|
continue;
|
||||||
|
contribution.add(lib);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.add(new ContributedLibraryReleases(lib));
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateContributions() {
|
private void updateContributions() {
|
||||||
|
List<ContributedLibraryReleases> all = rebuildContributionsFromIndex();
|
||||||
contributions.clear();
|
contributions.clear();
|
||||||
BaseNoGui.librariesIndexer.getIndex().getLibraries()
|
all.stream().filter(this::filterCondition).forEach(contributions::add);
|
||||||
.forEach(this::applyFilterToLibrary);
|
|
||||||
BaseNoGui.librariesIndexer.getInstalledLibraries()
|
|
||||||
.forEach(this::applyFilterToLibrary);
|
|
||||||
Collections.sort(contributions,
|
Collections.sort(contributions,
|
||||||
new ContributedLibraryReleasesComparator("Arduino"));
|
new ContributedLibraryReleasesComparator("Arduino"));
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,9 @@ import javax.swing.JLabel;
|
|||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.table.TableCellRenderer;
|
import javax.swing.table.TableCellRenderer;
|
||||||
|
|
||||||
import cc.arduino.contributions.DownloadableContribution;
|
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.libraries.LibraryInstaller;
|
import cc.arduino.contributions.libraries.LibraryInstaller;
|
||||||
import cc.arduino.contributions.libraries.LibraryTypeComparator;
|
import cc.arduino.contributions.libraries.LibraryTypeComparator;
|
||||||
import cc.arduino.contributions.ui.DropdownAllItem;
|
|
||||||
import cc.arduino.contributions.ui.DropdownItem;
|
import cc.arduino.contributions.ui.DropdownItem;
|
||||||
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
|
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
|
||||||
import cc.arduino.contributions.ui.InstallerJDialog;
|
import cc.arduino.contributions.ui.InstallerJDialog;
|
||||||
@ -61,11 +59,11 @@ import cc.arduino.utils.Progress;
|
|||||||
import processing.app.BaseNoGui;
|
import processing.app.BaseNoGui;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryReleases> {
|
||||||
|
|
||||||
private final JComboBox typeChooser;
|
private final JComboBox typeChooser;
|
||||||
private final LibraryInstaller installer;
|
private final LibraryInstaller installer;
|
||||||
private Predicate<ContributedLibrary> typeFilter;
|
private Predicate<ContributedLibraryReleases> typeFilter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FilteredAbstractTableModel createContribModel() {
|
protected FilteredAbstractTableModel createContribModel() {
|
||||||
@ -117,7 +115,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
DropdownItem<ContributedLibrary> selected = (DropdownItem<ContributedLibrary>) typeChooser.getSelectedItem();
|
DropdownItem<ContributedLibraryReleases> selected = (DropdownItem<ContributedLibraryReleases>) typeChooser.getSelectedItem();
|
||||||
previousRowAtPoint = -1;
|
previousRowAtPoint = -1;
|
||||||
if (selected != null && typeFilter != selected.getFilterPredicate()) {
|
if (selected != null && typeFilter != selected.getFilterPredicate()) {
|
||||||
typeFilter = selected.getFilterPredicate();
|
typeFilter = selected.getFilterPredicate();
|
||||||
@ -130,8 +128,8 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public void updateUI() {
|
public void updateUI() {
|
||||||
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser.getSelectedItem();
|
DropdownItem<ContributedLibraryReleases> previouslySelectedCategory = (DropdownItem<ContributedLibraryReleases>) categoryChooser.getSelectedItem();
|
||||||
DropdownItem<DownloadableContribution> previouslySelectedType = (DropdownItem<DownloadableContribution>) typeChooser.getSelectedItem();
|
DropdownItem<ContributedLibraryReleases> previouslySelectedType = (DropdownItem<ContributedLibraryReleases>) typeChooser.getSelectedItem();
|
||||||
|
|
||||||
categoryChooser.removeActionListener(categoryChooserActionListener);
|
categoryChooser.removeActionListener(categoryChooserActionListener);
|
||||||
typeChooser.removeActionListener(typeChooserActionListener);
|
typeChooser.removeActionListener(typeChooserActionListener);
|
||||||
@ -140,7 +138,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
|||||||
// Load categories
|
// Load categories
|
||||||
categoryFilter = x -> true;
|
categoryFilter = x -> true;
|
||||||
categoryChooser.removeAllItems();
|
categoryChooser.removeAllItems();
|
||||||
categoryChooser.addItem(new DropdownAllItem());
|
categoryChooser.addItem(new DropdownAllLibraries());
|
||||||
Collection<String> categories = BaseNoGui.librariesIndexer.getIndex().getCategories();
|
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));
|
||||||
@ -157,7 +155,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
|||||||
|
|
||||||
typeFilter = x -> true;
|
typeFilter = x -> true;
|
||||||
typeChooser.removeAllItems();
|
typeChooser.removeAllItems();
|
||||||
typeChooser.addItem(new DropdownAllItem());
|
typeChooser.addItem(new DropdownAllLibraries());
|
||||||
typeChooser.addItem(new DropdownUpdatableLibrariesItem());
|
typeChooser.addItem(new DropdownUpdatableLibrariesItem());
|
||||||
typeChooser.addItem(new DropdownInstalledLibraryItem());
|
typeChooser.addItem(new DropdownInstalledLibraryItem());
|
||||||
java.util.List<String> types = new LinkedList<>(BaseNoGui.librariesIndexer.getIndex().getTypes());
|
java.util.List<String> types = new LinkedList<>(BaseNoGui.librariesIndexer.getIndex().getTypes());
|
||||||
|
Loading…
Reference in New Issue
Block a user