Skip to content

Commit 80dc652

Browse files
authored
Merge pull request arduino#10541 from cmaglie/board-lib-manager-fixes
Fixed Boards and Libraries Manager "filters" persistence
2 parents 4c45ea8 + 10bee20 commit 80dc652

File tree

3 files changed

+45
-21
lines changed

3 files changed

+45
-21
lines changed

app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ protected FilteredAbstractTableModel createContribModel() {
7272
return new LibrariesIndexTableModel();
7373
}
7474

75+
private LibrariesIndexTableModel getContribModel() {
76+
return (LibrariesIndexTableModel) contribModel;
77+
}
78+
7579
@Override
7680
protected TableCellRenderer createCellRenderer() {
7781
return new ContributedLibraryTableCellRenderer();
@@ -197,8 +201,11 @@ protected void onUpdatePressed() {
197201
try {
198202
setProgressVisible(true, "");
199203
installer.updateIndex(this::setProgress);
200-
((LibrariesIndexTableModel) contribModel).update();
201204
onIndexesUpdated();
205+
if (contribTable.getCellEditor() != null) {
206+
contribTable.getCellEditor().stopCellEditing();
207+
}
208+
getContribModel().update();
202209
} catch (Exception e) {
203210
throw new RuntimeException(e);
204211
} finally {
@@ -234,12 +241,11 @@ public void onInstallPressed(final ContributedLibrary lib) {
234241
} else {
235242
installer.install(lib, this::setProgress);
236243
}
237-
// TODO: Do a better job in refreshing only the needed element
244+
onIndexesUpdated();
238245
if (contribTable.getCellEditor() != null) {
239246
contribTable.getCellEditor().stopCellEditing();
240247
}
241-
((LibrariesIndexTableModel) contribModel).update();
242-
onIndexesUpdated();
248+
getContribModel().update();
243249
} catch (Exception e) {
244250
throw new RuntimeException(e);
245251
} finally {
@@ -266,12 +272,11 @@ public void onRemovePressed(final ContributedLibrary lib) {
266272
try {
267273
setProgressVisible(true, tr("Removing..."));
268274
installer.remove(lib, this::setProgress);
269-
// TODO: Do a better job in refreshing only the needed element
275+
onIndexesUpdated();
270276
if (contribTable.getCellEditor() != null) {
271277
contribTable.getCellEditor().stopCellEditing();
272278
}
273-
((LibrariesIndexTableModel) contribModel).update();
274-
onIndexesUpdated();
279+
getContribModel().update();
275280
} catch (Exception e) {
276281
throw new RuntimeException(e);
277282
} finally {

app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java

+9
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ public class ContributionIndexTableModel
4747
private final List<ContributedPlatformReleases> contributions = new ArrayList<>();
4848
private final String[] columnNames = { "Description" };
4949
private final Class<?>[] columnTypes = { ContributedPlatform.class };
50+
private Predicate<ContributedPlatform> filter;
51+
private String[] filters;
5052

5153
public void updateIndexFilter(String[] filters,
5254
Predicate<ContributedPlatform> filter) {
55+
this.filter = filter;
56+
this.filters = filters;
57+
updateContributions();
58+
}
59+
60+
private void updateContributions() {
5361
contributions.clear();
5462
for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) {
5563
for (ContributedPlatform platform : pack.getPlatforms()) {
@@ -146,6 +154,7 @@ public ContributedPlatform getSelectedRelease(int row) {
146154
}
147155

148156
public void update() {
157+
updateContributions();
149158
fireTableDataChanged();
150159
}
151160

app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java

+24-14
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
package cc.arduino.contributions.packages.ui;
3131

32-
import cc.arduino.contributions.DownloadableContribution;
3332
import cc.arduino.contributions.packages.ContributedPlatform;
3433
import cc.arduino.contributions.packages.ContributionInstaller;
3534
import cc.arduino.contributions.ui.*;
@@ -41,6 +40,7 @@
4140
import javax.swing.table.TableCellRenderer;
4241

4342
import java.awt.*;
43+
import java.util.ArrayList;
4444
import java.util.Collection;
4545
import java.util.LinkedList;
4646
import java.util.List;
@@ -92,30 +92,28 @@ public ContributionManagerUI(Frame parent, ContributionInstaller installer) {
9292
this.installer = installer;
9393
}
9494

95+
private Collection<String> oldCategories = new ArrayList<>();
96+
9597
public void updateUI() {
96-
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser
97-
.getSelectedItem();
98+
// Check if categories have changed
99+
Collection<String> categories = BaseNoGui.indexer.getCategories();
100+
if (categories.equals(oldCategories)) {
101+
return;
102+
}
103+
oldCategories = categories;
98104

99105
categoryChooser.removeActionListener(categoryChooserActionListener);
100-
101-
filterField.setEnabled(getContribModel().getRowCount() > 0);
102-
103-
categoryChooser.addActionListener(categoryChooserActionListener);
104-
105106
// Enable categories combo only if there are two or more choices
107+
filterField.setEnabled(getContribModel().getRowCount() > 0);
106108
categoryFilter = x -> true;
107109
categoryChooser.removeAllItems();
108110
categoryChooser.addItem(new DropdownAllCoresItem());
109111
categoryChooser.addItem(new DropdownUpdatableCoresItem());
110-
Collection<String> categories = BaseNoGui.indexer.getCategories();
111112
for (String s : categories) {
112113
categoryChooser.addItem(new DropdownCoreOfCategoryItem(s));
113114
}
114-
if (previouslySelectedCategory != null) {
115-
categoryChooser.setSelectedItem(previouslySelectedCategory);
116-
} else {
117-
categoryChooser.setSelectedIndex(0);
118-
}
115+
categoryChooser.addActionListener(categoryChooserActionListener);
116+
categoryChooser.setSelectedIndex(0);
119117
}
120118

121119
public void setProgress(Progress progress) {
@@ -146,6 +144,10 @@ public void onUpdatePressed() {
146144
.updateIndex(this::setProgress);
147145
installer.deleteUnknownFiles(downloadedPackageIndexFiles);
148146
onIndexesUpdated();
147+
if (contribTable.getCellEditor() != null) {
148+
contribTable.getCellEditor().stopCellEditing();
149+
}
150+
getContribModel().update();
149151
} catch (Exception e) {
150152
throw new RuntimeException(e);
151153
} finally {
@@ -171,6 +173,10 @@ public void onInstallPressed(final ContributedPlatform platformToInstall,
171173
}
172174
errors.addAll(installer.install(platformToInstall, this::setProgress));
173175
onIndexesUpdated();
176+
if (contribTable.getCellEditor() != null) {
177+
contribTable.getCellEditor().stopCellEditing();
178+
}
179+
getContribModel().update();
174180
} catch (Exception e) {
175181
throw new RuntimeException(e);
176182
} finally {
@@ -209,6 +215,10 @@ public void onRemovePressed(final ContributedPlatform platform,
209215
setProgressVisible(true, tr("Removing..."));
210216
installer.remove(platform);
211217
onIndexesUpdated();
218+
if (contribTable.getCellEditor() != null) {
219+
contribTable.getCellEditor().stopCellEditing();
220+
}
221+
getContribModel().update();
212222
} catch (Exception e) {
213223
throw new RuntimeException(e);
214224
} finally {

0 commit comments

Comments
 (0)