|
@@ -15,53 +15,60 @@ |
15 |
15 |
|
*/ |
16 |
16 |
|
package com.google.gwt.gen2.table.client; |
17 |
17 |
|
|
18 |
|
- |
import com.google.gwt.gen2.table.client.TableDefinition.AbstractCellView; |
19 |
|
- |
import com.google.gwt.user.client.ui.Widget; |
|
18 |
+ |
import com.google.gwt.gen2.table.client.TableDefinition.*; |
|
19 |
+ |
import com.google.gwt.user.client.ui.*; |
20 |
20 |
|
|
21 |
21 |
|
/** |
22 |
22 |
|
* The default {@link CellRenderer} used by the {@link AbstractColumnDefinition} |
23 |
23 |
|
* when the user does not specify one. By default, {@link Widget}s are rendered |
24 |
24 |
|
* as {@link Widget}s, and all other values are rendered as text. |
25 |
|
- |
* |
26 |
|
- |
* |
|
25 |
+ |
* |
27 |
26 |
|
* @param <RowType> the type of the row value |
28 |
27 |
|
* @param <ColType> the data type of the column |
29 |
28 |
|
*/ |
30 |
|
- |
public class DefaultCellRenderer<RowType, ColType> implements |
31 |
|
- |
CellRenderer<RowType, ColType> { |
|
29 |
+ |
public class DefaultCellRenderer<RowType, ColType> implements CellRenderer<RowType, ColType> |
|
30 |
+ |
{ |
32 |
31 |
|
|
33 |
|
- |
/** |
34 |
|
- |
* If true, text will be rendered as html. |
35 |
|
- |
*/ |
36 |
|
- |
private boolean asHtml; |
37 |
|
- |
|
38 |
|
- |
/** |
39 |
|
- |
* Construct a new {@link DefaultCellRenderer}. |
40 |
|
- |
*/ |
41 |
|
- |
public DefaultCellRenderer() { |
42 |
|
- |
} |
43 |
|
- |
|
44 |
|
- |
/** |
45 |
|
- |
* Construct a new {@link DefaultCellRenderer}. |
46 |
|
- |
* |
47 |
|
- |
* @param asHtml if true, non-widget cell contents will be rendered as html |
48 |
|
- |
*/ |
49 |
|
- |
public DefaultCellRenderer(boolean asHtml) { |
50 |
|
- |
this.asHtml = asHtml; |
51 |
|
- |
} |
52 |
|
- |
|
53 |
|
- |
public void renderRowValue(RowType rowValue, |
54 |
|
- |
ColumnDefinition<RowType, ColType> columnDef, |
55 |
|
- |
AbstractCellView<RowType> view) { |
56 |
|
- |
Object cellValue = columnDef.getCellValue(rowValue); |
57 |
|
- |
if (cellValue == null) { |
58 |
|
- |
view.setText(""); |
59 |
|
- |
} else if (cellValue instanceof Widget) { |
60 |
|
- |
view.setWidget((Widget) cellValue); |
61 |
|
- |
} else if (asHtml) { |
62 |
|
- |
view.setHTML(cellValue.toString()); |
63 |
|
- |
} else { |
64 |
|
- |
view.setText(cellValue.toString()); |
|
32 |
+ |
/** |
|
33 |
+ |
* If true, text will be rendered as html. |
|
34 |
+ |
*/ |
|
35 |
+ |
private boolean asHtml; |
|
36 |
+ |
|
|
37 |
+ |
/** |
|
38 |
+ |
* Construct a new {@link DefaultCellRenderer}. |
|
39 |
+ |
*/ |
|
40 |
+ |
public DefaultCellRenderer() |
|
41 |
+ |
{ |
|
42 |
+ |
} |
|
43 |
+ |
|
|
44 |
+ |
/** |
|
45 |
+ |
* Construct a new {@link DefaultCellRenderer}. |
|
46 |
+ |
* |
|
47 |
+ |
* @param asHtml if true, non-widget cell contents will be rendered as html |
|
48 |
+ |
*/ |
|
49 |
+ |
public DefaultCellRenderer( boolean asHtml ) |
|
50 |
+ |
{ |
|
51 |
+ |
this.asHtml = asHtml; |
|
52 |
+ |
} |
|
53 |
+ |
|
|
54 |
+ |
public void renderRowValue( RowType rowValue, ColumnDefinition<RowType, ColType> columnDef, AbstractCellView<RowType> view ) |
|
55 |
+ |
{ |
|
56 |
+ |
Object cellValue = columnDef.getCellValue( rowValue ); |
|
57 |
+ |
if ( cellValue == null ) |
|
58 |
+ |
{ |
|
59 |
+ |
view.setText( "" ); |
|
60 |
+ |
} |
|
61 |
+ |
else if ( cellValue instanceof Widget ) |
|
62 |
+ |
{ |
|
63 |
+ |
view.setWidget( (Widget) cellValue ); |
|
64 |
+ |
} |
|
65 |
+ |
else if ( asHtml ) |
|
66 |
+ |
{ |
|
67 |
+ |
view.setHTML( cellValue.toString() ); |
|
68 |
+ |
} |
|
69 |
+ |
else |
|
70 |
+ |
{ |
|
71 |
+ |
view.setText( cellValue.toString() ); |
|
72 |
+ |
} |
65 |
73 |
|
} |
66 |
|
- |
} |
67 |
74 |
|
} |