Search in sources :

Example 1 with IHistoryPage

use of org.eclipse.team.ui.history.IHistoryPage in project egit by eclipse.

the class GitAdapterFactory method getAdapter.

@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adapterType.isAssignableFrom(IHistoryPageSource.class)) {
        return GitHistoryPageSource.INSTANCE;
    }
    if (IWorkbenchAdapter.class == adapterType) {
        // property page names for git repository tree nodes
        if (adaptableObject instanceof RepositoryTreeNode) {
            return getRepositoryTreeNodeWorkbenchAdapter((RepositoryTreeNode) adaptableObject);
        }
        if (gitModelWorkbenchAdapter == null) {
            gitModelWorkbenchAdapter = new GitModelWorkbenchAdapter();
        }
        return gitModelWorkbenchAdapter;
    }
    if (adaptableObject instanceof IHistoryView && IShowInSource.class == adapterType) {
        IHistoryView historyView = (IHistoryView) adaptableObject;
        IHistoryPage historyPage = historyView.getHistoryPage();
        if (historyPage instanceof GitHistoryPage) {
            return historyPage;
        }
    }
    if (adaptableObject instanceof IURIEditorInput && adapterType == Repository.class) {
        return getRepository((IURIEditorInput) adaptableObject);
    }
    if (adaptableObject instanceof IURIEditorInput && adapterType == File.class) {
        return getFile((IURIEditorInput) adaptableObject);
    }
    if (adaptableObject instanceof GitModelObject && adapterType == ResourceMapping.class) {
        return GitObjectMapping.create((GitModelObject) adaptableObject);
    }
    if (adaptableObject instanceof GitModelObject && adapterType == IResource.class) {
        GitModelObject obj = (GitModelObject) adaptableObject;
        if (obj instanceof GitModelBlob) {
            IResource res = ResourceUtil.getFileForLocation(obj.getLocation(), false);
            if (res == null) {
                // Deleted resource?
                res = getWorkspaceResourceFromGitPath(obj.getLocation());
            }
            return res;
        }
        if (obj instanceof GitModelTree) {
            IResource res = root.getContainerForLocation(obj.getLocation());
            if (res == null) {
                res = root.getFolder(obj.getLocation());
            }
            return res;
        }
    }
    if (adapterType == Repository.class) {
        ResourceMapping m = AdapterUtils.adapt(adaptableObject, ResourceMapping.class);
        if (m != null) {
            return SelectionUtils.getRepository(new StructuredSelection(m));
        }
    }
    return null;
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject) IHistoryPage(org.eclipse.team.ui.history.IHistoryPage) Repository(org.eclipse.jgit.lib.Repository) GitHistoryPage(org.eclipse.egit.ui.internal.history.GitHistoryPage) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) GitModelWorkbenchAdapter(org.eclipse.egit.ui.internal.synchronize.mapping.GitModelWorkbenchAdapter) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IShowInSource(org.eclipse.ui.part.IShowInSource) IHistoryView(org.eclipse.team.ui.history.IHistoryView) File(java.io.File) IResource(org.eclipse.core.resources.IResource) GitModelBlob(org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob)

Example 2 with IHistoryPage

use of org.eclipse.team.ui.history.IHistoryPage 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 3 with IHistoryPage

use of org.eclipse.team.ui.history.IHistoryPage in project egit by eclipse.

the class AbstractHistoryCommandHandler method getPageFromPart.

private GitHistoryPage getPageFromPart(IWorkbenchPart part) {
    if (!(part instanceof IHistoryView))
        return null;
    IHistoryView view = (IHistoryView) part;
    IHistoryPage page = view.getHistoryPage();
    if (page instanceof GitHistoryPage)
        return (GitHistoryPage) page;
    return null;
}
Also used : IHistoryPage(org.eclipse.team.ui.history.IHistoryPage) GitHistoryPage(org.eclipse.egit.ui.internal.history.GitHistoryPage) IHistoryView(org.eclipse.team.ui.history.IHistoryView)

Aggregations

IHistoryPage (org.eclipse.team.ui.history.IHistoryPage)3 IHistoryView (org.eclipse.team.ui.history.IHistoryView)3 IResource (org.eclipse.core.resources.IResource)2 GitHistoryPage (org.eclipse.egit.ui.internal.history.GitHistoryPage)2 Repository (org.eclipse.jgit.lib.Repository)2 File (java.io.File)1 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)1 RepositoryNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryNode)1 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)1 GitModelWorkbenchAdapter (org.eclipse.egit.ui.internal.synchronize.mapping.GitModelWorkbenchAdapter)1 GitModelBlob (org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob)1 GitModelObject (org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)1 GitModelTree (org.eclipse.egit.ui.internal.synchronize.model.GitModelTree)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IURIEditorInput (org.eclipse.ui.IURIEditorInput)1 IShowInSource (org.eclipse.ui.part.IShowInSource)1