Search in sources :

Example 1 with GridHeaderColumnRenderContext

use of org.uberfire.ext.wires.core.grids.client.widget.context.GridHeaderColumnRenderContext in project kie-wb-common by kiegroup.

the class RendererUtilsTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    text = spy(new Text(""));
    headerContext = new GridHeaderColumnRenderContext(0, Collections.singletonList(uiColumn), Collections.singletonList(uiColumn), 0, uiModel, gridRenderer);
    bodyContext = new GridBodyCellRenderContext(0, 0, BLOCK_WIDTH, ROW_HEIGHT, 0, 0, 0, 0, false, transform, gridRenderer);
    when(cellContext.getRenderer()).thenReturn(gridRenderer);
    when(gridRenderer.getTheme()).thenReturn(gridTheme);
    when(gridTheme.getBodyText()).thenReturn(text);
    when(cellContext.getCellWidth()).thenReturn(WIDTH);
    when(cellContext.getCellHeight()).thenReturn(HEIGHT);
    when(gridTheme.getHeaderText()).thenReturn(headerText1, headerText2);
    when(gridTheme.getPlaceholderText()).thenReturn(placeHolderText);
    when(headerText1.asNode()).thenReturn(mock(Node.class));
    when(headerText2.asNode()).thenReturn(mock(Node.class));
    when(placeHolderText.asNode()).thenReturn(mock(Node.class));
}
Also used : GridHeaderColumnRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridHeaderColumnRenderContext) Node(com.ait.lienzo.client.core.shape.Node) Text(com.ait.lienzo.client.core.shape.Text) GridBodyCellRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellRenderContext) Before(org.junit.Before)

Example 2 with GridHeaderColumnRenderContext

use of org.uberfire.ext.wires.core.grids.client.widget.context.GridHeaderColumnRenderContext in project kie-wb-common by kiegroup.

the class BaseNameAndDataTypeColumnRendererTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    this.renderer = getColumnRenderer();
    this.headerContext = new GridHeaderColumnRenderContext(0, Collections.singletonList(uiColumn), Collections.singletonList(uiColumn), 0, uiModel, gridRenderer);
    this.bodyContext = new GridBodyCellRenderContext(0, 0, BLOCK_WIDTH, ROW_HEIGHT, 0, 0, 0, 0, false, transform, gridRenderer);
    when(gridRenderer.getTheme()).thenReturn(gridRendererTheme);
    when(gridRendererTheme.getHeaderText()).thenReturn(text1, text2);
    when(gridRendererTheme.getBodyText()).thenReturn(text1);
    when(gridRendererTheme.getPlaceholderText()).thenReturn(text1);
    when(text1.asNode()).thenReturn(mock(Node.class));
    when(text2.asNode()).thenReturn(mock(Node.class));
}
Also used : GridHeaderColumnRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridHeaderColumnRenderContext) Node(com.ait.lienzo.client.core.shape.Node) GridBodyCellRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellRenderContext) Before(org.junit.Before)

Example 3 with GridHeaderColumnRenderContext

use of org.uberfire.ext.wires.core.grids.client.widget.context.GridHeaderColumnRenderContext in project appformer by kiegroup.

the class BaseGridColumnRenderer method renderHeader.

@Override
@SuppressWarnings("unchecked")
public List<GridRenderer.RendererCommand> renderHeader(final List<GridColumn.HeaderMetaData> headerMetaData, final GridHeaderColumnRenderContext context, final BaseGridRendererHelper.RenderingInformation renderingInformation, final BiFunction<Boolean, GridColumn<?>, Boolean> columnRenderingConstraint) {
    final GridData model = context.getModel();
    final GridRenderer renderer = context.getRenderer();
    final GridRendererTheme theme = renderer.getTheme();
    final double x = context.getX();
    final double headerRowsHeight = renderingInformation.getHeaderRowsHeight();
    final double headerRowsYOffset = renderingInformation.getHeaderRowsYOffset();
    final double rowHeight = headerRowsHeight / headerMetaData.size();
    final List<GridColumn<?>> allBlockColumns = context.getAllColumns();
    final List<GridColumn<?>> visibleBlockColumns = context.getBlockColumns();
    final int headerStartColumnIndex = allBlockColumns.indexOf(visibleBlockColumns.get(0));
    final int headerColumnIndex = allBlockColumns.indexOf(visibleBlockColumns.get(context.getColumnIndex()));
    final GridColumn<?> column = visibleBlockColumns.get(context.getColumnIndex());
    final List<GridRenderer.RendererCommand> commands = new ArrayList<>();
    // Grid lines
    commands.add((GridRenderer.RenderHeaderGridLinesCommand) (rc) -> {
        if (!rc.isSelectionLayer()) {
            final Group g = new Group().setX(x);
            final MultiPath headerGrid = theme.getHeaderGridLine().setY(headerRowsYOffset);
            for (int headerRowIndex = 0; headerRowIndex < headerMetaData.size(); headerRowIndex++) {
                final int blockStartColumnIndex = ColumnIndexUtilities.getHeaderBlockStartColumnIndex(allBlockColumns, headerMetaData.get(headerRowIndex), headerRowIndex, headerColumnIndex);
                final int blockEndColumnIndex = ColumnIndexUtilities.getHeaderBlockEndColumnIndex(allBlockColumns, headerMetaData.get(headerRowIndex), headerRowIndex, headerColumnIndex);
                if (headerColumnIndex < model.getColumnCount() - 1) {
                    if (blockEndColumnIndex == headerColumnIndex) {
                        final double hx = column.getWidth();
                        headerGrid.M(hx + 0.5, headerRowIndex * rowHeight).L(hx + 0.5, (headerRowIndex + 1) * rowHeight);
                    }
                }
                boolean skip;
                if (blockStartColumnIndex >= headerStartColumnIndex) {
                    skip = headerColumnIndex > blockStartColumnIndex;
                } else {
                    skip = headerColumnIndex > headerStartColumnIndex;
                }
                if (skip) {
                    continue;
                }
                final double offsetX = getBlockOffset(allBlockColumns, blockStartColumnIndex, headerColumnIndex);
                final double blockWidth = getBlockWidth(allBlockColumns, blockStartColumnIndex, blockEndColumnIndex);
                if (headerRowIndex > 0) {
                    headerGrid.M(offsetX, (headerRowIndex * rowHeight) + 0.5).L(offsetX + blockWidth, (headerRowIndex * rowHeight) + 0.5);
                }
            }
            g.add(headerGrid);
            rc.getGroup().add(g);
        }
    });
    // Grid content
    commands.add((GridRenderer.RenderHeaderContentCommand) (rc) -> {
        if (!rc.isSelectionLayer()) {
            final Group g = new Group().setX(x);
            for (int headerRowIndex = 0; headerRowIndex < headerMetaData.size(); headerRowIndex++) {
                final int blockStartColumnIndex = ColumnIndexUtilities.getHeaderBlockStartColumnIndex(allBlockColumns, headerMetaData.get(headerRowIndex), headerRowIndex, headerColumnIndex);
                final int blockEndColumnIndex = ColumnIndexUtilities.getHeaderBlockEndColumnIndex(allBlockColumns, headerMetaData.get(headerRowIndex), headerRowIndex, headerColumnIndex);
                boolean skip;
                if (blockStartColumnIndex >= headerStartColumnIndex) {
                    skip = headerColumnIndex > blockStartColumnIndex;
                } else {
                    skip = headerColumnIndex > headerStartColumnIndex;
                }
                if (skip) {
                    continue;
                }
                final double offsetX = getBlockOffset(allBlockColumns, blockStartColumnIndex, headerColumnIndex);
                final double blockWidth = getBlockWidth(allBlockColumns, blockStartColumnIndex, blockEndColumnIndex);
                final Group headerGroup = renderHeaderContent(headerMetaData, context, headerRowIndex, blockWidth, rowHeight);
                final BoundingBox bb = new BoundingBox(0, 0, blockWidth, rowHeight);
                final IPathClipper clipper = getBoundingBoxPathClipper(bb);
                headerGroup.setX(offsetX);
                headerGroup.setY(headerRowsYOffset + headerRowIndex * rowHeight);
                headerGroup.setPathClipper(clipper);
                clipper.setActive(true);
                g.add(headerGroup);
            }
            rc.getGroup().add(g);
        }
    });
    return commands;
}
Also used : IPathClipper(com.ait.lienzo.client.core.shape.IPathClipper) ColumnIndexUtilities(org.uberfire.ext.wires.core.grids.client.util.ColumnIndexUtilities) MultiPath(com.ait.lienzo.client.core.shape.MultiPath) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) GridBodyCellRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellRenderContext) BiFunction(java.util.function.BiFunction) BoundingBoxPathClipper(com.ait.lienzo.client.core.shape.BoundingBoxPathClipper) Text(com.ait.lienzo.client.core.shape.Text) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) Group(com.ait.lienzo.client.core.shape.Group) GWT(com.google.gwt.core.client.GWT) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridRenderer(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.GridRenderer) GridRendererTheme(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.themes.GridRendererTheme) ArrayList(java.util.ArrayList) GridHeaderColumnRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridHeaderColumnRenderContext) BaseGridRendererHelper(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.impl.BaseGridRendererHelper) List(java.util.List) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) GridColumnRenderer(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.columns.GridColumnRenderer) GridBodyColumnRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyColumnRenderContext) Group(com.ait.lienzo.client.core.shape.Group) MultiPath(com.ait.lienzo.client.core.shape.MultiPath) IPathClipper(com.ait.lienzo.client.core.shape.IPathClipper) ArrayList(java.util.ArrayList) GridRendererTheme(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.themes.GridRendererTheme) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) GridRenderer(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.GridRenderer)

Example 4 with GridHeaderColumnRenderContext

use of org.uberfire.ext.wires.core.grids.client.widget.context.GridHeaderColumnRenderContext in project appformer by kiegroup.

the class BaseGridRenderer method renderHeader.

@Override
public List<RendererCommand> renderHeader(final GridData model, final GridHeaderRenderContext context, final BaseGridRendererHelper rendererHelper, final BaseGridRendererHelper.RenderingInformation renderingInformation) {
    final List<RendererCommand> commands = new ArrayList<>();
    final int headerRowCount = renderingInformation.getHeaderRowCount();
    if (headerRowCount == 0) {
        return commands;
    }
    final List<GridColumn<?>> allBlockColumns = context.getAllColumns();
    final List<GridColumn<?>> visibleBlockColumns = context.getBlockColumns();
    final double headerRowsHeight = renderingInformation.getHeaderRowsHeight();
    final double headerRowsYOffset = renderingInformation.getHeaderRowsYOffset();
    // Column backgrounds
    double cx = 0;
    for (final GridColumn<?> column : visibleBlockColumns) {
        if (column.isVisible()) {
            final double x = cx;
            final double w = column.getWidth();
            Rectangle header;
            if (column.isLinked()) {
                header = theme.getHeaderLinkBackground(column);
            } else {
                header = theme.getHeaderBackground(column);
            }
            if (header != null) {
                commands.add((RenderHeaderBackgroundCommand) (rc) -> {
                    if (columnRenderingConstraint.apply(rc.isSelectionLayer(), column)) {
                        header.setWidth(w).setListening(true).setHeight(headerRowsHeight).setY(headerRowsYOffset).setX(x);
                        rc.getGroup().add(header);
                    }
                });
            }
            cx = cx + w;
        }
    }
    // Column title and grid lines
    cx = 0;
    for (final GridColumn<?> column : visibleBlockColumns) {
        if (column.isVisible()) {
            final double columnWidth = column.getWidth();
            final int columnIndex = visibleBlockColumns.indexOf(column);
            final GridHeaderColumnRenderContext headerCellRenderContext = new GridHeaderColumnRenderContext(cx, allBlockColumns, visibleBlockColumns, columnIndex, model, this);
            commands.addAll(column.getColumnRenderer().renderHeader(column.getHeaderMetaData(), headerCellRenderContext, renderingInformation, columnRenderingConstraint));
            cx = cx + columnWidth;
        }
    }
    // Linked column icons
    cx = 0;
    for (final GridColumn<?> column : visibleBlockColumns) {
        if (column.isVisible()) {
            final double x = cx;
            final double w = column.getWidth();
            if (column.isLinked()) {
                commands.add((RenderHeaderContentCommand) (rc) -> {
                    if (columnRenderingConstraint.apply(rc.isSelectionLayer(), column)) {
                        final Text t = theme.getBodyText().setFontFamily(LINK_FONT_FAMILY).setFontSize(LINK_FONT_SIZE).setText(LINK_ICON).setY(headerRowsYOffset + LINK_FONT_SIZE).setX(x + w - LINK_FONT_SIZE);
                        rc.getGroup().add(t);
                    }
                });
            }
            cx = cx + w;
        }
    }
    // Divider between header and body
    commands.add(renderHeaderBodyDivider(rendererHelper.getWidth(visibleBlockColumns)));
    return commands;
}
Also used : MultiPath(com.ait.lienzo.client.core.shape.MultiPath) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) BiFunction(java.util.function.BiFunction) Text(com.ait.lienzo.client.core.shape.Text) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) Group(com.ait.lienzo.client.core.shape.Group) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridHeaderRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridHeaderRenderContext) GridRenderer(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.GridRenderer) Function(java.util.function.Function) GridRendererTheme(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.themes.GridRendererTheme) ArrayList(java.util.ArrayList) Objects(java.util.Objects) GridHeaderColumnRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridHeaderColumnRenderContext) Line(com.ait.lienzo.client.core.shape.Line) Transform(com.ait.lienzo.client.core.types.Transform) List(java.util.List) SelectionsTransformer(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.SelectionsTransformer) Point2D(com.ait.lienzo.client.core.types.Point2D) GridBodyRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyRenderContext) Rectangle(com.ait.lienzo.client.core.shape.Rectangle) Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) GridBoundaryRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridBoundaryRenderContext) GridBodyColumnRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyColumnRenderContext) GridHeaderColumnRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridHeaderColumnRenderContext) ArrayList(java.util.ArrayList) Rectangle(com.ait.lienzo.client.core.shape.Rectangle) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) Text(com.ait.lienzo.client.core.shape.Text)

Aggregations

GridHeaderColumnRenderContext (org.uberfire.ext.wires.core.grids.client.widget.context.GridHeaderColumnRenderContext)4 Text (com.ait.lienzo.client.core.shape.Text)3 GridBodyCellRenderContext (org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellRenderContext)3 Group (com.ait.lienzo.client.core.shape.Group)2 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)2 Node (com.ait.lienzo.client.core.shape.Node)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BiFunction (java.util.function.BiFunction)2 Before (org.junit.Before)2 GridCell (org.uberfire.ext.wires.core.grids.client.model.GridCell)2 GridColumn (org.uberfire.ext.wires.core.grids.client.model.GridColumn)2 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)2 GridBodyColumnRenderContext (org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyColumnRenderContext)2 GridRenderer (org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.GridRenderer)2 GridRendererTheme (org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.themes.GridRendererTheme)2 BoundingBoxPathClipper (com.ait.lienzo.client.core.shape.BoundingBoxPathClipper)1 IPathClipper (com.ait.lienzo.client.core.shape.IPathClipper)1 Line (com.ait.lienzo.client.core.shape.Line)1 Rectangle (com.ait.lienzo.client.core.shape.Rectangle)1