Search in sources :

Example 21 with RepositoryNode

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

the class GitFlowAdapterFactory method getAdapter.

@SuppressWarnings("unchecked")
@Override
public Repository getAdapter(Object adaptableObject, Class adapterType) {
    Repository repository = null;
    if (adaptableObject instanceof IResource) {
        IResource resource = (IResource) adaptableObject;
        repository = getRepository(resource);
    } else if (adaptableObject instanceof IHistoryView) {
        IHistoryView historyView = (IHistoryView) adaptableObject;
        IHistoryPage historyPage = historyView.getHistoryPage();
        Object input = historyPage.getInput();
        if (input instanceof RepositoryNode) {
            RepositoryNode node = (RepositoryNode) input;
            repository = node.getRepository();
        } else if (input instanceof IResource) {
            repository = getRepository((IResource) input);
        }
    } else if (adaptableObject instanceof ISelection) {
        IStructuredSelection structuredSelection = SelectionUtils.getStructuredSelection((ISelection) adaptableObject);
        repository = SelectionUtils.getRepository(structuredSelection);
    } else {
        throw new IllegalStateException();
    }
    return repository;
}
Also used : IHistoryPage(org.eclipse.team.ui.history.IHistoryPage) Repository(org.eclipse.jgit.lib.Repository) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) IHistoryView(org.eclipse.team.ui.history.IHistoryView) IResource(org.eclipse.core.resources.IResource)

Example 22 with RepositoryNode

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

the class GitFlowLightweightDecorator method getRepository.

@Nullable
private static GitFlowRepository getRepository(Object element) {
    GitFlowRepository repository = null;
    if (element instanceof GitFlowRepository) {
        repository = (GitFlowRepository) element;
    }
    if (element instanceof RepositoryNode) {
        RepositoryNode node = (RepositoryNode) element;
        Repository repo = node.getObject();
        if (repo != null) {
            repository = new GitFlowRepository(repo);
        }
    }
    return repository;
}
Also used : GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Nullable(org.eclipse.jgit.annotations.Nullable)

Example 23 with RepositoryNode

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

the class RepositoriesView method getShowInElements.

private static List<Object> getShowInElements(IStructuredSelection selection) {
    List<Object> elements = new ArrayList<>();
    for (Object element : selection.toList()) {
        if (element instanceof FileNode || element instanceof FolderNode || element instanceof WorkingDirNode) {
            RepositoryTreeNode treeNode = (RepositoryTreeNode) element;
            IPath path = treeNode.getPath();
            IResource resource = ResourceUtil.getResourceForLocation(path, false);
            if (resource != null)
                elements.add(resource);
        } else if (element instanceof RepositoryNode) {
            // Can be shown in History, Reflog and Properties views
            elements.add(element);
        } else if (element instanceof RepositoryNode || element instanceof RemoteNode || element instanceof FetchNode || element instanceof PushNode || element instanceof TagNode || element instanceof RefNode) {
            // These can be shown in Properties view directly
            elements.add(element);
        }
    }
    return elements;
}
Also used : FolderNode(org.eclipse.egit.ui.internal.repository.tree.FolderNode) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) RemoteNode(org.eclipse.egit.ui.internal.repository.tree.RemoteNode) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) PushNode(org.eclipse.egit.ui.internal.repository.tree.PushNode) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) FetchNode(org.eclipse.egit.ui.internal.repository.tree.FetchNode) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) WorkingDirNode(org.eclipse.egit.ui.internal.repository.tree.WorkingDirNode) FileNode(org.eclipse.egit.ui.internal.repository.tree.FileNode) IResource(org.eclipse.core.resources.IResource) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Example 24 with RepositoryNode

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

the class PushConfiguredRemoteCommand method getRemoteConfig.

private RemoteConfig getRemoteConfig(RepositoryTreeNode node) {
    if (node instanceof RepositoryNode)
        return SimpleConfigurePushDialog.getConfiguredRemote(node.getRepository());
    if (node instanceof RemoteNode || node instanceof PushNode) {
        RemoteNode remoteNode;
        if (node instanceof PushNode)
            remoteNode = (RemoteNode) node.getParent();
        else
            remoteNode = (RemoteNode) node;
        try {
            RemoteConfig config = new RemoteConfig(remoteNode.getRepository().getConfig(), remoteNode.getObject());
            boolean fetchConfigured = !config.getFetchRefSpecs().isEmpty();
            boolean pushConfigured = !config.getPushRefSpecs().isEmpty();
            if (fetchConfigured || pushConfigured)
                return config;
            else
                return null;
        } catch (URISyntaxException e) {
            return null;
        }
    }
    return null;
}
Also used : RemoteNode(org.eclipse.egit.ui.internal.repository.tree.RemoteNode) URISyntaxException(java.net.URISyntaxException) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) PushNode(org.eclipse.egit.ui.internal.repository.tree.PushNode)

Example 25 with RepositoryNode

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

the class RemoveCommand method findProjectsToDelete.

private List<IProject> findProjectsToDelete(final List<RepositoryNode> selectedNodes) {
    final List<IProject> projectsToDelete = new ArrayList<>();
    for (RepositoryNode node : selectedNodes) {
        if (node.getRepository().isBare())
            continue;
        File workDir = node.getRepository().getWorkTree();
        final IPath wdPath = new Path(workDir.getAbsolutePath());
        for (IProject prj : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
            IPath location = prj.getLocation();
            if (location != null && wdPath.isPrefixOf(location)) {
                projectsToDelete.add(prj);
            }
        }
    }
    return projectsToDelete;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Aggregations

RepositoryNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryNode)27 Repository (org.eclipse.jgit.lib.Repository)18 File (java.io.File)7 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 LocalNode (org.eclipse.egit.ui.internal.repository.tree.LocalNode)4 TagsNode (org.eclipse.egit.ui.internal.repository.tree.TagsNode)4 Before (org.junit.Before)4 URISyntaxException (java.net.URISyntaxException)3 RepositoriesViewLabelProvider (org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider)3 BranchesNode (org.eclipse.egit.ui.internal.repository.tree.BranchesNode)3 RefNode (org.eclipse.egit.ui.internal.repository.tree.RefNode)3 RemoteTrackingNode (org.eclipse.egit.ui.internal.repository.tree.RemoteTrackingNode)3 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 List (java.util.List)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IProject (org.eclipse.core.resources.IProject)2 IResource (org.eclipse.core.resources.IResource)2