Search in sources :

Example 6 with GitModelTree

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelTree in project egit by eclipse.

the class GitChangeSetSorterTest method treeShouldBeGreaterThanCommit.

@Test
public void treeShouldBeGreaterThanCommit() {
    // given
    Viewer viewer = mock(Viewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelTree tree = mock(GitModelTree.class);
    GitModelCommit commit = mock(GitModelCommit.class);
    // when
    int actual = sorter.compare(viewer, tree, commit);
    // then
    assertTrue(actual > 0);
}
Also used : GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) CommonViewer(org.eclipse.ui.navigator.CommonViewer) Viewer(org.eclipse.jface.viewers.Viewer) Test(org.junit.Test)

Example 7 with GitModelTree

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelTree in project egit by eclipse.

the class GitChangeSetSorterTest method commitTreeShouldBeLessThanTree.

@Test
public void commitTreeShouldBeLessThanTree() {
    // given
    Viewer viewer = mock(Viewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelTree tree = mock(GitModelTree.class);
    GitModelBlob blob = mock(GitModelBlob.class);
    // when
    int actual = sorter.compare(viewer, tree, blob);
    // then
    assertTrue(actual < 0);
}
Also used : GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) CommonViewer(org.eclipse.ui.navigator.CommonViewer) Viewer(org.eclipse.jface.viewers.Viewer) GitModelBlob(org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob) Test(org.junit.Test)

Example 8 with GitModelTree

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelTree 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 9 with GitModelTree

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelTree in project egit by eclipse.

the class GitChangeSetSorterTest method treeShouldBeGreaterThanCache.

@Test
public void treeShouldBeGreaterThanCache() {
    // given
    Viewer viewer = mock(Viewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelTree tree = mock(GitModelTree.class);
    GitModelCache cache = mock(GitModelCache.class);
    // when
    int actual = sorter.compare(viewer, tree, cache);
    // then
    assertTrue(actual > 0);
}
Also used : GitModelCache(org.eclipse.egit.ui.internal.synchronize.model.GitModelCache) GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) CommonViewer(org.eclipse.ui.navigator.CommonViewer) Viewer(org.eclipse.jface.viewers.Viewer) Test(org.junit.Test)

Example 10 with GitModelTree

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelTree in project egit by eclipse.

the class GitChangeSetSorterTest method shouldOrderTreesAlphabetically.

/*
	 * Tests for alphabetical order
	 */
@Test
public void shouldOrderTreesAlphabetically() {
    // given
    CommonViewer viewer = mock(CommonViewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelTree tree1 = mock(GitModelTree.class);
    GitModelTree tree2 = mock(GitModelTree.class);
    ILabelProvider labelProvider = mock(ILabelProvider.class);
    when(labelProvider.getText(tree1)).thenReturn("aaa");
    when(labelProvider.getText(tree2)).thenReturn("zzz");
    when(viewer.getLabelProvider()).thenReturn(labelProvider);
    // when
    int actual1 = sorter.compare(viewer, tree1, tree2);
    int actual2 = sorter.compare(viewer, tree2, tree1);
    // then
    assertTrue(actual1 < 0);
    assertTrue(actual2 > 0);
}
Also used : CommonViewer(org.eclipse.ui.navigator.CommonViewer) GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Test(org.junit.Test)

Aggregations

GitModelTree (org.eclipse.egit.ui.internal.synchronize.model.GitModelTree)12 CommonViewer (org.eclipse.ui.navigator.CommonViewer)9 Test (org.junit.Test)9 Viewer (org.eclipse.jface.viewers.Viewer)8 GitModelBlob (org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob)5 GitModelCache (org.eclipse.egit.ui.internal.synchronize.model.GitModelCache)3 GitModelWorkingTree (org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingTree)3 IResource (org.eclipse.core.resources.IResource)2 GitModelCommit (org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit)2 GitModelObject (org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)2 File (java.io.File)1 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)1 ResourceTraversal (org.eclipse.core.resources.mapping.ResourceTraversal)1 Commit (org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit)1 GitHistoryPage (org.eclipse.egit.ui.internal.history.GitHistoryPage)1 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)1 GitModelWorkbenchAdapter (org.eclipse.egit.ui.internal.synchronize.mapping.GitModelWorkbenchAdapter)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Repository (org.eclipse.jgit.lib.Repository)1