diff --git a/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java b/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java index 67221f91c3e..69ab10006c9 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java +++ b/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java @@ -72,6 +72,10 @@ protected FilteredAbstractTableModel createContribModel() { return new LibrariesIndexTableModel(); } + private LibrariesIndexTableModel getContribModel() { + return (LibrariesIndexTableModel) contribModel; + } + @Override protected TableCellRenderer createCellRenderer() { return new ContributedLibraryTableCellRenderer(); @@ -197,8 +201,11 @@ protected void onUpdatePressed() { 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 void onInstallPressed(final ContributedLibrary lib) { } 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 void onRemovePressed(final ContributedLibrary lib) { 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 { diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java b/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java index f143e33172a..7472c62479b 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java @@ -47,9 +47,17 @@ public class ContributionIndexTableModel private final List contributions = new ArrayList<>(); private final String[] columnNames = { "Description" }; private final Class[] columnTypes = { ContributedPlatform.class }; + private Predicate filter; + private String[] filters; public void updateIndexFilter(String[] filters, Predicate 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 ContributedPlatform getSelectedRelease(int row) { } public void update() { + updateContributions(); fireTableDataChanged(); } diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java b/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java index 6f9c903c3c0..0c949fe1cd3 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java @@ -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.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 ContributionManagerUI(Frame parent, ContributionInstaller installer) { this.installer = installer; } + private Collection oldCategories = new ArrayList<>(); + public void updateUI() { - DropdownItem previouslySelectedCategory = (DropdownItem) categoryChooser - .getSelectedItem(); + // Check if categories have changed + Collection 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 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 void onUpdatePressed() { .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 void onInstallPressed(final ContributedPlatform platformToInstall, } 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 void onRemovePressed(final ContributedPlatform platform, 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 {