Skip to content

Conversation

aarnapant-sap
Copy link
Contributor

fix: Run transport check in a new thread to prevent UI freeze

  • The previous implementation of the transport check was running on the main UI
    thread, which caused the application to become unresponsive during long
    operations.

  • This change moves the transport check to a ModalContext thread, ensuring the
    UI remains responsive and providing visual feedback to the user via a modal
    progress dialog.

IAdtTransportCheckData checkData = AbapGitWizardPull.this.transportService.check(checkRef, packageRef.getPackageName(),
true);
AbapGitWizardPull.this.transportPage.setCheckData(checkData);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor refactoring and exception handling suggestions:

  1. Shall we move the transport check into a separate method which returns the check data?
  2. monitor.done can be added in a finally block
  3. There are mainly two exceptions from the process, InterruptedException ( caused if it is cancelled ) and InvocationTargetException ( when any exception occurs inside the code block ). Added some suggestions for the handling of these. Please have a look and also test it once.
	private IAdtTransportCheckData getTransportCheckData(IAdtObjectReference packageRef) {
		WizardPage currentPage = ((WizardPage) getContainer().getCurrentPage());
		IAdtObjectReference checkRef = IAdtCoreFactory.eINSTANCE.createAdtObjectReference();
		checkRef.setUri(packageRef.getUri());

		final IAdtTransportCheckData[] checkData = new IAdtTransportCheckData[1];

		try {
			getContainer().run(true, true, monitor -> {
				try {
					monitor.beginTask(Messages.AbapGitWizardPageTransportSelection_transport_check, IProgressMonitor.UNKNOWN);
					checkData[0] = AbapGitWizardPull.this.transportService.check(checkRef, packageRef.getPackageName(), true);
				} finally {
					monitor.done();
				}
			});
			return checkData[0];
		} catch (Exception exception) {
			handleError(exception, currentPage);
		}
		return null;
	}

	private void handleError(Exception exception, WizardPage currentPage) {
		currentPage.setPageComplete(false);
		Throwable cause = exception instanceof InvocationTargetException ? exception.getCause() : exception;
		if (cause != null && cause instanceof OutDatedClientException) {
			AdtUtilUiPlugin.getDefault().getAdtStatusService().handle(cause, null);
		} else {
			currentPage.setMessage(cause != null ? cause.getMessage() : exception.getMessage(), DialogPage.ERROR);
		}
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I will modularize the transport check data code

private void handleOutdatedClientException(Exception e) {

Display.getDefault().asyncExec(() -> {
WizardDialog d = (WizardDialog) getContainer();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d -> dialog

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

}
}
});
AdtUtilUiPlugin.getDefault().getAdtStatusService().handle(e, null);
Copy link
Collaborator

@abinbaby-sap abinbaby-sap Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be done after d.close() inside the thread? Will that work? So that only after closing the wizard we will open this dialog.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that should work.

page.setPageComplete(false);
Throwable cause = exception instanceof InvocationTargetException ? exception.getCause() : exception;
if (cause != null && cause instanceof OutDatedClientException) {
Display.getDefault().asyncExec(() -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could call the new method for handling the OutDatedClientException right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I forgot to change this implementation with method name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants