All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dominokit.domino.ui.datatable.RowCell Maven / Gradle / Ivy

There is a newer version: 1.0.139
Show newest version
package org.dominokit.domino.ui.datatable;

import elemental2.dom.HTMLTableCellElement;
import org.dominokit.domino.ui.style.Style;
import org.dominokit.domino.ui.utils.ElementUtil;
import org.dominokit.domino.ui.utils.TextNode;
import org.jboss.elemento.IsElement;

import static java.util.Objects.nonNull;

public class RowCell {

    private final ColumnConfig columnConfig;
    private final CellRenderer.CellInfo cellInfo;
    private CellRenderer defaultCellRenderer=  cell -> TextNode.of("");

    public RowCell(CellRenderer.CellInfo cellInfo, ColumnConfig columnConfig) {
        this.columnConfig = columnConfig;
        this.cellInfo = cellInfo;
    }

    public ColumnConfig getColumnConfig() {
        return columnConfig;
    }

    public void updateCell() {
        ElementUtil.clear(cellInfo.getElement());
        Style> style = Style.of(cellInfo.getElement());
        if (nonNull(columnConfig.getMinWidth())) {
            style.setMinWidth(columnConfig.getMinWidth());
            columnConfig.getHeadElement().style().setMinWidth(columnConfig.getMinWidth());
        }

        if (nonNull(columnConfig.getMaxWidth())) {
            style.setMaxWidth(columnConfig.getMaxWidth());
            columnConfig.getHeadElement().style().setMaxWidth(columnConfig.getMaxWidth());
        }

        if (nonNull(columnConfig.getTextAlign())) {
            style.setTextAlign(columnConfig.getTextAlign());
            columnConfig.getHeadElement().style().setTextAlign(columnConfig.getTextAlign());
        }

        if(cellInfo.getTableRow().isEditable()){
            if(nonNull(columnConfig.getEditableCellRenderer())) {
                cellInfo.getElement().appendChild(columnConfig.getEditableCellRenderer().asElement(cellInfo));
            }else{
                cellInfo.getElement().appendChild(defaultCellRenderer.asElement(cellInfo));
            }
        }else {
            if(nonNull(columnConfig.getCellRenderer())) {
                cellInfo.getElement().appendChild(columnConfig.getCellRenderer().asElement(cellInfo));
            }else{
                cellInfo.getElement().appendChild(defaultCellRenderer.asElement(cellInfo));
            }
        }
    }

    public CellRenderer.CellInfo getCellInfo() {
        return cellInfo;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy