use of org.eclipse.egit.ui.internal.dialogs.CancelableFuture in project egit by eclipse.
the class AsynchronousRefProposalProvider method getCandidates.
@Override
public Collection<? extends Ref> getCandidates() {
String uri = uriProvider.get();
if (uri == null) {
return null;
}
CancelableFuture<Collection<Ref>> list = listProvider.apply(uri);
try {
if (!list.isFinished()) {
IRunnableWithProgress operation = monitor -> {
monitor.beginTask(MessageFormat.format(UIText.AsynchronousRefProposalProvider_FetchingRemoteRefsMessage, uri), IProgressMonitor.UNKNOWN);
Collection<Ref> result = list.get();
if (monitor.isCanceled()) {
return;
}
// If we get here, the ChangeList future is done.
if (result == null || result.isEmpty()) {
// Don't bother if we didn't get any results
return;
}
// If we do have results now, open the proposals.
Job showProposals = new WorkbenchJob(UIText.AsynchronousRefProposalProvider_ShowingProposalsJobName) {
@Override
public boolean shouldRun() {
return super.shouldRun() && contentProposer != null;
}
@Override
public IStatus runInUIThread(IProgressMonitor uiMonitor) {
// is still the same
try {
if (container instanceof NonBlockingWizardDialog) {
// and focus will be restored
if (textField.isDisposed() || !textField.isVisible() || textField != textField.getDisplay().getFocusControl()) {
return Status.CANCEL_STATUS;
}
String uriNow = uriProvider.get();
if (!uriNow.equals(uri)) {
return Status.CANCEL_STATUS;
}
}
contentProposer.openProposalPopup();
} catch (SWTException e) {
// Disposed already
return Status.CANCEL_STATUS;
} finally {
uiMonitor.done();
}
return Status.OK_STATUS;
}
};
showProposals.schedule();
};
if (container instanceof NonBlockingWizardDialog) {
NonBlockingWizardDialog dialog = (NonBlockingWizardDialog) container;
dialog.run(operation, () -> list.cancel(CancelableFuture.CancelMode.ABANDON));
} else {
container.run(true, true, operation);
}
return null;
}
return list.get();
} catch (InterruptedException | InvocationTargetException e) {
return null;
}
}
Aggregations