public RenderingInformation getRenderingInformation()

in packages/stunner-editors/uberfire-extensions/uberfire-wires/uberfire-wires-core/uberfire-wires-core-grids/src/main/java/org/uberfire/ext/wires/core/grids/client/widget/grid/renderers/grids/impl/BaseGridRendererHelper.java [163:341]


    public RenderingInformation getRenderingInformation() {
        final GridData model = view.getModel();
        final Bounds bounds = getVisibleBounds();
        final List<GridColumn<?>> allColumns = new ArrayList<>();
        final List<GridColumn<?>> bodyColumns = new ArrayList<>();
        final List<GridColumn<?>> floatingColumns = new ArrayList<>();

        double viewHeight = 0;
        final int rowCount = model.getRowCount();
        final List<Double> rowHeights = new ArrayList<>();
        for (GridRow row : model.getRows()) {
            final double rowHeight = row.getHeight();
            viewHeight = viewHeight + rowHeight;
            rowHeights.add(rowHeight);
        }

        final double vpX = bounds.getX();
        final double vpY = bounds.getY();
        final double vpWidth = bounds.getWidth();
        final double vpHeight = bounds.getHeight();
        final double headerOffsetY = getHeaderOffsetY();
        final GridRenderer renderer = view.getRenderer();

        //Simple bounds check
        if (view.getComputedLocation().getX() > vpX + vpWidth) {
            return null;
        } else if (view.getComputedLocation().getX() + view.getWidth() < vpX) {
            return null;
        } else if (view.getComputedLocation().getY() > vpY + vpHeight) {
            return null;
        } else if (view.getComputedLocation().getY() + viewHeight < vpY) {
            return null;
        }

        //Identify type of header
        boolean isFixedHeader = false;
        boolean isFloatingHeader = false;
        if (view.isSelected()) {
            if (view.getComputedLocation().getY() < vpY) {
                //GridWidget is selected and clipped at the top
                if (view.getComputedLocation().getY() + viewHeight > vpY + renderer.getHeaderHeight()) {
                    //GridWidget is taller than the Header; add floating header
                    isFloatingHeader = true;
                } else {
                    //GridWidget is shorter than the Header; add fixed header
                    isFixedHeader = true;
                }
            } else if (view.getComputedLocation().getY() <= vpY + vpHeight) {
                //GridWidget is selected and not clipped at the top; add fixed header
                isFixedHeader = true;
            }
        } else if (view.getComputedLocation().getY() + renderer.getHeaderHeight() > vpY && view.getComputedLocation().getY() < vpY + vpHeight) {
            //GridWidget is not selected; add fixed header
            isFixedHeader = true;
        }

        //Identify rows to render
        long currentTimeMillis = log(LOGGER, " - Pre- identify rows to render");

        int minVisibleRowIndex = 0;
        if (model.getRowCount() > 0) {
            double clipTop = vpY - view.getComputedLocation().getY() - (isFloatingHeader ? 0.0 : renderer.getHeaderHeight());
            while (rowHeights.get(minVisibleRowIndex) < clipTop && minVisibleRowIndex < rowCount - 1) {
                clipTop = clipTop - rowHeights.get(minVisibleRowIndex);
                minVisibleRowIndex++;
            }
        }

        int maxVisibleRowIndex = minVisibleRowIndex;
        if (model.getRowCount() > 0) {
            double clipBottom = vpY - view.getComputedLocation().getY() - renderer.getHeaderHeight() + vpHeight - getRowOffset(minVisibleRowIndex, rowHeights);
            while (rowHeights.get(maxVisibleRowIndex) < clipBottom && maxVisibleRowIndex < rowCount - 1) {
                clipBottom = clipBottom - rowHeights.get(maxVisibleRowIndex);
                maxVisibleRowIndex++;
            }
        }
        log(LOGGER, " - Post- identify rows to render", currentTimeMillis);

        //Identify columns to render
        currentTimeMillis = log(LOGGER, " - Pre- identify columns to render");

        double x = 0;
        for (GridColumn<?> column : model.getColumns()) {
            allColumns.add(column);
            final double floatingColumnsWidth = getWidth(floatingColumns);
            if (view.getComputedLocation().getX() + x + column.getWidth() >= vpX + floatingColumnsWidth) {
                if (view.getComputedLocation().getX() + x < vpX + vpWidth) {
                    bodyColumns.add(column);
                }
            }
            if (view.isSelected()) {
                if (column.isFloatable()) {
                    if (view.getComputedLocation().getX() + x < vpX + floatingColumnsWidth) {
                        allColumns.remove(column);
                        bodyColumns.remove(column);
                        floatingColumns.add(column);
                    }
                }
            }
            if (column.isVisible()) {
                x = x + column.getWidth();
            }
        }

        //If the floating columns obscure the body columns remove the float and just show the body columns
        if (view.getComputedLocation().getX() + x - vpX < getWidth(floatingColumns)) {
            allColumns.clear();
            bodyColumns.clear();
            floatingColumns.clear();
            allColumns.addAll(model.getColumns());

            x = 0;
            for (GridColumn<?> column : model.getColumns()) {
                if (view.getComputedLocation().getX() + x + column.getWidth() >= vpX) {
                    if (view.getComputedLocation().getX() + x < vpX + vpWidth) {
                        bodyColumns.add(column);
                    }
                }
                if (column.isVisible()) {
                    x = x + column.getWidth();
                }
            }
        }
        log(LOGGER, " - Post- identify columns to render", currentTimeMillis);

        //Construct details of Floating and Body blocks
        double visibleRowOffset = getRowOffset(minVisibleRowIndex, rowHeights);
        final double bodyOffsetY = visibleRowOffset + renderer.getHeaderHeight();
        final double offsetX = (bodyColumns.size() > 0 ? getColumnOffset(bodyColumns.get(0)) : 0);
        final double floatingOffsetX = getFloatingColumnOffset();

        final RenderingBlockInformation bodyBlockInformation = new RenderingBlockInformation(bodyColumns,
                                                                                             offsetX,
                                                                                             headerOffsetY,
                                                                                             bodyOffsetY,
                                                                                             getWidth(bodyColumns));
        final RenderingBlockInformation floatingBlockInformation = new RenderingBlockInformation(floatingColumns,
                                                                                                 floatingOffsetX,
                                                                                                 headerOffsetY,
                                                                                                 bodyOffsetY,
                                                                                                 getWidth(floatingColumns));

        // Construct "row offsets". The row offsets are based from zero; for each row to be rendered.
        // The minVisibleRowIndex corresponds to index zero and maxVisibleRowIndex corresponds to visibleRowOffsets.size() - 1.
        // This is useful to calculate the Y co-ordinate of each Row's top. It is calculated once and passed to
        // each column as an optimisation to prevent each column from recalculating the same values.
        currentTimeMillis = log(LOGGER, " - Pre- calculate row offsets");

        final List<Double> visibleRowOffsets = new ArrayList<>();
        if (model.getRowCount() > 0) {
            for (int rowIndex = minVisibleRowIndex; rowIndex <= maxVisibleRowIndex; rowIndex++) {
                visibleRowOffsets.add(visibleRowOffset);
                visibleRowOffset = visibleRowOffset + rowHeights.get(rowIndex);
            }
        }
        log(LOGGER, " - Post- calculate row offsets", currentTimeMillis);

        final int headerRowCount = model.getHeaderRowCount();
        final double headerHeight = renderer.getHeaderHeight();
        final double headerRowHeight = renderer.getHeaderRowHeight();
        final double headerRowsHeight = headerRowHeight * headerRowCount;
        final double headerRowsYOffset = headerHeight - headerRowsHeight;

        //Finally return all rendering information
        return new RenderingInformation(bounds,
                                        allColumns,
                                        bodyBlockInformation,
                                        floatingBlockInformation,
                                        minVisibleRowIndex,
                                        maxVisibleRowIndex,
                                        rowHeights,
                                        visibleRowOffsets,
                                        isFixedHeader,
                                        isFloatingHeader,
                                        headerRowCount,
                                        headerRowHeight,
                                        headerRowsHeight,
                                        headerRowsYOffset);
    }