1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-26 20:54:22 +01:00

Cumulative patch for MSFT Store hot-fix release

The following commits have been added here:

- 42865229c2fbad7447ea430b08c69e507a606d72: Library manager: update filters combo box only if there are changes
- 326396789389b99f4728fe8e9f80ed2796760b19: Removed unused include and clueless whitespaces
- b66ed5e5d738e0e83c2ced183914cef3bd5f72fc: LibraryManager: correctly apply "type" and "category" filters together
- 1361bce6bc703602499c0bc7d4ac154063de4ade: Board manager: Update filters UI only if categories changes
- a81772afc68fb1497b6374ad58d197ef84bcba4c: Boards Manager: update UI after an install/remove
- 851b5b14b1dc48572649e9a291d34415f018447f: Lib manager GUI is updated after installing/upgrading library
- 10bee204e62a1339c803285d8ac9463bc2278f6a: Lib manager: added getContribModel() as in Boards manager
This commit is contained in:
Cristian Maglie 2020-06-29 16:58:25 +02:00
parent 5adf408270
commit d2e4d76afc
4 changed files with 70 additions and 51 deletions

View File

@ -35,12 +35,12 @@ import java.awt.Dialog;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import javax.swing.Box;
import javax.swing.JComboBox;
@ -66,13 +66,16 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
private final JComboBox typeChooser;
private final LibraryInstaller installer;
private Predicate<ContributedLibraryReleases> typeFilter;
@Override
protected FilteredAbstractTableModel createContribModel() {
return new LibrariesIndexTableModel();
}
private LibrariesIndexTableModel getContribModel() {
return (LibrariesIndexTableModel) contribModel;
}
@Override
protected TableCellRenderer createCellRenderer() {
return new ContributedLibraryTableCellRenderer();
@ -115,63 +118,60 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
}
protected final ActionListener typeChooserActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
DropdownItem<ContributedLibraryReleases> selected = (DropdownItem<ContributedLibraryReleases>) typeChooser.getSelectedItem();
previousRowAtPoint = -1;
if (selected != null && typeFilter != selected.getFilterPredicate()) {
typeFilter = selected.getFilterPredicate();
if (selected != null && extraFilter != selected.getFilterPredicate()) {
extraFilter = selected.getFilterPredicate();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
updateIndexFilter(filters, categoryFilter.and(typeFilter));
updateIndexFilter(filters, categoryFilter.and(extraFilter));
}
}
};
public void updateUI() {
DropdownItem<ContributedLibraryReleases> previouslySelectedCategory = (DropdownItem<ContributedLibraryReleases>) categoryChooser.getSelectedItem();
DropdownItem<ContributedLibraryReleases> previouslySelectedType = (DropdownItem<ContributedLibraryReleases>) typeChooser.getSelectedItem();
private Collection<String> oldCategories = new ArrayList<>();
private Collection<String> oldTypes = new ArrayList<>();
categoryChooser.removeActionListener(categoryChooserActionListener);
typeChooser.removeActionListener(typeChooserActionListener);
public void updateUI() {
// Check if categories or types have changed
Collection<String> categories = BaseNoGui.librariesIndexer.getIndex().getCategories();
List<String> types = new LinkedList<>(BaseNoGui.librariesIndexer.getIndex().getTypes());
Collections.sort(types, new LibraryTypeComparator());
if (categories.equals(oldCategories) && types.equals(oldTypes)) {
return;
}
oldCategories = categories;
oldTypes = types;
// Load categories
categoryFilter = x -> true;
categoryChooser.removeActionListener(categoryChooserActionListener);
categoryChooser.removeAllItems();
categoryChooser.addItem(new DropdownAllLibraries());
Collection<String> categories = BaseNoGui.librariesIndexer.getIndex().getCategories();
for (String category : categories) {
categoryChooser.addItem(new DropdownLibraryOfCategoryItem(category));
}
categoryChooser.setEnabled(categoryChooser.getItemCount() > 1);
categoryChooser.addActionListener(categoryChooserActionListener);
if (previouslySelectedCategory != null) {
categoryChooser.setSelectedItem(previouslySelectedCategory);
} else {
categoryChooser.setSelectedIndex(0);
}
categoryChooser.setSelectedIndex(0);
typeFilter = x -> true;
// Load types
extraFilter = x -> true;
typeChooser.removeActionListener(typeChooserActionListener);
typeChooser.removeAllItems();
typeChooser.addItem(new DropdownAllLibraries());
typeChooser.addItem(new DropdownUpdatableLibrariesItem());
typeChooser.addItem(new DropdownInstalledLibraryItem());
List<String> types = new LinkedList<>(BaseNoGui.librariesIndexer.getIndex().getTypes());
Collections.sort(types, new LibraryTypeComparator());
for (String type : types) {
typeChooser.addItem(new DropdownLibraryOfTypeItem(type));
}
typeChooser.setEnabled(typeChooser.getItemCount() > 1);
typeChooser.addActionListener(typeChooserActionListener);
if (previouslySelectedType != null) {
typeChooser.setSelectedItem(previouslySelectedType);
} else {
typeChooser.setSelectedIndex(0);
}
typeChooser.setSelectedIndex(0);
filterField.setEnabled(contribModel.getRowCount() > 0);
}
@ -201,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 {
@ -238,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 {
@ -270,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 {

View File

@ -71,7 +71,6 @@ import javax.swing.text.DefaultEditorKit;
import cc.arduino.contributions.ui.listeners.AbstractKeyListener;
import processing.app.Base;
import processing.app.Theme;
public abstract class InstallerJDialog<T> extends JDialog {
@ -82,6 +81,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
protected final FilterJTextField filterField;
protected final JPanel filtersContainer;
// Currently selected category and filters
protected Predicate<T> extraFilter = x -> true;
protected Predicate<T> categoryFilter;
protected String[] filters;
protected final String noConnectionErrorMessage;
@ -329,7 +329,6 @@ public abstract class InstallerJDialog<T> extends JDialog {
}
protected final ActionListener categoryChooserActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
DropdownItem<T> selected = (DropdownItem<T>) categoryChooser.getSelectedItem();
@ -339,7 +338,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
updateIndexFilter(filters, categoryFilter);
updateIndexFilter(filters, categoryFilter.and(extraFilter));
}
}
};