Search in sources :

Example 41 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.

the class MergeCommand method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    RepositoryTreeNode node = getSelectedNodes(event).get(0);
    final Repository repository = node.getRepository();
    if (!MergeActionHandler.checkMergeIsPossible(repository, getShell(event)) || LaunchFinder.shouldCancelBecauseOfRunningLaunches(repository, null)) {
        return null;
    }
    BasicConfigurationDialog.show(repository);
    String targetRef;
    if (node instanceof RefNode) {
        String refName = ((RefNode) node).getObject().getName();
        try {
            if (refName.equals(repository.getFullBranch()))
                targetRef = null;
            else
                targetRef = refName;
        } catch (IOException e) {
            targetRef = null;
        }
    } else if (node instanceof TagNode)
        targetRef = ((TagNode) node).getObject().getName();
    else
        targetRef = null;
    final String refName;
    final MergeOperation op;
    if (targetRef != null) {
        refName = targetRef;
        op = new MergeOperation(repository, refName);
    } else {
        MergeTargetSelectionDialog mergeTargetSelectionDialog = new MergeTargetSelectionDialog(getShell(event), repository);
        if (mergeTargetSelectionDialog.open() != IDialogConstants.OK_ID)
            return null;
        refName = mergeTargetSelectionDialog.getRefName();
        op = new MergeOperation(repository, refName);
        op.setSquash(mergeTargetSelectionDialog.isMergeSquash());
        op.setFastForwardMode(mergeTargetSelectionDialog.getFastForwardMode());
        op.setCommit(mergeTargetSelectionDialog.isCommit());
    }
    String jobname = NLS.bind(UIText.MergeAction_JobNameMerge, refName);
    Job job = new WorkspaceJob(jobname) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
                op.execute(monitor);
            } catch (final CoreException e) {
                return e.getStatus();
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.setRule(op.getSchedulingRule());
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent jobEvent) {
            IStatus result = jobEvent.getJob().getResult();
            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.MergeAction_MergeCanceledTitle, UIText.MergeAction_MergeCanceledMessage);
                    }
                });
            else if (!result.isOK())
                Activator.handleError(result.getMessage(), result.getException(), true);
            else
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        MergeResultDialog.getDialog(shell, repository, op.getResult()).open();
                    }
                });
        }
    });
    job.schedule();
    return null;
}
Also used : MergeOperation(org.eclipse.egit.core.op.MergeOperation) IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IOException(java.io.IOException) MergeTargetSelectionDialog(org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) CoreException(org.eclipse.core.runtime.CoreException) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Example 42 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.

the class FeatureFinishHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);
    if (gfRepo == null) {
        return error(UIText.Handlers_noGitflowRepositoryFound);
    }
    final String featureBranch;
    Repository repo = gfRepo.getRepository();
    try {
        featureBranch = repo.getBranch();
    } catch (IOException e) {
        return error(e.getMessage(), e);
    }
    Shell activeShell = HandlerUtil.getActiveShell(event);
    FinishFeatureDialog dialog = new FinishFeatureDialog(activeShell, featureBranch);
    if (dialog.open() != Window.OK) {
        return null;
    }
    final boolean squash = dialog.isSquash();
    boolean keepBranch = dialog.isKeepBranch();
    try {
        try {
            if (squash && !UIRepositoryUtils.handleUncommittedFiles(repo, activeShell))
                return null;
        } catch (GitAPIException e) {
            Activator.logError(e.getMessage(), e);
            return null;
        }
        final FeatureFinishOperation operation = new FeatureFinishOperation(gfRepo);
        operation.setSquash(squash);
        operation.setKeepBranch(keepBranch);
        JobUtil.scheduleUserWorkspaceJob(operation, UIText.FeatureFinishHandler_finishingFeature, JobFamilies.GITFLOW_FAMILY, new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent jobChangeEvent) {
                if (jobChangeEvent.getResult().isOK()) {
                    postMerge(gfRepo, featureBranch, squash, operation.getMergeResult());
                }
            }
        });
    } catch (WrongGitFlowStateException | CoreException | IOException | OperationCanceledException e) {
        return error(e.getMessage(), e);
    }
    return null;
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) FinishFeatureDialog(org.eclipse.egit.gitflow.ui.internal.dialogs.FinishFeatureDialog) IOException(java.io.IOException) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) FeatureFinishOperation(org.eclipse.egit.gitflow.op.FeatureFinishOperation) CoreException(org.eclipse.core.runtime.CoreException) WrongGitFlowStateException(org.eclipse.egit.gitflow.WrongGitFlowStateException) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository)

Example 43 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.

the class MergeActionHandler method doMerge.

/**
 * Run a {@link MergeOperation} in a {@link WorkspaceJob} and report the
 * result in a dialog.
 *
 * @param repository
 *            the merge operates on
 * @param op
 *            performing the merge
 * @param refName
 *            the merge is for; used in the job's name
 */
public static void doMerge(Repository repository, MergeOperation op, String refName) {
    JobUtil.scheduleUserWorkspaceJob(op, NLS.bind(UIText.MergeAction_JobNameMerge, refName), JobFamilies.MERGE, new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            IStatus result = event.getJob().getResult();
            if (result.getSeverity() == IStatus.CANCEL) {
                PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
                    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                    MessageDialog.openInformation(shell, UIText.MergeAction_MergeCanceledTitle, UIText.MergeAction_MergeCanceledMessage);
                });
            } else if (!result.isOK()) {
                Activator.handleError(result.getMessage(), result.getException(), true);
            } else {
                PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
                    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                    MergeResultDialog.getDialog(shell, repository, op.getResult()).open();
                });
            }
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Shell(org.eclipse.swt.widgets.Shell) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 44 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.

the class BranchOperationUI method start.

/**
 * Starts the operation asynchronously
 */
public void start() {
    target = confirmTarget(new NullProgressMonitor());
    if (target == null) {
        return;
    }
    String repoName = Activator.getDefault().getRepositoryUtil().getRepositoryName(repository);
    String jobname = NLS.bind(UIText.BranchAction_checkingOut, repoName, target);
    boolean restore = Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.CHECKOUT_PROJECT_RESTORE);
    final CheckoutJob job = new CheckoutJob(jobname, restore);
    job.setUser(true);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent cevent) {
            show(job.getCheckoutResult());
        }
    });
    job.schedule();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 45 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project egit by eclipse.

the class PullOperationUI method handleUncommittedChanges.

/**
 * @param repository
 * @param files
 *            uncommitted files that were in the way for the rebase
 * @param shell
 */
private void handleUncommittedChanges(final Repository repository, final List<String> files, Shell shell) {
    String repoName = Activator.getDefault().getRepositoryUtil().getRepositoryName(repository);
    CleanupUncomittedChangesDialog cleanupUncomittedChangesDialog = new CleanupUncomittedChangesDialog(shell, MessageFormat.format(UIText.AbstractRebaseCommandHandler_cleanupDialog_title, repoName), UIText.AbstractRebaseCommandHandler_cleanupDialog_text, repository, files);
    cleanupUncomittedChangesDialog.open();
    if (cleanupUncomittedChangesDialog.shouldContinue()) {
        final PullOperationUI parentOperation = this;
        final PullOperationUI pullOperationUI = new PullOperationUI(Collections.singleton(repository));
        pullOperationUI.checkForLaunches = false;
        tasksToWaitFor.incrementAndGet();
        pullOperationUI.start(new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
                // put the result from this subtask into the result map of
                // the outer PullOperationUI and display the results if all
                // subtasks have reported back
                parentOperation.results.putAll(pullOperationUI.results);
                int missing = parentOperation.tasksToWaitFor.decrementAndGet();
                if (missing == 0)
                    parentOperation.showResults();
            }
        });
    }
}
Also used : CleanupUncomittedChangesDialog(org.eclipse.egit.ui.internal.branch.CleanupUncomittedChangesDialog) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)166 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)157 Job (org.eclipse.core.runtime.jobs.Job)44 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)43 IStatus (org.eclipse.core.runtime.IStatus)36 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)30 ArrayList (java.util.ArrayList)13 IFile (org.eclipse.core.resources.IFile)13 CoreException (org.eclipse.core.runtime.CoreException)12 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)12 Status (org.eclipse.core.runtime.Status)11 IOException (java.io.IOException)10 DBException (org.jkiss.dbeaver.DBException)10 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)10 File (java.io.File)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)8 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 Composite (org.eclipse.swt.widgets.Composite)7 IProject (org.eclipse.core.resources.IProject)6