Search in sources :

Example 1 with Menu

use of com.revolsys.ui.model.Menu in project com.revolsys.open by revolsys.

the class MenuViewController method bootstrapMenu.

private void bootstrapMenu(final XmlWriter writer, final Collection<Menu> items, final int level, final JexlContext jexlContext) {
    if (items.size() > 0) {
        for (final Menu menu : items) {
            if (menu.isVisible()) {
                final List<Menu> menus = menu.getMenus();
                if (menus.isEmpty()) {
                    writer.startTag(HtmlElem.LI);
                    final String cssClass = menu.getCssClass();
                    if (cssClass != null) {
                        writer.attribute(HtmlAttr.CLASS, cssClass);
                    }
                    bootStrapMenuLink(writer, menu, jexlContext);
                    writer.endTag(HtmlElem.LI);
                } else {
                    BootstrapUtil.navbarDropdownStart(writer, menu);
                    bootstrapMenu(writer, menus, level + 1, jexlContext);
                    BootstrapUtil.navbarDropdownEnd(writer);
                }
            }
        }
    }
}
Also used : Menu(com.revolsys.ui.model.Menu)

Example 2 with Menu

use of com.revolsys.ui.model.Menu in project com.revolsys.open by revolsys.

the class MenuViewController method bootstrapNavbar.

private void bootstrapNavbar(final HttpServletRequest request, final HttpServletResponse response, final Navbar navBar) throws IOException {
    if (navBar != null) {
        try (final OutputStream out = response.getOutputStream();
            XmlWriter writer = new XmlWriter(out, false)) {
            writer.setIndent(false);
            final JexlHttpServletRequestContext jexlContext = new JexlHttpServletRequestContext(request);
            final List<Menu> menus = new ArrayList<>();
            for (final Menu menuItem : navBar.getMenus()) {
                if (menuItem.isVisible()) {
                    menus.add(menuItem);
                }
            }
            final String title = navBar.getTitle();
            if (Property.hasValue(title) || !menus.isEmpty()) {
                BootstrapUtil.navbarStart(writer, navBar, jexlContext);
                bootstrapMenu(writer, menus, 1, jexlContext);
                BootstrapUtil.navbarEnd(writer);
            }
            writer.flush();
        }
    }
}
Also used : OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Menu(com.revolsys.ui.model.Menu) XmlWriter(com.revolsys.record.io.format.xml.XmlWriter) JexlHttpServletRequestContext(com.revolsys.ui.web.config.JexlHttpServletRequestContext)

Example 3 with Menu

use of com.revolsys.ui.model.Menu in project com.revolsys.open by revolsys.

the class DisplayConfigAction method addSiteNode.

private void addSiteNode(final ElementContainer view, final SiteNode siteNode) {
    if (siteNode != null) {
        final ElementContainer nodeView = new ElementContainer();
        view.add(nodeView);
        final String path = siteNode.getPath();
        if (path == null) {
            nodeView.add(new XmlTagElement(HtmlElem.H4, "/"));
        } else {
            nodeView.add(new XmlTagElement(HtmlElem.H4, path));
        }
        final SiteNodeController controller = siteNode.getController();
        if (controller instanceof PageController) {
            final PageController pageController = (PageController) controller;
            final ElementContainer pageView = new ElementContainer(new DefinitionListLayout());
            nodeView.add(pageView);
            pageView.add("Actions");
            final ElementContainer actionsView = new ElementContainer(new UnorderedListLayout());
            pageView.add(actionsView);
            for (final Iterator actions = pageController.getActions().iterator(); actions.hasNext(); ) {
                final Action action = (Action) actions.next();
                actionsView.add(action.getClass().getName());
            }
            pageView.add("Menus");
            final ElementContainer menusView = new ElementContainer(new UnorderedListLayout());
            pageView.add(menusView);
            for (final Iterator menus = pageController.getMenus().entrySet().iterator(); menus.hasNext(); ) {
                final Map.Entry entry = (Entry) menus.next();
                final String name = (String) entry.getKey();
                final Menu menu = (Menu) entry.getValue();
                addMenu(menusView, name, menu);
            }
        }
        final Collection nodes = siteNode.getNodes();
        if (!nodes.isEmpty()) {
            final ElementContainer childNodesView = new ElementContainer(new UnorderedListLayout());
            nodeView.add(childNodesView);
            for (final Iterator nodeIter = nodes.iterator(); nodeIter.hasNext(); ) {
                final SiteNode childNode = (SiteNode) nodeIter.next();
                addSiteNode(childNodesView, childNode);
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) Action(com.revolsys.ui.web.config.Action) ElementContainer(com.revolsys.ui.html.view.ElementContainer) DivElementContainer(com.revolsys.ui.html.view.DivElementContainer) UnorderedListLayout(com.revolsys.ui.html.layout.UnorderedListLayout) SiteNodeController(com.revolsys.ui.web.config.SiteNodeController) Entry(java.util.Map.Entry) PageController(com.revolsys.ui.web.config.PageController) DefinitionListLayout(com.revolsys.ui.html.layout.DefinitionListLayout) Iterator(java.util.Iterator) Collection(java.util.Collection) Menu(com.revolsys.ui.model.Menu) XmlTagElement(com.revolsys.ui.html.view.XmlTagElement) Map(java.util.Map) SiteNode(com.revolsys.ui.web.config.SiteNode)

Example 4 with Menu

use of com.revolsys.ui.model.Menu in project com.revolsys.open by revolsys.

the class MenuElement method menu.

private void menu(final XmlWriter out, final Collection<Menu> items, final int level) {
    if (items.size() > 0) {
        out.startTag(HtmlElem.UL);
        for (final Menu menu : items) {
            if (menu.isVisible()) {
                out.startTag(HtmlElem.LI);
                final String cssClass = menu.getCssClass();
                if (cssClass != null) {
                    out.attribute(HtmlAttr.CLASS, cssClass);
                }
                menuLink(out, menu);
                if (level < this.numLevels) {
                    menu(out, menu.getMenus(), level + 1);
                }
                out.endTag(HtmlElem.LI);
            }
        }
        out.endTag(HtmlElem.UL);
    }
}
Also used : Menu(com.revolsys.ui.model.Menu)

Example 5 with Menu

use of com.revolsys.ui.model.Menu in project com.revolsys.open by revolsys.

the class HtmlUiBuilder method newObjectAddPage.

public Element newObjectAddPage(final Map<String, Object> defaultValues, final String prefix, final String preInsertMethod) throws IOException, ServletException {
    final T object = newObject();
    final HttpServletRequest request = HttpServletUtils.getRequest();
    Property.set(object, defaultValues);
    // if (!canAddObject(request)) {
    // response.sendError(HttpServletResponse.SC_FORBIDDEN,
    // "No permission to edit " + getTypeName() + " #" + getId());
    // return null;
    // }
    final Map<String, Object> parameters = new HashMap<>();
    final String pageName = getName(prefix, "add");
    final Set<String> parameterNamesToSave = new HashSet<>();
    final Form form = newTableForm(object, pageName);
    for (final String param : parameterNamesToSave) {
        form.addSavedParameter(param, request.getParameter(param));
    }
    form.initialize(request);
    if (form.isPosted() && form.isMainFormTask()) {
        if (form.isValid()) {
            if ((Boolean) JavaBeanUtil.method(this, preInsertMethod, form, object)) {
                insertObject(object);
                parameters.put("message", "Saved");
                final Object id = Property.get(object, getIdPropertyName());
                parameters.put(getIdParameterName(), id);
                postInsert(object);
                final String viewName = getName(prefix, "view");
                final String url = getPageUrl(viewName, parameters);
                redirectAfterCommit(url);
                return new TabElementContainer();
            }
        }
    }
    final Page page = getPage(pageName);
    final String title = page.getExpandedTitle();
    request.setAttribute("title", title);
    final Menu actionMenu = new Menu();
    addMenuItem(actionMenu, prefix, "list", "Cancel", "_top").addProperty("buttonClass", "btn-danger");
    addMenuItem(actionMenu, prefix, "add", "Clear Fields").addProperty("buttonClass", "btn-warning");
    final String name = form.getName();
    final Menu saveMenu = new Menu("Save", "javascript:$('#" + name + "').submit()");
    saveMenu.addProperty("buttonClass", "btn-primary");
    actionMenu.addMenuItem(saveMenu);
    final ButtonsToolbarElement buttonsToolbar = new ButtonsToolbarElement(actionMenu);
    final ElementContainer view = new ElementContainer(form, buttonsToolbar);
    final TabElementContainer tabs = new TabElementContainer();
    tabs.add(title, view);
    return tabs;
}
Also used : ElementContainer(com.revolsys.ui.html.view.ElementContainer) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UiBuilderObjectForm(com.revolsys.ui.html.form.UiBuilderObjectForm) HtmlUiBuilderObjectForm(com.revolsys.ui.html.form.HtmlUiBuilderObjectForm) Form(com.revolsys.ui.html.form.Form) Page(com.revolsys.ui.web.config.Page) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) HttpServletRequest(javax.servlet.http.HttpServletRequest) Menu(com.revolsys.ui.model.Menu) ButtonsToolbarElement(com.revolsys.ui.html.view.ButtonsToolbarElement) HashSet(java.util.HashSet)

Aggregations

Menu (com.revolsys.ui.model.Menu)16 ElementContainer (com.revolsys.ui.html.view.ElementContainer)5 ButtonsToolbarElement (com.revolsys.ui.html.view.ButtonsToolbarElement)4 TabElementContainer (com.revolsys.ui.html.view.TabElementContainer)4 Page (com.revolsys.ui.web.config.Page)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Form (com.revolsys.ui.html.form.Form)2 HtmlUiBuilderObjectForm (com.revolsys.ui.html.form.HtmlUiBuilderObjectForm)2 UiBuilderObjectForm (com.revolsys.ui.html.form.UiBuilderObjectForm)2 KeySerializer (com.revolsys.ui.html.serializer.key.KeySerializer)2 PageNotFoundException (com.revolsys.ui.web.exception.PageNotFoundException)2 OutputStream (java.io.OutputStream)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 XmlWriter (com.revolsys.record.io.format.xml.XmlWriter)1 DefinitionListLayout (com.revolsys.ui.html.layout.DefinitionListLayout)1 UnorderedListLayout (com.revolsys.ui.html.layout.UnorderedListLayout)1