1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-21 10:52:14 +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();
}
private LibrariesIndexTableModel getContribModel() {
return (LibrariesIndexTableModel) contribModel;
}
@Override
protected TableCellRenderer createCellRenderer() {
return new ContributedLibraryTableCellRenderer();
@ -197,8 +201,11 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
try {
setProgressVisible(true, "");
installer.updateIndex(this::setProgress);
((LibrariesIndexTableModel) contribModel).update();
onIndexesUpdated();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
getContribModel().update();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
@ -234,12 +241,11 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
} else {
installer.install(lib, this::setProgress);
}
// TODO: Do a better job in refreshing only the needed element
onIndexesUpdated();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
((LibrariesIndexTableModel) contribModel).update();
onIndexesUpdated();
getContribModel().update();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
@ -266,12 +272,11 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
try {
setProgressVisible(true, tr("Removing..."));
installer.remove(lib, this::setProgress);
// TODO: Do a better job in refreshing only the needed element
onIndexesUpdated();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
((LibrariesIndexTableModel) contribModel).update();
onIndexesUpdated();
getContribModel().update();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {

View File

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

View File

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