From 1361bce6bc703602499c0bc7d4ac154063de4ade Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 22 Jul 2020 17:06:46 +0200 Subject: [PATCH] Board manager: Update filters UI only if categories changes --- .../packages/ui/ContributionManagerUI.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java b/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java index 6f9c903c3..48fbca5d8 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.*; 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 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) {