Search in sources :

Example 11 with CPOrganization

use of org.olat.ims.cp.objects.CPOrganization in project openolat by klemens.

the class CPTreeController method getParentIdentifier.

/**
 * Retrieves the parent identifier of the current page
 *
 * @return The identifier of the current page's parent
 */
private String getParentIdentifier() {
    DefaultElement currentElem = CPManager.getInstance().getElementByIdentifier(cp, currentPage.getIdentifier());
    // Get the parent node to be displayed after deletion.
    String parentIdentifier = null;
    if (currentElem instanceof CPItem) {
        Element parent = ((CPItem) currentElem).getParentElement();
        if (parent instanceof CPItem) {
            CPItem parentItem = (CPItem) parent;
            parentIdentifier = parentItem.getIdentifier();
        } else if (parent instanceof CPOrganization) {
            CPOrganization parentItem = (CPOrganization) parent;
            parentIdentifier = parentItem.getIdentifier();
        }
    }
    return parentIdentifier;
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization)

Example 12 with CPOrganization

use of org.olat.ims.cp.objects.CPOrganization in project openolat by klemens.

the class CPCore method addElementAfter.

/**
 * adds an element to the cp. Adds it after the item with identifier "id"
 *
 * @param newElement
 * @param id
 * @return
 */
public boolean addElementAfter(DefaultElement newElement, String id) {
    DefaultElement beforeElement = rootNode.getElementByIdentifier(id);
    if (beforeElement == null)
        return false;
    if (beforeElement instanceof CPItem) {
        // beforeElement is a <item>
        // ==> newElement has to be an <item>
        CPItem beforeItem = (CPItem) beforeElement;
        DefaultElement parent = beforeItem.getParentElement();
        if (!(newElement instanceof CPItem)) {
            throw new OLATRuntimeException(CPOrganizations.class, "only <item> element allowed", new Exception());
        }
        if (parent instanceof CPItem) {
            CPItem p = (CPItem) parent;
            p.addItemAt((CPItem) newElement, beforeItem.getPosition() + 1);
        } else if (parent instanceof CPOrganization) {
            CPOrganization o = (CPOrganization) parent;
            o.addItemAt((CPItem) newElement, beforeItem.getPosition() + 1);
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you cannot add an <item> element to a " + parent.getName() + " element", new Exception());
        }
    }
    return true;
}
Also used : CPOrganizations(org.olat.ims.cp.objects.CPOrganizations) DefaultElement(org.dom4j.tree.DefaultElement) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPItem(org.olat.ims.cp.objects.CPItem) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPOrganization(org.olat.ims.cp.objects.CPOrganization)

Example 13 with CPOrganization

use of org.olat.ims.cp.objects.CPOrganization in project openolat by klemens.

the class CPCore method referencesCount.

/**
 * Checks how many item-elements link to the given resource element.
 *
 * @param resource
 * @return
 */
protected int referencesCount(CPResource resource) {
    int linkCount = 0;
    Vector<CPItem> items = new Vector<CPItem>();
    for (Iterator<CPOrganization> it = rootNode.getOrganizations().getOrganizationIterator(); it.hasNext(); ) {
        CPOrganization org = it.next();
        items.addAll(org.getAllItems());
    }
    for (CPItem item : items) {
        if (item.getIdentifierRef().equals(resource.getIdentifier()))
            linkCount++;
    }
    Vector<CPDependency> dependencies = rootNode.getResources().getAllDependencies();
    for (CPDependency dependency : dependencies) {
        if (dependency.getIdentifierRef().equals(resource.getIdentifier()))
            linkCount++;
    }
    return linkCount;
}
Also used : Vector(java.util.Vector) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization) CPDependency(org.olat.ims.cp.objects.CPDependency)

Example 14 with CPOrganization

use of org.olat.ims.cp.objects.CPOrganization in project openolat by klemens.

the class CPTreeDataModel method update.

public void update() {
    String realNodeId = getIdentifierForNodeID(rootNodeId);
    DefaultElement el = cp.getElementByIdentifier(realNodeId);
    if (el instanceof CPOrganization) {
        CPOrganization item = (CPOrganization) el;
        String rootTitle = cp.getFirstOrganizationInManifest().getTitle();
        GenericTreeNode rootNode = new GenericTreeNode(rootNodeId, rootTitle, item);
        rootNode.setIconCssClass("o_cp_org");
        List<TreeNode> children = getChildrenFor(rootNodeId);
        for (TreeNode child : children) {
            rootNode.addChild(child);
            buildTreeModel(child);
        }
        setRootNode(rootNode);
    }
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) CPOrganization(org.olat.ims.cp.objects.CPOrganization)

Example 15 with CPOrganization

use of org.olat.ims.cp.objects.CPOrganization in project OpenOLAT by OpenOLAT.

the class CPTreeDataModel method update.

public void update() {
    String realNodeId = getIdentifierForNodeID(rootNodeId);
    DefaultElement el = cp.getElementByIdentifier(realNodeId);
    if (el instanceof CPOrganization) {
        CPOrganization item = (CPOrganization) el;
        String rootTitle = cp.getFirstOrganizationInManifest().getTitle();
        GenericTreeNode rootNode = new GenericTreeNode(rootNodeId, rootTitle, item);
        rootNode.setIconCssClass("o_cp_org");
        List<TreeNode> children = getChildrenFor(rootNodeId);
        for (TreeNode child : children) {
            rootNode.addChild(child);
            buildTreeModel(child);
        }
        setRootNode(rootNode);
    }
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) CPOrganization(org.olat.ims.cp.objects.CPOrganization)

Aggregations

CPOrganization (org.olat.ims.cp.objects.CPOrganization)30 CPItem (org.olat.ims.cp.objects.CPItem)22 DefaultElement (org.dom4j.tree.DefaultElement)20 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)12 CPResource (org.olat.ims.cp.objects.CPResource)8 CPDependency (org.olat.ims.cp.objects.CPDependency)6 CPOrganizations (org.olat.ims.cp.objects.CPOrganizations)6 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)4 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 CPFile (org.olat.ims.cp.objects.CPFile)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Vector (java.util.Vector)2 Element (org.dom4j.Element)2 JSONException (org.json.JSONException)2 Test (org.junit.Test)2 DeliveryOptions (org.olat.core.gui.control.generic.iframe.DeliveryOptions)2 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2