svn commit: r652702 - in /ofbiz/trunk/framework/widget/src/org/ofbiz/widget: html/HtmlMenuRenderer.java menu/ModelMenu.java menu/ModelMenuAction.java menu/ModelMenuItem.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r652702 - in /ofbiz/trunk/framework/widget/src/org/ofbiz/widget: html/HtmlMenuRenderer.java menu/ModelMenu.java menu/ModelMenuAction.java menu/ModelMenuItem.java

adrianc
Author: adrianc
Date: Thu May  1 15:47:54 2008
New Revision: 652702

URL: http://svn.apache.org/viewvc?rev=652702&view=rev
Log:
Fixed the menu widget - the "extends" feature didn't work.

Modified:
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlMenuRenderer.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/html/HtmlMenuRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlMenuRenderer.java?rev=652702&r1=652701&r2=652702&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlMenuRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlMenuRenderer.java Thu May  1 15:47:54 2008
@@ -27,6 +27,7 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
+import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.StringUtil;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.GenericDelegator;
@@ -143,14 +144,14 @@
     public void renderMenuItem(StringBuffer buffer, Map context, ModelMenuItem menuItem) {
         
         //Debug.logInfo("in renderMenuItem, menuItem:" + menuItem.getName() + " context:" + context ,"");
-        boolean hideThisItem = isHideIfSelected(menuItem);
+        boolean hideThisItem = isHideIfSelected(menuItem, context);
         //if (Debug.infoOn()) Debug.logInfo("in HtmlMenuRendererImage, hideThisItem:" + hideThisItem,"");
         if (hideThisItem)
             return;
 
         String style = null;
         
-        if (menuItem.isSelected()) {
+        if (menuItem.isSelected(context)) {
             style = menuItem.getSelectedStyle();
             if (UtilValidate.isEmpty(style)) {
                 style = "selected";
@@ -308,9 +309,9 @@
         return this.userLoginIdAtPermGrant;
     }
 
-    public boolean isHideIfSelected( ModelMenuItem menuItem) {
+    public boolean isHideIfSelected(ModelMenuItem menuItem, Map context) {
         ModelMenu menu = menuItem.getModelMenu();
-        String currentMenuItemName = menu.getCurrentMenuItemName();
+        String currentMenuItemName = menu.getSelectedMenuItemContextFieldName(context);
         String currentItemName = menuItem.getName();
         Boolean hideIfSelected = menuItem.getHideIfSelected();
             //Debug.logInfo("in HtmlMenuRenderer, currentMenuItemName:" + currentMenuItemName + " currentItemName:" + currentItemName + " hideIfSelected:" + hideIfSelected,"");

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=652702&r1=652701&r2=652702&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 Thu May  1 15:47:54 2008
@@ -60,7 +60,6 @@
     protected String defaultTooltipStyle;
     protected String defaultSelectedStyle;
     protected String defaultMenuItemName;
-    protected String currentMenuItemName;
     protected String defaultPermissionOperation;
     protected String defaultPermissionEntityAction;
     protected FlexibleStringExpander defaultAssociatedContentId;
@@ -86,15 +85,15 @@
      * 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 menuItemList = new LinkedList();
+    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 menuItemMap = new HashMap();
+    protected Map<String, ModelMenuItem> menuItemMap = new HashMap<String, ModelMenuItem>();
     
-    protected List actions;
+    protected List<ModelMenuAction> actions;
 
     
    // ===== CONSTRUCTORS =====
@@ -151,8 +150,8 @@
                 this.defaultWidgetStyle = parent.defaultWidgetStyle;
                 this.defaultTooltipStyle = parent.defaultTooltipStyle;
                 this.defaultMenuItemName = parent.defaultMenuItemName;
-                this.menuItemList = parent.menuItemList;
-                this.menuItemMap = parent.menuItemMap;
+                this.menuItemList.addAll(parent.menuItemList);
+                this.menuItemMap.putAll(parent.menuItemMap);
                 this.defaultPermissionOperation = parent.defaultPermissionOperation;
                 this.defaultPermissionEntityAction = parent.defaultPermissionEntityAction;
                 this.defaultAssociatedContentId = parent.defaultAssociatedContentId;
@@ -166,6 +165,13 @@
                 this.defaultAlign = parent.defaultAlign;
                 this.defaultAlignStyle = parent.defaultAlignStyle;
                 this.fillStyle = parent.fillStyle;
+                this.selectedMenuItemContextFieldName = parent.selectedMenuItemContextFieldName;
+                this.menuContainerStyleExdr = parent.menuContainerStyleExdr;
+                if (parent.actions != null) {
+                    this.actions = new LinkedList<ModelMenuAction>();
+                    this.actions.addAll(parent.actions);
+                }
+                this.actions = parent.actions;
             }
         }
 
@@ -231,7 +237,11 @@
         // read all actions under the "actions" element
         Element actionsElement = UtilXml.firstChildElement(menuElement, "actions");
         if (actionsElement != null) {
-            this.actions = ModelMenuAction.readSubActions(this, actionsElement);
+            if (this.actions == null) {
+                this.actions = ModelMenuAction.readSubActions(this, actionsElement);
+            } else {
+                this.actions.addAll(ModelMenuAction.readSubActions(this, actionsElement));
+            }
         }
 
         // read in add item defs, add/override one by one using the menuItemList and menuItemMap
@@ -328,9 +338,6 @@
         // render formatting wrapper open
         menuStringRenderer.renderFormatSimpleWrapperOpen(buffer, context, this);
 
-        // Set the selected menu item from the context
-        this.setCurrentMenuItemName(context);
-
             //Debug.logInfo("in ModelMenu, menuItemList:" + menuItemList, module);
         // render each menuItem row, except hidden & ignored rows
         //menuStringRenderer.renderFormatSimpleWrapperRows(buffer, context, this);
@@ -434,16 +441,6 @@
         return (String)this.selectedMenuItemContextFieldName.get(context);
     }
 
-    /**
-     * @return
-     */
-    public String getCurrentMenuItemName() {
-        if (UtilValidate.isNotEmpty(this.currentMenuItemName))
-            return this.currentMenuItemName;
-        else
-            return this.defaultMenuItemName;
-    }
-
     public String getCurrentMenuName(Map context) {
         return this.name;
     }
@@ -535,20 +532,6 @@
     /**
      * @param string
      */
-    public void setCurrentMenuItemName(String string) {
-        this.currentMenuItemName = string;
-    }
-
-    /**
-     * @param context Map containing the menu context
-     */
-    public void setCurrentMenuItemName(Map context) {
-        this.currentMenuItemName = this.getSelectedMenuItemContextFieldName(context);
-    }
-
-    /**
-     * @param string
-     */
     public void setMenuLocation(String menuLocation) {
         this.menuLocation = menuLocation;
     }
@@ -734,18 +717,6 @@
         return this.defaultHideIfSelected;
     }
 
-    public ModelMenuItem getCurrentMenuItem() {
-        
-        ModelMenuItem currentMenuItem = (ModelMenuItem)menuItemMap.get(this.currentMenuItemName);
-        if (currentMenuItem == null) {
-            currentMenuItem = (ModelMenuItem)menuItemMap.get(this.defaultMenuItemName);
-            if (currentMenuItem == null && menuItemList.size() > 0) {
-                currentMenuItem = (ModelMenuItem)menuItemList.get(0);
-            }
-        }
-        return currentMenuItem;
-    }
-
     public List getMenuItemList() {
         return menuItemList;
     }
@@ -764,7 +735,6 @@
             + "\n defaultTooltipStyle=" + this.defaultTooltipStyle
             + "\n defaultSelectedStyle=" + this.defaultSelectedStyle
             + "\n defaultMenuItemName=" + this.defaultMenuItemName
-            + "\n currentMenuItemName=" + this.currentMenuItemName
             + "\n\n");
     
         Iterator iter = menuItemList.iterator();

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=652702&r1=652701&r2=652702&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 Thu May  1 15:47:54 2008
@@ -73,8 +73,8 @@
         return readSubActions(modelMenuItem.getModelMenu(), parentElement);
     }
     
-    public static List readSubActions(ModelMenu modelMenu, Element parentElement) {
-        List actions = new LinkedList();
+    public static List<ModelMenuAction> readSubActions(ModelMenu modelMenu, Element parentElement) {
+        List<ModelMenuAction> actions = new LinkedList<ModelMenuAction>();
         
         List actionElementList = UtilXml.childElementList(parentElement);
         Iterator actionElementIter = actionElementList.iterator();

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=652702&r1=652701&r2=652702&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 Thu May  1 15:47:54 2008
@@ -569,14 +569,8 @@
        return this.link;
     }
     
-    /** @deprecated use isSelected() */
     public boolean isSelected(Map context) {
-        String currentMenuItemName = modelMenu.getSelectedMenuItemContextFieldName(context);
-        return currentMenuItemName != null && currentMenuItemName.equals(this.name);
-    }
-
-    public boolean isSelected() {
-        return modelMenu.getCurrentMenuItemName() != null && modelMenu.getCurrentMenuItemName().equals(this.name);
+        return this.name.equals(modelMenu.getSelectedMenuItemContextFieldName(context));
     }
 
     public static class Link {