litesoft
@ 25
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 |
package org.litesoft.GWT.server; import org.litesoft.GWT.client.widgets.datatables.*; import org.litesoft.core.util.*; import org.litesoft.orsup.base.*; import org.litesoft.util.*; import com.google.gwt.user.client.ui.*; public class ReportColumnDefinition<T extends PersistentObject> extends TableColumnDefinition<T> { private final ValueAccessor<T> mValueAccessor; public ReportColumnDefinition( HasHorizontalAlignment.HorizontalAlignmentConstant pHorizontalAlignment, String pHeaderText ) { this( null, pHorizontalAlignment, null, pHeaderText ); } public ReportColumnDefinition( HasHorizontalAlignment.HorizontalAlignmentConstant pHorizontalAlignment, String pHeaderText, TableCellRenderer.Builder pCellRendererBuilder ) { this( new ReportCellRenderer<T>( pCellRendererBuilder ), pHorizontalAlignment, null, pHeaderText ); } public ReportColumnDefinition( HasHorizontalAlignment.HorizontalAlignmentConstant pHorizontalAlignment, String pHeaderText, ReportCellRenderer<T> pCellRenderer ) { this( pCellRenderer, pHorizontalAlignment, null, pHeaderText ); } public ReportColumnDefinition( String[] pAttributeNamePath ) { this( null, null, pAttributeNamePath, null ); } public ReportColumnDefinition( String[] pAttributeNamePath, TableCellRenderer.Builder pCellRendererBuilder ) { this( new ReportCellRenderer<T>( pCellRendererBuilder ), null, pAttributeNamePath, null ); } public ReportColumnDefinition( String[] pAttributeNamePath, ReportCellRenderer<T> pCellRenderer ) { this( pCellRenderer, null, pAttributeNamePath, null ); } public ReportColumnDefinition( String[] pAttributeNamePath, String pHeaderText ) { this( null, null, pAttributeNamePath, pHeaderText ); } public ReportColumnDefinition( String[] pAttributeNamePath, String pHeaderText, TableCellRenderer.Builder pCellRendererBuilder ) { this( new ReportCellRenderer<T>( pCellRendererBuilder ), null, pAttributeNamePath, pHeaderText ); } public ReportColumnDefinition( String[] pAttributeNamePath, String pHeaderText, ReportCellRenderer<T> pCellRenderer ) { this( pCellRenderer, null, pAttributeNamePath, pHeaderText ); } public ReportColumnDefinition( String[] pAttributeNamePath, HasHorizontalAlignment.HorizontalAlignmentConstant pHorizontalAlignment, TableCellRenderer.Builder pCellRendererBuilder ) { this( new ReportCellRenderer<T>( pCellRendererBuilder ), pHorizontalAlignment, pAttributeNamePath, null ); } public ReportColumnDefinition( String[] pAttributeNamePath, HasHorizontalAlignment.HorizontalAlignmentConstant pHorizontalAlignment, ReportCellRenderer<T> pCellRenderer ) { this( pCellRenderer, pHorizontalAlignment, pAttributeNamePath, null ); } public ReportColumnDefinition( String[] pAttributeNamePath, String pHeaderText, HasHorizontalAlignment.HorizontalAlignmentConstant pHorizontalAlignment, TableCellRenderer.Builder pCellRendererBuilder ) { this( new ReportCellRenderer<T>( pCellRendererBuilder ), pHorizontalAlignment, pAttributeNamePath, pHeaderText ); } public ReportColumnDefinition( String[] pAttributeNamePath, String pHeaderText, HasHorizontalAlignment.HorizontalAlignmentConstant pHorizontalAlignment, ReportCellRenderer<T> pCellRenderer ) { this( pCellRenderer, pHorizontalAlignment, pAttributeNamePath, pHeaderText ); } public ReportColumnDefinition( ReportCellRenderer<T> pCellRenderer, HasHorizontalAlignment.HorizontalAlignmentConstant pHorizontalAlignment, String[] pAttributeNamePath, String pHeaderText ) { super( null, ReportCellRenderer.deNull( pCellRenderer ) ); if ( pHorizontalAlignment != null ) { align( pHorizontalAlignment ); } if ( null == (pAttributeNamePath = Utils.noEmpty( pAttributeNamePath )) ) { if ( pHeaderText == null ) { throw new IllegalArgumentException( "Either HeaderText or the AttibuteNamePath must not be null" ); } header( pHeaderText ); mValueAccessor = new InvalidValueAccessor<T>(); } else { header( (pHeaderText != null) ? pHeaderText : DeCamelizer.resolve( pAttributeNamePath[pAttributeNamePath.length - 1] ) ); if ( pAttributeNamePath.length == 1 ) { mValueAccessor = new DirectValueAccessor<T>( pAttributeNamePath[0] ); } else { mValueAccessor = new PathValueAccessor<T>( pAttributeNamePath ); } } } @SuppressWarnings({"unchecked"}) @Override public Object getCellValue( T pRowValue ) { return mValueAccessor.getValue( pRowValue ); } private interface ValueAccessor<T extends PersistentObject> { public Object getValue( T pRowValue ); } private static class InvalidValueAccessor<T extends PersistentObject> implements ValueAccessor<T> { @Override public Object getValue( T pRowValue ) { throw new IllegalStateException( "getCellValue( T ) Not Overridden" ); } } private static class DirectValueAccessor<T extends PersistentObject> implements ValueAccessor<T> { private String mAttributeName; public DirectValueAccessor( String pAttributeName ) { mAttributeName = pAttributeName; } @Override public Object getValue( T pRowValue ) { return pRowValue.getAttributeValue( mAttributeName ); } } private static class PathValueAccessor<T extends PersistentObject> implements ValueAccessor<T> { private String[] mAttributeNamePath; private int mLastIndex; public PathValueAccessor( String[] pAttributeNamePath ) { mLastIndex = (mAttributeNamePath = pAttributeNamePath).length - 1; } @Override public Object getValue( T pRowValue ) { PersistentObject zPO = pRowValue; for ( int i = 0; i < mLastIndex; i++ ) { String zAttributeName = mAttributeNamePath[i]; if ( null == (zPO = (PersistentObject) zPO.getAttributeValue( zAttributeName )) ) { return null; } } return zPO.getAttributeValue( mAttributeNamePath[mLastIndex] ); } } } |