@@ -328,12 +328,14 @@ class DownloadTask extends SwingWorker<Object, Object> {
328
328
ProgressIndicator progress ;
329
329
JProgressBar progressBar ;
330
330
Boolean isPlatform ;
331
+ JLabel status ;
331
332
332
- DownloadTask (JProgressBar progressBar , Boolean isPlatform ) {
333
+ DownloadTask (JProgressBar progressBar , Boolean isPlatform , JLabel status ) {
333
334
super ();
334
335
progress = new ConsoleProgressIndicator ();
335
336
this .progressBar = progressBar ;
336
337
this .isPlatform = isPlatform ;
338
+ this .status = status ;
337
339
}
338
340
339
341
@ Override
@@ -350,6 +352,7 @@ protected Object doInBackground() throws Exception {
350
352
Downloader downloader = new LegacyDownloader (fop , settings );
351
353
352
354
RepoManager mRepoManager = mHandler .getSdkManager (progress );
355
+ status .setText ("Loading repository" );
353
356
mRepoManager .loadSynchronously (0 , progress , downloader , settings );
354
357
355
358
List <RemotePackage > remotes = new ArrayList <>();
@@ -375,6 +378,7 @@ protected Object doInBackground() throws Exception {
375
378
for (RemotePackage p : remotes ) {
376
379
Installer installer = SdkInstallerUtil .findBestInstallerFactory (p , mHandler )
377
380
.createInstaller (p , mRepoManager , downloader , mHandler .getFileOp ());
381
+ status .setText ("Downloading..." );
378
382
if (!(installer .prepare (progress ) && installer .complete (progress ))) {
379
383
// there was an error, abort.
380
384
throw new SdkManagerCli .CommandFailedException ();
@@ -398,6 +402,12 @@ protected void done() {
398
402
tabs .setEnabled (true );
399
403
status .setText ("Refreshing packages..." );
400
404
statusPlatform .setText ("Refreshing packages..." );
405
+
406
+ //reset the progress bar to indeterminate for querying
407
+ progressBar .setIndeterminate (false );
408
+ progressBarPlatform .setIndeterminate (false );
409
+
410
+ //start querying again
401
411
queryTask = new QueryTask ();
402
412
queryTask .addPropertyChangeListener (SDKUpdater .this );
403
413
queryTask .execute ();
@@ -456,6 +466,21 @@ public java.util.List<String> getPaths(RepoManager mgr,Boolean isPlatform) {
456
466
}
457
467
}
458
468
469
+ private void startProgressThread (final JProgressBar bar ){
470
+ Thread update = new Thread () {
471
+ @ Override
472
+ public void run () {
473
+ while (downloadTaskRunning ) {
474
+ try {
475
+ Thread .sleep (100 );
476
+ } catch (InterruptedException e ) { }
477
+ bar .setValue ((int ) (downloadTask .progress .getFraction () * 100 ));
478
+ }
479
+ }
480
+ };
481
+ update .start ();
482
+ }
483
+
459
484
private void createLayout (final boolean standalone ) {
460
485
setTitle (getMenuTitle ());
461
486
@@ -538,27 +563,16 @@ public String getColumnName(int column) {
538
563
actionButton .addActionListener (new ActionListener () {
539
564
public void actionPerformed (ActionEvent e ) {
540
565
if (downloadTaskRunning ) { // i.e button state is Cancel
566
+ status .setText ("Update canceled" );
567
+ actionButton .setText ("Update" );
541
568
cancelTasks ();
542
569
} else { // i.e button state is Update
543
- downloadTask = new DownloadTask (progressBar ,false );
544
- progressBar .setIndeterminate (true );
570
+ downloadTask = new DownloadTask (progressBar ,false ,status );
571
+ progressBar .setIndeterminate (false );
572
+ progressBar .setMaximum (100 );
545
573
downloadTask .execute ();
546
-
547
- // getFraction() always returns 0.0, needs to be set somewhere (??)
548
- // Thread update = new Thread() {
549
- // @Override
550
- // public void run() {
551
- // while (downloadTaskRunning) {
552
- // try {
553
- // Thread.sleep(100);
554
- // } catch (InterruptedException e) { }
555
- // System.out.println("Updating: " + downloadTask.progress.getFraction());
556
- // }
557
- // }
558
- // };
559
- // update.start();
560
-
561
- status .setText ("Downloading available updates..." );
574
+ startProgressThread (progressBar );
575
+ status .setText ("Downloading selected updates..." );
562
576
actionButton .setText ("Cancel" );
563
577
tabs .setEnabled (false );
564
578
}
@@ -661,11 +675,16 @@ public String getColumnName(int column) {
661
675
@ Override
662
676
public void actionPerformed (ActionEvent e ) {
663
677
if (downloadTaskRunning ) { // i.e button state is Cancel
678
+ statusPlatform .setText ("Download canceled" );
679
+ actionButtonPlatform .setText ("Install" );
664
680
cancelTasks ();
665
681
} else { // i.e button state is Update
666
- downloadTask = new DownloadTask (progressBarPlatform ,true );
667
- progressBarPlatform .setIndeterminate (true );
682
+ downloadTask = new DownloadTask (progressBarPlatform ,true ,statusPlatform );
683
+ progressBarPlatform .setIndeterminate (false );
684
+ progressBarPlatform .setMaximum (100 );
668
685
downloadTask .execute ();
686
+ startProgressThread (progressBarPlatform );
687
+ statusPlatform .setText ("Downloading selected platforms.." );
669
688
actionButtonPlatform .setText ("Cancel" );
670
689
tabs .setEnabled (false );
671
690
}
@@ -719,11 +738,15 @@ public void cancelTasks() {
719
738
queryTask .cancel (true );
720
739
if (downloadTaskRunning ) {
721
740
downloadTask .cancel (true );
722
- status .setText ("Download canceled" );
741
+
742
+ //reset UI
743
+ tabs .setEnabled (true );
723
744
JOptionPane .showMessageDialog (null ,
724
745
"Download canceled" , "Warning" , JOptionPane .WARNING_MESSAGE );
725
- actionButton .setText ("Update" );
726
- actionButtonPlatform .setText ("Install" );
746
+
747
+ //reset progress bar
748
+ progressBar .setValue (0 );
749
+ progressBarPlatform .setValue (0 );
727
750
}
728
751
}
729
752
0 commit comments