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;
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations