2929
3030package cc .arduino .contributions .packages .ui ;
3131
32- import cc .arduino .contributions .DownloadableContribution ;
3332import cc .arduino .contributions .packages .ContributedPlatform ;
3433import cc .arduino .contributions .packages .ContributionInstaller ;
3534import cc .arduino .contributions .ui .*;
4140import javax .swing .table .TableCellRenderer ;
4241
4342import java .awt .*;
43+ import java .util .ArrayList ;
4444import java .util .Collection ;
4545import java .util .LinkedList ;
4646import 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