64
64
import javax .swing .table .TableColumnModel ;
65
65
66
66
import cc .arduino .packages .contributions .ContributedPlatform ;
67
- import cc .arduino .packages .contributions .ContributionsIndex ;
67
+ import cc .arduino .packages .contributions .ContributionInstaller ;
68
+ import cc .arduino .packages .contributions .ContributionsIndexer ;
68
69
69
70
@ SuppressWarnings ("serial" )
70
71
public class ContributionManagerUI extends JDialog {
71
72
72
73
private FilterJTextField filterField ;
73
74
74
- private ContributionManagerUIListener listener = null ;
75
-
76
75
private JLabel categoryLabel ;
77
76
private JComboBox categoryChooser ;
78
77
private Component categoryStrut1 ;
@@ -92,8 +91,9 @@ public class ContributionManagerUI extends JDialog {
92
91
private String category ;
93
92
private String [] filters ;
94
93
95
- public ContributionManagerUI (Frame parent ) {
94
+ public ContributionManagerUI (Frame parent , ContributionsIndexer indexer ) {
96
95
super (parent , "Boards Manager" , Dialog .ModalityType .APPLICATION_MODAL );
96
+
97
97
setResizable (true );
98
98
99
99
Container pane = getContentPane ();
@@ -144,40 +144,25 @@ protected void onFilter(String[] _filters) {
144
144
145
145
contribTable = new JTable (contribModel );
146
146
contribTable .setTableHeader (null );
147
- // contribTable.getTableHeader().setEnabled(false);
148
- // contribTable.setRowSelectionAllowed(false);
149
147
contribTable .setSelectionMode (ListSelectionModel .SINGLE_SELECTION );
150
148
contribTable .setColumnSelectionAllowed (false );
151
149
contribTable .setDragEnabled (false );
152
150
contribTable .setIntercellSpacing (new Dimension (0 , 1 ));
153
151
contribTable .setShowVerticalLines (false );
154
- // contribTable.addMouseListener(new MouseAdapter() {
155
- // @Override
156
- // public void mousePressed(MouseEvent e) {
157
- // if (listener == null)
158
- // return;
159
- // Point point = e.getPoint();
160
- // int row = contribTable.rowAtPoint(point);
161
- // int col = contribTable.columnAtPoint(point);
162
- // }
163
- // });
152
+
164
153
{
165
154
TableColumnModel tcm = contribTable .getColumnModel ();
166
155
TableColumn col = tcm .getColumn (DESCRIPTION_COL );
167
156
col .setCellRenderer (new ContributedPlatformTableCell ());
168
157
cellEditor = new ContributedPlatformTableCell () {
169
158
@ Override
170
159
protected void onInstall (ContributedPlatform selectedPlatform ) {
171
- if (listener == null )
172
- return ;
173
- listener .onInstall (selectedPlatform );
160
+ onInstallPressed (selectedPlatform );
174
161
}
175
162
176
163
@ Override
177
164
protected void onRemove (ContributedPlatform installedPlatform ) {
178
- if (listener == null )
179
- return ;
180
- listener .onRemove (installedPlatform );
165
+ onRemovePressed (installedPlatform );
181
166
}
182
167
};
183
168
col .setCellEditor (cellEditor );
@@ -205,17 +190,15 @@ protected void onRemove(ContributedPlatform installedPlatform) {
205
190
cancelButton .addActionListener (new ActionListener () {
206
191
@ Override
207
192
public void actionPerformed (ActionEvent arg0 ) {
208
- if (listener != null )
209
- listener .onCancelPressed ();
193
+ onCancelPressed ();
210
194
}
211
195
});
212
196
213
197
JButton updateButton = new JButton (_ ("Update list" ));
214
198
updateButton .addActionListener (new ActionListener () {
215
199
@ Override
216
200
public void actionPerformed (ActionEvent arg0 ) {
217
- if (listener != null )
218
- listener .onUpdatePressed ();
201
+ onUpdatePressed ();
219
202
}
220
203
});
221
204
@@ -255,10 +238,18 @@ public void run() {
255
238
});
256
239
}
257
240
});
258
- }
259
241
260
- public void setListener (ContributionManagerUIListener listener ) {
261
- this .listener = listener ;
242
+ contribModel .setIndex (indexer .getIndex ());
243
+ setCategories (indexer .getIndex ().getCategories ());
244
+
245
+ // Create installer with his dialog
246
+ installer = new ContributionInstaller (indexer );
247
+ installer .setListener (new ContributionInstaller .Listener () {
248
+ @ Override
249
+ public void onProgress (double progress , String message ) {
250
+ setProgress ((int ) progress , message );
251
+ }
252
+ });
262
253
}
263
254
264
255
public void setCategories (Collection <String > categories ) {
@@ -280,11 +271,6 @@ public void setCategories(Collection<String> categories) {
280
271
categoryStrut3 .setVisible (show );
281
272
}
282
273
283
- public void setContributions (ContributionsIndex index ) {
284
- contribModel .setIndex (index );
285
- setCategories (index .getCategories ());
286
- }
287
-
288
274
public void setProgressVisible (boolean visible ) {
289
275
progressBox .setVisible (visible );
290
276
@@ -318,4 +304,58 @@ public void setProgress(int progress, String text) {
318
304
if (text != null )
319
305
progressBar .setString (text );
320
306
}
307
+
308
+ public void onUpdatePressed () {
309
+ // TODO Auto-generated method stub
310
+ System .out .println ("Update pressed" );
311
+ }
312
+
313
+ /*
314
+ * Installer methods follows
315
+ */
316
+
317
+ private ContributionInstaller installer ;
318
+ private Thread installerThread = null ;
319
+
320
+ public void onCancelPressed () {
321
+ if (installerThread != null )
322
+ installerThread .interrupt ();
323
+ }
324
+
325
+ public void onInstallPressed (final ContributedPlatform platform ) {
326
+ installerThread = new Thread (new Runnable () {
327
+ @ Override
328
+ public void run () {
329
+ try {
330
+ setProgressVisible (true );
331
+ installer .install (platform );
332
+ } catch (Exception e ) {
333
+ // TODO Show ERROR
334
+ e .printStackTrace ();
335
+ } finally {
336
+ setProgressVisible (false );
337
+ }
338
+ }
339
+ });
340
+ installerThread .start ();
341
+ }
342
+
343
+ public void onRemovePressed (final ContributedPlatform platform ) {
344
+ installerThread = new Thread (new Runnable () {
345
+ @ Override
346
+ public void run () {
347
+ try {
348
+ setProgressVisible (true );
349
+ installer .remove (platform );
350
+ } catch (Exception e ) {
351
+ // TODO Show ERROR
352
+ e .printStackTrace ();
353
+ } finally {
354
+ setProgressVisible (false );
355
+ }
356
+ }
357
+ });
358
+ installerThread .start ();
359
+ }
360
+
321
361
}
0 commit comments