Author: adrianc
Date: Sun Nov 2 12:03:09 2014 New Revision: 1636102 URL: http://svn.apache.org/r1636102 Log: Delegate most menu widget actions to ModelWidgetAction. Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidgetVisitor.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java?rev=1636102&r1=1636101&r2=1636102&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java Sun Nov 2 12:03:09 2014 @@ -19,6 +19,7 @@ package org.ofbiz.widget; import org.ofbiz.widget.form.ModelFormAction; +import org.ofbiz.widget.menu.ModelMenuAction; /** * A <code>ModelWidgetAction</code> visitor. @@ -52,4 +53,6 @@ public interface ModelActionVisitor { void visit(ModelFormAction.EntityAnd entityAnd); void visit(ModelFormAction.EntityCondition entityCondition); + + void visit(ModelMenuAction.SetField setField); } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java?rev=1636102&r1=1636101&r2=1636102&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java Sun Nov 2 12:03:09 2014 @@ -44,6 +44,17 @@ public abstract class ModelWidget implem /** * Derived classes must call this constructor. + * @param name The widget name + */ + protected ModelWidget(String name) { + this.name = name; + this.systemId = "anonymous"; + this.startColumn = 0; + this.startLine = 0; + } + + /** + * Derived classes must call this constructor. * @param widgetElement The XML Element for the widget */ protected ModelWidget(Element widgetElement) { Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidgetVisitor.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidgetVisitor.java?rev=1636102&r1=1636101&r2=1636102&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidgetVisitor.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidgetVisitor.java Sun Nov 2 12:03:09 2014 @@ -20,6 +20,7 @@ package org.ofbiz.widget; import org.ofbiz.widget.form.ModelForm; import org.ofbiz.widget.menu.ModelMenu; +import org.ofbiz.widget.menu.ModelMenuItem; import org.ofbiz.widget.screen.HtmlWidget; import org.ofbiz.widget.screen.IterateSectionWidget; import org.ofbiz.widget.screen.ModelScreen; @@ -45,6 +46,8 @@ public interface ModelWidgetVisitor { void visit(ModelMenu modelMenu); + void visit(ModelMenuItem modelMenuItem); + void visit(ModelScreen modelScreen); void visit(ModelScreenWidget.ColumnContainer columnContainer); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java?rev=1636102&r1=1636101&r2=1636102&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java Sun Nov 2 12:03:09 2014 @@ -67,6 +67,8 @@ import org.ofbiz.widget.form.ModelFormFi import org.ofbiz.widget.form.ModelFormField.TextFindField; import org.ofbiz.widget.form.ModelFormField.TextareaField; import org.ofbiz.widget.menu.ModelMenu; +import org.ofbiz.widget.menu.ModelMenuAction; +import org.ofbiz.widget.menu.ModelMenuItem; import org.ofbiz.widget.screen.HtmlWidget; import org.ofbiz.widget.screen.HtmlWidget.HtmlTemplate; import org.ofbiz.widget.screen.HtmlWidget.HtmlTemplateDecorator; @@ -279,6 +281,14 @@ public final class ArtifactInfoGatherer } @Override + public void visit(ModelMenuAction.SetField setField) { + } + + @Override + public void visit(ModelMenuItem modelMenuItem) { + } + + @Override public void visit(ModelScreen modelScreen) { String screenLocation = modelScreen.getSourceLocation().concat("#").concat(modelScreen.getName()); infoContext.addScreenLocation(screenLocation); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java?rev=1636102&r1=1636101&r2=1636102&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java Sun Nov 2 12:03:09 2014 @@ -30,6 +30,7 @@ import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.widget.ModelWidget; +import org.ofbiz.widget.ModelWidgetAction; import org.ofbiz.widget.ModelWidgetVisitor; import org.w3c.dom.Element; @@ -41,35 +42,27 @@ public class ModelMenu extends ModelWidg public static final String module = ModelMenu.class.getName(); - protected String menuLocation; - protected String type; - protected String target; - protected String id; - protected FlexibleStringExpander title; - protected String tooltip; + protected List<ModelWidgetAction> actions; + protected String defaultAlign; + protected String defaultAlignStyle; + protected FlexibleStringExpander defaultAssociatedContentId; + protected String defaultCellWidth; + protected String defaultDisabledTitleStyle; protected String defaultEntityName; - protected String defaultTitleStyle; - protected String defaultWidgetStyle; - protected String defaultTooltipStyle; - protected String defaultSelectedStyle; + protected Boolean defaultHideIfSelected; protected String defaultMenuItemName; - protected String defaultPermissionOperation; protected String defaultPermissionEntityAction; - protected FlexibleStringExpander defaultAssociatedContentId; + protected String defaultPermissionOperation; protected String defaultPermissionStatusId; protected String defaultPrivilegeEnumId; - protected String orientation = "horizontal"; - protected String menuWidth; - protected String defaultCellWidth; - protected Boolean defaultHideIfSelected; - protected String defaultDisabledTitleStyle; - protected FlexibleMapAccessor<String> selectedMenuItemContextFieldName; - protected FlexibleStringExpander menuContainerStyleExdr; - protected String defaultAlign; - protected String defaultAlignStyle; - protected String fillStyle; + protected String defaultSelectedStyle; + protected String defaultTitleStyle; + protected String defaultTooltipStyle; + protected String defaultWidgetStyle; protected FlexibleStringExpander extraIndex; - + protected String fillStyle; + protected String id; + protected FlexibleStringExpander menuContainerStyleExdr; /** This List will contain one copy of each item for each item name in the order * they were encountered in the service, entity, or menu definition; item definitions * with constraints will also be in this list but may appear multiple times for the same @@ -80,14 +73,19 @@ public class ModelMenu extends ModelWidg * list clean and implement the override features for item definitions. */ protected List<ModelMenuItem> menuItemList = new ArrayList<ModelMenuItem>(); - /** This Map is keyed with the item name and has a ModelMenuItem for the value; items * with conditions will not be put in this Map so item definition overrides for items * with conditions is not possible. */ protected Map<String, ModelMenuItem> menuItemMap = new HashMap<String, ModelMenuItem>(); - - protected List<ModelMenuAction> actions; + protected String menuLocation; + protected String menuWidth; + protected String orientation = "horizontal"; + protected FlexibleMapAccessor<String> selectedMenuItemContextFieldName; + protected String target; + protected FlexibleStringExpander title; + protected String tooltip; + protected String type; // ===== CONSTRUCTORS ===== @@ -156,7 +154,7 @@ public class ModelMenu extends ModelWidg this.selectedMenuItemContextFieldName = parent.selectedMenuItemContextFieldName; this.menuContainerStyleExdr = parent.menuContainerStyleExdr; if (parent.actions != null) { - this.actions = new ArrayList<ModelMenuAction>(); + this.actions = new ArrayList<ModelWidgetAction>(); this.actions.addAll(parent.actions); } } @@ -229,7 +227,7 @@ public class ModelMenu extends ModelWidg this.actions = ModelMenuAction.readSubActions(this, actionsElement); } else { this.actions.addAll(ModelMenuAction.readSubActions(this, actionsElement)); - ArrayList<ModelMenuAction> actionsList = (ArrayList<ModelMenuAction>)this.actions; + ArrayList<ModelWidgetAction> actionsList = (ArrayList<ModelWidgetAction>)this.actions; actionsList.trimToSize(); } } @@ -282,7 +280,7 @@ public class ModelMenu extends ModelWidg * use the same menu definitions for many types of menu UIs */ public void renderMenuString(Appendable writer, Map<String, Object> context, MenuStringRenderer menuStringRenderer) throws IOException { - ModelMenuAction.runSubActions(this.actions, context); + ModelWidgetAction.runSubActions(this.actions, context); if ("simple".equals(this.type)) { this.renderSimpleMenuString(writer, context, menuStringRenderer); } else { Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java?rev=1636102&r1=1636101&r2=1636102&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java Sun Nov 2 12:03:09 2014 @@ -18,8 +18,8 @@ *******************************************************************************/ package org.ofbiz.widget.menu; -import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -33,88 +33,37 @@ import javax.servlet.http.HttpSession; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.ObjectType; -import org.ofbiz.base.util.ScriptUtil; -import org.ofbiz.base.util.UtilFormatOut; import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.collections.FlexibleMapAccessor; -import org.ofbiz.base.util.collections.ResourceBundleMapWrapper; import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.entity.finder.ByAndFinder; -import org.ofbiz.entity.finder.ByConditionFinder; -import org.ofbiz.entity.finder.PrimaryKeyFinder; -import org.ofbiz.entity.util.EntityUtilProperties; -import org.ofbiz.service.GenericServiceException; -import org.ofbiz.service.ModelService; -import org.ofbiz.widget.WidgetWorker; +import org.ofbiz.widget.ModelActionVisitor; +import org.ofbiz.widget.ModelWidgetAction; import org.w3c.dom.Element; - /** * Widget Library - Screen model class */ public abstract class ModelMenuAction { - public static final String module = ModelMenuAction.class.getName(); - - protected ModelMenu modelMenu; - protected ModelMenuItem modelMenuItem; - - public ModelMenuAction(ModelMenu modelMenu, Element actionElement) { - this.modelMenu = modelMenu; - if (Debug.verboseOn()) Debug.logVerbose("Reading Screen action with name: " + actionElement.getNodeName(), module); - } - - public ModelMenuAction(ModelMenuItem modelMenuItem, Element actionElement) { - this.modelMenuItem = modelMenuItem; - this.modelMenu = modelMenuItem.getModelMenu(); - if (Debug.verboseOn()) Debug.logVerbose("Reading Screen action with name: " + actionElement.getNodeName(), module); - } - - public abstract void runAction(Map<String, Object> context); - public static List<ModelMenuAction> readSubActions(ModelMenuItem modelMenuItem, Element parentElement) { - return readSubActions(modelMenuItem.getModelMenu(), parentElement); - } + public static final String module = ModelMenuAction.class.getName(); - public static List<ModelMenuAction> readSubActions(ModelMenu modelMenu, Element parentElement) { + public static List<ModelWidgetAction> readSubActions(ModelMenu modelMenu, Element parentElement) { List<? extends Element> actionElementList = UtilXml.childElementList(parentElement); - ArrayList<ModelMenuAction> actions = new ArrayList<ModelMenuAction>(actionElementList.size()); + List<ModelWidgetAction> actions = new ArrayList<ModelWidgetAction>(actionElementList.size()); for (Element actionElement : actionElementList) { if ("set".equals(actionElement.getNodeName())) { actions.add(new SetField(modelMenu, actionElement)); - } else if ("property-map".equals(actionElement.getNodeName())) { - actions.add(new PropertyMap(modelMenu, actionElement)); - } else if ("property-to-field".equals(actionElement.getNodeName())) { - actions.add(new PropertyToField(modelMenu, actionElement)); - } else if ("script".equals(actionElement.getNodeName())) { - actions.add(new Script(modelMenu, actionElement)); - } else if ("service".equals(actionElement.getNodeName())) { - actions.add(new Service(modelMenu, actionElement)); - } else if ("entity-one".equals(actionElement.getNodeName())) { - actions.add(new EntityOne(modelMenu, actionElement)); - } else if ("entity-and".equals(actionElement.getNodeName())) { - actions.add(new EntityAnd(modelMenu, actionElement)); - } else if ("entity-condition".equals(actionElement.getNodeName())) { - actions.add(new EntityCondition(modelMenu, actionElement)); } else { - throw new IllegalArgumentException("Action element not supported with name: " + actionElement.getNodeName()); + actions.add(ModelWidgetAction.toModelWidgetAction(modelMenu, actionElement)); } } - actions.trimToSize(); - return actions; + return Collections.unmodifiableList(actions); } - public static void runSubActions(List<ModelMenuAction> actions, Map<String, Object> context) { - if (actions == null) return; - for (ModelMenuAction action : actions) { - if (Debug.verboseOn()) Debug.logVerbose("Running screen action " + action.getClass().getName(), module); - action.runAction(context); - } - } - - public static class SetField extends ModelMenuAction { + @SuppressWarnings("serial") + public static class SetField extends ModelWidgetAction { protected FlexibleMapAccessor<Object> field; protected FlexibleMapAccessor<Object> fromField; protected FlexibleStringExpander valueExdr; @@ -236,257 +185,10 @@ public abstract class ModelMenuAction { this.field.put(page, newValue); } } - } - - public static class PropertyMap extends ModelMenuAction { - protected FlexibleStringExpander resourceExdr; - protected FlexibleMapAccessor<ResourceBundleMapWrapper> mapNameAcsr; - protected FlexibleStringExpander globalExdr; - - public PropertyMap(ModelMenu modelMenu, Element setElement) { - super (modelMenu, setElement); - this.resourceExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("resource")); - this.mapNameAcsr = FlexibleMapAccessor.getInstance(setElement.getAttribute("map-name")); - this.globalExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("global")); - } - - @Override - public void runAction(Map<String, Object> context) { - String globalStr = this.globalExdr.expandString(context); - // default to false - boolean global = "true".equals(globalStr); - - Locale locale = (Locale) context.get("locale"); - String resource = this.resourceExdr.expandString(context, locale); - - ResourceBundleMapWrapper existingPropMap = this.mapNameAcsr.get(context); - if (existingPropMap == null) { - this.mapNameAcsr.put(context, UtilProperties.getResourceBundleMap(resource, locale, context)); - } else { - try { - existingPropMap.addBottomResourceBundle(resource); - } catch (IllegalArgumentException e) { - // log the error, but don't let it kill everything just for a typo or bad char in an l10n file - Debug.logError(e, "Error adding resource bundle [" + resource + "]: " + e.toString(), module); - } - } - - if (global) { - Map<String, Object> globalCtx = UtilGenerics.checkMap(context.get("globalContext")); - if (globalCtx != null) { - ResourceBundleMapWrapper globalExistingPropMap = this.mapNameAcsr.get(globalCtx); - if (globalExistingPropMap == null) { - this.mapNameAcsr.put(globalCtx, UtilProperties.getResourceBundleMap(resource, locale, context)); - } else { - // is it the same object? if not add it in here too... - if (existingPropMap != globalExistingPropMap) { - try { - globalExistingPropMap.addBottomResourceBundle(resource); - } catch (IllegalArgumentException e) { - // log the error, but don't let it kill everything just for a typo or bad char in an l10n file - Debug.logError(e, "Error adding resource bundle [" + resource + "]: " + e.toString(), module); - } - } - } - } - } - } - } - - public static class PropertyToField extends ModelMenuAction { - - protected FlexibleStringExpander resourceExdr; - protected FlexibleStringExpander propertyExdr; - protected FlexibleMapAccessor<Object> fieldAcsr; - protected FlexibleStringExpander defaultExdr; - protected boolean noLocale; - protected FlexibleMapAccessor<List<? extends Object>> argListAcsr; - protected FlexibleStringExpander globalExdr; - - public PropertyToField(ModelMenu modelMenu, Element setElement) { - super (modelMenu, setElement); - this.resourceExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("resource")); - this.propertyExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("property")); - this.fieldAcsr = FlexibleMapAccessor.getInstance(setElement.getAttribute("field")); - this.defaultExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("default")); - noLocale = "true".equals(setElement.getAttribute("no-locale")); - this.argListAcsr = FlexibleMapAccessor.getInstance(setElement.getAttribute("arg-list-name")); - this.globalExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("global")); - } - - @Override - public void runAction(Map<String, Object> context) { - // default to false - - Locale locale = (Locale) context.get("locale"); - String resource = this.resourceExdr.expandString(context, locale); - String property = this.propertyExdr.expandString(context, locale); - - String value = null; - if (noLocale) { - value = EntityUtilProperties.getPropertyValue(resource, property, WidgetWorker.getDelegator(context)); - } else { - value = EntityUtilProperties.getMessage(resource, property, locale, WidgetWorker.getDelegator(context)); - } - if (UtilValidate.isEmpty(value)) { - value = this.defaultExdr.expandString(context); - } - - // note that expanding the value string here will handle defaultValue and the string from - // the properties file; if we decide later that we don't want the string from the properties - // file to be expanded we should just expand the defaultValue at the beginning of this method. - value = FlexibleStringExpander.expandString(value, context); - - if (!argListAcsr.isEmpty()) { - List<? extends Object> argList = argListAcsr.get(context); - if (UtilValidate.isNotEmpty(argList)) { - value = MessageFormat.format(value, argList.toArray()); - } - } - - fieldAcsr.put(context, value); - } - } - - public static class Script extends ModelMenuAction { - protected String location; - protected String method; - - public Script(ModelMenu modelMenu, Element scriptElement) { - super (modelMenu, scriptElement); - String scriptLocation = scriptElement.getAttribute("location"); - this.location = WidgetWorker.getScriptLocation(scriptLocation); - this.method = WidgetWorker.getScriptMethodName(scriptLocation); - } @Override - public void runAction(Map<String, Object> context) { - ScriptUtil.executeScript(this.location, this.method, context); - } - } - - public static class Service extends ModelMenuAction { - protected FlexibleStringExpander serviceNameExdr; - protected FlexibleMapAccessor<Map<String, Object>> resultMapNameAcsr; - protected FlexibleStringExpander autoFieldMapExdr; - protected Map<FlexibleMapAccessor<Object>, FlexibleMapAccessor<Object>> fieldMap; - - public Service(ModelMenu modelMenu, Element serviceElement) { - super (modelMenu, serviceElement); - this.serviceNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("service-name")); - this.resultMapNameAcsr = FlexibleMapAccessor.getInstance(serviceElement.getAttribute("result-map-name")); - this.autoFieldMapExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("auto-field-map")); - - List<? extends Element> fieldMapElementList = UtilXml.childElementList(serviceElement, "field-map"); - if (fieldMapElementList.size() > 0) { - this.fieldMap = new HashMap<FlexibleMapAccessor<Object>, FlexibleMapAccessor<Object>>(); - for (Element fieldMapElement: fieldMapElementList) { - // set the env-name for each field-name, noting that if no field-name is specified it defaults to the env-name - this.fieldMap.put( - FlexibleMapAccessor.getInstance(UtilFormatOut.checkEmpty(fieldMapElement.getAttribute("field-name"), fieldMapElement.getAttribute("env-name"))), - FlexibleMapAccessor.getInstance(fieldMapElement.getAttribute("env-name"))); - } - } - } - - @Override - public void runAction(Map<String, Object> context) { - String serviceNameExpanded = this.serviceNameExdr.expandString(context); - if (UtilValidate.isEmpty(serviceNameExpanded)) { - throw new IllegalArgumentException("Service name was empty, expanded from: " + this.serviceNameExdr.getOriginal()); - } - - String autoFieldMapString = this.autoFieldMapExdr.expandString(context); - boolean autoFieldMapBool = !"false".equals(autoFieldMapString); - - try { - Map<String, Object> serviceContext = null; - if (autoFieldMapBool) { - serviceContext = WidgetWorker.getDispatcher(context).getDispatchContext().makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); - } else { - serviceContext = new HashMap<String, Object>(); - } - - if (this.fieldMap != null) { - for (Map.Entry<FlexibleMapAccessor<Object>, FlexibleMapAccessor<Object>> entry: this.fieldMap.entrySet()) { - FlexibleMapAccessor<Object> serviceContextFieldAcsr = entry.getKey(); - FlexibleMapAccessor<Object> contextEnvAcsr = entry.getValue(); - serviceContextFieldAcsr.put(serviceContext, contextEnvAcsr.get(context)); - } - } - - Map<String, Object> result = WidgetWorker.getDispatcher(context).runSync(serviceNameExpanded, serviceContext); - - if (!this.resultMapNameAcsr.isEmpty()) { - this.resultMapNameAcsr.put(context, result); - } else { - context.putAll(result); - } - } catch (GenericServiceException e) { - String errMsg = "Error calling service with name " + serviceNameExpanded + ": " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } - } - - public static class EntityOne extends ModelMenuAction { - protected PrimaryKeyFinder finder; - - public EntityOne(ModelMenu modelMenu, Element entityOneElement) { - super (modelMenu, entityOneElement); - finder = new PrimaryKeyFinder(entityOneElement); - } - - @Override - public void runAction(Map<String, Object> context) { - try { - finder.runFind(context, WidgetWorker.getDelegator(context)); - } catch (GeneralException e) { - String errMsg = "Error doing entity query by condition: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } - } - - public static class EntityAnd extends ModelMenuAction { - protected ByAndFinder finder; - - public EntityAnd(ModelMenu modelMenu, Element entityAndElement) { - super (modelMenu, entityAndElement); - finder = new ByAndFinder(entityAndElement); - } - - @Override - public void runAction(Map<String, Object> context) { - try { - finder.runFind(context, WidgetWorker.getDelegator(context)); - } catch (GeneralException e) { - String errMsg = "Error doing entity query by condition: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } - } - - public static class EntityCondition extends ModelMenuAction { - ByConditionFinder finder; - - public EntityCondition(ModelMenu modelMenu, Element entityConditionElement) { - super (modelMenu, entityConditionElement); - finder = new ByConditionFinder(entityConditionElement); - } - - @Override - public void runAction(Map<String, Object> context) { - try { - finder.runFind(context, WidgetWorker.getDelegator(context)); - } catch (GeneralException e) { - String errMsg = "Error doing entity query by condition: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } + public void accept(ModelActionVisitor visitor) { + visitor.visit(this); } } } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java?rev=1636102&r1=1636101&r2=1636102&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java Sun Nov 2 12:03:09 2014 @@ -37,6 +37,9 @@ import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericValue; +import org.ofbiz.widget.ModelWidget; +import org.ofbiz.widget.ModelWidgetAction; +import org.ofbiz.widget.ModelWidgetVisitor; import org.ofbiz.widget.PortalPageWorker; import org.ofbiz.widget.WidgetWorker; import org.w3c.dom.Element; @@ -45,78 +48,94 @@ import org.xml.sax.SAXException; /** * Widget Library - Form model class */ -public class ModelMenuItem { +@SuppressWarnings("serial") +public class ModelMenuItem extends ModelWidget { public static final String module = ModelMenuItem.class.getName(); - protected ModelMenu modelMenu; - - protected Map<String, Object> dataMap = new HashMap<String, Object>(); - protected String name; - protected String entityName; - protected FlexibleStringExpander title; - protected FlexibleStringExpander tooltip; - protected FlexibleStringExpander parentPortalPageId; - protected String titleStyle; - protected String disabledTitleStyle; - protected String widgetStyle; - protected String tooltipStyle; - protected String selectedStyle; - protected Integer position = null; - + protected List<ModelWidgetAction> actions; + protected String align; + protected String alignStyle; protected FlexibleStringExpander associatedContentId; protected String cellWidth; - protected Boolean hideIfSelected; - protected Boolean hasPermission; + protected ModelMenuCondition condition; + protected Map<String, Object> dataMap = new HashMap<String, Object>(); + protected boolean disabled = false; + protected String disabledTitleStyle; protected String disableIfEmpty; - protected ModelMenu subMenu; + protected String entityName; + protected Boolean hasPermission; + protected Boolean hideIfSelected; protected Link link; - + /** This List will contain one copy of each item for each item name in the order + * they were encountered in the service, entity, or menu definition; item definitions + * with constraints will also be in this list but may appear multiple times for the same + * item name. + * + * When rendering the menu the order in this list should be following and it should not be + * necessary to use the Map. The Map is used when loading the menu definition to keep the + * list clean and implement the override features for item definitions. + */ protected List<ModelMenuItem> menuItemList = new LinkedList<ModelMenuItem>(); + /** This Map is keyed with the item name and has a ModelMenuItem for the value; items + * with conditions will not be put in this Map so item definition overrides for items + * with conditions is not possible. + */ protected Map<String, ModelMenuItem> menuItemMap = new HashMap<String, ModelMenuItem>(); - + protected ModelMenu modelMenu; + protected String overrideName = null; protected ModelMenuItem parentMenuItem; - protected ModelMenuCondition condition; - protected boolean disabled = false; - protected List<ModelMenuAction> actions; - protected String align; - protected String alignStyle; + protected FlexibleStringExpander parentPortalPageId; + protected Integer position = null; + protected String selectedStyle; + protected ModelMenu subMenu; + protected FlexibleStringExpander title; + protected String titleStyle; + protected FlexibleStringExpander tooltip; + protected String tooltipStyle; + protected String widgetStyle; // ===== CONSTRUCTORS ===== - /** Default Constructor */ - public ModelMenuItem(ModelMenu modelMenu) { - this.modelMenu = modelMenu; + public ModelMenuItem(String name) { + super(name); } - /** XML Constructor */ - public ModelMenuItem(Element fieldElement, ModelMenuItem modelMenuItem) { - parentMenuItem = modelMenuItem; - loadMenuItem(fieldElement, modelMenuItem.getModelMenu()); + public ModelMenuItem(Element menuItemElement) { + super(menuItemElement); + loadMenuItem(menuItemElement); } + public ModelMenuItem(Element menuItemElement, ModelMenu modelMenu) { + super(menuItemElement); + loadMenuItem(menuItemElement, modelMenu); + } - public ModelMenuItem(Element fieldElement, ModelMenu modelMenu) { - loadMenuItem(fieldElement, modelMenu); + public ModelMenuItem(Element menuItemElement, ModelMenuItem modelMenuItem) { + super(menuItemElement); + parentMenuItem = modelMenuItem; + loadMenuItem(menuItemElement, modelMenuItem.getModelMenu()); } - public void loadMenuItem(Element fieldElement, ModelMenu modelMenu) { + private void loadMenuItem(Element menuItemElement, 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.setParentPortalPageId(fieldElement.getAttribute("parent-portal-page-value")); - 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"); + loadMenuItem(menuItemElement); + } - String positionStr = fieldElement.getAttribute("position"); + private void loadMenuItem(Element menuItemElement) { + this.entityName = menuItemElement.getAttribute("entity-name"); + this.setTitle(menuItemElement.getAttribute("title")); + this.setTooltip(menuItemElement.getAttribute("tooltip")); + this.setParentPortalPageId(menuItemElement.getAttribute("parent-portal-page-value")); + this.titleStyle = menuItemElement.getAttribute("title-style"); + this.disabledTitleStyle = menuItemElement.getAttribute("disabled-title-style"); + this.widgetStyle = menuItemElement.getAttribute("widget-style"); + this.tooltipStyle = menuItemElement.getAttribute("tooltip-style"); + this.selectedStyle = menuItemElement.getAttribute("selected-style"); + this.setHideIfSelected(menuItemElement.getAttribute("hide-if-selected")); + this.disableIfEmpty = menuItemElement.getAttribute("disable-if-empty"); + this.align = menuItemElement.getAttribute("align"); + this.alignStyle = menuItemElement.getAttribute("align-style"); + String positionStr = menuItemElement.getAttribute("position"); try { if (UtilValidate.isNotEmpty(positionStr)) { position = Integer.valueOf(positionStr); @@ -126,12 +145,12 @@ public class ModelMenuItem { positionStr + "], using the default of the menu renderer", module); } - this.setAssociatedContentId(fieldElement.getAttribute("associated-content-id")); - this.cellWidth = fieldElement.getAttribute("cell-width"); + this.setAssociatedContentId(menuItemElement.getAttribute("associated-content-id")); + this.cellWidth = menuItemElement.getAttribute("cell-width"); - dataMap.put("name", this.name); + dataMap.put("name", getName()); - Element subMenuElement = UtilXml.firstChildElement(fieldElement, "sub-menu"); + Element subMenuElement = UtilXml.firstChildElement(menuItemElement, "sub-menu"); if (subMenuElement != null) { String subMenuLocation = subMenuElement.getAttribute("location"); String subMenuName = subMenuElement.getAttribute("name"); @@ -152,26 +171,26 @@ public class ModelMenuItem { } } - Element linkElement = UtilXml.firstChildElement(fieldElement, "link"); + Element linkElement = UtilXml.firstChildElement(menuItemElement, "link"); if (linkElement != null) { link = new Link(linkElement, this); } // read in add item defs, add/override one by one using the menuItemList and menuItemMap - List<? extends Element> itemElements = UtilXml.childElementList(fieldElement, "menu-item"); + List<? extends Element> itemElements = UtilXml.childElementList(menuItemElement, "menu-item"); for (Element itemElement: itemElements) { ModelMenuItem modelMenuItem = new ModelMenuItem(itemElement, this); modelMenuItem = this.addUpdateMenuItem(modelMenuItem); } // read condition under the "condition" element - Element conditionElement = UtilXml.firstChildElement(fieldElement, "condition"); + Element conditionElement = UtilXml.firstChildElement(menuItemElement, "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); + this.actions = ModelWidgetAction.readSubActions(this, actionsElement); } } @@ -215,13 +234,21 @@ public class ModelMenuItem { return this.disabled; } + @Override + public String getName() { + if (this.overrideName != null) { + return this.overrideName; + } + return super.getName(); + } + public void mergeOverrideModelMenuItem(ModelMenuItem overrideMenuItem) { if (overrideMenuItem == 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.getName())) + this.overrideName = overrideMenuItem.getName(); if (UtilValidate.isNotEmpty(overrideMenuItem.entityName)) this.entityName = overrideMenuItem.entityName; if (UtilValidate.isNotEmpty(overrideMenuItem.parentPortalPageId)) @@ -262,15 +289,15 @@ public class ModelMenuItem { Locale locale = (Locale) context.get("locale"); //Debug.logInfo("in ModelMenu, name:" + this.getName(), module); if (passed) { - ModelMenuAction.runSubActions(this.actions, context); + ModelWidgetAction.runSubActions(this.actions, context); String parentPortalPageId = this.getParentPortalPageId(context); if (UtilValidate.isNotEmpty(parentPortalPageId)) { List<GenericValue> portalPages = PortalPageWorker.getPortalPages(parentPortalPageId, context); if (UtilValidate.isNotEmpty(portalPages)) { for (GenericValue portalPage : portalPages) { if (UtilValidate.isNotEmpty(portalPage.getString("portalPageName"))) { - ModelMenuItem localItem = new ModelMenuItem(this.getModelMenu()); - localItem.name = portalPage.getString("portalPageId"); + String itemName = portalPage.getString("portalPageId"); + ModelMenuItem localItem = new ModelMenuItem(itemName); localItem.setTitle((String) portalPage.get("portalPageName", locale)); localItem.link = new Link(this); List<WidgetWorker.Parameter> linkParams = localItem.link.getParameterList(); @@ -298,7 +325,7 @@ public class ModelMenuItem { return modelMenu; } - public List<ModelMenuAction> getActions() { + public List<ModelWidgetAction> getActions() { return actions; } @@ -322,11 +349,6 @@ public class ModelMenuItem { } } - - public String getName() { - return name; - } - public int getPosition() { if (this.position == null) { return 1; @@ -427,13 +449,6 @@ public class ModelMenuItem { } /** - * @param string - */ - public void setName(String string) { - name = string; - } - - /** * @param i */ public void setPosition(int i) { @@ -546,7 +561,7 @@ public class ModelMenuItem { } public boolean isSelected(Map<String, Object> context) { - return this.name.equals(modelMenu.getSelectedMenuItemContextFieldName(context)); + return getName().equals(modelMenu.getSelectedMenuItemContextFieldName(context)); } public static class Link { @@ -905,4 +920,9 @@ public class ModelMenuItem { } } + + @Override + public void accept(ModelWidgetVisitor visitor) { + visitor.visit(this); + } } |
Free forum by Nabble | Edit this page |