litesoft
@ 939
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
/* * Copyright 2008 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.google.gwt.gen2.table.client; import java.util.*; import com.google.gwt.user.client.ui.HasHorizontalAlignment.*; import com.google.gwt.user.client.ui.HasVerticalAlignment.*; import com.google.gwt.user.client.ui.*; /** * A collection of {@link ColumnDefinition ColumnDefinitions} that define a * table. * * @param <RowType> the type of the row values */ public interface TableDefinition<RowType> { /** * A hook into where the rendered cell will be displayed. * * @param <RowType> the type of the row values */ public abstract static class AbstractCellView<RowType> { private int cellIndex = 0; private int rowIndex = 0; private HasTableDefinition<RowType> source; /** * Construct a new {@link TableDefinition.AbstractCellView}. * * @param sourceTableDef the {@link HasTableDefinition} that defined the * cell view */ public AbstractCellView( HasTableDefinition<RowType> sourceTableDef ) { this.source = sourceTableDef; } /** * @return the actual cell index being rendered */ public int getCellIndex() { return cellIndex; } /** * @return the actual row index being rendered */ public int getRowIndex() { return rowIndex; } /** * @return the source of the {@link TableDefinition} */ public HasTableDefinition<RowType> getSourceTableDefinition() { return source; } /** * Sets the horizontal alignment of the specified cell. * * @param align the cell's new horizontal alignment as specified in * {@link com.google.gwt.user.client.ui.HasHorizontalAlignment}. */ public abstract void setHorizontalAlignment( HorizontalAlignmentConstant align ); /** * Set the html string in the current cell. * * @param html the html string to set */ public abstract void setHTML( String html ); /** * Sets an attribute on the cell's style. * * @param attr the name of the style attribute to be set * @param value the style attribute's new value */ public abstract void setStyleAttribute( String attr, String value ); /** * Set the style name of the cell, which can be a space delimited list of * style names. */ public abstract void setStyleName( String stylename ); /** * Set the text string in the current cell. * * @param text the text string to set */ public abstract void setText( String text ); /** * Sets the vertical alignment of the specified cell. * * @param align the cell's new vertical alignment as specified in * {@link com.google.gwt.user.client.ui.HasVerticalAlignment}. */ public abstract void setVerticalAlignment( VerticalAlignmentConstant align ); /** * Set the {@link Widget} in the current cell. * * @param widget the widget to set */ public abstract void setWidget( Widget widget ); /** * Render a single cell. * * @param rowIndex the index of the row * @param cellIndex the index of the cell * @param rowValue the row value associated with the row * @param columnDef the {@link ColumnDefinition} associated with the column */ protected void renderCellImpl( int rowIndex, int cellIndex, RowType rowValue, ColumnDefinition<RowType, ?> columnDef ) { this.rowIndex = rowIndex; this.cellIndex = cellIndex; renderRowValue( rowValue, columnDef ); } /** * Render a row value into a cell. * * @param rowValue the row value associated with the row * @param columnDef the {@link ColumnDefinition} associated with the column */ protected void renderRowValue( RowType rowValue, ColumnDefinition columnDef ) { columnDef.getCellRenderer().renderRowValue( rowValue, columnDef, this ); } } /** * A hook into where the rendered row will be displayed. * * @param <RowType> the type of the row values */ public abstract static class AbstractRowView<RowType> { private int rowIndex = 0; private AbstractCellView<RowType> cellView; /** * Construct a new {@link TableDefinition.AbstractRowView}. * * @param cellView the view of the cell */ public AbstractRowView( AbstractCellView<RowType> cellView ) { this.cellView = cellView; } /** * @return the actual row index being rendered */ public int getRowIndex() { return rowIndex; } /** * @return the source of the {@link TableDefinition} */ public HasTableDefinition<RowType> getSourceTableDefinition() { return cellView.getSourceTableDefinition(); } /** * Sets an attribute on the cell's style. * * @param attr the name of the style attribute to be set * @param value the style attribute's new value */ public abstract void setStyleAttribute( String attr, String value ); /** * Set the style name of the cell, which can be a space delimited list of * style names. */ public abstract void setStyleName( String stylename ); /** * Render all of the cells in a single row. * * @param rowIndex the index of the row * @param rowValue the row value associated with the row * @param rowRenderer the renderer used to render the rows * @param visibleColumns the list of visible {@link ColumnDefinition} */ protected void renderRowImpl( int rowIndex, RowType rowValue, RowRenderer<RowType> rowRenderer, List<ColumnDefinition<RowType, ?>> visibleColumns ) { this.rowIndex = rowIndex; renderRowValue( rowValue, rowRenderer ); int numColumns = visibleColumns.size(); for ( int i = 0; i < numColumns; i++ ) { cellView.renderCellImpl( rowIndex, i, rowValue, visibleColumns.get( i ) ); } } /** * Render the rows in the table given the list of visible * {@link ColumnDefinition ColumnDefinitions}. * * @param startRowIndex the index of the first row to render * @param rowValues the values associated with each row * @param rowRenderer the renderer used to render the rows * @param visibleColumns the list of visible {@link ColumnDefinition} */ protected void renderRowsImpl( int startRowIndex, Iterator<RowType> rowValues, RowRenderer<RowType> rowRenderer, List<ColumnDefinition<RowType, ?>> visibleColumns ) { int curRow = startRowIndex; while ( rowValues.hasNext() ) { renderRowImpl( curRow, rowValues.next(), rowRenderer, visibleColumns ); curRow++; } } /** * Render a row value into a row. * * @param rowValue the row value associated with the row * @param rowRenderer the renderer used to render the rows */ protected void renderRowValue( RowType rowValue, RowRenderer<RowType> rowRenderer ) { rowRenderer.renderRowValue( rowValue, this ); } } /** * Get the {@link RowRenderer} used to render rows. The return value should * not be null. * * @return the row renderer */ RowRenderer<RowType> getRowRenderer(); /** * Get a list of the visible {@link ColumnDefinition ColumnDefinitions}. * * @return the visible {@link ColumnDefinition ColumnDefinitions} */ List<ColumnDefinition<RowType, ?>> getVisibleColumnDefinitions(); /** * Iterator over the row values, rendering every cell in every row. * * @param startRowIndex the index of the first row to render * @param rowValues the values associated with the rows * @param view the view used to render the rows and cells */ void renderRows( int startRowIndex, Iterator<RowType> rowValues, AbstractRowView<RowType> view ); } |