29
29
30
30
package cc .arduino .contributions .packages .ui ;
31
31
32
- import cc .arduino .contributions .DownloadableContribution ;
33
32
import cc .arduino .contributions .packages .ContributedPlatform ;
34
33
import cc .arduino .contributions .packages .ContributionInstaller ;
35
34
import cc .arduino .contributions .ui .*;
41
40
import javax .swing .table .TableCellRenderer ;
42
41
43
42
import java .awt .*;
43
+ import java .util .ArrayList ;
44
44
import java .util .Collection ;
45
45
import java .util .LinkedList ;
46
46
import java .util .List ;
@@ -92,30 +92,28 @@ public ContributionManagerUI(Frame parent, ContributionInstaller installer) {
92
92
this .installer = installer ;
93
93
}
94
94
95
+ private Collection <String > oldCategories = new ArrayList <>();
96
+
95
97
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 ;
98
104
99
105
categoryChooser .removeActionListener (categoryChooserActionListener );
100
-
101
- filterField .setEnabled (getContribModel ().getRowCount () > 0 );
102
-
103
- categoryChooser .addActionListener (categoryChooserActionListener );
104
-
105
106
// Enable categories combo only if there are two or more choices
107
+ filterField .setEnabled (getContribModel ().getRowCount () > 0 );
106
108
categoryFilter = x -> true ;
107
109
categoryChooser .removeAllItems ();
108
110
categoryChooser .addItem (new DropdownAllCoresItem ());
109
111
categoryChooser .addItem (new DropdownUpdatableCoresItem ());
110
- Collection <String > categories = BaseNoGui .indexer .getCategories ();
111
112
for (String s : categories ) {
112
113
categoryChooser .addItem (new DropdownCoreOfCategoryItem (s ));
113
114
}
114
- if (previouslySelectedCategory != null ) {
115
- categoryChooser .setSelectedItem (previouslySelectedCategory );
116
- } else {
117
- categoryChooser .setSelectedIndex (0 );
118
- }
115
+ categoryChooser .addActionListener (categoryChooserActionListener );
116
+ categoryChooser .setSelectedIndex (0 );
119
117
}
120
118
121
119
public void setProgress (Progress progress ) {
@@ -146,6 +144,10 @@ public void onUpdatePressed() {
146
144
.updateIndex (this ::setProgress );
147
145
installer .deleteUnknownFiles (downloadedPackageIndexFiles );
148
146
onIndexesUpdated ();
147
+ if (contribTable .getCellEditor () != null ) {
148
+ contribTable .getCellEditor ().stopCellEditing ();
149
+ }
150
+ getContribModel ().update ();
149
151
} catch (Exception e ) {
150
152
throw new RuntimeException (e );
151
153
} finally {
@@ -171,6 +173,10 @@ public void onInstallPressed(final ContributedPlatform platformToInstall,
171
173
}
172
174
errors .addAll (installer .install (platformToInstall , this ::setProgress ));
173
175
onIndexesUpdated ();
176
+ if (contribTable .getCellEditor () != null ) {
177
+ contribTable .getCellEditor ().stopCellEditing ();
178
+ }
179
+ getContribModel ().update ();
174
180
} catch (Exception e ) {
175
181
throw new RuntimeException (e );
176
182
} finally {
@@ -209,6 +215,10 @@ public void onRemovePressed(final ContributedPlatform platform,
209
215
setProgressVisible (true , tr ("Removing..." ));
210
216
installer .remove (platform );
211
217
onIndexesUpdated ();
218
+ if (contribTable .getCellEditor () != null ) {
219
+ contribTable .getCellEditor ().stopCellEditing ();
220
+ }
221
+ getContribModel ().update ();
212
222
} catch (Exception e ) {
213
223
throw new RuntimeException (e );
214
224
} finally {
0 commit comments