Search in sources :

Example 1 with MenuStringRenderer

use of org.apache.ofbiz.widget.renderer.MenuStringRenderer in project ofbiz-framework by apache.

the class MacroScreenViewHandler method loadRenderers.

private ScreenStringRenderer loadRenderers(HttpServletRequest request, HttpServletResponse response, Map<String, Object> context, Writer writer) throws TemplateException, IOException {
    VisualTheme visualTheme = UtilHttp.getVisualTheme(request);
    ModelTheme modelTheme = visualTheme.getModelTheme();
    String screenMacroLibraryPath = modelTheme.getScreenRendererLocation(getName());
    String formMacroLibraryPath = modelTheme.getFormRendererLocation(getName());
    String treeMacroLibraryPath = modelTheme.getTreeRendererLocation(getName());
    String menuMacroLibraryPath = modelTheme.getMenuRendererLocation(getName());
    ScreenStringRenderer screenStringRenderer = new MacroScreenRenderer(modelTheme.getType(getName()), screenMacroLibraryPath);
    if (UtilValidate.isNotEmpty(formMacroLibraryPath)) {
        FormStringRenderer formStringRenderer = new MacroFormRenderer(formMacroLibraryPath, request, response);
        context.put("formStringRenderer", formStringRenderer);
    }
    if (UtilValidate.isNotEmpty(treeMacroLibraryPath)) {
        TreeStringRenderer treeStringRenderer = new MacroTreeRenderer(treeMacroLibraryPath, writer);
        context.put("treeStringRenderer", treeStringRenderer);
    }
    if (UtilValidate.isNotEmpty(menuMacroLibraryPath)) {
        MenuStringRenderer menuStringRenderer = new MacroMenuRenderer(menuMacroLibraryPath, request, response);
        context.put("menuStringRenderer", menuStringRenderer);
    }
    return screenStringRenderer;
}
Also used : TreeStringRenderer(org.apache.ofbiz.widget.renderer.TreeStringRenderer) FormStringRenderer(org.apache.ofbiz.widget.renderer.FormStringRenderer) ModelTheme(org.apache.ofbiz.widget.model.ModelTheme) VisualTheme(org.apache.ofbiz.widget.renderer.VisualTheme) ScreenStringRenderer(org.apache.ofbiz.widget.renderer.ScreenStringRenderer) MenuStringRenderer(org.apache.ofbiz.widget.renderer.MenuStringRenderer)

Example 2 with MenuStringRenderer

use of org.apache.ofbiz.widget.renderer.MenuStringRenderer in project ofbiz-framework by apache.

the class MacroScreenRenderer method renderScreenletBegin.

public void renderScreenletBegin(Appendable writer, Map<String, Object> context, boolean collapsed, ModelScreenWidget.Screenlet screenlet) throws IOException {
    HttpServletRequest request = (HttpServletRequest) context.get("request");
    HttpServletResponse response = (HttpServletResponse) context.get("response");
    VisualTheme visualTheme = UtilHttp.getVisualTheme(request);
    ModelTheme modelTheme = visualTheme.getModelTheme();
    boolean javaScriptEnabled = UtilHttp.isJavaScriptEnabled(request);
    ModelScreenWidget.Menu tabMenu = screenlet.getTabMenu();
    if (tabMenu != null) {
        tabMenu.renderWidgetString(writer, context, this);
    }
    String title = screenlet.getTitle(context);
    boolean collapsible = screenlet.collapsible();
    ModelScreenWidget.Menu navMenu = screenlet.getNavigationMenu();
    ModelScreenWidget.Form navForm = screenlet.getNavigationForm();
    String expandToolTip = "";
    String collapseToolTip = "";
    String fullUrlString = "";
    String menuString = "";
    boolean showMore = false;
    if (UtilValidate.isNotEmpty(title) || navMenu != null || navForm != null || collapsible) {
        showMore = true;
        if (collapsible) {
            this.getNextElementId();
            Map<String, Object> uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap"));
            Map<String, Object> paramMap = UtilGenerics.checkMap(context.get("requestParameters"));
            Map<String, Object> requestParameters = new HashMap<>(paramMap);
            if (uiLabelMap != null) {
                expandToolTip = (String) uiLabelMap.get("CommonExpand");
                collapseToolTip = (String) uiLabelMap.get("CommonCollapse");
            }
            if (!javaScriptEnabled) {
                requestParameters.put(screenlet.getPreferenceKey(context) + "_collapsed", collapsed ? "false" : "true");
                String queryString = UtilHttp.urlEncodeArgs(requestParameters);
                fullUrlString = request.getRequestURI() + "?" + queryString;
            }
        }
        StringWriter sb = new StringWriter();
        if (navMenu != null) {
            MenuStringRenderer savedRenderer = (MenuStringRenderer) context.get("menuStringRenderer");
            MenuStringRenderer renderer;
            try {
                renderer = new MacroMenuRenderer(modelTheme.getMenuRendererLocation("screen"), request, response);
                context.put("menuStringRenderer", renderer);
                navMenu.renderWidgetString(sb, context, this);
                context.put("menuStringRenderer", savedRenderer);
            } catch (TemplateException e) {
                Debug.logError(e, module);
            }
        } else if (navForm != null) {
            renderScreenletPaginateMenu(sb, context, navForm);
        }
        menuString = sb.toString();
    }
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("title", title);
    parameters.put("collapsible", collapsible);
    parameters.put("saveCollapsed", screenlet.saveCollapsed());
    if (UtilValidate.isNotEmpty(screenlet.getId(context))) {
        parameters.put("id", screenlet.getId(context));
        parameters.put("collapsibleAreaId", screenlet.getId(context) + "_col");
    } else {
        parameters.put("id", "screenlet_" + screenLetsIdCounter);
        parameters.put("collapsibleAreaId", "screenlet_" + screenLetsIdCounter + "_col");
        screenLetsIdCounter++;
    }
    parameters.put("expandToolTip", expandToolTip);
    parameters.put("collapseToolTip", collapseToolTip);
    parameters.put("fullUrlString", fullUrlString);
    parameters.put("padded", screenlet.padded());
    parameters.put("menuString", menuString);
    parameters.put("showMore", showMore);
    parameters.put("collapsed", collapsed);
    parameters.put("javaScriptEnabled", javaScriptEnabled);
    executeMacro(writer, "renderScreenletBegin", parameters);
}
Also used : HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) TemplateException(freemarker.template.TemplateException) HttpServletResponse(javax.servlet.http.HttpServletResponse) ModelTheme(org.apache.ofbiz.widget.model.ModelTheme) MenuStringRenderer(org.apache.ofbiz.widget.renderer.MenuStringRenderer) HttpServletRequest(javax.servlet.http.HttpServletRequest) StringWriter(java.io.StringWriter) VisualTheme(org.apache.ofbiz.widget.renderer.VisualTheme) ModelScreenWidget(org.apache.ofbiz.widget.model.ModelScreenWidget)

Aggregations

ModelTheme (org.apache.ofbiz.widget.model.ModelTheme)2 MenuStringRenderer (org.apache.ofbiz.widget.renderer.MenuStringRenderer)2 VisualTheme (org.apache.ofbiz.widget.renderer.VisualTheme)2 TemplateException (freemarker.template.TemplateException)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 WeakHashMap (java.util.WeakHashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ModelScreenWidget (org.apache.ofbiz.widget.model.ModelScreenWidget)1 FormStringRenderer (org.apache.ofbiz.widget.renderer.FormStringRenderer)1 ScreenStringRenderer (org.apache.ofbiz.widget.renderer.ScreenStringRenderer)1 TreeStringRenderer (org.apache.ofbiz.widget.renderer.TreeStringRenderer)1