use of org.eclipse.egit.ui.internal.dialogs.NonBlockingWizardDialog in project egit by eclipse.
the class FetchGerritChangePage method getRefsForContentAssist.
private Collection<Change> getRefsForContentAssist(String originalRefText) throws InvocationTargetException, InterruptedException {
String uriText = uriCombo.getText();
if (!changeRefs.containsKey(uriText)) {
changeRefs.put(uriText, new ChangeList(repository, uriText));
}
ChangeList list = changeRefs.get(uriText);
if (!list.isFinished()) {
IWizardContainer container = getContainer();
IRunnableWithProgress operation = monitor -> {
monitor.beginTask(MessageFormat.format(UIText.AsynchronousRefProposalProvider_FetchingRemoteRefsMessage, uriText), IProgressMonitor.UNKNOWN);
Collection<Change> result = list.get();
if (monitor.isCanceled()) {
return;
}
// If we get here, the ChangeList future is done.
if (result == null || result.isEmpty() || fetching) {
// 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() && !fetching;
}
@Override
public IStatus runInUIThread(IProgressMonitor uiMonitor) {
// the same
try {
if (container instanceof NonBlockingWizardDialog) {
// focus will be restored
if (fetching) {
return Status.CANCEL_STATUS;
}
String uriNow = uriCombo.getText();
if (!uriNow.equals(uriText)) {
return Status.CANCEL_STATUS;
}
if (refText != refText.getDisplay().getFocusControl()) {
fillInPatchSet(result, null);
return Status.CANCEL_STATUS;
}
// Try not to interfere with the user's typing.
// Only fill in the patch set number if the text
// is still the same.
fillInPatchSet(result, originalRefText);
doAutoFill = false;
} else {
// Dialog was blocked
fillInPatchSet(result, null);
doAutoFill = false;
}
contentProposer.openProposalPopup();
} catch (SWTException e) {
// Disposed already
return Status.CANCEL_STATUS;
} finally {
doAutoFill = true;
uiMonitor.done();
}
return Status.OK_STATUS;
}
};
showProposals.schedule();
};
if (container instanceof NonBlockingWizardDialog) {
NonBlockingWizardDialog dialog = (NonBlockingWizardDialog) container;
dialog.run(operation, () -> {
if (!fetching) {
list.cancel(ChangeList.CancelMode.ABANDON);
}
});
} else {
container.run(true, true, operation);
}
return null;
}
// ChangeList is already here, so get() won't block
Collection<Change> changes = list.get();
if (doAutoFill) {
fillInPatchSet(changes, originalRefText);
}
return changes;
}
use of org.eclipse.egit.ui.internal.dialogs.NonBlockingWizardDialog in project egit by eclipse.
the class FetchChangeFromGerritCommand method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Repository repository = getRepository(event);
if (repository == null) {
Shell shell = getShell(event);
MessageDialog.openInformation(shell, UIText.FetchChangeFromGerritCommand_noRepositorySelectedTitle, UIText.FetchChangeFromGerritCommand_noRepositorySelectedMessage);
return null;
}
FetchGerritChangeWizard wiz = new FetchGerritChangeWizard(repository);
NonBlockingWizardDialog dlg = new NonBlockingWizardDialog(HandlerUtil.getActiveShellChecked(event), wiz);
dlg.setHelpAvailable(false);
dlg.open();
return null;
}
use of org.eclipse.egit.ui.internal.dialogs.NonBlockingWizardDialog 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