mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
Boards/Libs Manager: added Updatable filter. Shows Boards/Libs that can be updated
This commit is contained in:
parent
fe3fa56a15
commit
ad1062455d
@ -0,0 +1,33 @@
|
||||
package cc.arduino.contributions.libraries.filters;
|
||||
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndexer;
|
||||
import com.google.common.base.Predicate;
|
||||
import processing.app.packages.UserLibrary;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UpdatableLibraryPredicate implements Predicate<ContributedLibrary> {
|
||||
|
||||
private final LibrariesIndexer indexer;
|
||||
private final VersionComparator versionComparator;
|
||||
|
||||
public UpdatableLibraryPredicate(LibrariesIndexer indexer) {
|
||||
this.indexer = indexer;
|
||||
this.versionComparator = new VersionComparator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary contributedLibrary) {
|
||||
String libraryName = contributedLibrary.getName();
|
||||
UserLibrary installed = indexer.getInstalledLibraries().getByName(libraryName);
|
||||
if (installed == null) {
|
||||
return false;
|
||||
}
|
||||
List<ContributedLibrary> libraries = indexer.getIndex().find(libraryName);
|
||||
return libraries.stream()
|
||||
.filter(library -> versionComparator.greaterThan(library.getParsedVersion(), installed.getParsedVersion()))
|
||||
.count() > 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package cc.arduino.contributions.libraries.ui;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndexer;
|
||||
import cc.arduino.contributions.libraries.filters.UpdatableLibraryPredicate;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
public class DropdownUpdatableLibrariesItem implements DropdownItem<ContributedLibrary> {
|
||||
|
||||
private final LibrariesIndexer indexer;
|
||||
|
||||
public DropdownUpdatableLibrariesItem(LibrariesIndexer indexer) {
|
||||
this.indexer = indexer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<ContributedLibrary> getFilterPredicate() {
|
||||
return new UpdatableLibraryPredicate(indexer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return _("Updatable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof DropdownUpdatableLibrariesItem;
|
||||
}
|
||||
|
||||
}
|
@ -165,6 +165,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
typeFilter = null;
|
||||
typeChooser.removeAllItems();
|
||||
typeChooser.addItem(new DropdownAllItem());
|
||||
typeChooser.addItem(new DropdownUpdatableLibrariesItem(indexer));
|
||||
typeChooser.addItem(new DropdownInstalledLibraryItem(indexer.getIndex()));
|
||||
java.util.List<String> types = new LinkedList<String>(indexer.getIndex().getTypes());
|
||||
Collections.sort(types, new LibraryTypeComparator());
|
||||
|
@ -0,0 +1,35 @@
|
||||
package cc.arduino.contributions.packages.filters;
|
||||
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UpdatablePlatformPredicate implements Predicate<ContributedPlatform> {
|
||||
|
||||
private final ContributionsIndexer indexer;
|
||||
private final VersionComparator versionComparator;
|
||||
|
||||
public UpdatablePlatformPredicate(ContributionsIndexer indexer) {
|
||||
this.indexer = indexer;
|
||||
this.versionComparator = new VersionComparator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedPlatform contributedPlatform) {
|
||||
String packageName = contributedPlatform.getParentPackage().getName();
|
||||
String architecture = contributedPlatform.getArchitecture();
|
||||
|
||||
ContributedPlatform installed = indexer.getInstalled(packageName, architecture);
|
||||
if (installed == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<ContributedPlatform> platforms = indexer.getIndex().findPlatforms(packageName, architecture);
|
||||
return platforms.stream()
|
||||
.filter(platform -> versionComparator.greaterThan(platform.getParsedVersion(), installed.getParsedVersion()))
|
||||
.count() > 0;
|
||||
}
|
||||
}
|
@ -106,6 +106,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
|
||||
// Enable categories combo only if there are two or more choices
|
||||
categoryChooser.addItem(new DropdownAllCoresItem());
|
||||
categoryChooser.addItem(new DropdownUpdatableCoresItem(indexer));
|
||||
Collection<String> categories = indexer.getCategories();
|
||||
for (String s : categories) {
|
||||
categoryChooser.addItem(new DropdownCoreOfCategoryItem(s));
|
||||
|
@ -0,0 +1,33 @@
|
||||
package cc.arduino.contributions.packages.ui;
|
||||
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import cc.arduino.contributions.packages.filters.UpdatablePlatformPredicate;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
public class DropdownUpdatableCoresItem implements DropdownItem<ContributedPlatform> {
|
||||
|
||||
private final ContributionsIndexer indexer;
|
||||
|
||||
public DropdownUpdatableCoresItem(ContributionsIndexer indexer) {
|
||||
this.indexer = indexer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<ContributedPlatform> getFilterPredicate() {
|
||||
return new UpdatablePlatformPredicate(indexer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return _("Updatable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof DropdownUpdatableCoresItem;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user