Skip to content

Commit

Permalink
Cumulative patch for MSFT Store hot-fix release
Browse files Browse the repository at this point in the history
The following commits have been added here:

- 4286522: Library manager: update filters combo box only if there are changes
- 3263967: Removed unused include and clueless whitespaces
- b66ed5e: LibraryManager: correctly apply "type" and "category" filters together
- 1361bce: Board manager: Update filters UI only if categories changes
- a81772a: Boards Manager: update UI after an install/remove
- 851b5b1: Lib manager GUI is updated after installing/upgrading library
- 10bee20: Lib manager: added getContribModel() as in Boards manager
  • Loading branch information
cmaglie committed Jul 23, 2020
1 parent 5adf408 commit d2e4d76
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 50 deletions.
67 changes: 34 additions & 33 deletions app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
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;
Expand All @@ -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();
Expand Down Expand Up @@ -115,63 +118,60 @@ public LibraryManagerUI(Frame parent, LibraryInstaller installer) {
}

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));
}
}
};

private Collection<String> oldCategories = new ArrayList<>();
private Collection<String> oldTypes = new ArrayList<>();

public void updateUI() {
DropdownItem<ContributedLibraryReleases> previouslySelectedCategory = (DropdownItem<ContributedLibraryReleases>) categoryChooser.getSelectedItem();
DropdownItem<ContributedLibraryReleases> previouslySelectedType = (DropdownItem<ContributedLibraryReleases>) typeChooser.getSelectedItem();
// 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());

categoryChooser.removeActionListener(categoryChooserActionListener);
typeChooser.removeActionListener(typeChooserActionListener);
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);
}
Expand Down Expand Up @@ -201,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 {
Expand Down Expand Up @@ -238,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 {
Expand All @@ -270,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -146,6 +154,7 @@ public ContributedPlatform getSelectedRelease(int row) {
}

public void update() {
updateContributions();
fireTableDataChanged();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand Down Expand Up @@ -92,30 +92,28 @@ public ContributionManagerUI(Frame parent, ContributionInstaller installer) {
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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions app/src/cc/arduino/contributions/ui/InstallerJDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@

import cc.arduino.contributions.ui.listeners.AbstractKeyListener;
import processing.app.Base;
import processing.app.Theme;

public abstract class InstallerJDialog<T> extends JDialog {

Expand All @@ -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;
Expand Down Expand Up @@ -329,7 +329,6 @@ private void setErrorMessageVisible(boolean visible) {
}

protected final ActionListener categoryChooserActionListener = new ActionListener() {

@Override
public void actionPerformed(ActionEvent event) {
DropdownItem<T> selected = (DropdownItem<T>) categoryChooser.getSelectedItem();
Expand All @@ -339,7 +338,7 @@ public void actionPerformed(ActionEvent event) {
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
updateIndexFilter(filters, categoryFilter);
updateIndexFilter(filters, categoryFilter.and(extraFilter));
}
}
};
Expand Down

0 comments on commit d2e4d76

Please sign in to comment.