Skip to content

Commit 767cd25

Browse files
facchinmcmaglie
authored andcommitted
Clear cell cache when a dropdown/filter is selected
Completes and fixes 50d1e60
1 parent c2389d3 commit 767cd25

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
@SuppressWarnings("serial")
5555
public class ContributedLibraryTableCellEditor extends InstallerTableCell {
5656

57-
private List<Component> cellList = new ArrayList<Component>();
58-
5957
private ContributedLibraryReleases editorValue;
6058
private ContributedLibraryTableCellJPanel editorCell;
6159

@@ -143,6 +141,15 @@ public Component getTableCellEditorComponent(JTable table, Object value,
143141

144142
editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3
145143

144+
if (cellList.size() < row) {
145+
// allocate the empty slots
146+
int i = cellList.size();
147+
while (i < row) {
148+
cellList.add(i, null);
149+
i++;
150+
}
151+
}
152+
146153
cellList.add(row, editorCell);
147154

148155
return editorCell;

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
@SuppressWarnings("serial")
5353
public class ContributedPlatformTableCellEditor extends InstallerTableCell {
5454

55-
private List<Component> cellList = new ArrayList<Component>();
56-
5755
private ContributedPlatformTableCellJPanel cell;
5856
private ContributedPlatformReleases value;
5957

@@ -138,6 +136,14 @@ public Component getTableCellEditorComponent(JTable table, Object _value,
138136
cell.update(table, _value, true, !installedBuiltIn.isEmpty());
139137
cell.setBackground(new Color(218, 227, 227)); // #dae3e3
140138

139+
if (cellList.size() < row) {
140+
// allocate the empty slots
141+
int i = cellList.size();
142+
while (i < row) {
143+
cellList.add(i, null);
144+
i++;
145+
}
146+
}
141147
cellList.add(row, cell);
142148

143149
return cell;

app/src/cc/arduino/contributions/ui/InstallerJDialog.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
8585

8686
// Real contribution table
8787
protected JTable contribTable;
88+
private InstallerTableCell cellEditor;
8889
// Model behind the table
8990
protected final FilteredAbstractTableModel<T> contribModel;
9091
private final JButton closeButton;
@@ -125,6 +126,7 @@ protected void onFilter(String[] _filters) {
125126
contribTable.getCellEditor().stopCellEditing();
126127
}
127128
updateIndexFilter(filters, categoryFilter);
129+
cellEditor.clearCache();
128130
if (contribModel.getRowCount() == 1) {
129131
// TODO: understand why it doesn't work
130132
//contribTable.addRowSelectionInterval(0, 0);
@@ -187,7 +189,8 @@ public void mouseMoved(MouseEvent e) {
187189
TableColumnModel tcm = contribTable.getColumnModel();
188190
TableColumn col = tcm.getColumn(0);
189191
col.setCellRenderer(createCellRenderer());
190-
col.setCellEditor(createCellEditor());
192+
cellEditor = createCellEditor();
193+
col.setCellEditor(cellEditor);
191194
col.setResizable(true);
192195
}
193196

@@ -260,6 +263,7 @@ public void mouseMoved(MouseEvent e) {
260263
public void updateIndexFilter(String[] filters, Predicate<T>... additionalFilters) {
261264
Stream<Predicate<T>> notNullAdditionalFilters = Stream.of(additionalFilters).filter(filter -> filter != null);
262265
contribModel.updateIndexFilter(filters, notNullAdditionalFilters);
266+
cellEditor.clearCache();
263267
}
264268

265269
public void setErrorMessage(String message) {
@@ -308,6 +312,7 @@ public void actionPerformed(ActionEvent event) {
308312
contribTable.getCellEditor().stopCellEditing();
309313
}
310314
updateIndexFilter(filters, categoryFilter);
315+
cellEditor.clearCache();
311316
}
312317
}
313318
};

app/src/cc/arduino/contributions/ui/InstallerTableCell.java

+9
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929

3030
package cc.arduino.contributions.ui;
3131

32+
import java.awt.Component;
3233
import java.awt.Dimension;
3334
import java.awt.Rectangle;
35+
import java.util.ArrayList;
36+
import java.util.List;
3437

3538
import javax.swing.AbstractCellEditor;
3639
import javax.swing.JTextPane;
@@ -39,6 +42,8 @@
3942

4043
public abstract class InstallerTableCell extends AbstractCellEditor implements TableCellEditor {
4144

45+
protected List<Component> cellList = new ArrayList<Component>();
46+
4247
abstract public void setEnabled(boolean b);
4348

4449
abstract public void setStatus(String s);
@@ -59,4 +64,8 @@ public static void setJTextPaneDimensionToFitContainedText(JTextPane jTextPane,
5964

6065
}
6166

67+
public void clearCache() {
68+
cellList.clear();
69+
}
70+
6271
}

0 commit comments

Comments
 (0)