Search in sources :

Example 1 with NonBlockingWizardDialog

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;
}
Also used : SortedSet(java.util.SortedSet) UIPreferences(org.eclipse.egit.ui.UIPreferences) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) ExplicitContentProposalAdapter(org.eclipse.egit.ui.UIUtils.ExplicitContentProposalAdapter) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) Clipboard(org.eclipse.swt.dnd.Clipboard) RevWalk(org.eclipse.jgit.revwalk.RevWalk) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Matcher(java.util.regex.Matcher) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) KeyEvent(org.eclipse.swt.events.KeyEvent) URIish(org.eclipse.jgit.transport.URIish) FetchResult(org.eclipse.jgit.transport.FetchResult) SWTException(org.eclipse.swt.SWTException) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) JobFamilies(org.eclipse.egit.ui.JobFamilies) Text(org.eclipse.swt.widgets.Text) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) TagBuilder(org.eclipse.jgit.lib.TagBuilder) NLS(org.eclipse.osgi.util.NLS) ActionUtils(org.eclipse.egit.ui.internal.ActionUtils) RefSpec(org.eclipse.jgit.transport.RefSpec) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) Constants(org.eclipse.jgit.lib.Constants) AsynchronousListOperation(org.eclipse.egit.ui.internal.components.AsynchronousListOperation) AbstractBranchSelectionDialog(org.eclipse.egit.ui.internal.dialogs.AbstractBranchSelectionDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Transfer(org.eclipse.swt.dnd.Transfer) Objects(java.util.Objects) PersonIdent(org.eclipse.jgit.lib.PersonIdent) TagOperation(org.eclipse.egit.core.op.TagOperation) GerritDialogSettings(org.eclipse.egit.ui.internal.gerrit.GerritDialogSettings) List(java.util.List) Window(org.eclipse.jface.window.Window) UIText(org.eclipse.egit.ui.internal.UIText) Ref(org.eclipse.jgit.lib.Ref) SWT(org.eclipse.swt.SWT) Pattern(java.util.regex.Pattern) IPageChangeProvider(org.eclipse.jface.dialogs.IPageChangeProvider) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) Label(org.eclipse.swt.widgets.Label) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Activator(org.eclipse.egit.ui.Activator) SubMonitor(org.eclipse.core.runtime.SubMonitor) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) JFaceResources(org.eclipse.jface.resource.JFaceResources) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) TreeSet(java.util.TreeSet) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ValidationUtils(org.eclipse.egit.ui.internal.ValidationUtils) IWorkspace(org.eclipse.core.resources.IWorkspace) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) TextTransfer(org.eclipse.swt.dnd.TextTransfer) WizardPage(org.eclipse.jface.wizard.WizardPage) GridData(org.eclipse.swt.layout.GridData) LinkedHashSet(java.util.LinkedHashSet) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) BranchNameNormalizer(org.eclipse.egit.ui.internal.components.BranchNameNormalizer) Combo(org.eclipse.swt.widgets.Combo) Job(org.eclipse.core.runtime.jobs.Job) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IOException(java.io.IOException) NonBlockingWizardDialog(org.eclipse.egit.ui.internal.dialogs.NonBlockingWizardDialog) Group(org.eclipse.swt.widgets.Group) BranchOperationUI(org.eclipse.egit.ui.internal.branch.BranchOperationUI) Dialog(org.eclipse.jface.dialogs.Dialog) ModifyListener(org.eclipse.swt.events.ModifyListener) GerritUtil(org.eclipse.egit.core.internal.gerrit.GerritUtil) UIUtils(org.eclipse.egit.ui.UIUtils) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) BranchEditDialog(org.eclipse.egit.ui.internal.dialogs.BranchEditDialog) ActionFactory(org.eclipse.ui.actions.ActionFactory) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) IStatus(org.eclipse.core.runtime.IStatus) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NonBlockingWizardDialog(org.eclipse.egit.ui.internal.dialogs.NonBlockingWizardDialog) SWTException(org.eclipse.swt.SWTException) Collection(java.util.Collection) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) Job(org.eclipse.core.runtime.jobs.Job)

Example 2 with NonBlockingWizardDialog

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;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) NonBlockingWizardDialog(org.eclipse.egit.ui.internal.dialogs.NonBlockingWizardDialog) FetchGerritChangeWizard(org.eclipse.egit.ui.internal.fetch.FetchGerritChangeWizard)

Example 3 with NonBlockingWizardDialog

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;
    }
}
Also used : Text(org.eclipse.swt.widgets.Text) Job(org.eclipse.core.runtime.jobs.Job) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) ExplicitContentProposalAdapter(org.eclipse.egit.ui.UIUtils.ExplicitContentProposalAdapter) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) Function(java.util.function.Function) Supplier(java.util.function.Supplier) NonBlockingWizardDialog(org.eclipse.egit.ui.internal.dialogs.NonBlockingWizardDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) MessageFormat(java.text.MessageFormat) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) UIText(org.eclipse.egit.ui.internal.UIText) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Ref(org.eclipse.jgit.lib.Ref) SWTException(org.eclipse.swt.SWTException) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) IContentProposalCandidateProvider(org.eclipse.egit.ui.UIUtils.IContentProposalCandidateProvider) CancelableFuture(org.eclipse.egit.ui.internal.dialogs.CancelableFuture) IStatus(org.eclipse.core.runtime.IStatus) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NonBlockingWizardDialog(org.eclipse.egit.ui.internal.dialogs.NonBlockingWizardDialog) SWTException(org.eclipse.swt.SWTException) Collection(java.util.Collection) Job(org.eclipse.core.runtime.jobs.Job) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MessageFormat (java.text.MessageFormat)2 Collection (java.util.Collection)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Job (org.eclipse.core.runtime.jobs.Job)2 ExplicitContentProposalAdapter (org.eclipse.egit.ui.UIUtils.ExplicitContentProposalAdapter)2 UIText (org.eclipse.egit.ui.internal.UIText)2 NonBlockingWizardDialog (org.eclipse.egit.ui.internal.dialogs.NonBlockingWizardDialog)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1