litesoft
@ 947
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 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.server; import java.io.*; import org.litesoft.commonfoundation.exceptions.*; import org.litesoft.commonfoundation.typeutils.*; import java.util.*; import org.litesoft.db.*; import org.litesoft.orsup.base.*; import com.google.gwt.gen2.table.client.*; import com.google.gwt.gen2.table.client.TableDefinition.*; import com.google.gwt.user.client.ui.HasHorizontalAlignment.*; import com.google.gwt.user.client.ui.HasVerticalAlignment.*; import com.google.gwt.user.client.ui.*; public class TableReportRenderer<RowType extends PersistentObject> implements HasTableDefinition<RowType> { private ReportTableDefinition<RowType> mTableDefinition; public TableReportRenderer( ReportTableDefinition<RowType> pTableDefinition ) { mTableDefinition = pTableDefinition; } @Override public TableDefinition<RowType> getTableDefinition() { return mTableDefinition; } public final void renderRows( Writer pWriter, Iterator<RowType> rows ) throws DBException, FileSystemException { try { pWriter.append( " <table cellspacing='0' cellpadding='0' border='0'>\n" ); pWriter.append( " <thead>\n" ); mTableDefinition.addHeaders( pWriter ); pWriter.append( " </thead>\n" ); pWriter.append( " <tbody>\n" ); mTableDefinition.addInitialBodyRows( pWriter ); getTableDefinition().renderRows( 0, rows, // new ReportRowView<RowType>( pWriter, // new ReportCellView<RowType>( pWriter, this ) ) ); mTableDefinition.addFinalBodyRows( pWriter ); pWriter.append( " </tbody>\n" ); pWriter.append( " <tfoot>\n" ); mTableDefinition.addFooters( pWriter ); pWriter.append( " </tfoot>\n" ); pWriter.append( " </table>" ); } catch ( IOException e ) { throw new FileSystemException( e ); } } protected static class ReportCellView<RowType> extends AbstractCellView<RowType> { private Writer mWriter; private HorizontalAlignmentConstant curCellHorizontalAlign = null; private String curCellHtml = null; private Map<String, String> curCellStyles = new HashMap<String, String>(); private String curCellStyleName = null; private VerticalAlignmentConstant curCellVerticalAlign = null; public ReportCellView( Writer pWriter, HasTableDefinition<RowType> pHasTableDefinition ) { super( pHasTableDefinition ); mWriter = pWriter; } @Override public void setHorizontalAlignment( HorizontalAlignmentConstant align ) { curCellHorizontalAlign = align; } @Override public void setHTML( String html ) { curCellHtml = html; } @Override public void setStyleAttribute( String attr, String value ) { curCellStyles.put( attr, value ); } @Override public void setStyleName( String stylename ) { curCellStyleName = stylename; } @Override public void setText( String text ) { throw new UnsupportedOperationException( "setText(String) is not supported by the TableReportRenderer. Use setHTML(String) instead." ); } @Override public void setVerticalAlignment( VerticalAlignmentConstant align ) { curCellVerticalAlign = align; } @Override public void setWidget( Widget widget ) { throw new UnsupportedOperationException(); } @Override protected void renderRowValue( RowType rowValue, ColumnDefinition columnDef ) { curCellHtml = null; curCellStyleName = null; curCellHorizontalAlign = null; curCellVerticalAlign = null; curCellStyles.clear(); super.renderRowValue( rowValue, columnDef ); // Add the open tag try { mWriter.append( " <td" ); if ( curCellHorizontalAlign != null ) { mWriter.append( " align=\"" ); mWriter.append( curCellHorizontalAlign.getTextAlignString() ); mWriter.append( "\"" ); } if ( curCellVerticalAlign != null ) { mWriter.append( " valign=\"" ); mWriter.append( curCellVerticalAlign.getVerticalAlignString() ); mWriter.append( "\"" ); } if ( curCellStyleName != null ) { mWriter.append( " class=\"" ); mWriter.append( curCellStyleName ); mWriter.append( "\"" ); } if ( curCellStyles.size() > 0 ) { mWriter.append( " style=\"" ); for ( Map.Entry<String, String> entry : curCellStyles.entrySet() ) { mWriter.append( fixStyleNames( entry.getKey() ) ); mWriter.append( ":" ); mWriter.append( entry.getValue() ); mWriter.append( ";" ); } mWriter.append( "\"" ); } mWriter.append( ">" ); // Add contents if ( curCellHtml != null ) { mWriter.append( curCellHtml ); } // Add close tag mWriter.append( "</td>\n" ); } catch ( IOException e ) { throw new FileSystemException( e ); } } } protected static class ReportRowView<RowType> extends AbstractRowView<RowType> { private Writer mWriter; private Map<String, String> curRowStyles = new HashMap<String, String>(); private String curRowStyleName = null; private int rowIndex = 0; public ReportRowView( Writer pWriter, ReportCellView<RowType> cellView ) { super( cellView ); mWriter = pWriter; } @Override public void setStyleAttribute( String attr, String value ) { curRowStyles.put( attr, value ); } @Override public void setStyleName( String stylename ) { curRowStyleName = stylename; } @Override protected void renderRowImpl( int rowIndex, RowType rowValue, RowRenderer<RowType> rowRenderer, List<ColumnDefinition<RowType, ?>> visibleColumns ) { super.renderRowImpl( rowIndex, rowValue, rowRenderer, visibleColumns ); try { mWriter.append( " </tr>\n" ); } catch ( IOException e ) { throw new FileSystemException( e ); } } @Override protected void renderRowsImpl( int startRowIndex, final Iterator<RowType> rowValues, final RowRenderer<RowType> rowRenderer, final List<ColumnDefinition<RowType, ?>> visibleColumns ) { // Reset the row index rowIndex = startRowIndex; // Loop through the rows while ( rowValues.hasNext() ) { // Render a single row and increment the row index renderRowImpl( rowIndex, rowValues.next(), rowRenderer, visibleColumns ); rowIndex++; } } @Override protected void renderRowValue( RowType rowValue, RowRenderer<RowType> rowRenderer ) { curRowStyleName = null; curRowStyles.clear(); super.renderRowValue( rowValue, rowRenderer ); // Add the open tag try { mWriter.append( " <tr" ); if ( curRowStyleName != null ) { mWriter.append( " class=\"" ); mWriter.append( curRowStyleName ); mWriter.append( "\"" ); } if ( curRowStyles.size() > 0 ) { mWriter.append( " style=\"" ); for ( Map.Entry<String, String> entry : curRowStyles.entrySet() ) { mWriter.append( fixStyleNames( entry.getKey() ) ); mWriter.append( ":" ); mWriter.append( entry.getValue() ); mWriter.append( ";" ); } mWriter.append( "\"" ); } mWriter.append( ">\n" ); } catch ( IOException e ) { throw new FileSystemException( e ); } } } private static String fixStyleNames( String pJSstyleName ) { String zValue = STYLE_MAP.get( pJSstyleName ); if ( zValue == null ) { System.err.println( "What is: " + pJSstyleName ); return pJSstyleName; } return zValue; } public static final Map<String, String> STYLE_MAP // = Maps.createHashMap( "paddingTop", "padding-top", // "paddingRight", "padding-right", // "paddingBottom", "padding-bottom", // "paddingLeft", "padding-left", // "", "", // "", "" ); } |
Commits for litesoft/trunk/Java/GWT/Server/src/org/litesoft/GWT/server/TableReportRenderer.java
Revision | Author | Commited | Message |
---|---|---|---|
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
821 Diff | GeorgeS | Sun 19 Aug, 2012 00:08:41 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
25 Diff | GeorgeS | Mon 01 Mar, 2010 14:09:51 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |