36
36
import cc .arduino .contributions .libraries .LibraryTypeComparator ;
37
37
import cc .arduino .contributions .ui .*;
38
38
import cc .arduino .utils .Progress ;
39
- import processing .app .Platform ;
40
39
41
40
import javax .swing .*;
42
41
import java .awt .*;
53
52
public class LibraryManagerUI extends InstallerJDialog <ContributedLibrary > {
54
53
55
54
private final JComboBox typeChooser ;
56
- private final Platform platform ;
57
- private LibrariesIndexer indexer ;
55
+ private final LibrariesIndexer indexer ;
56
+ private final LibraryInstaller installer ;
58
57
private Predicate <ContributedLibrary > typeFilter ;
59
58
60
59
@ Override
@@ -90,9 +89,10 @@ protected void onRemove(ContributedLibrary library) {
90
89
};
91
90
}
92
91
93
- public LibraryManagerUI (Frame parent , Platform platform ) {
92
+ public LibraryManagerUI (Frame parent , LibrariesIndexer indexer , LibraryInstaller installer ) {
94
93
super (parent , "Library Manager" , Dialog .ModalityType .APPLICATION_MODAL , tr ("Unable to reach Arduino.cc due to possible network issues." ));
95
- this .platform = platform ;
94
+ this .indexer = indexer ;
95
+ this .installer = installer ;
96
96
97
97
filtersContainer .add (new JLabel (tr ("Topic" )), 1 );
98
98
filtersContainer .remove (2 );
@@ -125,14 +125,12 @@ public void actionPerformed(ActionEvent event) {
125
125
@ Override
126
126
public void updateIndexFilter (String [] filters , Predicate <ContributedLibrary >... additionalFilters ) {
127
127
if (additionalFilters .length == 1 ) {
128
- additionalFilters = new Predicate [] { additionalFilters [0 ], typeFilter };
128
+ additionalFilters = new Predicate []{ additionalFilters [0 ], typeFilter };
129
129
}
130
130
super .updateIndexFilter (filters , additionalFilters );
131
131
}
132
132
133
- public void setIndexer (LibrariesIndexer indexer ) {
134
- this .indexer = indexer ;
135
-
133
+ public void updateUI () {
136
134
DropdownItem <DownloadableContribution > previouslySelectedCategory = (DropdownItem <DownloadableContribution >) categoryChooser .getSelectedItem ();
137
135
DropdownItem <DownloadableContribution > previouslySelectedType = (DropdownItem <DownloadableContribution >) typeChooser .getSelectedItem ();
138
136
@@ -181,29 +179,16 @@ public void setIndexer(LibrariesIndexer indexer) {
181
179
}
182
180
183
181
filterField .setEnabled (contribModel .getRowCount () > 0 );
184
-
185
- // Create LibrariesInstaller tied with the provided index
186
- installer = new LibraryInstaller (indexer , platform ) {
187
- @ Override
188
- public void onProgress (Progress progress ) {
189
- setProgress (progress );
190
- }
191
- };
192
182
}
193
183
194
- public LibrariesIndexer getIndexer ( ) {
195
- return indexer ;
184
+ public void selectDropdownItemByClassName ( String dropdownItem ) {
185
+ selectDropdownItemByClassName ( typeChooser , dropdownItem ) ;
196
186
}
197
187
198
188
public void setProgress (Progress progress ) {
199
189
progressBar .setValue (progress );
200
190
}
201
191
202
- /*
203
- * Installer methods follows
204
- */
205
-
206
- private LibraryInstaller installer ;
207
192
private Thread installerThread = null ;
208
193
209
194
@ Override
@@ -220,7 +205,7 @@ protected void onUpdatePressed() {
220
205
installerThread = new Thread (() -> {
221
206
try {
222
207
setProgressVisible (true , "" );
223
- installer .updateIndex ();
208
+ installer .updateIndex (this :: setProgress );
224
209
onIndexesUpdated ();
225
210
} catch (Exception e ) {
226
211
throw new RuntimeException (e );
@@ -237,7 +222,7 @@ public void onInstallPressed(final ContributedLibrary lib, final ContributedLibr
237
222
installerThread = new Thread (() -> {
238
223
try {
239
224
setProgressVisible (true , tr ("Installing..." ));
240
- installer .install (lib , replaced );
225
+ installer .install (lib , replaced , this :: setProgress );
241
226
onIndexesUpdated (); // TODO: Do a better job in refreshing only the needed element
242
227
//getContribModel().updateLibrary(lib);
243
228
} catch (Exception e ) {
@@ -264,7 +249,7 @@ public void onRemovePressed(final ContributedLibrary lib) {
264
249
installerThread = new Thread (() -> {
265
250
try {
266
251
setProgressVisible (true , tr ("Removing..." ));
267
- installer .remove (lib );
252
+ installer .remove (lib , this :: setProgress );
268
253
onIndexesUpdated (); // TODO: Do a better job in refreshing only the needed element
269
254
//getContribModel().updateLibrary(lib);
270
255
} catch (Exception e ) {
0 commit comments