Search in sources :

Example 1 with IRepositoryCommit

use of org.eclipse.egit.core.internal.IRepositoryCommit in project egit by eclipse.

the class AbstractHistoryCommandHandler method getRepository.

protected Repository getRepository(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = getSelection(event);
    if (!selection.isEmpty()) {
        IRepositoryCommit commit = AdapterUtils.adapt(selection.getFirstElement(), IRepositoryCommit.class);
        if (commit != null) {
            return commit.getRepository();
        }
    }
    Object input = getInput(event);
    if (input == null) {
        return null;
    }
    if (input instanceof HistoryPageInput) {
        return ((HistoryPageInput) input).getRepository();
    }
    if (input instanceof RepositoryTreeNode) {
        return ((RepositoryTreeNode) input).getRepository();
    }
    Repository repo = AdapterUtils.adapt(input, Repository.class);
    if (repo != null) {
        return repo;
    }
    IResource resource = AdapterUtils.adaptToAnyResource(input);
    if (resource != null) {
        Repository repository = ResourceUtil.getRepository(resource);
        if (repository != null) {
            return repository;
        }
    }
    throw new ExecutionException(UIText.AbstractHistoryCommanndHandler_CouldNotGetRepositoryMessage);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) HistoryPageInput(org.eclipse.egit.ui.internal.history.HistoryPageInput) IRepositoryCommit(org.eclipse.egit.core.internal.IRepositoryCommit) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) IResource(org.eclipse.core.resources.IResource)

Aggregations

ExecutionException (org.eclipse.core.commands.ExecutionException)1 IResource (org.eclipse.core.resources.IResource)1 IRepositoryCommit (org.eclipse.egit.core.internal.IRepositoryCommit)1 HistoryPageInput (org.eclipse.egit.ui.internal.history.HistoryPageInput)1 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Repository (org.eclipse.jgit.lib.Repository)1