Search in sources :

Example 1 with StashApplyOperation

use of org.eclipse.egit.core.op.StashApplyOperation in project egit by eclipse.

the class StashApplyHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final RevCommit commit = getSelectedItem(RevCommit.class, event);
    if (commit == null)
        return null;
    Repository repo = getSelectedItem(Repository.class, event);
    if (repo == null)
        return null;
    final StashApplyOperation op = new StashApplyOperation(repo, commit);
    Job job = new WorkspaceJob(MessageFormat.format(UIText.StashApplyCommand_jobTitle, commit.name())) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
                op.execute(monitor);
            } catch (CoreException e) {
                return new Status(IStatus.ERROR, Activator.getPluginId(), MessageFormat.format(UIText.StashApplyCommand_applyFailed, commit.abbreviate(7).name(), e.getLocalizedMessage()), e);
            }
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.STASH.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    job.setUser(true);
    job.setRule(op.getSchedulingRule());
    job.schedule();
    return null;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) StashApplyOperation(org.eclipse.egit.core.op.StashApplyOperation) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with StashApplyOperation

use of org.eclipse.egit.core.op.StashApplyOperation in project egit by eclipse.

the class StashApplyCommand method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    List<StashedCommitNode> nodes = getSelectedNodes(event);
    if (nodes.isEmpty())
        return null;
    Repository repo = nodes.get(0).getRepository();
    if (repo == null)
        return null;
    final RevCommit commit = nodes.get(0).getObject();
    if (commit == null)
        return null;
    final StashApplyOperation op = new StashApplyOperation(repo, commit);
    Job job = new WorkspaceJob(MessageFormat.format(UIText.StashApplyCommand_jobTitle, commit.name())) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
                op.execute(monitor);
            } catch (CoreException e) {
                return new Status(IStatus.ERROR, Activator.getPluginId(), MessageFormat.format(UIText.StashApplyCommand_applyFailed, commit.abbreviate(7).name(), e.getLocalizedMessage()), e);
            }
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.STASH.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    job.setUser(true);
    job.setRule(op.getSchedulingRule());
    job.schedule();
    return null;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) StashApplyOperation(org.eclipse.egit.core.op.StashApplyOperation) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) StashedCommitNode(org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 CoreException (org.eclipse.core.runtime.CoreException)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 StashApplyOperation (org.eclipse.egit.core.op.StashApplyOperation)2 Repository (org.eclipse.jgit.lib.Repository)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 StashedCommitNode (org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode)1