Search in sources :

Example 1 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode 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)

Example 2 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class StagingView method reactOnSelection.

private void reactOnSelection(StructuredSelection selection) {
    if (selection.size() != 1 || isDisposed()) {
        return;
    }
    if (!shouldUpdateSelection()) {
        // Remember it all the same to be able to update the view when it
        // becomes active again
        lastSelection = reactOnSelection ? selection : null;
        return;
    }
    lastSelection = null;
    Object firstElement = selection.getFirstElement();
    if (firstElement instanceof RepositoryTreeNode) {
        RepositoryTreeNode repoNode = (RepositoryTreeNode) firstElement;
        if (currentRepository != repoNode.getRepository()) {
            reload(repoNode.getRepository());
        }
    } else if (firstElement instanceof Repository) {
        Repository repo = (Repository) firstElement;
        if (currentRepository != repo) {
            reload(repo);
        }
    } else {
        Repository repo = AdapterUtils.adapt(firstElement, Repository.class);
        if (repo != null) {
            if (currentRepository != repo) {
                reload(repo);
            }
        } else {
            IResource resource = AdapterUtils.adaptToAnyResource(firstElement);
            if (resource != null) {
                showResource(resource);
            }
        }
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) IResource(org.eclipse.core.resources.IResource)

Example 3 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class StagingView method show.

@Override
public boolean show(ShowInContext context) {
    ISelection selection = context.getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        for (Object element : structuredSelection.toList()) {
            if (element instanceof RepositoryTreeNode) {
                RepositoryTreeNode node = (RepositoryTreeNode) element;
                reload(node.getRepository());
                return true;
            }
        }
    }
    return false;
}
Also used : RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class AbstractBranchSelectionDialog method refNameFromDialog.

/**
 * @return the selected ref name from the tree, may be null
 */
protected String refNameFromDialog() {
    IStructuredSelection sel = (IStructuredSelection) branchTree.getSelection();
    if (sel.size() != 1)
        return null;
    RepositoryTreeNode node = (RepositoryTreeNode) sel.getFirstElement();
    if (node.getType() == RepositoryTreeNodeType.REF || node.getType() == RepositoryTreeNodeType.TAG || node.getType() == RepositoryTreeNodeType.ADDITIONALREF)
        return ((Ref) node.getObject()).getName();
    return null;
}
Also used : RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 5 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class PushCommand method createPushTagsWizard.

private PushTagsWizard createPushTagsWizard(List<RepositoryTreeNode> nodes) {
    List<String> tagNames = new ArrayList<>();
    for (RepositoryTreeNode node : nodes) {
        if (node instanceof TagNode) {
            TagNode tagNode = (TagNode) node;
            tagNames.add(tagNode.getObject().getName());
        }
    }
    Repository repository = nodes.get(0).getRepository();
    return new PushTagsWizard(repository, tagNames);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) PushTagsWizard(org.eclipse.egit.ui.internal.push.PushTagsWizard) ArrayList(java.util.ArrayList) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Aggregations

RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)46 Repository (org.eclipse.jgit.lib.Repository)17 Ref (org.eclipse.jgit.lib.Ref)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)11 ArrayList (java.util.ArrayList)10 TagNode (org.eclipse.egit.ui.internal.repository.tree.TagNode)10 IOException (java.io.IOException)9 File (java.io.File)8 IResource (org.eclipse.core.resources.IResource)7 RefNode (org.eclipse.egit.ui.internal.repository.tree.RefNode)6 IPath (org.eclipse.core.runtime.IPath)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 RevObject (org.eclipse.jgit.revwalk.RevObject)4 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)3 Path (org.eclipse.core.runtime.Path)3 Job (org.eclipse.core.runtime.jobs.Job)3 FileNode (org.eclipse.egit.ui.internal.repository.tree.FileNode)3 RemoteNode (org.eclipse.egit.ui.internal.repository.tree.RemoteNode)3 StashedCommitNode (org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode)3