Skip to content

Commit

Permalink
Merge pull request arduino#10541 from cmaglie/board-lib-manager-fixes
Browse files Browse the repository at this point in the history
Fixed Boards and Libraries Manager "filters" persistence
  • Loading branch information
cmaglie authored Jul 23, 2020
2 parents 4c45ea8 + 10bee20 commit 80dc652
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ protected FilteredAbstractTableModel createContribModel() {
return new LibrariesIndexTableModel();
}

private LibrariesIndexTableModel getContribModel() {
return (LibrariesIndexTableModel) contribModel;
}

@Override
protected TableCellRenderer createCellRenderer() {
return new ContributedLibraryTableCellRenderer();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
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

0 comments on commit 80dc652

Please sign in to comment.