1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-01 21:52:12 +01:00

Merge pull request #10541 from cmaglie/board-lib-manager-fixes

Fixed Boards and Libraries Manager "filters" persistence
This commit is contained in:
Cristian Maglie 2020-07-23 15:59:55 +02:00 committed by GitHub
commit 80dc652ceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 21 deletions

View File

@ -72,6 +72,10 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
return new LibrariesIndexTableModel(); return new LibrariesIndexTableModel();
} }
private LibrariesIndexTableModel getContribModel() {
return (LibrariesIndexTableModel) contribModel;
}
@Override @Override
protected TableCellRenderer createCellRenderer() { protected TableCellRenderer createCellRenderer() {
return new ContributedLibraryTableCellRenderer(); return new ContributedLibraryTableCellRenderer();
@ -197,8 +201,11 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
try { try {
setProgressVisible(true, ""); setProgressVisible(true, "");
installer.updateIndex(this::setProgress); installer.updateIndex(this::setProgress);
((LibrariesIndexTableModel) contribModel).update();
onIndexesUpdated(); onIndexesUpdated();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
getContribModel().update();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {
@ -234,12 +241,11 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
} else { } else {
installer.install(lib, this::setProgress); installer.install(lib, this::setProgress);
} }
// TODO: Do a better job in refreshing only the needed element onIndexesUpdated();
if (contribTable.getCellEditor() != null) { if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing(); contribTable.getCellEditor().stopCellEditing();
} }
((LibrariesIndexTableModel) contribModel).update(); getContribModel().update();
onIndexesUpdated();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {
@ -266,12 +272,11 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
try { try {
setProgressVisible(true, tr("Removing...")); setProgressVisible(true, tr("Removing..."));
installer.remove(lib, this::setProgress); installer.remove(lib, this::setProgress);
// TODO: Do a better job in refreshing only the needed element onIndexesUpdated();
if (contribTable.getCellEditor() != null) { if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing(); contribTable.getCellEditor().stopCellEditing();
} }
((LibrariesIndexTableModel) contribModel).update(); getContribModel().update();
onIndexesUpdated();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {

View File

@ -47,9 +47,17 @@ public class ContributionIndexTableModel
private final List<ContributedPlatformReleases> contributions = new ArrayList<>(); private final List<ContributedPlatformReleases> contributions = new ArrayList<>();
private final String[] columnNames = { "Description" }; private final String[] columnNames = { "Description" };
private final Class<?>[] columnTypes = { ContributedPlatform.class }; private final Class<?>[] columnTypes = { ContributedPlatform.class };
private Predicate<ContributedPlatform> filter;
private String[] filters;
public void updateIndexFilter(String[] filters, public void updateIndexFilter(String[] filters,
Predicate<ContributedPlatform> filter) { Predicate<ContributedPlatform> filter) {
this.filter = filter;
this.filters = filters;
updateContributions();
}
private void updateContributions() {
contributions.clear(); contributions.clear();
for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) { for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) {
for (ContributedPlatform platform : pack.getPlatforms()) { for (ContributedPlatform platform : pack.getPlatforms()) {
@ -146,6 +154,7 @@ public class ContributionIndexTableModel
} }
public void update() { public void update() {
updateContributions();
fireTableDataChanged(); fireTableDataChanged();
} }

View File

@ -29,7 +29,6 @@
package cc.arduino.contributions.packages.ui; package cc.arduino.contributions.packages.ui;
import cc.arduino.contributions.DownloadableContribution;
import cc.arduino.contributions.packages.ContributedPlatform; import cc.arduino.contributions.packages.ContributedPlatform;
import cc.arduino.contributions.packages.ContributionInstaller; import cc.arduino.contributions.packages.ContributionInstaller;
import cc.arduino.contributions.ui.*; import cc.arduino.contributions.ui.*;
@ -41,6 +40,7 @@ import javax.swing.*;
import javax.swing.table.TableCellRenderer; import javax.swing.table.TableCellRenderer;
import java.awt.*; import java.awt.*;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -92,31 +92,29 @@ public class ContributionManagerUI extends InstallerJDialog {
this.installer = installer; this.installer = installer;
} }
private Collection<String> oldCategories = new ArrayList<>();
public void updateUI() { public void updateUI() {
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser // Check if categories have changed
.getSelectedItem(); Collection<String> categories = BaseNoGui.indexer.getCategories();
if (categories.equals(oldCategories)) {
return;
}
oldCategories = categories;
categoryChooser.removeActionListener(categoryChooserActionListener); categoryChooser.removeActionListener(categoryChooserActionListener);
filterField.setEnabled(getContribModel().getRowCount() > 0);
categoryChooser.addActionListener(categoryChooserActionListener);
// Enable categories combo only if there are two or more choices // Enable categories combo only if there are two or more choices
filterField.setEnabled(getContribModel().getRowCount() > 0);
categoryFilter = x -> true; categoryFilter = x -> true;
categoryChooser.removeAllItems(); categoryChooser.removeAllItems();
categoryChooser.addItem(new DropdownAllCoresItem()); categoryChooser.addItem(new DropdownAllCoresItem());
categoryChooser.addItem(new DropdownUpdatableCoresItem()); categoryChooser.addItem(new DropdownUpdatableCoresItem());
Collection<String> categories = BaseNoGui.indexer.getCategories();
for (String s : categories) { for (String s : categories) {
categoryChooser.addItem(new DropdownCoreOfCategoryItem(s)); categoryChooser.addItem(new DropdownCoreOfCategoryItem(s));
} }
if (previouslySelectedCategory != null) { categoryChooser.addActionListener(categoryChooserActionListener);
categoryChooser.setSelectedItem(previouslySelectedCategory);
} else {
categoryChooser.setSelectedIndex(0); categoryChooser.setSelectedIndex(0);
} }
}
public void setProgress(Progress progress) { public void setProgress(Progress progress) {
progressBar.setValue(progress); progressBar.setValue(progress);
@ -146,6 +144,10 @@ public class ContributionManagerUI extends InstallerJDialog {
.updateIndex(this::setProgress); .updateIndex(this::setProgress);
installer.deleteUnknownFiles(downloadedPackageIndexFiles); installer.deleteUnknownFiles(downloadedPackageIndexFiles);
onIndexesUpdated(); onIndexesUpdated();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
getContribModel().update();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {
@ -171,6 +173,10 @@ public class ContributionManagerUI extends InstallerJDialog {
} }
errors.addAll(installer.install(platformToInstall, this::setProgress)); errors.addAll(installer.install(platformToInstall, this::setProgress));
onIndexesUpdated(); onIndexesUpdated();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
getContribModel().update();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {
@ -209,6 +215,10 @@ public class ContributionManagerUI extends InstallerJDialog {
setProgressVisible(true, tr("Removing...")); setProgressVisible(true, tr("Removing..."));
installer.remove(platform); installer.remove(platform);
onIndexesUpdated(); onIndexesUpdated();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
getContribModel().update();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {