📄 modelmenuitem.java
字号:
/* * $Id: ModelMenuItem.java 5470 2005-08-07 16:07:37Z jonesde $ * * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.widget.menu;import java.io.IOException;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import javax.xml.parsers.ParserConfigurationException;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilFormatOut;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.UtilXml;import org.ofbiz.base.util.string.FlexibleStringExpander;import org.ofbiz.entityext.permission.EntityPermissionChecker;import org.w3c.dom.Element;import org.xml.sax.SAXException;/** * Widget Library - Form model class * * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a> * @version $Rev: 5470 $ * @since 2.2 */public class ModelMenuItem { public static final String module = ModelMenuItem.class.getName(); protected ModelMenu modelMenu; protected Map dataMap = new HashMap(); protected String name; protected String entityName; protected FlexibleStringExpander title; protected FlexibleStringExpander tooltip; protected String titleStyle; protected String disabledTitleStyle; protected String widgetStyle; protected String tooltipStyle; protected String selectedStyle; protected Integer position = null; protected FlexibleStringExpander associatedContentId; protected String cellWidth; protected Boolean hideIfSelected; protected Boolean hasPermission; protected String disableIfEmpty; protected ModelMenu subMenu; protected Link link; protected List menuItemList = new LinkedList(); protected Map menuItemMap = new HashMap(); public static String DEFAULT_TARGET_TYPE = "intra-app"; protected EntityPermissionChecker permissionChecker; protected ModelMenuItem parentMenuItem; protected ModelMenuCondition condition; protected boolean disabled = false; protected List actions; protected String align; protected String alignStyle; // ===== CONSTRUCTORS ===== /** Default Constructor */ public ModelMenuItem(ModelMenu modelMenu) { this.modelMenu = modelMenu; } /** XML Constructor */ public ModelMenuItem(Element fieldElement, ModelMenuItem modelMenuItem) { parentMenuItem = modelMenuItem; loadMenuItem(fieldElement, modelMenuItem.getModelMenu()); } public ModelMenuItem(Element fieldElement, ModelMenu modelMenu) { loadMenuItem(fieldElement, modelMenu); } public void loadMenuItem(Element fieldElement, ModelMenu modelMenu) { this.modelMenu = modelMenu; this.name = fieldElement.getAttribute("name"); this.entityName = fieldElement.getAttribute("entity-name"); this.setTitle(fieldElement.getAttribute("title")); this.setTooltip(fieldElement.getAttribute("tooltip")); this.titleStyle = fieldElement.getAttribute("title-style"); this.disabledTitleStyle = fieldElement.getAttribute("disabled-title-style"); this.widgetStyle = fieldElement.getAttribute("widget-style"); this.tooltipStyle = fieldElement.getAttribute("tooltip-style"); this.selectedStyle = fieldElement.getAttribute("selected-style"); this.setHideIfSelected(fieldElement.getAttribute("hide-if-selected")); this.disableIfEmpty = fieldElement.getAttribute("disable-if-empty"); this.align = fieldElement.getAttribute("align"); this.alignStyle = fieldElement.getAttribute("align-style"); String positionStr = fieldElement.getAttribute("position"); try { if (positionStr != null && positionStr.length() > 0) { position = Integer.valueOf(positionStr); } } catch (Exception e) { Debug.logError( e, "Could not convert position attribute of the field element to an integer: [" + positionStr + "], using the default of the menu renderer", module); } this.setAssociatedContentId( fieldElement.getAttribute("associated-content-id")); this.cellWidth = fieldElement.getAttribute("cell-width"); dataMap.put("name", this.name); //dataMap.put("associatedContentId", this.associatedContentId); Element subMenuElement = UtilXml.firstChildElement(fieldElement, "sub-menu"); if (subMenuElement != null) { String subMenuLocation = subMenuElement.getAttribute("location"); String subMenuName = subMenuElement.getAttribute("name"); try { this.subMenu = MenuFactory.getMenuFromLocation(subMenuLocation, subMenuName, modelMenu.getDelegator(), modelMenu.getDispacher()); } catch (IOException e) { String errMsg = "Error getting subMenu in menu named [" + this.modelMenu.getName() + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new RuntimeException(errMsg); } catch (SAXException e2) { String errMsg = "Error getting subMenu in menu named [" + this.modelMenu.getName() + "]: " + e2.toString(); Debug.logError(e2, errMsg, module); throw new RuntimeException(errMsg); } catch (ParserConfigurationException e3) { String errMsg = "Error getting subMenu in menu named [" + this.modelMenu.getName() + "]: " + e3.toString(); Debug.logError(e3, errMsg, module); throw new RuntimeException(errMsg); } } Element linkElement = UtilXml.firstChildElement(fieldElement, "link"); //if (Debug.infoOn()) Debug.logInfo("in ModelMenuItem, linkElement:" + linkElement, module); if (linkElement != null) { link = new Link(linkElement, this); } // Element permissionElement = UtilXml.firstChildElement(fieldElement, "if-entity-permission");// if (permissionElement != null)// permissionChecker = new EntityPermissionChecker(permissionElement); // read in add item defs, add/override one by one using the menuItemList and menuItemMap List itemElements = UtilXml.childElementList(fieldElement, "menu-item"); Iterator itemElementIter = itemElements.iterator(); while (itemElementIter.hasNext()) { Element itemElement = (Element) itemElementIter.next(); ModelMenuItem modelMenuItem = new ModelMenuItem(itemElement, this); modelMenuItem = this.addUpdateMenuItem(modelMenuItem); //Debug.logInfo("Added item " + modelMenuItem.getName() + " from def, mapName=" + modelMenuItem.getMapName(), module); } // read condition under the "condition" element Element conditionElement = UtilXml.firstChildElement(fieldElement, "condition"); if (conditionElement != null) { this.condition = new ModelMenuCondition(this, conditionElement); } // read all actions under the "actions" element Element actionsElement = UtilXml.firstChildElement(conditionElement, "actions"); if (actionsElement != null) { this.actions = ModelMenuAction.readSubActions(this, actionsElement); } } public ModelMenuItem addUpdateMenuItem(ModelMenuItem modelMenuItem) { // not a conditional item, see if a named item exists in Map ModelMenuItem existingMenuItem = (ModelMenuItem) this.menuItemMap.get(modelMenuItem.getName()); if (existingMenuItem != null) { // does exist, update the item by doing a merge/override existingMenuItem.mergeOverrideModelMenuItem(modelMenuItem); return existingMenuItem; } else { // does not exist, add to List and Map this.menuItemList.add(modelMenuItem); this.menuItemMap.put(modelMenuItem.getName(), modelMenuItem); return modelMenuItem; } } public void setHideIfSelected(String val) { if (UtilValidate.isNotEmpty(val)) if (val.equalsIgnoreCase("true")) hideIfSelected = new Boolean(true); else hideIfSelected = new Boolean(false); else hideIfSelected = null; return; } public void setDisabled(boolean val) { this.disabled = val; } public boolean getDisabled() { return this.disabled; } public void mergeOverrideModelMenuItem(ModelMenuItem overrideModelMenuItem) { if (overrideModelMenuItem == null) return;/* // incorporate updates for values that are not empty in the overrideMenuItem if (UtilValidate.isNotEmpty(overrideMenuItem.name)) this.name = overrideMenuItem.name; if (UtilValidate.isNotEmpty(overrideMenuItem.entityName)) this.entityName = overrideMenuItem.entityName; if (overrideMenuItem.entryAcsr != null && !overrideMenuItem.entryAcsr.isEmpty()) this.entryAcsr = overrideMenuItem.entryAcsr; if (UtilValidate.isNotEmpty(overrideMenuItem.attributeName)) this.attributeName = overrideMenuItem.attributeName; if (overrideMenuItem.title != null && !overrideMenuItem.title.isEmpty()) this.title = overrideMenuItem.title; if (overrideMenuItem.tooltip != null && !overrideMenuItem.tooltip.isEmpty()) this.tooltip = overrideMenuItem.tooltip; if (UtilValidate.isNotEmpty(overrideMenuItem.titleStyle)) this.titleStyle = overrideMenuItem.titleStyle; if (UtilValidate.isNotEmpty(overrideMenuItem.selectedStyle)) this.selectedStyle = overrideMenuItem.selectedStyle; if (UtilValidate.isNotEmpty(overrideMenuItem.widgetStyle)) this.widgetStyle = overrideMenuItem.widgetStyle; if (overrideMenuItem.position != null) this.position = overrideMenuItem.position;*/ return; } public void renderMenuItemString(StringBuffer buffer, Map context, MenuStringRenderer menuStringRenderer) { boolean passed = true; if (this.condition != null) { if (!this.condition.eval(context)) { passed = false; } } //Debug.logInfo("in ModelMenu, name:" + this.getName(), module); if (passed) { ModelMenuAction.runSubActions(this.actions, context); menuStringRenderer.renderMenuItem(buffer, context, this); } } /** * @return */ public ModelMenu getModelMenu() { return modelMenu; } /** * @return */ public String getEntityName() { if (UtilValidate.isNotEmpty(this.entityName)) { return this.entityName; } else if (parentMenuItem != null) { return parentMenuItem.getEntityName(); } else { return this.modelMenu.getDefaultEntityName(); } } /** * @return */ public String getAlign() { if (UtilValidate.isNotEmpty(this.align)) { return this.align; } else if (parentMenuItem != null) { return parentMenuItem.getAlign(); } else { return this.modelMenu.getDefaultAlign(); } } /** * @return */ public String getName() { return name; } /** * @return */ public int getPosition() { if (this.position == null) { return 1; } else { return position.intValue(); } } /** * @return */ public String getTitle(Map context) { return title.expandString(context); } /** * @return */ public String getTitleStyle() { if (UtilValidate.isNotEmpty(this.titleStyle)) { return this.titleStyle; } else if (parentMenuItem != null) { return parentMenuItem.getTitleStyle(); } else { return this.modelMenu.getDefaultTitleStyle(); } } /** * @return */ public String getDisabledTitleStyle() { if (UtilValidate.isNotEmpty(this.disabledTitleStyle)) { return this.disabledTitleStyle; } else if (parentMenuItem != null) { return parentMenuItem.getDisabledTitleStyle(); } else { return this.modelMenu.getDefaultDisabledTitleStyle(); } } public void setDisabledTitleStyle(String style) { this.disabledTitleStyle = style; } /** * @return */ public String getSelectedStyle() { if (UtilValidate.isNotEmpty(this.selectedStyle)) { return this.selectedStyle; } else if (parentMenuItem != null) { return parentMenuItem.getSelectedStyle(); } else { return this.modelMenu.getDefaultSelectedStyle(); } } /** * @return */ public String getTooltip(Map context) { if (tooltip != null && !tooltip.isEmpty()) { return tooltip.expandString(context); } else { return ""; } } /** * @return */ public String getWidgetStyle() { if (UtilValidate.isNotEmpty(this.widgetStyle)) { return this.widgetStyle; } else if (parentMenuItem != null) { return parentMenuItem.getWidgetStyle(); } else { return this.modelMenu.getDefaultWidgetStyle(); } } /** * @return */ public String getAlignStyle() { if (UtilValidate.isNotEmpty(this.alignStyle)) { return this.alignStyle; } else if (parentMenuItem != null) { return parentMenuItem.getAlignStyle(); } else { return this.modelMenu.getDefaultAlignStyle(); } } /** * @return */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -