Search in sources :

Example 1 with GenericActionExtension

use of org.olat.core.extensions.action.GenericActionExtension in project OpenOLAT by OpenOLAT.

the class GenericMainController method activate.

protected void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (entries == null || entries.isEmpty())
        return;
    ContextEntry entry = entries.get(0);
    TreeNode selectedNode = getMenuTree().getSelectedNode();
    String node = entry.getOLATResourceable().getResourceableTypeName();
    if (node != null && node.startsWith(GMCMT)) {
        activate(ureq, node + ":" + entries.get(0).getOLATResourceable().getResourceableId());
        if (entries.size() >= 1) {
            entries = entries.subList(1, entries.size());
        }
        if (contentCtr instanceof Activateable2) {
            ((Activateable2) contentCtr).activate(ureq, entries, entry.getTransientState());
        }
    } else {
        // maybe the node is a GAE-NavigationKey ?
        GenericActionExtension gAE = ExtManager.getInstance().getActionExtensioByNavigationKey(className, node);
        if (gAE != null) {
            // if the controller is already selected, only activate it, don't reinstanciate it
            if (selectedNode != null && selectedNode.getUserObject() != gAE) {
                activateTreeNodeByActionExtension(ureq, gAE);
            }
            if (entries.size() >= 1) {
                entries = entries.subList(1, entries.size());
            }
            if (contentCtr instanceof Activateable2) {
                ((Activateable2) contentCtr).activate(ureq, entries, entry.getTransientState());
            }
        }
    }
}
Also used : Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 2 with GenericActionExtension

use of org.olat.core.extensions.action.GenericActionExtension in project openolat by klemens.

the class GenericMainController method buildTreeModel.

private TreeModel buildTreeModel(UserRequest ureq) {
    GenericTreeNode rootTreeNode = new GenericTreeNode();
    rootTreeNode.setTitle(getTranslator().translate("main.menu.title"));
    rootTreeNode.setAltText(getTranslator().translate("main.menu.title.alt"));
    GenericTreeModel gtm = new GenericTreeModel();
    gtm.setRootNode(rootTreeNode);
    // Prepend
    boolean rootNodeSet = false;
    if (nodesToPrepend.size() != 0) {
        for (GenericTreeNode node : nodesToPrepend) {
            rootTreeNode.addChild(node);
            if (!rootNodeSet) {
                rootTreeNode.setDelegate(node);
                rootTreeNode.setUserObject(node.getUserObject());
                rootNodeSet = true;
            }
        }
    }
    // add extension menues
    ExtManager extm = ExtManager.getInstance();
    int j = 0;
    GenericTreeNode gtnChild;
    Map<GenericTreeNode, String> subMenuNodes = new LinkedHashMap<GenericTreeNode, String>();
    for (Extension anExt : extm.getExtensions()) {
        // check for sites
        ActionExtension ae = (ActionExtension) anExt.getExtensionFor(className, ureq);
        if (ae != null && ae instanceof GenericActionExtension) {
            if (anExt.isEnabled()) {
                GenericActionExtension gAe = (GenericActionExtension) ae;
                gtnChild = gAe.createMenuNode(ureq);
                if (StringHelper.containsNonWhitespace(gAe.getNavigationKey())) {
                    gtnChild.setCssClass("o_sel_" + gAe.getNavigationKey());
                }
                if (gAe.getNodeIdentifierIfParent() != null) {
                    // it's a parent-node, set identifier
                    gtnChild.setIdent(gAe.getNodeIdentifierIfParent());
                }
                if (j == 0 && !rootNodeSet) {
                    // first node, set as delegate of rootTreenode
                    rootTreeNode.setDelegate(gtnChild);
                    rootTreeNode.setUserObject(gAe);
                    rootTreeNode.addChild(gtnChild);
                } else // navigation (submenues)
                if (gAe.getParentTreeNodeIdentifier() != null) {
                    // this is a sub-menu-node, do not add to tree-model already, since
                    // parent tree may not yet be in model
                    // (parent could be "after" child, in ActionExtensions-Collection)
                    String parentNodeID = gAe.getParentTreeNodeIdentifier();
                    subMenuNodes.put(gtnChild, parentNodeID);
                } else // "normal" menu-entry
                {
                    rootTreeNode.addChild(gtnChild);
                }
                j++;
            } else {
                logInfo("found disabled GenericActionExtension for " + className + " ", ae.toString());
            }
        }
    }
    // loop over submenuNodes and add to their parents
    for (Entry<GenericTreeNode, String> childNodeEntry : subMenuNodes.entrySet()) {
        GenericTreeNode childNode = childNodeEntry.getKey();
        GenericTreeNode parentNode = (GenericTreeNode) gtm.getNodeById(childNodeEntry.getValue());
        if (parentNode != null) {
            parentNode.addChild(childNode);
            if (parentNode.getDelegate() == null) {
                boolean addDelegate = true;
                // add delegate only if hte parent hasn't not a controller defined
                Object uo = parentNode.getUserObject();
                if (uo instanceof GenericActionExtension) {
                    GenericActionExtension gae = (GenericActionExtension) uo;
                    if (StringHelper.containsNonWhitespace(gae.getClassNameOfCorrespondingController())) {
                        addDelegate = false;
                    }
                }
                if (addDelegate) {
                    parentNode.setDelegate(childNode);
                    parentNode.setUserObject(childNode.getUserObject());
                }
            }
        } else {
            logWarn("Could not add navigation-menu (" + childNode.getTitle() + ") to parent:: " + childNodeEntry.getValue(), null);
            // make it at least appear on top level
            rootTreeNode.addChild(childNode);
        }
    }
    // Append
    if (nodesToAppend.size() != 0) {
        for (GenericTreeNode node : nodesToAppend) {
            rootTreeNode.addChild(node);
        }
    }
    return gtm;
}
Also used : ExtManager(org.olat.core.extensions.ExtManager) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) LinkedHashMap(java.util.LinkedHashMap) Extension(org.olat.core.extensions.Extension) ActionExtension(org.olat.core.extensions.action.ActionExtension) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) ActionExtension(org.olat.core.extensions.action.ActionExtension) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 3 with GenericActionExtension

use of org.olat.core.extensions.action.GenericActionExtension in project openolat by klemens.

the class GenericMainController method activate.

protected void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (entries == null || entries.isEmpty())
        return;
    ContextEntry entry = entries.get(0);
    TreeNode selectedNode = getMenuTree().getSelectedNode();
    String node = entry.getOLATResourceable().getResourceableTypeName();
    if (node != null && node.startsWith(GMCMT)) {
        activate(ureq, node + ":" + entries.get(0).getOLATResourceable().getResourceableId());
        if (entries.size() >= 1) {
            entries = entries.subList(1, entries.size());
        }
        if (contentCtr instanceof Activateable2) {
            ((Activateable2) contentCtr).activate(ureq, entries, entry.getTransientState());
        }
    } else {
        // maybe the node is a GAE-NavigationKey ?
        GenericActionExtension gAE = ExtManager.getInstance().getActionExtensioByNavigationKey(className, node);
        if (gAE != null) {
            // if the controller is already selected, only activate it, don't reinstanciate it
            if (selectedNode != null && selectedNode.getUserObject() != gAE) {
                activateTreeNodeByActionExtension(ureq, gAE);
            }
            if (entries.size() >= 1) {
                entries = entries.subList(1, entries.size());
            }
            if (contentCtr instanceof Activateable2) {
                ((Activateable2) contentCtr).activate(ureq, entries, entry.getTransientState());
            }
        }
    }
}
Also used : Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 4 with GenericActionExtension

use of org.olat.core.extensions.action.GenericActionExtension in project openolat by klemens.

the class ExtManager method initExtentions.

private ArrayList<Extension> initExtentions() {
    logInfo("****** start loading extensions *********");
    Map<Integer, Extension> orderKeys = new HashMap<Integer, Extension>();
    idExtensionlookup = new HashMap<Long, Extension>();
    navKeyGAExtensionlookup = new HashMap<ExtensionPointKeyPair, GenericActionExtension>();
    ArrayList<Extension> extensionsList = new ArrayList<Extension>();
    Map<String, Extension> extensionMap = CoreSpringFactory.getBeansOfType(Extension.class);
    Collection<Extension> extensionValues = extensionMap.values();
    int count_disabled = 0;
    int count_duplid = 0;
    AtomicInteger count_duplnavkey = new AtomicInteger(0);
    boolean debug = isLogDebugEnabled();
    // first build ordered list
    for (Extension extension : extensionValues) {
        if (!extension.isEnabled()) {
            count_disabled++;
            logInfo("* Disabled Extension got loaded :: " + extension + ".  Check that you don't use it or that extension returns null for getExtensionFor() when disabled, resp. overwrite isEnabled().", null);
        }
        int orderKey = extension.getOrder();
        if (orderKey == 0) {
            // not configured via spring (order not set)
            logDebug("Extension-Configuration Warning: Order-value was not set for extension=" + extension + ", set order-value to config positionioning of extension...", null);
            if (extension instanceof AbstractExtension) {
                ((AbstractExtension) extension).setOrder(100000);
            }
        }
        if (orderKeys.containsKey(orderKey)) {
            Extension occupant = orderKeys.get(orderKey);
            if (debug)
                logDebug("Extension-Configuration Problem: Dublicate order-value (" + extension.getOrder() + ") for extension=" + extension + ", orderKey already occupied by " + occupant, null);
        } else {
            orderKeys.put(orderKey, extension);
        }
        Long uid = CodeHelper.getUniqueIDFromString(extension.getUniqueExtensionID());
        if (idExtensionlookup.containsKey(uid)) {
            count_duplid++;
            logWarn("Devel-Info :: duplicate unique id generated for extensions :: " + uid + " [ [" + idExtensionlookup.get(uid) + "]  and [" + extension + "] ]", null);
        } else {
            extensionsList.add(extension);
            idExtensionlookup.put(uid, extension);
            if (extension instanceof GenericActionExtension) {
                GenericActionExtension gAE = (GenericActionExtension) extension;
                if (StringHelper.containsNonWhitespace(gAE.getNavigationKey()) && gAE.getExtensionPoints() != null) {
                    List<String> extensionPoints = gAE.getExtensionPoints();
                    for (String extensionPoint : extensionPoints) {
                        ExtensionPointKeyPair key = new ExtensionPointKeyPair(extensionPoint, gAE.getNavigationKey());
                        append(key, gAE, count_duplnavkey);
                        List<String> alternativeNavigationKeys = gAE.getAlternativeNavigationKeys();
                        if (alternativeNavigationKeys != null && alternativeNavigationKeys.size() > 0) {
                            for (String alternativeNavigationKey : alternativeNavigationKeys) {
                                ExtensionPointKeyPair altKey = new ExtensionPointKeyPair(extensionPoint, alternativeNavigationKey);
                                append(altKey, gAE, count_duplnavkey);
                            }
                        }
                    }
                }
            }
        }
        if (debug)
            logDebug("Created unique-id " + uid + " for extension:: " + extension);
    }
    logInfo("Devel-Info :: initExtensions done. :: " + count_disabled + " disabled Extensions, " + count_duplid + " extensions with duplicate ids, " + count_duplnavkey + " extensions with duplicate navigationKeys");
    Collections.sort(extensionsList);
    return extensionsList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 5 with GenericActionExtension

use of org.olat.core.extensions.action.GenericActionExtension in project openolat by klemens.

the class HomeMainController method activate.

@Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (entries == null || entries.isEmpty())
        return;
    ContextEntry entry = entries.get(0);
    String navKey = entry.getOLATResourceable().getResourceableTypeName();
    if ("HomeSite".equals(navKey)) {
        entries = entries.subList(1, entries.size());
        if (entries.size() > 0) {
            entry = entries.get(0);
            navKey = entry.getOLATResourceable().getResourceableTypeName();
        }
    }
    if (navKey.equals(currentNavKey) && currentCtr instanceof ReusableHomeController) {
        if (currentCtr instanceof Activateable2) {
            ((Activateable2) currentCtr).activate(ureq, entries, entry.getTransientState());
        }
    } else {
        GenericActionExtension gAE = ExtManager.getInstance().getActionExtensioByNavigationKey(HomeMainController.class.getName(), navKey);
        if (gAE != null) {
            currentNavKey = navKey;
            stackPanel.popUpToRootController(ureq);
            currentCtr = createController(gAE, ureq);
            contentCtr = new LayoutMain3ColsController(ureq, getWindowControl(), currentCtr);
            listenTo(contentCtr);
            if (entries.size() >= 1) {
                entries = entries.subList(1, entries.size());
            }
            String actionText = gAE.getActionText(getLocale());
            stackPanel.rootController(actionText, contentCtr);
            if (currentCtr instanceof Activateable2) {
                ((Activateable2) currentCtr).activate(ureq, entries, entry.getTransientState());
            }
        }
    }
}
Also used : Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) ContextEntry(org.olat.core.id.context.ContextEntry)

Aggregations

GenericActionExtension (org.olat.core.extensions.action.GenericActionExtension)14 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)8 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)8 Extension (org.olat.core.extensions.Extension)6 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)4 ExtManager (org.olat.core.extensions.ExtManager)4 ActionExtension (org.olat.core.extensions.action.ActionExtension)4 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 WindowControl (org.olat.core.gui.control.WindowControl)4 Activateable2 (org.olat.core.gui.control.generic.dtabs.Activateable2)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 ContextEntry (org.olat.core.id.context.ContextEntry)4 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 NewUsersNotificationsController (org.olat.admin.user.NewUsersNotificationsController)2