Search in sources :

Example 1 with GarbageCollectOperation

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

the class GarbageCollectCommand method execute.

/**
 * Execute garbage collection
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // get selected nodes
    final List<RepositoryNode> selectedNodes;
    try {
        selectedNodes = getSelectedNodes(event);
        if (selectedNodes.isEmpty())
            return null;
    } catch (ExecutionException e) {
        Activator.handleError(e.getMessage(), e, true);
        return null;
    }
    Job job = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "Collecting Garbage...") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            for (RepositoryNode node : selectedNodes) {
                Repository repo = node.getRepository();
                String name = MessageFormat.format(UIText.GarbageCollectCommand_jobTitle, getRepositoryName(repo));
                this.setName(name);
                final GarbageCollectOperation op = new GarbageCollectOperation(repo);
                try {
                    op.execute(monitor);
                } catch (CoreException e) {
                    Activator.logError(MessageFormat.format(UIText.GarbageCollectCommand_failed, repo), e);
                }
            }
            return Status.OK_STATUS;
        }
    };
    IServiceLocator serviceLocator = HandlerUtil.getActiveSite(event);
    if (serviceLocator != null) {
        IWorkbenchSiteProgressService service = CommonUtils.getService(serviceLocator, IWorkbenchSiteProgressService.class);
        service.schedule(job);
    } else {
        job.schedule();
    }
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) GarbageCollectOperation(org.eclipse.egit.core.op.GarbageCollectOperation) IServiceLocator(org.eclipse.ui.services.IServiceLocator) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) ExecutionException(org.eclipse.core.commands.ExecutionException) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

ExecutionException (org.eclipse.core.commands.ExecutionException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 GarbageCollectOperation (org.eclipse.egit.core.op.GarbageCollectOperation)1 RepositoryNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryNode)1 Repository (org.eclipse.jgit.lib.Repository)1 IWorkbenchSiteProgressService (org.eclipse.ui.progress.IWorkbenchSiteProgressService)1 IServiceLocator (org.eclipse.ui.services.IServiceLocator)1