Search in sources :

Example 6 with IMenuObject

use of com.helger.photon.core.menu.IMenuObject in project peppol-practical by phax.

the class AppCommonUI method createViewLink.

@Nonnull
public static IHCNode createViewLink(@Nonnull final IWebPageExecutionContext aWPEC, @Nullable final ITypedObject<String> aObject, @Nullable final String sDisplayName) {
    if (aObject == null)
        return HCTextNode.createOnDemand(sDisplayName);
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    if (aObject instanceof IRole) {
        final IRole aTypedObj = (IRole) aObject;
        final String sRealDisplayName = sDisplayName != null ? sDisplayName : aTypedObj.getName();
        final String sMenuItemID = BootstrapPagesMenuConfigurator.MENU_ADMIN_SECURITY_ROLE;
        final IMenuObject aObj = aWPEC.getMenuTree().getItemDataWithID(sMenuItemID);
        if (aObj != null && aObj.matchesDisplayFilter())
            return new HCA(getViewLink(aWPEC, sMenuItemID, aTypedObj)).addChild(sRealDisplayName).setTitle("Show details of role '" + sRealDisplayName + "'");
        return new HCTextNode(sRealDisplayName);
    }
    if (aObject instanceof IUser) {
        final IUser aTypedObj = (IUser) aObject;
        final String sRealDisplayName = sDisplayName != null ? sDisplayName : SecurityHelper.getUserDisplayName(aTypedObj, aDisplayLocale);
        final String sMenuItemID = BootstrapPagesMenuConfigurator.MENU_ADMIN_SECURITY_USER;
        final IMenuObject aObj = aWPEC.getMenuTree().getItemDataWithID(sMenuItemID);
        if (aObj != null && aObj.matchesDisplayFilter())
            return new HCA(getViewLink(aWPEC, sMenuItemID, aTypedObj)).addChild(sRealDisplayName).setTitle("Show details of user '" + sRealDisplayName + "'");
        return new HCTextNode(sRealDisplayName);
    }
    if (aObject instanceof IUserGroup) {
        final IUserGroup aTypedObj = (IUserGroup) aObject;
        final String sRealDisplayName = sDisplayName != null ? sDisplayName : aTypedObj.getName();
        final String sMenuItemID = BootstrapPagesMenuConfigurator.MENU_ADMIN_SECURITY_USER_GROUP;
        final IMenuObject aObj = aWPEC.getMenuTree().getItemDataWithID(sMenuItemID);
        if (aObj != null && aObj.matchesDisplayFilter())
            return new HCA(getViewLink(aWPEC, sMenuItemID, aTypedObj)).addChild(sRealDisplayName).setTitle("Show details of user group '" + sRealDisplayName + "'");
        return new HCTextNode(sRealDisplayName);
    }
    // add other types as desired
    throw new IllegalArgumentException("Unsupported object: " + aObject);
}
Also used : Locale(java.util.Locale) IRole(com.helger.photon.security.role.IRole) IUserGroup(com.helger.photon.security.usergroup.IUserGroup) HCA(com.helger.html.hc.html.textlevel.HCA) IUser(com.helger.photon.security.user.IUser) IMenuObject(com.helger.photon.core.menu.IMenuObject) PDTToString(com.helger.commons.datetime.PDTToString) HCTextNode(com.helger.html.hc.impl.HCTextNode) Nonnull(javax.annotation.Nonnull)

Aggregations

IMenuObject (com.helger.photon.core.menu.IMenuObject)6 Nonnull (javax.annotation.Nonnull)6 HCNodeList (com.helger.html.hc.impl.HCNodeList)3 IMenuTree (com.helger.photon.core.menu.IMenuTree)3 MenuItemDeterminatorCallback (com.helger.photon.core.menu.MenuItemDeterminatorCallback)3 Locale (java.util.Locale)3 ISimpleURL (com.helger.commons.url.ISimpleURL)2 SimpleURL (com.helger.commons.url.SimpleURL)2 HCUL (com.helger.html.hc.html.grouping.HCUL)2 HCA (com.helger.html.hc.html.textlevel.HCA)2 BootstrapContainer (com.helger.photon.bootstrap4.layout.BootstrapContainer)2 BootstrapMenuItemRendererHorz (com.helger.photon.bootstrap4.uictrls.ext.BootstrapMenuItemRendererHorz)2 IMenuItemExternal (com.helger.photon.core.menu.IMenuItemExternal)2 IMenuItemPage (com.helger.photon.core.menu.IMenuItemPage)2 IMenuSeparator (com.helger.photon.core.menu.IMenuSeparator)2 PDTToString (com.helger.commons.datetime.PDTToString)1 HCImg (com.helger.html.hc.html.embedded.HCImg)1 HCForm (com.helger.html.hc.html.forms.HCForm)1 HCHiddenField (com.helger.html.hc.html.forms.HCHiddenField)1 HCInput (com.helger.html.hc.html.forms.HCInput)1