Search in sources :

Example 1 with TreeNode

use of org.xwiki.tree.TreeNode in project xwiki-platform by xwiki.

the class DocumentTreeNodeTest method pagination.

/**
 * @see "XWIKI-14643: Missing page in breadcrumbs treeview when treeview is expanded"
 */
@Test
public void pagination() throws Exception {
    TreeNode documentTreeNode = this.mocker.getComponentUnderTest();
    documentTreeNode.getProperties().put("hierarchyMode", "reference");
    documentTreeNode.getProperties().put("showTranslations", true);
    documentTreeNode.getProperties().put("showAttachments", true);
    documentTreeNode.getProperties().put("showClassProperties", true);
    documentTreeNode.getProperties().put("showObjects", true);
    documentTreeNode.getProperties().put("showAddDocument", true);
    when(this.authorization.hasAccess(Right.EDIT, documentReference.getParent())).thenReturn(true);
    when(this.translationsTreeNode.getChildCount("translations:wiki:Path.To.Page.WebHome")).thenReturn(1);
    when(this.attachmentsTreeNode.getChildCount("attachments:wiki:Path.To.Page.WebHome")).thenReturn(1);
    when(this.classPropertiesTreeNode.getChildCount("classProperties:wiki:Path.To.Page.WebHome")).thenReturn(1);
    when(this.objectsTreeNode.getChildCount("objects:wiki:Path.To.Page.WebHome")).thenReturn(1);
    assertEquals(Arrays.asList("translations:wiki:Path.To.Page.WebHome", "attachments:wiki:Path.To.Page.WebHome", "classProperties:wiki:Path.To.Page.WebHome"), documentTreeNode.getChildren("document:wiki:Path.To.Page.WebHome", 0, 3));
    verify(this.nestedPagesOrderedByName, never()).execute();
    DocumentReference alice = new DocumentReference("wiki", Arrays.asList("Path.To.Page"), "Alice");
    when(this.nestedPagesOrderedByName.execute()).thenReturn(Collections.singletonList(alice));
    when(this.defaultEntityReferenceSerializer.serialize(alice)).thenReturn("wiki:Path.To.Page.Alice");
    assertEquals(Arrays.asList("objects:wiki:Path.To.Page.WebHome", "addDocument:wiki:Path.To.Page.WebHome", "document:wiki:Path.To.Page.Alice"), documentTreeNode.getChildren("document:wiki:Path.To.Page.WebHome", 3, 3));
    verify(this.nestedPagesOrderedByName).setOffset(0);
    verify(this.nestedPagesOrderedByName).setLimit(1);
    DocumentReference bob = new DocumentReference("wiki", Arrays.asList("Path.To.Page"), "Bob");
    DocumentReference carol = new DocumentReference("wiki", Arrays.asList("Path.To.Page"), "Carol");
    when(this.nestedPagesOrderedByName.execute()).thenReturn(Arrays.asList(bob, carol));
    when(this.defaultEntityReferenceSerializer.serialize(bob)).thenReturn("wiki:Path.To.Page.Bob");
    when(this.defaultEntityReferenceSerializer.serialize(carol)).thenReturn("wiki:Path.To.Page.Carol");
    assertEquals(Arrays.asList("document:wiki:Path.To.Page.Bob", "document:wiki:Path.To.Page.Carol"), documentTreeNode.getChildren("document:wiki:Path.To.Page.WebHome", 6, 3));
    verify(this.nestedPagesOrderedByName).setOffset(1);
    verify(this.nestedPagesOrderedByName).setLimit(3);
}
Also used : TreeNode(org.xwiki.tree.TreeNode) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 2 with TreeNode

use of org.xwiki.tree.TreeNode in project xwiki-platform by xwiki.

the class DocumentTreeNode method initialize.

@Override
public void initialize() throws InitializationException {
    String[] nonLeafChildNodeTypes = new String[] { "translations", "attachments", "classProperties", "objects" };
    ComponentManager contextComponentManager = this.contextComponentManagerProvider.get();
    try {
        for (String nonLeafChildNodeType : nonLeafChildNodeTypes) {
            TreeNode treeNode = contextComponentManager.getInstance(TreeNode.class, nonLeafChildNodeType);
            this.nonLeafChildNodes.put(nonLeafChildNodeType, treeNode);
        }
    } catch (ComponentLookupException e) {
        throw new InitializationException("Failed to lookup the child components.", e);
    }
}
Also used : TreeNode(org.xwiki.tree.TreeNode) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) InitializationException(org.xwiki.component.phase.InitializationException)

Aggregations

TreeNode (org.xwiki.tree.TreeNode)2 Test (org.junit.Test)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 ComponentManager (org.xwiki.component.manager.ComponentManager)1 InitializationException (org.xwiki.component.phase.InitializationException)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1