svn commit: r620699 - in /ofbiz/trunk/framework/widget: dtd/ src/org/ofbiz/widget/fo/ src/org/ofbiz/widget/form/ src/org/ofbiz/widget/html/ src/org/ofbiz/widget/screen/ src/org/ofbiz/widget/text/

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

svn commit: r620699 - in /ofbiz/trunk/framework/widget: dtd/ src/org/ofbiz/widget/fo/ src/org/ofbiz/widget/form/ src/org/ofbiz/widget/html/ src/org/ofbiz/widget/screen/ src/org/ofbiz/widget/text/

adrianc
Author: adrianc
Date: Mon Feb 11 19:57:14 2008
New Revision: 620699

URL: http://svn.apache.org/viewvc?rev=620699&view=rev
Log:
New screenlet widget. For details, refer to the xsd or the Jira issue - https://issues.apache.org/jira/browse/OFBIZ-1626.

Modified:
    ofbiz/trunk/framework/widget/dtd/widget-screen.xsd
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenStringRenderer.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/text/TextScreenRenderer.java

Modified: ofbiz/trunk/framework/widget/dtd/widget-screen.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-screen.xsd?rev=620699&r1=620698&r2=620699&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/dtd/widget-screen.xsd (original)
+++ ofbiz/trunk/framework/widget/dtd/widget-screen.xsd Mon Feb 11 19:57:14 2008
@@ -838,6 +838,53 @@
             </xs:simpleType>
         </xs:attribute>
     </xs:attributeGroup>
+    <xs:element name="screenlet" substitutionGroup="AllWidgets">
+        <xs:complexType>
+            <xs:sequence>
+                <xs:element minOccurs="0" maxOccurs="unbounded" ref="AllWidgets"/>
+            </xs:sequence>
+            <xs:attributeGroup ref="attlist.screenlet"/>
+        </xs:complexType>
+    </xs:element>
+    <xs:attributeGroup name="attlist.screenlet">
+        <xs:attribute type="xs:string" name="title">
+            <xs:annotation><xs:documentation>Title text to be placed in the screenlet title bar.</xs:documentation></xs:annotation>
+        </xs:attribute>
+        <xs:attribute type="xs:string" name="id">
+            <xs:annotation><xs:documentation>Collapsible screenlets must have a name or ID.</xs:documentation></xs:annotation>
+        </xs:attribute>
+        <xs:attribute type="xs:string" name="name">
+            <xs:annotation><xs:documentation>Collapsible screenlets must have a name or ID.</xs:documentation></xs:annotation>
+        </xs:attribute>
+        <xs:attribute name="collapsible" default="false">
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="true"/>
+                    <xs:enumeration value="false"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
+        <xs:attribute name="padded" default="true">
+            <xs:annotation><xs:documentation>When set to true, screenlet content will be padded. Defaults to true.</xs:documentation></xs:annotation>
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="true"/>
+                    <xs:enumeration value="false"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
+        <xs:attribute type="xs:string" name="navigation-menu-name">
+            <xs:annotation><xs:documentation>Name of the screenlet include-menu sub element that will be used for screenlet navigation.</xs:documentation></xs:annotation>
+        </xs:attribute>
+        <xs:attribute type="xs:string" name="navigation-form-name">
+            <xs:annotation>
+                <xs:documentation>Name of the screenlet include-form sub element that will be used for screenlet navigation. The form's pagination menu will be included in the screenlet title bar.</xs:documentation>
+            </xs:annotation>
+        </xs:attribute>
+        <xs:attribute type="xs:string" name="tab-menu-name">
+            <xs:annotation><xs:documentation>Name of the screenlet include-menu sub element that will be used for the screenlet tab bar.</xs:documentation></xs:annotation>
+        </xs:attribute>
+    </xs:attributeGroup>
 
     <!-- ================ WIDGETS - Includers ================ -->
     <xs:element name="content" substitutionGroup="AllWidgets">

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java?rev=620699&r1=620698&r2=620699&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java Mon Feb 11 19:57:14 2008
@@ -22,6 +22,7 @@
 import java.io.Writer;
 import java.util.Map;
 
+import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.widget.html.HtmlWidgetRenderer;
@@ -124,6 +125,18 @@
     }
 
     public void renderSubContentEnd(Writer writer, Map context, ModelScreenWidget.SubContent content) throws IOException {
+        // TODO: not implemented
+    }
+
+    public void renderScreenletBegin(Writer writer, Map context, boolean collapsed, ModelScreenWidget.Screenlet screenlet) throws IOException {
+        // TODO: not implemented
+    }
+
+    public void renderScreenletSubWidget(Writer writer, Map context, ModelScreenWidget subWidget, ModelScreenWidget.Screenlet screenlet) throws GeneralException {
+        // TODO: not implemented
+    }
+
+    public void renderScreenletEnd(Writer writer, Map context, ModelScreenWidget.Screenlet screenlet) throws IOException {
         // TODO: not implemented
     }
 }

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=620699&r1=620698&r2=620699&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Mon Feb 11 19:57:14 2008
@@ -676,6 +676,10 @@
         return this.addUpdateField(newFormField);
     }
 
+    public void runFormActions(Map context) {
+        ModelFormAction.runSubActions(this.actions, context);
+    }
+
     /**
      * Renders this form to a String, i.e. in a text format, as defined with the
      * FormStringRenderer implementation.
@@ -692,7 +696,7 @@
      *   use the same form definitions for many types of form UIs
      */
     public void renderFormString(Writer writer, Map context, FormStringRenderer formStringRenderer) throws IOException {
-        ModelFormAction.runSubActions(this.actions, context);
+        runFormActions(context);
         
         setWidgetBoundaryComments(context);
 

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java?rev=620699&r1=620698&r2=620699&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java Mon Feb 11 19:57:14 2008
@@ -74,6 +74,7 @@
     HttpServletRequest request;
     HttpServletResponse response;
     protected String lastFieldGroupId = "";
+    protected boolean renderPagination = true;
 
     protected HtmlFormRenderer() {}
 
@@ -82,6 +83,14 @@
         this.response = response;
     }
 
+    public boolean getRenderPagination() {
+        return this.renderPagination;
+    }
+
+    public void setRenderPagination(boolean renderPagination) {
+        this.renderPagination = renderPagination;
+    }
+
     public void appendOfbizUrl(StringBuffer buffer, String location) {
         ServletContext ctx = (ServletContext) this.request.getAttribute("servletContext");
         RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
@@ -1159,7 +1168,9 @@
         context.put("_QBESTRING_", queryString);
 
         renderBeginningBoundaryComment(buffer, "Form Widget", modelForm);
-        this.renderNextPrev(buffer, context, modelForm);
+        if (this.renderPagination) {
+            this.renderNextPrev(buffer, context, modelForm);
+        }
         buffer.append(" <table cellspacing=\"0\" class=\"");
         if(UtilValidate.isNotEmpty(modelForm.getDefaultTableStyle())) {
             buffer.append(modelForm.getDefaultTableStyle());
@@ -1174,7 +1185,9 @@
         buffer.append(" </table>");
 
         appendWhitespace(buffer);
-        this.renderNextPrev(buffer, context, modelForm);
+        if (this.renderPagination) {
+            this.renderNextPrev(buffer, context, modelForm);
+        }
         renderEndingBoundaryComment(buffer, "Form Widget", modelForm);
     }
 
@@ -1973,7 +1986,7 @@
         // if this is all there seems to be (if listSize < 0, then size is unknown)
         if (actualPageSize >= listSize && listSize >= 0) return;
 
-        // needed ofr the "Page" and "rows" labels
+        // needed for the "Page" and "rows" labels
         Map uiLabelMap = (Map) context.get("uiLabelMap");
         String pageLabel = "";
         String rowsLabel = "";

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java?rev=620699&r1=620698&r2=620699&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java Mon Feb 11 19:57:14 2008
@@ -20,6 +20,8 @@
 
 import java.io.IOException;
 import java.io.Writer;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Locale;
 import java.util.Map;
 
@@ -31,13 +33,18 @@
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilFormatOut;
+import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.webapp.control.RequestHandler;
 import org.ofbiz.webapp.taglib.ContentUrlTag;
+import org.ofbiz.widget.form.FormStringRenderer;
+import org.ofbiz.widget.form.ModelForm;
 import org.ofbiz.widget.html.HtmlWidgetRenderer;
+import org.ofbiz.widget.menu.MenuStringRenderer;
+import org.ofbiz.widget.menu.ModelMenu;
 import org.ofbiz.widget.WidgetContentWorker;
 import org.ofbiz.widget.WidgetDataResourceWorker;
 import org.ofbiz.widget.screen.ModelScreenWidget;
@@ -84,6 +91,270 @@
     public void renderContainerEnd(Writer writer, Map context, ModelScreenWidget.Container container) throws IOException {
         writer.write("</div>");
         appendWhitespace(writer);
+    }
+
+    public void renderScreenletBegin(Writer writer, Map context, boolean collapsed, ModelScreenWidget.Screenlet screenlet) throws IOException {
+        HttpServletRequest request = (HttpServletRequest) context.get("request");
+        HttpServletResponse response = (HttpServletResponse) context.get("response");
+        ModelScreenWidget.Menu tabMenu = screenlet.getTabMenu();
+        if (tabMenu != null) {
+            tabMenu.renderWidgetString(writer, context, this);
+        }
+        writer.write("<div class=\"screenlet\"");
+        String id = screenlet.getId(context);
+        if (UtilValidate.isNotEmpty(id)) {
+            writer.write(" id=\"");
+            writer.write(id);
+            writer.write("\"");
+        }
+        writer.write(">");
+        appendWhitespace(writer);
+
+        String title = screenlet.getTitle(context);
+        ModelScreenWidget.Menu navMenu = screenlet.getNavigationMenu();
+        ModelScreenWidget.Form navForm = screenlet.getNavigationForm();
+        if (UtilValidate.isNotEmpty(title) || navMenu != null || navForm != null || screenlet.collapsible()) {
+            writer.write("<div class=\"screenlet-title-bar\">");
+            appendWhitespace(writer);
+            writer.write("<ul>");
+            appendWhitespace(writer);
+            if (UtilValidate.isNotEmpty(title)) {
+                writer.write("<li class=\"head3\">");
+                writer.write(title);
+                writer.write("</li>");
+                appendWhitespace(writer);
+            }
+            if (screenlet.collapsible()) {
+                String toolTip = null;
+                Map uiLabelMap = (Map) context.get("uiLabelMap");
+                Map requestParameters = new HashMap((Map)context.get("requestParameters"));
+                writer.write("<li class=\"");
+                if (collapsed) {
+                    requestParameters.put(screenlet.getPreferenceKey(context) + "_collapsed", "false");
+                    String queryString = UtilHttp.urlEncodeArgs(requestParameters);
+                    writer.write("collapsed\"><a href=\"");
+                    writer.write(request.getRequestURI() + "?" + queryString);
+                    if (uiLabelMap != null) {
+                        toolTip = (String) uiLabelMap.get("CommonExpand");
+                    }
+                } else {
+                    requestParameters.put(screenlet.getPreferenceKey(context) + "_collapsed", "true");
+                    String queryString = UtilHttp.urlEncodeArgs(requestParameters);
+                    writer.write("expanded\"><a href=\"");
+                    writer.write(request.getRequestURI() + "?" + queryString);
+                    if (uiLabelMap != null) {
+                        toolTip = (String) uiLabelMap.get("CommonCollapse");
+                    }
+                }
+                writer.write("\"");
+                if (UtilValidate.isNotEmpty(toolTip)) {
+                    writer.write(" title=\"" + toolTip + "\"");
+                }
+                writer.write(">&nbsp</a></li>");
+                appendWhitespace(writer);
+            }
+            if (!collapsed) {
+                if (navMenu != null) {
+                    MenuStringRenderer savedRenderer = (MenuStringRenderer) context.get("menuStringRenderer");
+                    MenuStringRenderer renderer = new ScreenletMenuRenderer(request, response);
+                    context.put("menuStringRenderer", renderer);
+                    navMenu.renderWidgetString(writer, context, this);
+                    context.put("menuStringRenderer", savedRenderer);
+                } else if (navForm != null) {
+                    renderScreenletPaginateMenu(writer, context, navForm);
+                }
+            }
+            writer.write("</ul>");
+            appendWhitespace(writer);
+            writer.write("<br class=\"clear\" />");
+            appendWhitespace(writer);
+            writer.write("</div>");
+            appendWhitespace(writer);
+            if (screenlet.padded()) {
+                writer.write("<div class=\"screenlet-body\">");
+                appendWhitespace(writer);
+            }
+        }
+    }
+    
+    protected void renderScreenletPaginateMenu(Writer writer, Map context, ModelScreenWidget.Form form) throws IOException {
+        HttpServletResponse response = (HttpServletResponse) context.get("response");
+        HttpServletRequest request = (HttpServletRequest) context.get("request");
+        ModelForm modelForm = form.getModelForm(context);
+        modelForm.runFormActions(context);
+        modelForm.preparePager(context);
+        String targetService = modelForm.getPaginateTarget(context);
+        if (targetService == null) {
+            targetService = "${targetService}";
+        }
+
+        // get the parametrized pagination index and size fields
+        String viewIndexParam = modelForm.getPaginateIndexField(context);
+        String viewSizeParam = modelForm.getPaginateSizeField(context);
+
+        int viewIndex = modelForm.getViewIndex(context);
+        int viewSize = modelForm.getViewSize(context);
+        int listSize = modelForm.getListSize(context);
+
+        int lowIndex = modelForm.getLowIndex(context);
+        int highIndex = modelForm.getHighIndex(context);
+        int actualPageSize = modelForm.getActualPageSize(context);
+
+        // if this is all there seems to be (if listSize < 0, then size is unknown)
+        if (actualPageSize >= listSize && listSize >= 0) return;
+
+        // needed for the "Page" and "rows" labels
+        Map uiLabelMap = (Map) context.get("uiLabelMap");
+        String pageLabel = "";
+        String rowsLabel = "";
+        String ofLabel = "";
+        if (uiLabelMap == null) {
+            Debug.logWarning("Could not find uiLabelMap in context", module);
+        } else {
+            pageLabel = (String) uiLabelMap.get("CommonPage");
+            rowsLabel = (String) uiLabelMap.get("CommonRows");
+            ofLabel = (String) uiLabelMap.get("CommonOf");
+            ofLabel = ofLabel.toLowerCase();
+        }
+
+        // for legacy support, the viewSizeParam is VIEW_SIZE and viewIndexParam is VIEW_INDEX when the fields are "viewSize" and "viewIndex"
+        if (viewIndexParam.equals("viewIndex")) viewIndexParam = "VIEW_INDEX";
+        if (viewSizeParam.equals("viewSize")) viewSizeParam = "VIEW_SIZE";
+
+        ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
+        RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
+
+        Map inputFields = (Map) context.get("requestParameters");
+        // strip out any multi form fields if the form is of type multi
+        if (modelForm.getType().equals("multi")) {
+            inputFields = UtilHttp.removeMultiFormParameters(inputFields);
+        }
+        String queryString = UtilHttp.urlEncodeArgs(inputFields);
+        // strip legacy viewIndex/viewSize params from the query string
+        queryString = UtilHttp.stripViewParamsFromQueryString(queryString);
+        // strip parametrized index/size params from the query string
+        HashSet paramNames = new HashSet();
+        paramNames.add(viewIndexParam);
+        paramNames.add(viewSizeParam);
+        queryString = UtilHttp.stripNamedParamsFromQueryString(queryString, paramNames);
+
+        String anchor = "";
+        String paginateAnchor = modelForm.getPaginateTargetAnchor();
+        if (paginateAnchor != null) anchor = "#" + paginateAnchor;
+
+        // preparing the link text, so that later in the code we can reuse this and just add the viewIndex
+        String prepLinkText = "";
+        prepLinkText = targetService;
+        if (prepLinkText.indexOf("?") < 0) {
+            prepLinkText += "?";
+        } else if (!prepLinkText.endsWith("?")) {
+            prepLinkText += "&amp;";
+        }
+        if (!UtilValidate.isEmpty(queryString) && !queryString.equals("null")) {
+            prepLinkText += queryString + "&amp;";
+        }
+        prepLinkText += viewSizeParam + "=" + viewSize + "&amp;" + viewIndexParam + "=";
+
+        String linkText;
+
+        appendWhitespace(writer);
+        // The current screenlet title bar navigation syling requires rendering
+        // these links in reverse order
+        // Last button
+        writer.write("<li class=\"" + modelForm.getPaginateLastStyle());
+        if (highIndex < listSize) {
+            writer.write("\"><a href=\"");
+            int page = (listSize / viewSize) - 1;
+            linkText = prepLinkText + page + anchor;
+            // - make the link
+            writer.write(rh.makeLink(request, response, linkText));
+            writer.write("\">" + modelForm.getPaginateLastLabel(context) + "</a>");
+        } else {
+            // disabled button
+            writer.write(" disabled\">" + modelForm.getPaginateLastLabel(context));
+        }
+        writer.write("</li>");
+        appendWhitespace(writer);
+        // Next button
+        writer.write("<li class=\"" + modelForm.getPaginateNextStyle());
+        if (highIndex < listSize) {
+            writer.write("\"><a href=\"");
+            linkText = prepLinkText + (viewIndex + 1) + anchor;
+            // - make the link
+            writer.write(rh.makeLink(request, response, linkText));
+            writer.write("\">" + modelForm.getPaginateNextLabel(context) + "</a>");
+        } else {
+            // disabled button
+            writer.write(" disabled\">" + modelForm.getPaginateNextLabel(context));
+        }
+        writer.write("</li>");
+        appendWhitespace(writer);
+        if (listSize > 0) {
+            writer.write("<li>");
+            writer.write((lowIndex + 1) + " - " + (lowIndex + actualPageSize ) + " " + ofLabel + " " + listSize);
+            writer.write("</li>");
+            appendWhitespace(writer);
+        }
+        // Previous button
+        writer.write("<li class=\"nav-previous");
+        if (viewIndex > 0) {
+            writer.write("\"><a href=\"");
+            linkText = prepLinkText + (viewIndex - 1) + anchor;
+            // - make the link
+            writer.write(rh.makeLink(request, response, linkText));
+            writer.write("\">" + modelForm.getPaginatePreviousLabel(context) + "</a>");
+        } else {
+            // disabled button
+            writer.write(" disabled\">" + modelForm.getPaginatePreviousLabel(context));
+        }
+        writer.write("</li>");
+        appendWhitespace(writer);
+        // First button
+        writer.write("<li class=\"nav-first");
+        if (viewIndex > 0) {
+            writer.write("\"><a href=\"");
+            linkText = prepLinkText + 0 + anchor;
+            writer.write(rh.makeLink(request, response, linkText));
+            writer.write("\">" + modelForm.getPaginateFirstLabel(context) + "</a>");
+        } else {
+            writer.write(" disabled\">" + modelForm.getPaginateFirstLabel(context));
+        }
+        writer.write("</li>");
+        appendWhitespace(writer);
+    }
+    
+    public void renderScreenletSubWidget(Writer writer, Map context, ModelScreenWidget subWidget, ModelScreenWidget.Screenlet screenlet) throws GeneralException {
+        if (subWidget.equals(screenlet.getNavigationForm())) {
+            HttpServletRequest request = (HttpServletRequest) context.get("request");
+            HttpServletResponse response = (HttpServletResponse) context.get("response");
+            if (request != null && response != null) {
+                FormStringRenderer savedRenderer = (FormStringRenderer) context.get("formStringRenderer");
+                HtmlFormRenderer renderer = new HtmlFormRenderer(request, response);
+                renderer.setRenderPagination(false);
+                context.put("formStringRenderer", renderer);
+                subWidget.renderWidgetString(writer, context, this);
+                context.put("formStringRenderer", savedRenderer);
+            }
+        } else {
+            subWidget.renderWidgetString(writer, context, this);
+        }
+    }
+
+    public void renderScreenletEnd(Writer writer, Map context, ModelScreenWidget.Screenlet screenlet) throws IOException {
+        if (screenlet.padded()) {
+            writer.write("</div>");
+            appendWhitespace(writer);
+        }
+        writer.write("</div>");
+        appendWhitespace(writer);
+    }
+
+    public static class ScreenletMenuRenderer extends HtmlMenuRenderer {
+        public ScreenletMenuRenderer(HttpServletRequest request, HttpServletResponse response) {
+            super(request, response);
+        }
+        public void renderMenuOpen(StringBuffer buffer, Map context, ModelMenu modelMenu) {}
+        public void renderMenuClose(StringBuffer buffer, Map context, ModelMenu modelMenu) {}
     }
 
     public void renderLabel(Writer writer, Map context, ModelScreenWidget.Label label) throws IOException {

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java?rev=620699&r1=620698&r2=620699&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java Mon Feb 11 19:57:14 2008
@@ -77,8 +77,8 @@
 
     public abstract String rawString();
     
-    public static List readSubWidgets(ModelScreen modelScreen, List subElementList) {
-        List subWidgets = new LinkedList();
+    public static List<ModelScreenWidget> readSubWidgets(ModelScreen modelScreen, List subElementList) {
+        List<ModelScreenWidget> subWidgets = new LinkedList<ModelScreenWidget>();
         Iterator subElementIter = subElementList.iterator();
         while (subElementIter.hasNext()) {
             Element subElement = (Element) subElementIter.next();
@@ -87,6 +87,8 @@
                 subWidgets.add(new Section(modelScreen, subElement));
             } else if ("container".equals(subElement.getNodeName())) {
                 subWidgets.add(new Container(modelScreen, subElement));
+            } else if ("screenlet".equals(subElement.getNodeName())) {
+                subWidgets.add(new Screenlet(modelScreen, subElement));
             } else if ("include-screen".equals(subElement.getNodeName())) {
                 subWidgets.add(new IncludeScreen(modelScreen, subElement));
             } else if ("decorator-screen".equals(subElement.getNodeName())) {
@@ -299,6 +301,127 @@
         }
     }
 
+    @SuppressWarnings("serial")
+    public static class Screenlet extends ModelScreenWidget {
+        protected FlexibleStringExpander idExdr;
+        protected FlexibleStringExpander titleExdr;
+        protected Menu navigationMenu = null;
+        protected Menu tabMenu = null;
+        protected Form navigationForm = null;
+        protected boolean collapsible = false;
+        protected boolean padded = true;
+        protected List<ModelScreenWidget> subWidgets;
+        
+        public Screenlet(ModelScreen modelScreen, Element screenletElement) {
+            super(modelScreen, screenletElement);
+            this.idExdr = new FlexibleStringExpander(screenletElement.getAttribute("id"));
+            this.collapsible = "true".equals(screenletElement.getAttribute("collapsible"));
+            this.padded = !"false".equals(screenletElement.getAttribute("padded"));
+            if (this.collapsible && UtilValidate.isEmpty(this.name) && idExdr.isEmpty()) {
+                throw new IllegalArgumentException("Collapsible screenlets must have a name or id [" + this.modelScreen.getName() + "]");
+            }
+            this.titleExdr = new FlexibleStringExpander(screenletElement.getAttribute("title"));
+            List subElementList = UtilXml.childElementList(screenletElement);
+            this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList);
+            String navMenuName = screenletElement.getAttribute("navigation-menu-name");
+            if (UtilValidate.isNotEmpty(navMenuName)) {
+                for (ModelWidget subWidget : this.subWidgets) {
+                    if (navMenuName.equals(subWidget.getName()) && subWidget instanceof Menu) {
+                        this.navigationMenu = (Menu) subWidget;
+                        subWidgets.remove(subWidget);
+                        break;
+                    }
+                }
+            }
+            String tabMenuName = screenletElement.getAttribute("tab-menu-name");
+            if (UtilValidate.isNotEmpty(tabMenuName)) {
+                for (ModelWidget subWidget : this.subWidgets) {
+                    if (tabMenuName.equals(subWidget.getName()) && subWidget instanceof Menu) {
+                        this.tabMenu = (Menu) subWidget;
+                        subWidgets.remove(subWidget);
+                        break;
+                    }
+                }
+            }
+            String formName = screenletElement.getAttribute("navigation-form-name");
+            if (UtilValidate.isNotEmpty(formName) && this.navigationMenu == null) {
+                for (ModelWidget subWidget : this.subWidgets) {
+                    if (formName.equals(subWidget.getName()) && subWidget instanceof Form) {
+                        this.navigationForm = (Form) subWidget;
+                        // Let's give this a try, it can be removed later if it
+                        // proves to cause problems
+                        this.padded = false;
+                        break;
+                    }
+                }
+            }
+        }
+
+        public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
+            boolean collapsed = false;
+            if (this.collapsible) {
+                String preferenceKey = getPreferenceKey(context) + "_collapsed";
+                Map requestParameters = (Map)context.get("requestParameters");
+                if (requestParameters != null) {
+                    collapsed = "true".equals(requestParameters.get(preferenceKey));
+                }
+            }
+            try {
+                screenStringRenderer.renderScreenletBegin(writer, context, collapsed, this);
+                if (!collapsed) {
+                    for (ModelScreenWidget subWidget : this.subWidgets) {
+                        screenStringRenderer.renderScreenletSubWidget(writer, context, subWidget, this);
+                    }
+                }
+                screenStringRenderer.renderScreenletEnd(writer, context, this);
+            } catch (IOException e) {
+                String errMsg = "Error rendering screenlet in screen named [" + this.modelScreen.getName() + "]: ";
+                Debug.logError(e, errMsg, module);
+                throw new RuntimeException(errMsg + e);
+            }
+        }
+        
+        public boolean collapsible() {
+            return this.collapsible;
+        }
+
+        public boolean padded() {
+            return this.padded;
+        }
+
+        public String getPreferenceKey(Map context) {
+            String name = this.modelScreen.getName();
+            if (UtilValidate.isEmpty(name)) {
+                name = this.idExdr.expandString(context);
+            }
+            return name + "_" + this.name;
+        }
+
+        public String getId(Map<String, Object> context) {
+            return this.idExdr.expandString(context);
+        }
+        
+        public String getTitle(Map<String, Object> context) {
+            return this.titleExdr.expandString(context);
+        }
+        
+        public Menu getNavigationMenu() {
+            return this.navigationMenu;
+        }
+
+        public Form getNavigationForm() {
+            return this.navigationForm;
+        }
+
+        public Menu getTabMenu() {
+            return this.tabMenu;
+        }
+
+        public String rawString() {
+            return "<screenlet id=\"" + this.idExdr.getOriginal() + "\" title=\"" + this.titleExdr.getOriginal() + "\">";
+        }
+    }
+
     public static class IncludeScreen extends ModelScreenWidget {
         protected FlexibleStringExpander nameExdr;
         protected FlexibleStringExpander locationExdr;
@@ -585,6 +708,7 @@
         protected FlexibleStringExpander nameExdr;
         protected FlexibleStringExpander locationExdr;
         protected FlexibleStringExpander shareScopeExdr;
+        protected ModelForm modelForm = null;
         
         public Form(ModelScreen modelScreen, Element formElement) {
             super(modelScreen, formElement);
@@ -625,7 +749,7 @@
             } catch (IOException e) {
                 String errMsg = "Error rendering included form named [" + name + "] at location [" + this.getLocation(context) + "]: " + e.toString();
                 Debug.logError(e, errMsg, module);
-                throw new RuntimeException(errMsg);
+                throw new RuntimeException(errMsg + e);
             }
 
             if (protectScope) {
@@ -998,20 +1122,27 @@
         }
 
         public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) {
-            getModelMenu(context);
             // try finding the menuStringRenderer by name in the context in case one was prepared and put there
             MenuStringRenderer menuStringRenderer = (MenuStringRenderer) context.get("menuStringRenderer");
             // if there was no menuStringRenderer put in place, now try finding the request/response in the context and creating a new one
             if (menuStringRenderer == null) {
-                HttpServletRequest request = (HttpServletRequest) context.get("request");
-                HttpServletResponse response = (HttpServletResponse) context.get("response");
-                if (request != null && response != null) {
-                    menuStringRenderer = new HtmlMenuRenderer(request, response);
+                // try finding the menuStringRenderer by name in the context in
+                // case one was prepared and put there
+                menuStringRenderer = (MenuStringRenderer) context.get("menuStringRenderer");
+                // if there was no menuStringRenderer put in place, now try
+                // finding the request/response in the context and creating a
+                // new one
+                if (menuStringRenderer == null) {
+                    HttpServletRequest request = (HttpServletRequest) context.get("request");
+                    HttpServletResponse response = (HttpServletResponse) context.get("response");
+                    if (request != null && response != null) {
+                        menuStringRenderer = new HtmlMenuRenderer(request, response);
+                    }
+                }
+                // still null, throw an error
+                if (menuStringRenderer == null) {
+                    throw new IllegalArgumentException("Could not find a menuStringRenderer in the context, and could not find HTTP request/response objects need to create one.");
                 }
-            }
-            // still null, throw an error
-            if (menuStringRenderer == null) {
-                throw new IllegalArgumentException("Could not find a menuStringRenderer in the context, and could not find HTTP request/response objects need to create one.");
             }
             
             StringBuffer renderBuffer = new StringBuffer();

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenStringRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenStringRenderer.java?rev=620699&r1=620698&r2=620699&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenStringRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenStringRenderer.java Mon Feb 11 19:57:14 2008
@@ -22,6 +22,7 @@
 import java.io.Writer;
 import java.util.Map;
 
+import org.ofbiz.base.util.GeneralException;
 
 /**
  * Widget Library - Screen String Renderer interface
@@ -43,5 +44,8 @@
     public void renderImage(Writer writer, Map context, ModelScreenWidget.Image image) throws IOException;
 
     public void renderContentFrame(Writer writer, Map context, ModelScreenWidget.Content content) throws IOException;
+    public void renderScreenletBegin(Writer writer, Map context, boolean collapsed, ModelScreenWidget.Screenlet screenlet) throws IOException;
+    public void renderScreenletSubWidget(Writer writer, Map context, ModelScreenWidget subWidget, ModelScreenWidget.Screenlet screenlet) throws GeneralException;
+    public void renderScreenletEnd(Writer writer, Map context, ModelScreenWidget.Screenlet screenlet) throws IOException;
 }
 

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/text/TextScreenRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/text/TextScreenRenderer.java?rev=620699&r1=620698&r2=620699&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/text/TextScreenRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/text/TextScreenRenderer.java Mon Feb 11 19:57:14 2008
@@ -116,4 +116,13 @@
         // appending line ends for now, but this could be replaced with a simple space or something
         writer.write("\r\n");
     }
+    public void renderScreenletBegin(Writer writer, Map context, boolean collapsed, ModelScreenWidget.Screenlet screenlet) throws IOException {
+        // TODO: not implemented
+    }
+    public void renderScreenletSubWidget(Writer writer, Map context, ModelScreenWidget subWidget, ModelScreenWidget.Screenlet screenlet) throws GeneralException {
+        // TODO: not implemented
+    }
+    public void renderScreenletEnd(Writer writer, Map context, ModelScreenWidget.Screenlet screenlet) throws IOException {
+        // TODO: not implemented
+    }
 }