/// <summary>Gets the column widths.</summary>
 /// <param name="colgroups">the colgroups helper class</param>
 /// <returns>the column widths</returns>
 private UnitValue[] GetColWidths(WaitingColgroupsHelper colgroups)
 {
     UnitValue[] colWidths = new UnitValue[numberOfColumns];
     if (colgroups == null)
     {
         for (int i = 0; i < numberOfColumns; i++)
         {
             colWidths[i] = null;
         }
     }
     else
     {
         for (int i = 0; i < numberOfColumns; i++)
         {
             colWidths[i] = colgroups.GetColWrapper(i) != null?colgroups.GetColWrapper(i).GetWidth() : null;
         }
     }
     return(colWidths);
 }
        /// <summary>
        /// Renders all the rows to a
        /// <see cref="iText.Layout.Element.Table"/>
        /// object.
        /// </summary>
        /// <param name="colgroupsHelper">the colgroups helper class</param>
        /// <returns>the table</returns>
        public virtual Table ToTable(WaitingColgroupsHelper colgroupsHelper)
        {
            Table table;

            if (numberOfColumns > 0)
            {
                table = new Table(GetColWidths(colgroupsHelper));
            }
            else
            {
                // if table is empty, create empty table with single column
                table = new Table(1);
            }
            AccessiblePropHelper.TrySetLangAttribute(table, lang);
            if (headerRows != null)
            {
                for (int i = 0; i < headerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(headerRows[i]);
                    }
                    for (int j = 0; j < headerRows[i].Count; j++)
                    {
                        Cell       cell       = headerRows[i][j].cell;
                        ColWrapper colWrapper = colgroupsHelper.GetColWrapper(j);
                        if (colWrapper != null)
                        {
                            if (headerLang == null && cell.GetAccessibilityProperties().GetLanguage() == null)
                            {
                                if (colWrapper.GetLang() != null)
                                {
                                    cell.GetAccessibilityProperties().SetLanguage(colWrapper.GetLang());
                                }
                            }
                        }
                        table.AddHeaderCell(cell);
                    }
                    if (i != headerRows.Count - 1)
                    {
                        table.GetHeader().StartNewRow();
                    }
                }
                AccessiblePropHelper.TrySetLangAttribute(table.GetHeader(), headerLang);
            }
            if (footerRows != null)
            {
                for (int i = 0; i < footerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(footerRows[i]);
                    }
                    for (int j = 0; j < footerRows[i].Count; j++)
                    {
                        Cell       cell       = footerRows[i][j].cell;
                        ColWrapper colWrapper = colgroupsHelper.GetColWrapper(j);
                        if (colWrapper != null)
                        {
                            if (footerLang == null && cell.GetAccessibilityProperties().GetLanguage() == null)
                            {
                                if (colWrapper.GetLang() != null)
                                {
                                    cell.GetAccessibilityProperties().SetLanguage(colWrapper.GetLang());
                                }
                            }
                        }
                        table.AddFooterCell(cell);
                    }
                    if (i != footerRows.Count - 1)
                    {
                        table.GetFooter().StartNewRow();
                    }
                }
                AccessiblePropHelper.TrySetLangAttribute(table.GetFooter(), footerLang);
            }
            if (rows != null)
            {
                for (int i = 0; i < rows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(rows[i]);
                    }
                    for (int j = 0; j < rows[i].Count; j++)
                    {
                        table.AddCell(rows[i][j].cell);
                    }
                    if (i != rows.Count - 1)
                    {
                        table.StartNewRow();
                    }
                }
            }
            if (caption != null)
            {
                table.SetCaption(caption);
            }
            return(table);
        }