Search in sources :

Example 1 with RebaseInteractivePlan

use of org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan in project egit by eclipse.

the class AbstractRebaseCommandHandler method startRebaseJob.

private void startRebaseJob(final RebaseOperation rebase, final Repository repository, final RebaseCommand.Operation operation) {
    JobUtil.scheduleUserWorkspaceJob(rebase, jobname, JobFamilies.REBASE, new JobChangeAdapter() {

        @Override
        public void aboutToRun(IJobChangeEvent event) {
            // that repository state is safe
            if (operation == Operation.BEGIN && !repository.getRepositoryState().equals(RepositoryState.SAFE)) {
                throw new IllegalStateException(// $NON-NLS-1$
                "Can't start rebase if repository state isn't SAFE");
            }
            super.aboutToRun(event);
        }

        @Override
        public void done(IJobChangeEvent cevent) {
            finishRebaseInteractive();
            IStatus result = cevent.getJob().getResult();
            if (result == null) {
                return;
            }
            // abort and show exception
            if (operation == Operation.BEGIN && result.getSeverity() == IStatus.ERROR) {
                handleBeginError(repository, result);
            } else if (result.getSeverity() == IStatus.CANCEL)
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        // don't use getShell(event) here since
                        // the active shell has changed since the
                        // execution has been triggered.
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        MessageDialog.openInformation(shell, UIText.AbstractRebaseCommand_DialogTitle, dialogMessage);
                    }
                });
            else if (result.isOK()) {
                if (rebase.getResult().getStatus() == Status.UNCOMMITTED_CHANGES) {
                    handleUncommittedChanges(repository, rebase.getResult().getUncommittedChanges());
                } else {
                    RebaseResultDialog.show(rebase.getResult(), repository);
                    if (operation == Operation.ABORT)
                        setAmending(false, false);
                    if (rebase.getResult().getStatus() == Status.EDIT)
                        setAmending(true, true);
                }
            }
        }

        private void setAmending(final boolean amending, final boolean openStagingView) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        IViewPart view;
                        if (openStagingView)
                            view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(StagingView.VIEW_ID);
                        else
                            view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(StagingView.VIEW_ID);
                        if (view instanceof StagingView) {
                            final StagingView sv = (StagingView) view;
                            sv.reload(repository);
                            Display.getDefault().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    sv.setAmending(amending);
                                }
                            });
                        }
                    } catch (PartInitException e) {
                        Activator.logError(e.getMessage(), e);
                    }
                }
            });
        }

        private void finishRebaseInteractive() {
            RebaseInteractivePlan plan = RebaseInteractivePlan.getPlan(repository);
            if (plan != null && !plan.isRebasingInteractive())
                plan.dispose();
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Shell(org.eclipse.swt.widgets.Shell) IViewPart(org.eclipse.ui.IViewPart) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) RebaseInteractivePlan(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) StagingView(org.eclipse.egit.ui.internal.staging.StagingView) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 RebaseInteractivePlan (org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan)1 StagingView (org.eclipse.egit.ui.internal.staging.StagingView)1 Shell (org.eclipse.swt.widgets.Shell)1 IViewPart (org.eclipse.ui.IViewPart)1 PartInitException (org.eclipse.ui.PartInitException)1