Search in sources :

Example 31 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WComponentGroupRenderer method doRender.

/**
 * Paints the given WComponentGroup.
 *
 * @param component the WComponentGroup to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WComponentGroup group = (WComponentGroup) component;
    XmlStringBuilder xml = renderContext.getWriter();
    List<WComponent> components = group.getComponents();
    if (components != null && !components.isEmpty()) {
        xml.appendTagOpen("ui:componentGroup");
        xml.appendAttribute("id", component.getId());
        xml.appendOptionalAttribute("track", component.isTracking(), "true");
        xml.appendClose();
        for (WComponent comp : components) {
            xml.appendTagOpen("ui:component");
            xml.appendAttribute("id", comp.getId());
            xml.appendEnd();
        }
        xml.appendEndTag("ui:componentGroup");
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 32 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WDataTableRowRendererRenderer method doRender.

/**
 * Paints the given WDataTableRowRenderer.
 *
 * @param component the WDataTableRowRenderer to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WDataTableRowRenderer renderer = (WDataTableRowRenderer) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WDataTable table = renderer.getTable();
    TableDataModel dataModel = table.getDataModel();
    UIContext uic = UIContextHolder.getCurrent();
    final int numCols = table.getColumnCount();
    int[] columnOrder = table.getColumnOrder();
    int rowIndex = getRowIndex(table, (SubUIContext) uic);
    boolean unselectable = table.getSelectMode() != SelectMode.NONE && !dataModel.isSelectable(rowIndex);
    xml.appendTagOpen("ui:tr");
    xml.appendAttribute("rowIndex", rowIndex);
    xml.appendOptionalAttribute("unselectable", unselectable, "true");
    xml.appendOptionalAttribute("selected", table.getSelectedRows().contains(rowIndex), "true");
    xml.appendOptionalAttribute("filterValues", getFilterValues(dataModel, rowIndex));
    if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
        TableTreeNode node = ((TreeTableDataModel) dataModel).getNodeAtLine(rowIndex);
        boolean expandable = !node.isLeaf() && !node.isExpanded();
        xml.appendOptionalAttribute("expandable", expandable, "true");
    }
    xml.appendClose();
    if (table.isShowRowHeaders()) {
        xml.appendTag("ui:th");
        renderer.getRowHeader().paint(renderContext);
        xml.appendEndTag("ui:th");
    }
    for (int i = 0; i < numCols; i++) {
        int colIndex = columnOrder == null ? i : columnOrder[i];
        WTableColumn col = table.getColumn(colIndex);
        if (col.isVisible()) {
            xml.appendTag("ui:td");
            renderer.getRenderer(colIndex).paint(renderContext);
            xml.appendEndTag("ui:td");
        }
    }
    if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
        TreeTableDataModel treeModel = (TreeTableDataModel) dataModel;
        TableTreeNode node = treeModel.getNodeAtLine(rowIndex);
        if (!node.isLeaf()) {
            xml.appendTagOpen("ui:subtr");
            xml.appendOptionalAttribute("open", node.isExpanded(), "true");
            xml.appendClose();
            if (node.isExpanded() || table.getExpandMode() == ExpandMode.CLIENT) {
                WRepeater repeater = table.getRepeater();
                // If there a renderer specified by any child, we only paint content that has a specified renderer
                boolean rendererPresent = false;
                for (Iterator<TreeNode> i = node.children(); !rendererPresent && i.hasNext(); ) {
                    TableTreeNode child = (TableTreeNode) i.next();
                    if (child.getRendererClass() != null) {
                        rendererPresent = true;
                    }
                }
                // Paint immediate children only.
                if (rendererPresent) {
                    xml.appendTagOpen("ui:content");
                    xml.appendOptionalAttribute("spanAllCols", node.isRendererSpansAllCols(), "true");
                    xml.appendClose();
                    for (Iterator<TreeNode> i = node.children(); i.hasNext(); ) {
                        TableTreeNode child = (TableTreeNode) i.next();
                        Integer rowId = child.getRowIndex() - 1;
                        UIContext nodeContext = repeater.getRowContext(rowId);
                        WComponent expandedRenderer = renderer.getExpandedTreeNodeRenderer(child.getRendererClass());
                        if (expandedRenderer != null) {
                            UIContextHolder.pushContext(nodeContext);
                            try {
                                expandedRenderer.paint(renderContext);
                            } finally {
                                UIContextHolder.popContext();
                            }
                        }
                    }
                    xml.appendEndTag("ui:content");
                } else {
                    for (Iterator<TreeNode> i = node.children(); i.hasNext(); ) {
                        TableTreeNode child = (TableTreeNode) i.next();
                        Integer rowId = child.getRowIndex() - 1;
                        UIContext nodeContext = repeater.getRowContext(rowId);
                        UIContextHolder.pushContext(nodeContext);
                        try {
                            render(component, renderContext);
                        } finally {
                            UIContextHolder.popContext();
                        }
                    }
                }
            }
            xml.appendEndTag("ui:subtr");
        }
    }
    xml.appendEndTag("ui:tr");
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) UIContext(com.github.bordertech.wcomponents.UIContext) SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WRepeater(com.github.bordertech.wcomponents.WRepeater) WComponent(com.github.bordertech.wcomponents.WComponent) WDataTable(com.github.bordertech.wcomponents.WDataTable) TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeNode(com.github.bordertech.wcomponents.util.TreeNode) WDataTableRowRenderer(com.github.bordertech.wcomponents.WDataTableRowRenderer) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 33 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WDateFieldRenderer method doRender.

/**
 * Paints the given WDateField.
 *
 * @param component the WDateField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WDateField dateField = (WDateField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = dateField.isReadOnly();
    Date date = dateField.getDate();
    xml.appendTagOpen("ui:datefield");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", dateField.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        xml.appendOptionalAttribute("disabled", dateField.isDisabled(), "true");
        xml.appendOptionalAttribute("required", dateField.isMandatory(), "true");
        xml.appendOptionalAttribute("toolTip", dateField.getToolTip());
        xml.appendOptionalAttribute("accessibleText", dateField.getAccessibleText());
        WComponent submitControl = dateField.getDefaultSubmitButton();
        String submitControlId = submitControl == null ? null : submitControl.getId();
        xml.appendOptionalAttribute("buttonId", submitControlId);
        Date minDate = dateField.getMinDate();
        Date maxDate = dateField.getMaxDate();
        if (minDate != null) {
            xml.appendAttribute("min", new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(minDate));
        }
        if (maxDate != null) {
            xml.appendAttribute("max", new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(maxDate));
        }
    }
    if (date != null) {
        xml.appendAttribute("date", new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(date));
    }
    xml.appendClose();
    if (date == null) {
        xml.appendEscaped(dateField.getText());
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(dateField, renderContext);
    }
    xml.appendEndTag("ui:datefield");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WDateField(com.github.bordertech.wcomponents.WDateField) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 34 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WServlet method serviceInt.

/**
 * Service internal. This method does the real work in servicing the http request. It integrates wcomponents into a
 * servlet environment via a servlet specific helper class.
 *
 * @param request the http servlet request.
 * @param response the http servlet response.
 * @throws IOException an IO exception
 * @throws ServletException a servlet exception
 */
protected void serviceInt(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    // Check for resource request
    boolean continueProcess = ServletUtil.checkResourceRequest(request, response);
    if (!continueProcess) {
        return;
    }
    // Create a support class to coordinate the web request.
    WServletHelper helper = createServletHelper(request, response);
    // Get the interceptors that will be used to plug in features.
    InterceptorComponent interceptorChain = createInterceptorChain(request);
    // Get the WComponent that represents the application we are serving.
    WComponent ui = getUI(request);
    ServletUtil.processRequest(helper, ui, interceptorChain);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) InterceptorComponent(com.github.bordertech.wcomponents.container.InterceptorComponent)

Example 35 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class HandlebarsRendererImpl method renderTemplate.

/**
 * {@inheritDoc}
 */
@Override
public void renderTemplate(final String templateName, final Map<String, Object> context, final Map<String, WComponent> taggedComponents, final Writer writer, final Map<String, Object> options) {
    LOG.debug("Rendering handlebars template " + templateName);
    try {
        // Map the tagged components to be used in the replace writer
        Map<String, WComponent> componentsByKey = TemplateUtil.mapTaggedComponents(context, taggedComponents);
        // Get Engine
        Handlebars handlebars = getHandlebarsEngine(options);
        // Load template (Handlebars loader makes the template name "absolute")
        Template template = handlebars.compile(templateName);
        // Setup handlebars context
        Context handlebarsContext = createContext(context);
        // Render
        writeTemplate(template, handlebarsContext, componentsByKey, writer);
    } catch (FileNotFoundException e) {
        throw new SystemException("Could not find handlebars template [" + templateName + "]. " + e.getMessage(), e);
    } catch (Exception e) {
        throw new SystemException("Problems with handlebars template [" + templateName + "]. " + e.getMessage(), e);
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Context(com.github.jknack.handlebars.Context) UIContext(com.github.bordertech.wcomponents.UIContext) SystemException(com.github.bordertech.wcomponents.util.SystemException) Handlebars(com.github.jknack.handlebars.Handlebars) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SystemException(com.github.bordertech.wcomponents.util.SystemException) Template(com.github.jknack.handlebars.Template)

Aggregations

WComponent (com.github.bordertech.wcomponents.WComponent)107 Test (org.junit.Test)35 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)30 UIContext (com.github.bordertech.wcomponents.UIContext)20 SystemException (com.github.bordertech.wcomponents.util.SystemException)16 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)8 WApplication (com.github.bordertech.wcomponents.WApplication)8 WLabel (com.github.bordertech.wcomponents.WLabel)8 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)7 IOException (java.io.IOException)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)5 PrintWriter (java.io.PrintWriter)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Size (com.github.bordertech.wcomponents.Size)4 WRepeater (com.github.bordertech.wcomponents.WRepeater)4 WText (com.github.bordertech.wcomponents.WText)4 WTextField (com.github.bordertech.wcomponents.WTextField)4