use of org.olat.core.util.tree.TreeVisitor in project OpenOLAT by OpenOLAT.
the class CPSelectPrintPagesController method getSelectedNodeIdentifiers.
public List<String> getSelectedNodeIdentifiers() {
final Set<String> selectedKeys = cpTree.getSelectedKeys();
final List<String> orderedIdentifiers = new ArrayList<>();
TreeVisitor visitor = new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (selectedKeys.contains(node.getIdent())) {
orderedIdentifiers.add(node.getIdent());
}
}
}, ctm.getRootNode(), false);
visitor.visitAll();
return orderedIdentifiers;
}
use of org.olat.core.util.tree.TreeVisitor in project OpenOLAT by OpenOLAT.
the class CourseRuntimeController method initTools.
private void initTools(Dropdown tools, ICourse course, final UserCourseEnvironmentImpl uce) {
// 1) administrative tools
if (reSecurity.isEntryAdmin() || reSecurity.isCourseCoach() || reSecurity.isGroupCoach() || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR) || hasCourseRight(CourseRights.RIGHT_MEMBERMANAGEMENT) || hasCourseRight(CourseRights.RIGHT_GROUPMANAGEMENT) || hasCourseRight(CourseRights.RIGHT_ARCHIVING) || hasCourseRight(CourseRights.RIGHT_STATISTICS) || hasCourseRight(CourseRights.RIGHT_DB) || hasCourseRight(CourseRights.RIGHT_ASSESSMENT) || hasCourseRight(CourseRights.RIGHT_ASSESSMENT_MODE)) {
tools.setI18nKey("header.tools");
tools.setElementCssClass("o_sel_course_tools");
if (uce != null && (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR))) {
boolean managed = RepositoryEntryManagedFlag.isManaged(getRepositoryEntry(), RepositoryEntryManagedFlag.editcontent);
boolean readOnly = uce.isCourseReadOnly();
editLink = LinkFactory.createToolLink("edit.cmd", translate("command.openeditor"), this, "o_icon_courseeditor");
editLink.setElementCssClass("o_sel_course_editor");
editLink.setEnabled(!corrupted && !managed);
editLink.setVisible(!readOnly);
tools.addComponent(editLink);
folderLink = LinkFactory.createToolLink("cfd", translate("command.coursefolder"), this, "o_icon_coursefolder");
folderLink.setElementCssClass("o_sel_course_folder");
tools.addComponent(folderLink);
tools.addComponent(new Spacer(""));
}
if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_GROUPMANAGEMENT) || hasCourseRight(CourseRights.RIGHT_MEMBERMANAGEMENT)) {
membersLink = LinkFactory.createToolLink("unifiedusermngt", translate("command.opensimplegroupmngt"), this, "o_icon_membersmanagement");
membersLink.setElementCssClass("o_sel_course_members");
tools.addComponent(membersLink);
}
if (reSecurity.isEntryAdmin() || reSecurity.isCourseCoach() || reSecurity.isGroupCoach() || hasCourseRight(CourseRights.RIGHT_ASSESSMENT)) {
assessmentLink = LinkFactory.createToolLink("assessment", translate("command.openassessment"), this, "o_icon_assessment_tool");
assessmentLink.setElementCssClass("o_sel_course_assessment_tool");
tools.addComponent(assessmentLink);
}
if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_ARCHIVING)) {
archiverLink = LinkFactory.createToolLink("archiver", translate("command.openarchiver"), this, "o_icon_archive_tool");
tools.addComponent(archiverLink);
}
tools.addComponent(new Spacer(""));
if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_STATISTICS)) {
courseStatisticLink = LinkFactory.createToolLink("statistic", translate("command.openstatistic"), this, "o_icon_statistics_tool");
tools.addComponent(courseStatisticLink);
}
if (uce != null && (reSecurity.isEntryAdmin() || reSecurity.isCourseCoach() || reSecurity.isGroupCoach() || hasCourseRight(CourseRights.RIGHT_STATISTICS))) {
final AtomicInteger testNodes = new AtomicInteger();
final AtomicInteger surveyNodes = new AtomicInteger();
new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (((CourseNode) node).isStatisticNodeResultAvailable(uce, QTIType.test, QTIType.onyx)) {
testNodes.incrementAndGet();
} else if (((CourseNode) node).isStatisticNodeResultAvailable(uce, QTIType.survey)) {
surveyNodes.incrementAndGet();
}
}
}, course.getRunStructure().getRootNode(), true).visitAll();
if (testNodes.intValue() > 0) {
testStatisticLink = LinkFactory.createToolLink("qtistatistic", translate("command.openteststatistic"), this, "o_icon_statistics_tool");
tools.addComponent(testStatisticLink);
}
if (surveyNodes.intValue() > 0) {
surveyStatisticLink = LinkFactory.createToolLink("qtistatistic", translate("command.opensurveystatistic"), this, "o_icon_statistics_tool");
tools.addComponent(surveyStatisticLink);
}
}
tools.addComponent(new Spacer(""));
if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR)) {
areaLink = LinkFactory.createToolLink("careas", translate("command.courseareas"), this, "o_icon_courseareas");
areaLink.setElementCssClass("o_sel_course_areas");
tools.addComponent(areaLink);
}
if (courseDBManager.isEnabled() && (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_DB))) {
dbLink = LinkFactory.createToolLink("customDb", translate("command.opendb"), this, "o_icon_coursedb");
tools.addComponent(dbLink);
}
ordersLink = LinkFactory.createToolLink("bookings", translate("details.orders"), this, "o_sel_repo_booking");
ordersLink.setIconLeftCSS("o_icon o_icon-fw o_icon_booking");
ordersLink.setElementCssClass("o_sel_course_ac_tool");
boolean booking = acService.isResourceAccessControled(getRepositoryEntry().getOlatResource(), null);
ordersLink.setVisible(!corrupted && booking);
tools.addComponent(ordersLink);
}
}
use of org.olat.core.util.tree.TreeVisitor in project OpenOLAT by OpenOLAT.
the class StatisticCourseNodesController method buildTreeModel.
private TreeModel buildTreeModel(final UserRequest ureq, final UserCourseEnvironment userCourseEnv) {
final GenericTreeModel gtm = new GenericTreeModel();
final GenericTreeNode rootTreeNode = new GenericTreeNode();
rootTreeNode.setTitle("start");
gtm.setRootNode(rootTreeNode);
ICourse course = CourseFactory.loadCourse(userCourseEnv.getCourseEnvironment().getCourseResourceableId());
new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
CourseNode courseNode = (CourseNode) node;
StatisticResourceResult result = courseNode.createStatisticNodeResult(ureq, getWindowControl(), userCourseEnv, options, types);
if (result != null) {
StatisticResourceNode courseNodeTreeNode = new StatisticResourceNode(courseNode, result);
rootTreeNode.addChild(courseNodeTreeNode);
TreeModel subTreeModel = result.getSubTreeModel();
if (subTreeModel != null) {
TreeNode subRootNode = subTreeModel.getRootNode();
List<INode> subNodes = new ArrayList<>();
for (int i = 0; i < subRootNode.getChildCount(); i++) {
subNodes.add(subRootNode.getChildAt(i));
}
for (INode subNode : subNodes) {
courseNodeTreeNode.addChild(subNode);
}
}
}
}
}, course.getRunStructure().getRootNode(), true).visitAll();
return gtm;
}
use of org.olat.core.util.tree.TreeVisitor in project OpenOLAT by OpenOLAT.
the class QTIEditorMainController method createChangeMessage.
/**
* helper method to create the change log message
*
* @return
*/
private String createChangeMessage() {
// FIXME:pb:break down into smaller pieces
final StringBuilder result = new StringBuilder();
if (isRestrictedEdit()) {
Visitor v = new Visitor() {
/*
* a history key is built as follows
* sectionkey+"/"+itemkey+"/"+questionkey+"/"+responsekey
*/
String sectionKey = null;
Map<String, String> itemMap = new HashMap<>();
public void visit(INode node) {
if (node instanceof AssessmentNode) {
AssessmentNode an = (AssessmentNode) node;
String key = "null/null/null/null";
if (history.containsKey(key)) {
// some assessment top level data changed
Memento mem = history.get(key);
result.append("---+ Changes in test " + formatVariable(startedWithTitle) + ":");
result.append(an.createChangeMessage(mem));
}
} else if (node instanceof SectionNode) {
SectionNode sn = (SectionNode) node;
String tmpKey = ((Section) sn.getUnderlyingQTIObject()).getIdent();
String key = tmpKey + "/null/null/null";
if (history.containsKey(key)) {
// some section only data changed
Memento mem = history.get(key);
result.append("\n---++ Section " + formatVariable(sn.getAltText()) + " changes:");
result.append(sn.createChangeMessage(mem));
}
} else if (node instanceof ItemNode) {
ItemNode in = (ItemNode) node;
SectionNode sn = (SectionNode) in.getParent();
String parentSectkey = ((Section) ((SectionNode) in.getParent()).getUnderlyingQTIObject()).getIdent();
Item item = (Item) in.getUnderlyingQTIObject();
Question question = item.getQuestion();
String itemKey = item.getIdent();
String prefixKey = "null/" + itemKey;
String questionIdent = question != null ? question.getQuestion().getId() : "null";
String key = prefixKey + "/" + questionIdent + "/null";
StringBuilder changeMessage = new StringBuilder();
boolean hasChanges = false;
if (!itemMap.containsKey(itemKey)) {
Memento questMem = null;
Memento respMem = null;
if (history.containsKey(key)) {
// question changed!
questMem = history.get(key);
hasChanges = true;
}
// if(!hasChanges){
// check if a response changed
// new prefix for responses
prefixKey += "/null/";
// list contains org.olat.ims.qti.editor.beecom.objects.Response
List<Response> responses = question != null ? question.getResponses() : null;
if (responses != null && responses.size() > 0) {
// check for changes in each response
for (Iterator<Response> iter = responses.iterator(); iter.hasNext(); ) {
Response resp = iter.next();
if (history.containsKey(prefixKey + resp.getIdent())) {
// this response changed!
Memento tmpMem = history.get(prefixKey + resp.getIdent());
if (respMem != null) {
respMem = respMem.getTimestamp() > tmpMem.getTimestamp() ? tmpMem : respMem;
} else {
hasChanges = true;
respMem = tmpMem;
}
}
}
}
// output message
if (hasChanges) {
Memento mem = null;
if (questMem != null && respMem != null) {
// use the earlier memento
mem = questMem.getTimestamp() > respMem.getTimestamp() ? respMem : questMem;
} else if (questMem != null) {
mem = questMem;
} else if (respMem != null) {
mem = respMem;
}
changeMessage.append(in.createChangeMessage(mem));
itemMap.put(itemKey, itemKey);
if (!parentSectkey.equals(sectionKey)) {
// either this item belongs to a new section or no section
// is active
result.append("\n---++ Section " + formatVariable(sn.getAltText()) + " changes:");
result.append("\n").append(changeMessage);
sectionKey = parentSectkey;
} else {
result.append("\n").append(changeMessage);
}
}
}
}
}
private String formatVariable(String var) {
if (StringHelper.containsNonWhitespace(var)) {
return var;
}
return "[no entry]";
}
};
TreeVisitor tv = new TreeVisitor(v, menuTreeModel.getRootNode(), false);
tv.visitAll();
}
/*
*
*/
return result.toString();
}
use of org.olat.core.util.tree.TreeVisitor in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_11_0_0 method hasAssessableSTCourseNode.
private List<STCourseNode> hasAssessableSTCourseNode(ICourse course) {
List<STCourseNode> assessableSTNodes = new ArrayList<>();
CourseNode rootNode = course.getRunStructure().getRootNode();
new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof STCourseNode) {
STCourseNode stNode = (STCourseNode) node;
ScoreCalculator calculator = stNode.getScoreCalculator();
if (StringHelper.containsNonWhitespace(calculator.getPassedExpression())) {
assessableSTNodes.add(stNode);
} else if (StringHelper.containsNonWhitespace(calculator.getScoreExpression())) {
assessableSTNodes.add(stNode);
}
}
}
}, rootNode, true).visitAll();
return assessableSTNodes;
}
Aggregations