Skip to content

Commit 0a84685

Browse files
Run transport check in a new thread to prevent UI freeze (#291)
* Run transport check in a new thread to prevent UI freeze * switched to progress monitor in wizard container instead of a pop-up * modularization of check data method and exception handling * removed inner try block so that OutdatedClientException can be caught
1 parent 52129c7 commit 0a84685

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed

org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/i18n/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public class Messages extends NLS {
145145
public static String AbapGitWizardPageSwitch_credentials_description;
146146
public static String AbapGitWizardSwitch_branch_wizard_title;
147147
public static String AbapGitWizardSwitch_branch_package_ref_not_found_error;
148+
public static String AbapGitWizardPageTransportSelection_transport_check;
148149

149150
//ABAPGIT STAGING MESSAGES
150151
public static String AbapGitStaging_no_repository_selected;

org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/i18n/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ AbapGitWizardPageRepositoryAndCredentials_title=Link abapGit Repository
138138
AbapGitWizardPageRepositoryAndCredentials_validate_password_error=Specify password or personal access token
139139
AbapGitWizardPageRepositoryAndCredentials_validate_url_error=Enter a valid Git URL
140140
AbapGitWizardPageRepositoryAndCredentials_validate_user_error=Specify user
141+
AbapGitWizardPageTransportSelection_transport_check=Performing Transport Checks..
141142
AbapGitWizardSwitch_branch_package_ref_not_found_error=Could not find package ref for {0}
142143

143144
AbapGitStaging_no_repository_selected=No Repository Selected

org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardPull.java

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
import org.eclipse.jface.wizard.Wizard;
3030
import org.eclipse.jface.wizard.WizardDialog;
3131
import org.eclipse.jface.wizard.WizardPage;
32+
import org.eclipse.swt.widgets.Display;
3233
import org.eclipse.ui.PlatformUI;
3334
import org.eclipse.ui.plugin.AbstractUIPlugin;
3435

3536
import com.sap.adt.communication.resources.ResourceException;
37+
import com.sap.adt.compatibility.exceptions.OutDatedClientException;
3638
import com.sap.adt.tools.core.model.adtcore.IAdtCoreFactory;
3739
import com.sap.adt.tools.core.model.adtcore.IAdtObjectReference;
3840
import com.sap.adt.tools.core.project.AdtProjectServiceFactory;
@@ -43,6 +45,7 @@
4345
import com.sap.adt.transport.IAdtTransportService;
4446
import com.sap.adt.transport.ui.wizard.AdtTransportSelectionWizardPageFactory;
4547
import com.sap.adt.transport.ui.wizard.IAdtTransportSelectionWizardPage;
48+
import com.sap.adt.util.ui.AdtUtilUiPlugin;
4649

4750
/**
4851
* This is wizard that handles pull action on a repository. Includes selective
@@ -303,22 +306,12 @@ public void handlePageChanging(final PageChangingEvent event) {
303306

304307
//-> Prepare transport page
305308
if (event.getTargetPage() == AbapGitWizardPull.this.transportPage) {
306-
try {
307-
// The transport service requires URIs to objects we want to create in the
308-
// target package.
309-
// However, we do not know these URIs from the client.
310-
// Instead, give it the URI of the package in which we clone.
311-
IAdtObjectReference packageRef = AbapGitWizardPull.this.cloneData.packageRef;
312-
IAdtObjectReference checkRef = IAdtCoreFactory.eINSTANCE.createAdtObjectReference();
313-
checkRef.setUri(packageRef.getUri());
314-
IAdtTransportCheckData checkData = AbapGitWizardPull.this.transportService.check(checkRef, packageRef.getPackageName(),
315-
true);
316-
AbapGitWizardPull.this.transportPage.setCheckData(checkData);
317-
} catch (Exception e) {
318-
AbapGitWizardPull.this.pageBranchAndPackage.setMessage(e.getMessage(), DialogPage.ERROR);
319-
}
309+
IAdtObjectReference packageRef = AbapGitWizardPull.this.cloneData.packageRef;
310+
IAdtTransportCheckData transportCheckData = getTransportCheckData(packageRef);
311+
AbapGitWizardPull.this.transportPage.setCheckData(transportCheckData);
320312
}
321313

314+
322315
//-> APACK page -> Any page
323316
if (event.getCurrentPage() == AbapGitWizardPull.this.pageApack) {
324317
if (!AbapGitWizardPull.this.pageApack.validateAll()) {
@@ -327,5 +320,55 @@ public void handlePageChanging(final PageChangingEvent event) {
327320
}
328321
}
329322
}
323+
324+
private IAdtTransportCheckData getTransportCheckData(IAdtObjectReference packageRef) {
325+
326+
IAdtObjectReference checkRef = IAdtCoreFactory.eINSTANCE.createAdtObjectReference();
327+
checkRef.setUri(packageRef.getUri());
328+
329+
final IAdtTransportCheckData[] checkData = new IAdtTransportCheckData[1];
330+
331+
try {
332+
getContainer().run(true, true, monitor -> {
333+
monitor.beginTask(Messages.AbapGitWizardPageTransportSelection_transport_check, IProgressMonitor.UNKNOWN);
334+
checkData[0] = AbapGitWizardPull.this.transportService.check(checkRef, packageRef.getPackageName(), true);
335+
});
336+
return checkData[0];
337+
338+
} catch (Exception e) {
339+
// Catches InterruptedException and other general exceptions
340+
WizardPage currentPage = ((WizardPage) getContainer().getCurrentPage());
341+
handleException(e, currentPage);
342+
return null;
343+
}
344+
}
345+
346+
private void handleOutdatedClientException(Throwable e) {
347+
348+
Display.getDefault().asyncExec(() -> {
349+
WizardDialog d = (WizardDialog) getContainer();
350+
351+
if (d != null) {
352+
// Check if the dialog is still open before attempting to close
353+
if (d.getShell() != null && !d.getShell().isDisposed()) {
354+
d.close();
355+
AdtUtilUiPlugin.getDefault().getAdtStatusService().handle(e, null);
356+
}
357+
}
358+
});
359+
360+
}
361+
362+
private void handleException(Exception exception, WizardPage page) {
363+
364+
page.setPageComplete(false);
365+
Throwable cause = exception instanceof InvocationTargetException ? exception.getCause() : exception;
366+
if (cause != null && cause instanceof OutDatedClientException) {
367+
handleOutdatedClientException(cause);
368+
} else {
369+
page.setMessage(cause != null ? cause.getMessage() : exception.getMessage(), DialogPage.ERROR);
370+
}
371+
}
372+
330373
}
331374
}

0 commit comments

Comments
 (0)