Search in sources :

Example 1 with FormDecorator

use of org.olat.core.gui.components.form.flexible.impl.FormDecorator in project OpenOLAT by OpenOLAT.

the class FlexiTableCustomRenderer method renderRow.

@Override
protected void renderRow(Renderer renderer, StringOutput sb, FlexiTableComponent ftC, String rowIdPrefix, int row, URLBuilder ubu, Translator translator, RenderResult renderResult) {
    sb.append("<div class='");
    if (ftC.getFlexiTableElement().getCssDelegate() != null) {
        String cssClass = ftC.getFlexiTableElement().getCssDelegate().getRowCssClass(FlexiTableRendererType.custom, row);
        if (cssClass == null) {
            sb.append("o_table_row row");
        } else {
            sb.append(cssClass);
        }
    } else {
        sb.append("o_table_row row");
    }
    sb.append("'>");
    FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
    VelocityContainer container = ftE.getRowRenderer();
    container.contextPut("f", new FormDecorator(ftE.getRootForm()));
    FlexiTableDataModel<?> dataModel = ftE.getTableDataModel();
    Object rowObject = ftE.getTableDataModel().getObject(row);
    container.contextPut("row", rowObject);
    container.contextPut("rowIndex", row);
    FlexiTableColumnModel columnsModel = ftE.getTableDataModel().getTableColumnModel();
    int numOfCols = columnsModel.getColumnCount();
    // link to the table element the form elements in the data model
    for (int j = 0; j < numOfCols; j++) {
        FlexiColumnModel fcm = columnsModel.getColumnModel(j);
        int columnIndex = fcm.getColumnIndex();
        Object cellValue = columnIndex >= 0 ? dataModel.getValueAt(row, columnIndex) : null;
        if (cellValue instanceof FormItem) {
            FormItem formItem = (FormItem) cellValue;
            formItem.setTranslator(translator);
            if (ftE.getRootForm() != formItem.getRootForm()) {
                formItem.setRootForm(ftE.getRootForm());
            }
            ftE.addFormItem(formItem);
            container.put(formItem.getComponent().getComponentName(), formItem.getComponent());
        }
    }
    FlexiTableComponentDelegate cmpDelegate = ftE.getComponentDelegate();
    if (cmpDelegate != null) {
        Iterable<Component> cmps = cmpDelegate.getComponents(row, rowObject);
        if (cmps != null) {
            for (Component cmp : cmps) {
                container.put(cmp.getComponentName(), cmp);
            }
        }
    }
    container.getHTMLRendererSingleton().render(renderer, sb, container, ubu, translator, renderResult, null);
    container.contextRemove("row");
    container.contextRemove("f");
    sb.append("</div>");
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) FormDecorator(org.olat.core.gui.components.form.flexible.impl.FormDecorator) Component(org.olat.core.gui.components.Component)

Example 2 with FormDecorator

use of org.olat.core.gui.components.form.flexible.impl.FormDecorator in project openolat by klemens.

the class FlexiTableCustomRenderer method renderRow.

@Override
protected void renderRow(Renderer renderer, StringOutput sb, FlexiTableComponent ftC, String rowIdPrefix, int row, URLBuilder ubu, Translator translator, RenderResult renderResult) {
    sb.append("<div class='");
    if (ftC.getFlexiTableElement().getCssDelegate() != null) {
        String cssClass = ftC.getFlexiTableElement().getCssDelegate().getRowCssClass(FlexiTableRendererType.custom, row);
        if (cssClass == null) {
            sb.append("o_table_row row");
        } else {
            sb.append(cssClass);
        }
    } else {
        sb.append("o_table_row row");
    }
    sb.append("'>");
    FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
    VelocityContainer container = ftE.getRowRenderer();
    container.contextPut("f", new FormDecorator(ftE.getRootForm()));
    FlexiTableDataModel<?> dataModel = ftE.getTableDataModel();
    Object rowObject = ftE.getTableDataModel().getObject(row);
    container.contextPut("row", rowObject);
    container.contextPut("rowIndex", row);
    FlexiTableColumnModel columnsModel = ftE.getTableDataModel().getTableColumnModel();
    int numOfCols = columnsModel.getColumnCount();
    // link to the table element the form elements in the data model
    for (int j = 0; j < numOfCols; j++) {
        FlexiColumnModel fcm = columnsModel.getColumnModel(j);
        int columnIndex = fcm.getColumnIndex();
        Object cellValue = columnIndex >= 0 ? dataModel.getValueAt(row, columnIndex) : null;
        if (cellValue instanceof FormItem) {
            FormItem formItem = (FormItem) cellValue;
            formItem.setTranslator(translator);
            if (ftE.getRootForm() != formItem.getRootForm()) {
                formItem.setRootForm(ftE.getRootForm());
            }
            ftE.addFormItem(formItem);
            container.put(formItem.getComponent().getComponentName(), formItem.getComponent());
        }
    }
    FlexiTableComponentDelegate cmpDelegate = ftE.getComponentDelegate();
    if (cmpDelegate != null) {
        Iterable<Component> cmps = cmpDelegate.getComponents(row, rowObject);
        if (cmps != null) {
            for (Component cmp : cmps) {
                container.put(cmp.getComponentName(), cmp);
            }
        }
    }
    container.getHTMLRendererSingleton().render(renderer, sb, container, ubu, translator, renderResult, null);
    container.contextRemove("row");
    container.contextRemove("f");
    sb.append("</div>");
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) FormDecorator(org.olat.core.gui.components.form.flexible.impl.FormDecorator) Component(org.olat.core.gui.components.Component)

Aggregations

Component (org.olat.core.gui.components.Component)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 FormDecorator (org.olat.core.gui.components.form.flexible.impl.FormDecorator)2 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2