Search in sources :

Example 1 with MergeTargetSelectionDialog

use of org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog 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 2 with MergeTargetSelectionDialog

use of org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog in project egit by eclipse.

the class MergeActionHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    Repository repository = getRepository(true, event);
    Shell shell = getShell(event);
    if (repository == null || !checkMergeIsPossible(repository, shell) || LaunchFinder.shouldCancelBecauseOfRunningLaunches(repository, null)) {
        return null;
    }
    BasicConfigurationDialog.show(repository);
    MergeTargetSelectionDialog mergeTargetSelectionDialog = new MergeTargetSelectionDialog(shell, repository);
    if (mergeTargetSelectionDialog.open() == IDialogConstants.OK_ID) {
        String refName = mergeTargetSelectionDialog.getRefName();
        MergeOperation op = new MergeOperation(repository, refName);
        op.setSquash(mergeTargetSelectionDialog.isMergeSquash());
        op.setFastForwardMode(mergeTargetSelectionDialog.getFastForwardMode());
        op.setCommit(mergeTargetSelectionDialog.isCommit());
        doMerge(repository, op, refName);
    }
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) MergeOperation(org.eclipse.egit.core.op.MergeOperation) MergeTargetSelectionDialog(org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog)

Aggregations

MergeOperation (org.eclipse.egit.core.op.MergeOperation)2 MergeTargetSelectionDialog (org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog)2 Repository (org.eclipse.jgit.lib.Repository)2 Shell (org.eclipse.swt.widgets.Shell)2 IOException (java.io.IOException)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 RefNode (org.eclipse.egit.ui.internal.repository.tree.RefNode)1 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)1 TagNode (org.eclipse.egit.ui.internal.repository.tree.TagNode)1