use of org.olat.core.gui.components.tree.TreeEvent in project OpenOLAT by OpenOLAT.
the class EPTOCController method doSelectTreeElement.
private void doSelectTreeElement(UserRequest ureq, TreeEvent te) {
TreeNode selectedNode = treeCtr.getTreeModel().getNodeById(te.getNodeId());
Object userObj = selectedNode.getUserObject();
if (userObj instanceof PortfolioStructure) {
// structure clicked
structureClicked = (PortfolioStructure) userObj;
refreshAddElements(ureq, structureClicked);
delButton.setVisible(true);
// send event to load this page
fireEvent(ureq, new EPStructureChangeEvent(EPStructureChangeEvent.SELECTED, structureClicked));
} else if (userObj instanceof AbstractArtefact) {
// artefact clicked
Object parentObj = ((TreeNode) selectedNode.getParent()).getUserObject();
if (parentObj instanceof PortfolioStructure) {
artefactClicked = (AbstractArtefact) userObj;
PortfolioStructure structure = (PortfolioStructure) parentObj;
refreshAddElements(ureq, null);
delButton.setVisible(true);
fireEvent(ureq, new EPArtefactClicked(ARTEFACT_NODE_CLICKED, structure));
}
} else {
// root tree node clicked, no add/delete link
delButton.setVisible(false);
refreshAddElements(ureq, null);
fireEvent(ureq, new Event(ARTEFACT_NODE_CLICKED));
}
}
use of org.olat.core.gui.components.tree.TreeEvent in project OpenOLAT by OpenOLAT.
the class EPTOCController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
*/
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source instanceof Link) {
Link link = (Link) source;
if (link.getCommand().equals(DELETE_LINK_CMD)) {
if (artefactClicked != null) {
AbstractArtefact artefact = artefactClicked;
PortfolioStructure parentStruct = getArtefactParentStruct(artefactClicked);
ePFMgr.removeArtefactFromStructure(artefact, parentStruct);
// refresh the view
fireEvent(ureq, Event.CHANGED_EVENT);
} else if (structureClicked != null) {
if ((structureClicked instanceof EPPage) && !(structureClicked instanceof EPAbstractMap)) {
PortfolioStructure ps = structureClicked;
while (ePFMgr.loadStructureParent(ps) != null) {
ps = ePFMgr.loadStructureParent(ps);
}
int childPages = ePFMgr.countStructureChildren(ps);
if (childPages > 1) {
eSTMgr.removeStructureRecursively(structureClicked);
// refresh the view
fireEvent(ureq, Event.CHANGED_EVENT);
} else {
showError("last.page.not.deletable");
}
} else if (structureClicked instanceof EPStructureElement && !(structureClicked instanceof EPAbstractMap)) {
// structures should always be deletable
eSTMgr.removeStructureRecursively(structureClicked);
// refresh the view
fireEvent(ureq, Event.CHANGED_EVENT);
} else {
showInfo("element.not.deletable");
}
}
}
} else if (source == treeCtr) {
if (event instanceof TreeEvent) {
TreeEvent te = (TreeEvent) event;
if (MenuTree.COMMAND_TREENODE_CLICKED.equals(te.getCommand())) {
doSelectTreeElement(ureq, te);
}
} else if (event instanceof TreeDropEvent) {
TreeDropEvent te = (TreeDropEvent) event;
doDrop(ureq, te.getDroppedNodeId(), te.getTargetNodeId(), te.isAsChild());
}
}
}
use of org.olat.core.gui.components.tree.TreeEvent in project OpenOLAT by OpenOLAT.
the class QTI12StatisticsToolController method event.
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (courseTree == source) {
if (event instanceof TreeEvent) {
TreeEvent te = (TreeEvent) event;
if (MenuTree.COMMAND_TREENODE_CLICKED.equals(te.getCommand())) {
String ident = te.getNodeId();
TreeNode selectedNode = courseTree.getTreeModel().getNodeById(ident);
doSelectNode(ureq, selectedNode);
}
}
}
}
use of org.olat.core.gui.components.tree.TreeEvent in project OpenOLAT by OpenOLAT.
the class FileChooserController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.components.Component,
* org.olat.core.gui.control.Event)
*/
@Override
protected void event(UserRequest ureq, Component source, Event event) {
// events from ajax tree view
if (source == cancelLink) {
fireEvent(ureq, Event.CANCELLED_EVENT);
} else if (source == selectLink) {
if (selectedItem != null) {
// fxdiff FXOLAT-125: virtual file system for CP
if (onlyLeafsSelectable && !(selectedItem instanceof VFSLeaf)) {
showWarning("filechooser.tree.error.only.leafs", selectedItem.getName());
} else {
fireEvent(ureq, new FileChoosenEvent(selectedItem));
}
} else {
fireEvent(ureq, Event.FAILED_EVENT);
}
} else if (source == selectionTree) {
TreeEvent te = (TreeEvent) event;
if (te.getCommand().equals(MenuTree.COMMAND_TREENODE_CLICKED)) {
String selectedPath = treeModel.getSelectedPath(selectionTree.getSelectedNode());
selectedItem = rootContainer.resolve(selectedPath);
selectLink.setCustomEnabledLinkCSS("btn btn-default o_button_dirty");
}
}
}
use of org.olat.core.gui.components.tree.TreeEvent in project OpenOLAT by OpenOLAT.
the class NavigationHandler method evaluateJumpToTreeNode.
/**
* to be called when the users clickes on a node when in the course
*
* @param ureq
* @param wControl
* @param treeModel
* @param treeEvent
* @param listeningController
* @param nodecmd null or a subcmd which activates a node-specific view (e.g. opens a certain uri in a contentpackaging- buildingblock)
* @return the NodeClickedRef
* @return currentNodeController the current node controller that will be dispose before creating the new one
*/
public NodeClickedRef evaluateJumpToTreeNode(UserRequest ureq, WindowControl wControl, TreeModel treeModel, TreeEvent treeEvent, ControllerEventListener listeningController, String nodecmd, Controller currentNodeController) {
NodeClickedRef ncr;
String treeNodeId = treeEvent.getNodeId();
TreeNode selTN = treeModel.getNodeById(treeNodeId);
if (selTN == null) {
selTN = treeModel.getRootNode();
}
if (!selTN.isAccessible()) {
// event to match the new node
if (selTN.getDelegate() != null) {
selTN = selTN.getDelegate();
treeNodeId = selTN.getIdent();
treeEvent = new TreeEvent(MenuTree.COMMAND_TREENODE_CLICKED, treeNodeId);
}
}
// check if appropriate for subtreemodelhandler
Object userObject = selTN.getUserObject();
if (!(userObject instanceof NodeEvaluation)) {
// yes, appropriate
NodeRunConstructionResult nrcr = null;
CourseNode internCourseNode = null;
GenericTreeModel subTreeModel;
ControllerEventListener subtreemodelListener = null;
if (selTN != null) {
TreeNode internNode = getFirstInternParentNode(selTN);
NodeEvaluation prevEval = (NodeEvaluation) internNode.getUserObject();
CourseNode courseNode = prevEval.getCourseNode();
if (externalTreeModels.containsKey(courseNode.getIdent())) {
SubTree subTree = externalTreeModels.get(courseNode.getIdent());
subtreemodelListener = subTree.getTreeModelListener();
}
}
if (subtreemodelListener == null) {
// throw new AssertException("no handler for subtreemodelcall!");
// reattach the subtreemodellistener
TreeNode internNode = getFirstInternParentNode(selTN);
NodeEvaluation prevEval = (NodeEvaluation) internNode.getUserObject();
internCourseNode = prevEval.getCourseNode();
final OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseNode.class, Long.parseLong(internCourseNode.getIdent()));
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
nrcr = internCourseNode.createNodeRunConstructionResult(ureq, bwControl, userCourseEnv, prevEval, nodecmd);
// remember as instance variable for next click
subtreemodelListener = nrcr.getSubTreeListener();
subTreeModel = (GenericTreeModel) nrcr.getSubTreeModel();
externalTreeModels.put(internCourseNode.getIdent(), new SubTree(nrcr.getRunController(), subTreeModel, subtreemodelListener));
} else {
TreeNode internNode = getFirstInternParentNode(selTN);
NodeEvaluation prevEval = (NodeEvaluation) internNode.getUserObject();
internCourseNode = prevEval.getCourseNode();
SubTree subTree = externalTreeModels.get(internCourseNode.getIdent());
subtreemodelListener = subTree.getTreeModelListener();
if (currentNodeController instanceof TitledWrapperController) {
currentNodeController = ((TitledWrapperController) currentNodeController).getContentController();
}
if (subtreemodelListener != currentNodeController) {
if (subtreemodelListener instanceof CPRunController) {
nrcr = ((CPRunController) subtreemodelListener).createNodeRunConstructionResult(ureq, selTN.getIdent());
} else {
nrcr = new NodeRunConstructionResult((Controller) subtreemodelListener);
}
}
subTreeModel = subTree.getTreeModel();
}
if (log.isDebug()) {
log.debug("delegating to handler: treeNodeId = " + treeNodeId);
}
// used in multiple nodes.
if (!selTN.getUserObject().equals(userObject)) {
selTN = subTreeModel.findNodeByUserObject(userObject);
}
treeEvent = new TreeEvent(treeEvent.getCommand(), treeEvent.getSubCommand(), selTN.getIdent());
boolean dispatch = true;
String selectedNodeId = null;
if (userObject instanceof String) {
String sObject = (String) userObject;
if (MenuTree.COMMAND_TREENODE_CLICKED.equals(treeEvent.getCommand()) && treeEvent.getSubCommand() == null) {
openCourseNodeIds.add(sObject);
if (!openTreeNodeIds.contains(sObject)) {
openTreeNodeIds.add(sObject);
}
selectedNodeId = selTN.getIdent();
} else if (TreeEvent.COMMAND_TREENODE_OPEN.equals(treeEvent.getSubCommand())) {
openCourseNodeIds.add(sObject);
if (!openTreeNodeIds.contains(sObject)) {
openTreeNodeIds.add(sObject);
}
selectedNodeId = selTN.getIdent();
dispatch = false;
} else if (TreeEvent.COMMAND_TREENODE_CLOSE.equals(treeEvent.getSubCommand())) {
removeChildrenFromOpenNodes(selTN);
openCourseNodeIds.remove(sObject);
openTreeNodeIds.remove(sObject);
openCourseNodeIds.remove(selTN.getIdent());
openTreeNodeIds.remove(selTN.getIdent());
dispatch = false;
}
}
if (dispatch) {
// null as controller source since we are not a controller
subtreemodelListener.dispatchEvent(ureq, null, treeEvent);
// no node construction result indicates handled
}
ncr = new NodeClickedRef(treeModel, true, selectedNodeId, openTreeNodeIds, internCourseNode, nrcr, true);
} else {
// normal dispatching to a coursenode.
// get the courseNode that was called
NodeEvaluation prevEval = (NodeEvaluation) selTN.getUserObject();
if (!prevEval.isVisible())
throw new AssertException("clicked on a node which is not visible: treenode=" + selTN.getIdent() + ", " + selTN.getTitle());
CourseNode calledCourseNode = prevEval.getCourseNode();
ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrap(calledCourseNode));
// might be used in both controllers with the same ID (e.g. the course folder)
if (TreeEvent.COMMAND_TREENODE_OPEN.equals(treeEvent.getSubCommand()) || TreeEvent.COMMAND_TREENODE_CLOSE.equals(treeEvent.getSubCommand())) {
if (isInParentLine(calledCourseNode)) {
if (currentNodeController != null && !currentNodeController.isDisposed() && !isListening(currentNodeController)) {
currentNodeController.dispose();
}
}
ncr = doEvaluateJumpTo(ureq, wControl, calledCourseNode, listeningController, nodecmd, treeEvent.getSubCommand(), currentNodeController);
} else {
if (currentNodeController != null && !currentNodeController.isDisposed() && !isListening(currentNodeController)) {
currentNodeController.dispose();
}
ncr = doEvaluateJumpTo(ureq, wControl, calledCourseNode, listeningController, nodecmd, treeEvent.getSubCommand(), currentNodeController);
}
}
return ncr;
}
Aggregations