Search in sources :

Example 1 with GitModelTree

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

the class GitChangeSetSorter method compare.

@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    if (e1 instanceof GitModelBlob && !(e2 instanceof GitModelBlob))
        return 1;
    if (e2 instanceof GitModelBlob && !(e1 instanceof GitModelBlob))
        return -1;
    if (e1 instanceof GitModelWorkingTree)
        return -1;
    if (e2 instanceof GitModelWorkingTree)
        return 1;
    if (e1 instanceof GitModelCache)
        return -2;
    if (e2 instanceof GitModelCache)
        return 2;
    if ((e1 instanceof GitModelTree && e2 instanceof GitModelTree) || (e1 instanceof GitModelBlob && e2 instanceof GitModelBlob))
        return super.compare(viewer, e1, e2);
    if (e1 instanceof GitModelTree && e2 instanceof GitModelCommit)
        return 1;
    if (e1 instanceof GitModelCommit && e2 instanceof GitModelCommit) {
        Commit rc1 = ((GitModelCommit) e1).getCachedCommitObj();
        Commit rc2 = ((GitModelCommit) e2).getCachedCommitObj();
        return rc2.getCommitDate().compareTo(rc1.getCommitDate());
    }
    return super.compare(viewer, e1, e2);
}
Also used : GitModelCache(org.eclipse.egit.ui.internal.synchronize.model.GitModelCache) Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) GitModelBlob(org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob) GitModelWorkingTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingTree)

Example 2 with GitModelTree

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

the class GitTreeMapping method getTraversals.

@Override
public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    GitModelObject[] objects = tree.getChildren();
    ResourceTraversal[] result = new ResourceTraversal[objects.length];
    for (int i = 0; i < objects.length; i++) {
        if (objects[i] instanceof GitModelTree)
            result[i] = new GitTreeTraversal((GitModelTree) objects[i]);
        else {
            IResource[] resources = getResources((GitModelBlob) objects[i]);
            result[i] = new ResourceTraversal(resources, IResource.DEPTH_ZERO, IResource.ALLOW_MISSING_LOCAL);
        }
    }
    return result;
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) IResource(org.eclipse.core.resources.IResource) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

Example 3 with GitModelTree

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

the class GitChangeSetSorterTest method blobShouldBeGreaterThanTree.

@Test
public void blobShouldBeGreaterThanTree() {
    // given
    Viewer viewer = mock(Viewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelBlob blob = mock(GitModelBlob.class);
    GitModelTree tree = mock(GitModelTree.class);
    // when
    int actual = sorter.compare(viewer, blob, tree);
    // 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 4 with GitModelTree

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

the class GitChangeSetSorterTest method cacheTreeShouldBeLessThanTree.

@Test
public void cacheTreeShouldBeLessThanTree() {
    // given
    Viewer viewer = mock(Viewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelCache cache = mock(GitModelCache.class);
    GitModelTree tree = mock(GitModelTree.class);
    // when
    int actual = sorter.compare(viewer, cache, tree);
    // 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 5 with GitModelTree

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

the class GitChangeSetSorterTest method workingTreeShouldBeLessThanTree.

@Test
public void workingTreeShouldBeLessThanTree() {
    // given
    Viewer viewer = mock(Viewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelTree tree = mock(GitModelTree.class);
    GitModelWorkingTree workingTree = mock(GitModelWorkingTree.class);
    // when
    int actual = sorter.compare(viewer, workingTree, tree);
    // 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) GitModelWorkingTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingTree) 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