1616import org .abapgit .adt .backend .model .abapgitexternalrepo .IBranch ;
1717import org .abapgit .adt .backend .model .abapgitrepositories .IRepository ;
1818import org .abapgit .adt .backend .model .abapgitrepositories .IRepository .FolderLogic ;
19+ import org .abapgit .adt .ui .AbapGitUIPlugin ;
1920import org .abapgit .adt .ui .internal .i18n .Messages ;
2021import org .abapgit .adt .ui .internal .util .AbapGitUIServiceFactory ;
2122import org .abapgit .adt .ui .internal .util .IAbapGitService ;
2223import org .abapgit .adt .ui .internal .util .RepositoryUtil ;
2324import org .abapgit .adt .ui .internal .wizards .AbapGitWizard .CloneData ;
2425import org .eclipse .core .resources .IProject ;
2526import org .eclipse .core .runtime .IProgressMonitor ;
27+ import org .eclipse .core .runtime .IStatus ;
2628import org .eclipse .core .runtime .NullProgressMonitor ;
29+ import org .eclipse .core .runtime .OperationCanceledException ;
30+ import org .eclipse .core .runtime .Status ;
31+ import org .eclipse .core .runtime .jobs .Job ;
2732import org .eclipse .jface .dialogs .DialogPage ;
2833import org .eclipse .jface .layout .GridDataFactory ;
2934import org .eclipse .jface .operation .IRunnableWithProgress ;
3843import org .eclipse .swt .SWT ;
3944import org .eclipse .swt .events .SelectionAdapter ;
4045import org .eclipse .swt .events .SelectionEvent ;
46+ import org .eclipse .swt .layout .GridData ;
4147import org .eclipse .swt .layout .GridLayout ;
4248import org .eclipse .swt .widgets .Button ;
4349import org .eclipse .swt .widgets .Composite ;
50+ import org .eclipse .swt .widgets .Display ;
4451import org .eclipse .swt .widgets .Label ;
52+ import org .eclipse .swt .widgets .ProgressBar ;
4553
54+ import com .sap .adt .communication .exceptions .CommunicationException ;
55+ import com .sap .adt .communication .resources .ResourceException ;
4656import com .sap .adt .tools .core .model .adtcore .IAdtObjectReference ;
4757import com .sap .adt .tools .core .ui .packages .AdtPackageProposalProviderFactory ;
4858import com .sap .adt .tools .core .ui .packages .AdtPackageServiceUIFactory ;
@@ -68,6 +78,10 @@ public class AbapGitWizardPageBranchAndPackage extends WizardPage {
6878 private boolean backButtonEnabled = true ;
6979 private final ApackParameters lastApackCall ;
7080
81+ private ProgressBar progressBar ;
82+
83+ private Label progressBarLabel ;
84+
7185 public AbapGitWizardPageBranchAndPackage (IProject project , String destination , CloneData cloneData , Boolean pullAction ) {
7286 super (PAGE_NAME );
7387 this .project = project ;
@@ -175,6 +189,8 @@ public void widgetSelected(SelectionEvent event) {
175189 });
176190 }
177191
192+ createProgressBarComposite (container );
193+
178194 setControl (container );
179195
180196 if (this .cloneData .url != null ) {
@@ -197,6 +213,35 @@ public void widgetSelected(SelectionEvent event) {
197213 }
198214 }
199215
216+ private void createProgressBarComposite (Composite container ) {
217+ Composite progressBarComposite = new Composite (container , SWT .NONE );
218+ progressBarComposite .setLayout (new GridLayout (1 , false )); // 1 column layout
219+
220+ this .progressBarLabel = new Label (progressBarComposite , SWT .NONE );
221+ this .progressBarLabel .setText (Messages .AbapGitWizardPageBranchAndPackage_FetchingModifiedObjectsForPull );
222+ this .progressBarLabel .setLayoutData (new GridData (SWT .BEGINNING , SWT .END , true , false ));
223+
224+ this .progressBar = new ProgressBar (progressBarComposite , SWT .INDETERMINATE );
225+ GridData pBGD = new GridData (SWT .FILL , SWT .END , true , false );
226+ this .progressBar .setLayoutData (pBGD );
227+
228+ GridData pbCompGD = new GridData (SWT .FILL , SWT .END , true , true );
229+ pbCompGD .horizontalSpan = 3 ;
230+ progressBarComposite .setLayoutData (pbCompGD );
231+
232+ setProgressVisible (false );
233+ }
234+
235+ public void setProgressVisible (boolean visible ) {
236+ if (this .progressBar != null && !this .progressBar .isDisposed ()) {
237+ this .progressBar .setVisible (visible );
238+ }
239+
240+ if (this .progressBarLabel != null && !this .progressBarLabel .isDisposed ()) {
241+ this .progressBarLabel .setVisible (visible );
242+ }
243+ }
244+
200245 private void setLnpSequence (boolean chboxValue ) {
201246 this .chboxLinkAndPull = chboxValue ;
202247 }
@@ -302,7 +347,7 @@ public void setVisible(boolean visible) {
302347
303348 @ Override
304349 public boolean canFlipToNextPage () {
305- return true ;
350+ return true && isPageComplete () ;
306351 }
307352
308353 @ Override
@@ -316,18 +361,51 @@ public IWizardPage getNextPage() {
316361 // This is valid only for back end versions from 2105 where selective pull is supported.
317362 // If selectivePull is not supported, fetching modified objects is not required and all objects are to be pulled
318363 if (abapGitService .isSelectivePullSupported (repository )) {
319- try {
320- getContainer (). run ( true , true , new IRunnableWithProgress () {
364+ setPageComplete ( false );
365+ setProgressVisible ( true );
321366
322- @ Override
323- public void run (IProgressMonitor monitor ) throws InvocationTargetException , InterruptedException {
324- monitor .beginTask (Messages .AbapGitWizardPageBranchAndPackage_FetchingModifiedObjectsForPull , IProgressMonitor .UNKNOWN );
367+ Job myRequestJob = new Job (Messages .AbapGitWizardPageBranchAndPackage_FetchingModifiedObjectsForPull ) {
368+
369+ @ Override
370+ protected IStatus run (IProgressMonitor monitor ) {
371+ try {
372+ if (monitor .isCanceled ()) {
373+ return Status .CANCEL_STATUS ;
374+ }
325375 RepositoryUtil .fetchAndExtractModifiedObjectsToPull (repository , repoService ,
326376 AbapGitWizardPageBranchAndPackage .this .cloneData );
377+
378+ if (monitor .isCanceled ()) {
379+ return Status .CANCEL_STATUS ;
380+ }
381+ } catch (CommunicationException e ) {
382+ return new Status (IStatus .ERROR , AbapGitUIPlugin .PLUGIN_ID , e .getLocalizedMessage (), e );
383+ } catch (ResourceException e ) {
384+ return new Status (IStatus .ERROR , AbapGitUIPlugin .PLUGIN_ID , e .getLocalizedMessage (), e );
385+ } catch (OperationCanceledException e ) {
386+ return new Status (IStatus .ERROR , AbapGitUIPlugin .PLUGIN_ID , e .getLocalizedMessage (), e );
387+ } finally {
388+ monitor .done ();
327389 }
328- });
329- } catch (InvocationTargetException | InterruptedException e ) {
330- setMessage (e .getMessage (), DialogPage .ERROR );
390+ return Status .OK_STATUS ;
391+ }
392+ };
393+
394+ myRequestJob .setUser (true );
395+ myRequestJob .schedule ();
396+
397+ // wait for the job to finish
398+ Display display = Display .getDefault ();
399+ while (myRequestJob .getResult () == null ) {
400+ if (!display .readAndDispatch ()) {
401+ display .sleep ();
402+ }
403+ }
404+
405+ setProgressVisible (false );
406+
407+ if (myRequestJob .getResult ().getSeverity () != Status .OK && myRequestJob .getResult ().getSeverity () != Status .INFO ) {
408+ setErrorMessage (myRequestJob .getResult ().getMessage ());
331409 setPageComplete (false );
332410 return null ;
333411 }
0 commit comments