Author: jnicolas
Date: Wed Oct 17 07:33:12 2018 New Revision: 1844068 URL: http://svn.apache.org/viewvc?rev=1844068&view=rev Log: Improved: Change the Menu extends-resource management to allow structure changes by themes (OFBIZ-10600) Thanks: Nicolas MALIN, Leila MEKIKA and Gil PORTENSEIGNE Modified: ofbiz/ofbiz-framework/trunk/framework/common/widget/CommonMenus.xml ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MenuFactory.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java ofbiz/ofbiz-framework/trunk/themes/bluelight/template/AppBarOpen.ftl ofbiz/ofbiz-framework/trunk/themes/common-theme/widget/Theme.xml ofbiz/ofbiz-framework/trunk/themes/tomahawk/template/AppBarClose.ftl ofbiz/ofbiz-framework/trunk/themes/tomahawk/template/AppBarOpen.ftl Modified: ofbiz/ofbiz-framework/trunk/framework/common/widget/CommonMenus.xml URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/widget/CommonMenus.xml?rev=1844068&r1=1844067&r2=1844068&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/common/widget/CommonMenus.xml (original) +++ ofbiz/ofbiz-framework/trunk/framework/common/widget/CommonMenus.xml Wed Oct 17 07:33:12 2018 @@ -19,18 +19,15 @@ under the License. --> <menus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ofbiz.apache.org/Widget-Menu" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Menu http://ofbiz.apache.org/dtds/widget-menu.xsd"> - <menu name="CommonAppBarMenu" default-menu-item-name="main" id="app-navigation" type="simple" title="${applicationTitle}&nbsp;" - default-selected-style="selected" menu-container-style="button-bar tab-bar" selected-menuitem-context-field-name="headerItem"> - <menu-item name="main" title="${uiLabelMap.CommonMain}"> - <condition><not><if-empty field="userLogin"/></not></condition> - <link target="main" link-type="anchor"/> - </menu-item> - </menu> + <menu name="CommonAppBarMenu" extends="CommonAppBarMenu" + extends-resource="${groovy:CommonAppBarMenu?CommonAppBarMenu:'component://common-theme/widget/CommonMenus.xml'}"/> - <menu name="CommonTabBarMenu" selected-menuitem-context-field-name="tabButtonItem" type="simple" - menu-container-style="button-bar tab-bar" default-selected-style="selected"/> + <menu name="CommonTabBarMenu" extends="CommonTabBarMenu" + extends-resource="${groovy:CommonTabBarMenu?CommonTabBarMenu:'component://common-theme/widget/CommonMenus.xml'}"/> - <menu name="CommonButtonBarMenu" type="simple" menu-container-style="button-bar" default-widget-style="buttontext"/> + <menu name="CommonButtonBarMenu" extends="CommonButtonBarMenu" + extends-resource="${groovy:CommonButtonBarMenu?CommonButtonBarMenu:'component://common-theme/widget/CommonMenus.xml'}"/> - <menu name="CommonInlineBarMenu" type="simple" menu-container-style="in-line-bar" default-widget-style="linktext"/> + <menu name="CommonInlineBarMenu" extends="CommonInlineBarMenu" + extends-resource="${groovy:CommonInlineBarMenu?CommonInlineBarMenu:'component://common-theme/widget/CommonMenus.xml'}"/> </menus> Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MenuFactory.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MenuFactory.java?rev=1844068&r1=1844067&r2=1844068&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MenuFactory.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MenuFactory.java Wed Oct 17 07:33:12 2018 @@ -32,6 +32,7 @@ import org.apache.ofbiz.base.util.UtilHt import org.apache.ofbiz.base.util.UtilValidate; import org.apache.ofbiz.base.util.UtilXml; import org.apache.ofbiz.base.util.cache.UtilCache; +import org.apache.ofbiz.widget.renderer.VisualTheme; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; @@ -50,7 +51,13 @@ public class MenuFactory { public static ModelMenu getMenuFromWebappContext(String resourceName, String menuName, HttpServletRequest request) throws IOException, SAXException, ParserConfigurationException { String webappName = UtilHttp.getApplicationName(request); - String cacheKey = webappName + "::" + resourceName; + VisualTheme visualTheme = ThemeFactory.resolveVisualTheme(request); + String location = webappName + "::" + resourceName; + String cacheKey = location; + + if (UtilValidate.isNotEmpty(visualTheme)) { + cacheKey += "::" + visualTheme.getVisualThemeId(); + } Map<String, ModelMenu> modelMenuMap = menuWebappCache.get(cacheKey); if (modelMenuMap == null) { @@ -58,7 +65,7 @@ public class MenuFactory { URL menuFileUrl = servletContext.getResource(resourceName); Document menuFileDoc = UtilXml.readXmlDocument(menuFileUrl, true, true); - modelMenuMap = readMenuDocument(menuFileDoc, cacheKey); + modelMenuMap = readMenuDocument(menuFileDoc, location, visualTheme); menuWebappCache.putIfAbsent(cacheKey, modelMenuMap); modelMenuMap = menuWebappCache.get(cacheKey); } @@ -74,7 +81,7 @@ public class MenuFactory { return modelMenu; } - public static Map<String, ModelMenu> readMenuDocument(Document menuFileDoc, String menuLocation) { + public static Map<String, ModelMenu> readMenuDocument(Document menuFileDoc, String menuLocation, VisualTheme visualTheme) { Map<String, ModelMenu> modelMenuMap = new HashMap<>(); if (menuFileDoc != null) { // read document and construct ModelMenu for each menu element @@ -83,21 +90,22 @@ public class MenuFactory { rootElement = UtilXml.firstChildElement(rootElement, "menus"); } for (Element menuElement: UtilXml.childElementList(rootElement, "menu")){ - ModelMenu modelMenu = new ModelMenu(menuElement, menuLocation); + ModelMenu modelMenu = new ModelMenu(menuElement, menuLocation, visualTheme); modelMenuMap.put(modelMenu.getName(), modelMenu); } } return modelMenuMap; } - public static ModelMenu getMenuFromLocation(String resourceName, String menuName) throws IOException, SAXException, ParserConfigurationException { - Map<String, ModelMenu> modelMenuMap = menuLocationCache.get(resourceName); + public static ModelMenu getMenuFromLocation(String resourceName, String menuName, VisualTheme visualTheme) throws IOException, SAXException, ParserConfigurationException { + String keyName = resourceName + "::" + visualTheme.getVisualThemeId(); + Map<String, ModelMenu> modelMenuMap = menuLocationCache.get(keyName); if (modelMenuMap == null) { URL menuFileUrl = FlexibleLocation.resolveLocation(resourceName); Document menuFileDoc = UtilXml.readXmlDocument(menuFileUrl, true, true); - modelMenuMap = readMenuDocument(menuFileDoc, resourceName); - menuLocationCache.putIfAbsent(resourceName, modelMenuMap); - modelMenuMap = menuLocationCache.get(resourceName); + modelMenuMap = readMenuDocument(menuFileDoc, resourceName, visualTheme); + menuLocationCache.putIfAbsent(keyName, modelMenuMap); + modelMenuMap = menuLocationCache.get(keyName); } if (UtilValidate.isEmpty(modelMenuMap)) { @@ -110,4 +118,4 @@ public class MenuFactory { } return modelMenu; } -} +} \ No newline at end of file Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java?rev=1844068&r1=1844067&r2=1844068&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java Wed Oct 17 07:33:12 2018 @@ -75,6 +75,7 @@ import org.apache.ofbiz.widget.renderer. import org.apache.ofbiz.widget.renderer.FormStringRenderer; import org.apache.ofbiz.widget.renderer.MenuStringRenderer; import org.apache.ofbiz.widget.renderer.ScreenRenderer; +import org.apache.ofbiz.widget.renderer.VisualTheme; import org.codehaus.groovy.control.CompilationFailedException; import org.w3c.dom.Element; @@ -3267,7 +3268,7 @@ public class ModelFormField { String location = this.getMenuLocation(context); ModelMenu modelMenu = null; try { - modelMenu = MenuFactory.getMenuFromLocation(location, name); + modelMenu = MenuFactory.getMenuFromLocation(location, name, (VisualTheme) context.get("visualTheme")); } catch (Exception e) { String errMsg = "Error rendering menu named [" + name + "] at location [" + location + "]: "; Debug.logError(e, errMsg, module); Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java?rev=1844068&r1=1844067&r2=1844068&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java Wed Oct 17 07:33:12 2018 @@ -31,6 +31,7 @@ import org.apache.ofbiz.base.util.UtilXm import org.apache.ofbiz.base.util.collections.FlexibleMapAccessor; import org.apache.ofbiz.base.util.string.FlexibleStringExpander; import org.apache.ofbiz.widget.renderer.MenuStringRenderer; +import org.apache.ofbiz.widget.renderer.VisualTheme; import org.w3c.dom.Element; /** @@ -102,7 +103,7 @@ public class ModelMenu extends ModelWidg private final String type; /** XML Constructor */ - public ModelMenu(Element menuElement, String menuLocation) { + public ModelMenu(Element menuElement, String menuLocation, VisualTheme visualTheme) { super(menuElement); ArrayList<ModelAction> actions = new ArrayList<>(); String defaultAlign = ""; @@ -139,22 +140,26 @@ public class ModelMenu extends ModelWidg if (!parentMenu.isEmpty()) { if (!parentResource.isEmpty()) { try { - parent = MenuFactory.getMenuFromLocation(parentResource, parentMenu); + FlexibleStringExpander parentResourceExp = FlexibleStringExpander.getInstance(parentResource); + Map<String, String> visualRessources = visualTheme.getModelTheme().getModelCommonMenus(); + parentResource = parentResourceExp.expandString(visualRessources); + parent = MenuFactory.getMenuFromLocation(parentResource, parentMenu, visualTheme); } catch (Exception e) { - Debug.logError(e, "Failed to load parent menu definition '" + parentMenu + "' at resource '" + parentResource - + "'", module); + Debug.logError(e, "Failed to load parent menu definition '" + parentMenu + "' at resource '" + parentResource, module); } } else { parentResource = menuLocation; // try to find a menu definition in the same file Element rootElement = menuElement.getOwnerDocument().getDocumentElement(); List<? extends Element> menuElements = UtilXml.childElementList(rootElement, "menu"); - for (Element menuElementEntry : menuElements) { - if (menuElementEntry.getAttribute("name").equals(parentMenu)) { - parent = new ModelMenu(menuElementEntry, parentResource); - break; - } + Element parentEntry = menuElements.stream() + .filter(elem -> elem.getAttribute("name").equals(parentMenu)) + .findFirst() + .orElse(null); + if (parentEntry != null) { + parent = new ModelMenu(parentEntry, parentResource, visualTheme); } + if (parent == null) { Debug.logError("Failed to find parent menu definition '" + parentMenu + "' in same document.", module); } Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java?rev=1844068&r1=1844067&r2=1844068&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java Wed Oct 17 07:33:12 2018 @@ -55,6 +55,7 @@ import org.apache.ofbiz.widget.renderer. import org.apache.ofbiz.widget.renderer.ScreenRenderer; import org.apache.ofbiz.widget.renderer.ScreenStringRenderer; import org.apache.ofbiz.widget.renderer.TreeStringRenderer; +import org.apache.ofbiz.widget.renderer.VisualTheme; import org.w3c.dom.Element; import org.xml.sax.SAXException; @@ -1599,7 +1600,7 @@ public abstract class ModelScreenWidget String location = this.getLocation(context); ModelMenu modelMenu = null; try { - modelMenu = MenuFactory.getMenuFromLocation(location, name); + modelMenu = MenuFactory.getMenuFromLocation(location, name, (VisualTheme) context.get("visualTheme")); } catch (Exception e) { String errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: "; Debug.logError(e, errMsg, module); Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java?rev=1844068&r1=1844067&r2=1844068&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java Wed Oct 17 07:33:12 2018 @@ -74,6 +74,7 @@ public class ModelTheme implements Seria //template rendering private final Map<String, ModelTemplate> modelTemplateMap; private final Map<String, String> modelCommonScreensMap; + private final Map<String, String> modelCommonMenusMap; /** * Only constructor to initialize a modelTheme from xml definition @@ -86,6 +87,7 @@ public class ModelTheme implements Seria Map<String, Object> initThemePropertiesMap = new HashMap<>(); Map<String, ModelTemplate> initModelTemplateMap = new HashMap<>(); Map<String, String> initModelCommonScreensMap = new HashMap<>(); + Map<String, String> initModelCommonMenusMap = new HashMap<>(); // first resolve value from the origin theme Element originThemeElement = UtilXml.firstChildElement(themeElement, "extends"); @@ -121,6 +123,9 @@ public class ModelTheme implements Seria if (originTheme.modelCommonScreensMap != null) { initModelCommonScreensMap = UtilMisc.makeMapWritable(originTheme.modelCommonScreensMap); } + if (originTheme.modelCommonMenusMap != null) { + initModelCommonMenusMap = UtilMisc.makeMapWritable(originTheme.modelCommonMenusMap); + } } //second collect value from XML and surcharge @@ -167,6 +172,23 @@ public class ModelTheme implements Seria } } break; + case "common-menus": + for (Element menuPurpose : UtilXml.childElementList(childElement)) { + String defaultLocation = menuPurpose.getAttribute("default-location"); + for (Element menu : UtilXml.childElementList(menuPurpose)) { + String name = menu.getAttribute("name"); + String location = menu.getAttribute("location"); + if (UtilValidate.isEmpty(location)) { + location = defaultLocation; + } + if (UtilValidate.isEmpty(location)) { + Debug.logWarning("We can resolve the menu location " + name + " in the theme " + this.name + " so no added it", module); + continue; + } + initModelCommonMenusMap.put(name, location); + } + } + break; } } @@ -186,6 +208,7 @@ public class ModelTheme implements Seria this.themePropertiesMap = Collections.unmodifiableMap(initThemePropertiesMap); this.modelTemplateMap = Collections.unmodifiableMap(initModelTemplateMap); this.modelCommonScreensMap = Collections.unmodifiableMap(initModelCommonScreensMap); + this.modelCommonMenusMap = Collections.unmodifiableMap(initModelCommonMenusMap); } public String getName() { @@ -370,6 +393,7 @@ public class ModelTheme implements Seria public Map<String,String> getModelCommonScreens() { return modelCommonScreensMap; } + public Map<String,String> getModelCommonMenus() { return modelCommonMenusMap; } /** * the ModelTemplate class, manage the complexity of macro library definition and the rendering technology Modified: ofbiz/ofbiz-framework/trunk/themes/bluelight/template/AppBarOpen.ftl URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/bluelight/template/AppBarOpen.ftl?rev=1844068&r1=1844067&r2=1844068&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/themes/bluelight/template/AppBarOpen.ftl (original) +++ ofbiz/ofbiz-framework/trunk/themes/bluelight/template/AppBarOpen.ftl Wed Oct 17 07:33:12 2018 @@ -23,7 +23,7 @@ under the License. <#assign displayApps = Static["org.apache.ofbiz.webapp.control.LoginWorker"].getAppBarWebInfos(security, userLogin, ofbizServerName, "main")> <#assign displaySecondaryApps = Static["org.apache.ofbiz.webapp.control.LoginWorker"].getAppBarWebInfos(security, userLogin, ofbizServerName, "secondary")> -<#assign appModelMenu = Static["org.apache.ofbiz.widget.model.MenuFactory"].getMenuFromLocation(applicationMenuLocation,applicationMenuName)> +<#assign appModelMenu = Static["org.apache.ofbiz.widget.model.MenuFactory"].getMenuFromLocation(applicationMenuLocation,applicationMenuName,visualTheme)> <#if appModelMenu.getModelMenuItemByName(headerItem)??> <#if headerItem!="main"> <#assign show_last_menu = true> Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/widget/Theme.xml URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/widget/Theme.xml?rev=1844068&r1=1844067&r2=1844068&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/themes/common-theme/widget/Theme.xml (original) +++ ofbiz/ofbiz-framework/trunk/themes/common-theme/widget/Theme.xml Wed Oct 17 07:33:12 2018 @@ -166,4 +166,12 @@ under the License. <screen name="ShowHelp" location="component://common-theme/widget/HelpScreens.xml"/> </generic-screen> </common-screens> + <common-menus><!--list all common menu to each application that each theme can be surcharge or not and use the menu present on common theme--> + <root-decorator default-location="component://common-theme/widget/CommonMenus.xml"> + <menu name="CommonAppBarMenu"/> + <menu name="CommonTabBarMenu"/> + <menu name="CommonButtonBarMenu"/> + <menu name="CommonInlineBarMenu"/> + </root-decorator> + </common-menus> </theme> Modified: ofbiz/ofbiz-framework/trunk/themes/tomahawk/template/AppBarClose.ftl URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/tomahawk/template/AppBarClose.ftl?rev=1844068&r1=1844067&r2=1844068&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/themes/tomahawk/template/AppBarClose.ftl (original) +++ ofbiz/ofbiz-framework/trunk/themes/tomahawk/template/AppBarClose.ftl Wed Oct 17 07:33:12 2018 @@ -16,7 +16,7 @@ KIND, either express or implied. See th specific language governing permissions and limitations under the License. --> -<#assign appModelMenu = Static["org.apache.ofbiz.widget.model.MenuFactory"].getMenuFromLocation(applicationMenuLocation,applicationMenuName)> +<#assign appModelMenu = Static["org.apache.ofbiz.widget.model.MenuFactory"].getMenuFromLocation(applicationMenuLocation,applicationMenuName,visualTheme)> <#if person?has_content> <#assign userName = (person.firstName!) + " " + (person.middleName!) + " " + person.lastName!> <#elseif partyGroup?has_content> Modified: ofbiz/ofbiz-framework/trunk/themes/tomahawk/template/AppBarOpen.ftl URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/tomahawk/template/AppBarOpen.ftl?rev=1844068&r1=1844067&r2=1844068&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/themes/tomahawk/template/AppBarOpen.ftl (original) +++ ofbiz/ofbiz-framework/trunk/themes/tomahawk/template/AppBarOpen.ftl Wed Oct 17 07:33:12 2018 @@ -24,7 +24,7 @@ under the License. <#assign displayApps = Static["org.apache.ofbiz.webapp.control.LoginWorker"].getAppBarWebInfos(security, userLogin, ofbizServerName, "main")> <#assign displaySecondaryApps = Static["org.apache.ofbiz.webapp.control.LoginWorker"].getAppBarWebInfos(security, userLogin, ofbizServerName, "secondary")> -<#assign appModelMenu = Static["org.apache.ofbiz.widget.model.MenuFactory"].getMenuFromLocation(applicationMenuLocation,applicationMenuName)> +<#assign appModelMenu = Static["org.apache.ofbiz.widget.model.MenuFactory"].getMenuFromLocation(applicationMenuLocation,applicationMenuName,visualTheme)> <#if appModelMenu.getModelMenuItemByName(headerItem)??> <#if headerItem!="main"> <#assign show_last_menu = true> |
Free forum by Nabble | Edit this page |