Subversion Repository Public Repository

litesoft

Diff Revisions 49 vs 151 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/datatables/AccordionTable.java

Diff revisions: vs.
  @@ -14,15 +14,16 @@
14 14 import com.google.gwt.gen2.table.client.TableDefinition.*;
15 15 import com.google.gwt.gen2.table.client.TableModelHelper.*;
16 16 import com.google.gwt.gen2.table.client.property.*;
17 - import com.google.gwt.user.client.*;
18 17 import com.google.gwt.user.client.Element;
18 + import com.google.gwt.user.client.*;
19 19 import com.google.gwt.user.client.Timer;
20 20 import com.google.gwt.user.client.ui.*;
21 21 import com.google.gwt.user.client.ui.HasHorizontalAlignment.*;
22 22 import com.google.gwt.user.client.ui.HasVerticalAlignment.*;
23 23 import com.google.gwt.widgetideas.client.*;
24 24
25 - public class AccordionTable<RowType> extends Composite implements HasTableDefinition<RowType>, HasShowRangeHandlers<Integer>
25 + public class AccordionTable<RowType> extends Composite implements HasTableDefinition<RowType>,
26 + HasShowRangeHandlers<Integer>
26 27 {
27 28 private final ListTableModel<RowType> mModel = new ListTableModel<RowType>();
28 29 private final AccordionTableTable mTable = new AccordionTableTable();
  @@ -45,25 +46,25 @@
45 46 public AccordionTable()
46 47 {
47 48 AbsolutePanel viewport = new AbsolutePanel();
48 - ResizableWidgetCollection.get().add(new ResizableWidgetAdaptor(this, viewport.getElement())
49 + ResizableWidgetCollection.get().add( new ResizableWidgetAdaptor( this, viewport.getElement() )
49 50 {
50 51 @Override
51 - public void onResize(int pWidth, int pHeight)
52 + public void onResize( int pWidth, int pHeight )
52 53 {
53 54 mViewportHeight = pHeight;
54 55 sizeOrDataChanged();
55 56 }
56 - });
57 - viewport.add(mTable, 0, 0);
58 - UIObject.setVisible(mGlassPane, false);
59 - mGlassPane.getStyle().setProperty("width", "100%");
60 - viewport.getElement().appendChild(mGlassPane);
61 - initWidget(viewport);
57 + } );
58 + viewport.add( mTable, 0, 0 );
59 + UIObject.setVisible( mGlassPane, false );
60 + mGlassPane.getStyle().setProperty( "width", "100%" );
61 + viewport.getElement().appendChild( mGlassPane );
62 + initWidget( viewport );
62 63 setStyleName( STYLE );
63 - setHeight("100%");
64 - setWidth("100%");
65 - mTable.setWidth("100%");
66 - mTable.addHighlightHandler(new HoverController());
64 + setHeight( "100%" );
65 + setWidth( "100%" );
66 + mTable.setWidth( "100%" );
67 + mTable.addHighlightHandler( new HoverController() );
67 68 }
68 69
69 70 /**
  @@ -73,54 +74,56 @@
73 74 * @see #getVisibleRowCount()
74 75 */
75 76 @Override
76 - public HandlerRegistration addShowRangeHandler(ShowRangeHandler<Integer> pHandler)
77 + public HandlerRegistration addShowRangeHandler( ShowRangeHandler<Integer> pHandler )
77 78 {
78 - return addHandler(pHandler, ShowRangeEvent.getType());
79 + return addHandler( pHandler, ShowRangeEvent.getType() );
79 80 }
80 81
81 - public void init(TableModel<RowType> pTableModel, TableDefinitionPlus<RowType> pTableDefinition)
82 + public void init( TableModel<RowType> pTableModel, TableDefinitionPlus<RowType> pTableDefinition )
82 83 {
83 84 RowType prototypeRowValue = pTableDefinition.getPrototypeRowValue();
84 85
85 - if (prototypeRowValue == null)
86 - throw new IllegalArgumentException("TableDefinition.prototypeRowValue cannot be null for AccordionTable");
86 + if ( prototypeRowValue == null )
87 + {
88 + throw new IllegalArgumentException( "TableDefinition.prototypeRowValue cannot be null for AccordionTable" );
89 + }
87 90
88 91 mDataSource = pTableModel;
89 92 mTableDefinition = pTableDefinition;
90 93
91 94 List<ColumnDefinition<RowType, ?>> colDefs = pTableDefinition.getVisibleColumnDefinitions();
92 - for (int col = 0, size = colDefs.size(); col < size; col++)
95 + for ( int col = 0, size = colDefs.size(); col < size; col++ )
93 96 {
94 - ColumnDefinition<RowType, ?> colDef = colDefs.get(col);
95 - Object headerValue = colDef.getColumnProperty(HeaderProperty.TYPE).getHeader(0);
96 - HorizontalAlignmentConstant alignment = colDef.getColumnProperty( HorizontalAlignmentProperty.TYPE).getValue();
97 - Element td = mTable.setHeader(col, headerValue, alignment);
97 + ColumnDefinition<RowType, ?> colDef = colDefs.get( col );
98 + Object headerValue = colDef.getColumnProperty( HeaderProperty.TYPE ).getHeader( 0 );
99 + HorizontalAlignmentConstant alignment = colDef.getColumnProperty( HorizontalAlignmentProperty.TYPE ).getValue();
100 + Element td = mTable.setHeader( col, headerValue, alignment );
98 101 Style style = td.getStyle();
99 - style.setPropertyPx("paddingLeft", colDef.getColumnProperty(PaddingProperty.LEFT).getValue());
100 - style.setPropertyPx("paddingRight", colDef.getColumnProperty(PaddingProperty.RIGHT).getValue());
101 - style.setPropertyPx("paddingTop", colDef.getColumnProperty(PaddingProperty.TOP).getValue());
102 - style.setPropertyPx("paddingBottom", colDef.getColumnProperty(PaddingProperty.BOTTOM).getValue());
103 - int minWidth = colDef.getColumnProperty(MinimumWidthProperty.TYPE).getMinimumColumnWidth();
104 - int maxWidth = colDef.getColumnProperty(MaximumWidthProperty.TYPE).getMaximumColumnWidth();
105 - if (minWidth != MinimumWidthProperty.NO_MINIMUM_WIDTH)
102 + style.setPropertyPx( "paddingLeft", colDef.getColumnProperty( PaddingProperty.LEFT ).getValue() );
103 + style.setPropertyPx( "paddingRight", colDef.getColumnProperty( PaddingProperty.RIGHT ).getValue() );
104 + style.setPropertyPx( "paddingTop", colDef.getColumnProperty( PaddingProperty.TOP ).getValue() );
105 + style.setPropertyPx( "paddingBottom", colDef.getColumnProperty( PaddingProperty.BOTTOM ).getValue() );
106 + int minWidth = colDef.getColumnProperty( MinimumWidthProperty.TYPE ).getMinimumColumnWidth();
107 + int maxWidth = colDef.getColumnProperty( MaximumWidthProperty.TYPE ).getMaximumColumnWidth();
108 + if ( minWidth != MinimumWidthProperty.NO_MINIMUM_WIDTH )
106 109 {
107 - mTable.setColumnWidth(col, maxWidth);
110 + mTable.setColumnWidth( col, maxWidth );
108 111 }
109 - else if (maxWidth != MaximumWidthProperty.NO_MAXIMUM_WIDTH)
112 + else if ( maxWidth != MaximumWidthProperty.NO_MAXIMUM_WIDTH )
110 113 {
111 - mTable.setColumnWidth(col, maxWidth);
114 + mTable.setColumnWidth( col, maxWidth );
112 115 }
113 116 }
114 117
115 118 // setup w/ some fake data so we can calculate row heights
116 - mTable.setFooter(0, "&nbsp;", null, 0);
117 - mTable.resizeRows(2);
118 - final Element detailTr = mTable.getRowElement(0);
119 - final Element normalTr = mTable.getRowElement(1);
120 - detailTr.getStyle().setProperty("visibility", "hidden");
121 - normalTr.getStyle().setProperty("visibility", "hidden");
119 + mTable.setFooter( 0, "&nbsp;", null, 0 );
120 + mTable.resizeRows( 2 );
121 + final Element detailTr = mTable.getRowElement( 0 );
122 + final Element normalTr = mTable.getRowElement( 1 );
123 + detailTr.getStyle().setProperty( "visibility", "hidden" );
124 + normalTr.getStyle().setProperty( "visibility", "hidden" );
122 125 AccordionTable.AccordionTableTable.RowView<RowType> rowView = mTable.new RowView<RowType>();
123 - AccordionTable.AccordionTableTable.CellView<RowType> cellView = mTable.new CellView<RowType>(-1, new DetailRowModel<RowType>()
126 + AccordionTable.AccordionTableTable.CellView<RowType> cellView = mTable.new CellView<RowType>( -1, new DetailRowModel<RowType>()
124 127 {
125 128 @Override
126 129 public DetailRowAlignment getAlign()
  @@ -135,49 +138,48 @@
135 138 }
136 139
137 140 @Override
138 - public boolean isDetailRow(int pIndex)
141 + public boolean isDetailRow( int pIndex )
139 142 {
140 143 return pIndex == 0;
141 144 }
142 -
143 - });
144 - renderRowImpl(0, prototypeRowValue, rowView, cellView);
145 - renderRowImpl(1, prototypeRowValue, rowView, cellView);
146 - ResizableWidgetCollection.get().add(new TemporaryResizableWidgetAdaptor(this, mTable.getElement())
145 + } );
146 + renderRowImpl( 0, prototypeRowValue, rowView, cellView );
147 + renderRowImpl( 1, prototypeRowValue, rowView, cellView );
148 + ResizableWidgetCollection.get().add( new TemporaryResizableWidgetAdaptor( this, mTable.getElement() )
147 149 {
148 150 @Override
149 - protected void onSizeInitialized(int pWidth, int pHeight)
151 + protected void onSizeInitialized( int pWidth, int pHeight )
150 152 {
151 153 mHeaderRowHeight = mTable.getHeaderRowElement().getOffsetHeight();
152 154 mFooterRowHeight = mTable.getFooterRowElement().getOffsetHeight();
153 155 mPrototypeDetailRowHeight = detailTr.getOffsetHeight();
154 156 mPrototypeNormalRowHeight = normalTr.getOffsetHeight();
155 - mTable.resizeRows(0);
157 + mTable.resizeRows( 0 );
156 158 sizeOrDataChanged();
157 159 }
158 - });
160 + } );
159 161
160 - mTable.addClickHandler(new TableHelper.GridClickHandler<RowType>(1, mTable.getGridHelper(), colDefs)
162 + mTable.addClickHandler( new TableHelper.GridClickHandler<RowType>( 1, mTable.getGridHelper(), colDefs )
161 163 {
162 164 @Override
163 - protected RowType getRowValue(int pRow)
165 + protected RowType getRowValue( int pRow )
164 166 {
165 - return mModel.get(pRow);
167 + return mModel.get( pRow );
166 168 }
167 - });
169 + } );
168 170 loadData();
169 171 }
170 172
171 173 public void loadData()
172 174 {
173 175 mOutstandingRequest = new TableModelHelper.Request();
174 - mDataSource.requestRows(mOutstandingRequest, new TableModel.Callback<RowType>()
176 + mDataSource.requestRows( mOutstandingRequest, new TableModel.Callback<RowType>()
175 177 {
176 178 @Override
177 - public void onRowsReady(Request pRequest, Response<RowType> pResponse)
179 + public void onRowsReady( Request pRequest, Response<RowType> pResponse )
178 180 {
179 181 // ignore responses to stale requests
180 - if (pRequest == mOutstandingRequest)
182 + if ( pRequest == mOutstandingRequest )
181 183 {
182 184 mOutstandingRequest = null;
183 185 mDataToRenderPendingSize = pResponse.getRowValues();
  @@ -186,68 +188,64 @@
186 188 }
187 189
188 190 @Override
189 - public void onFailure(Throwable pCaught)
191 + public void onFailure( Throwable pCaught )
190 192 {
191 193 // TODO: handle requestRows() failure
192 - Window.alert(pCaught.getMessage());
194 + Window.alert( pCaught.getMessage() );
193 195 }
194 - });
196 + } );
195 197 }
196 198
197 199 private boolean isSizeInitialized()
198 200 {
199 - return mViewportHeight > 0 &&
200 - mHeaderRowHeight > 0 &&
201 - mFooterRowHeight > 0 &&
202 - mPrototypeDetailRowHeight > 0 &&
203 - mPrototypeNormalRowHeight > 0;
201 + return mViewportHeight > 0 && mHeaderRowHeight > 0 && mFooterRowHeight > 0 && mPrototypeDetailRowHeight > 0 && mPrototypeNormalRowHeight > 0;
204 202 }
205 203
206 204 private void sizeOrDataChanged()
207 205 {
208 - if (isSizeInitialized())
206 + if ( isSizeInitialized() )
209 207 {
210 208 boolean fireRowCountChanged = false;
211 209 boolean fireShowRange = false;
212 210 int oldVisibleRowCount = getVisibleRowCount();
213 211 // TODO: subtract header and (optional) footer height
214 - int maxWholeRows = Math.max(1, (mViewportHeight - mPrototypeDetailRowHeight - mHeaderRowHeight - mFooterRowHeight) / mPrototypeNormalRowHeight + 1);
215 - if (mMaxWholeRows != maxWholeRows)
212 + int maxWholeRows = Math.max( 1, (mViewportHeight - mPrototypeDetailRowHeight - mHeaderRowHeight - mFooterRowHeight) / mPrototypeNormalRowHeight + 1 );
213 + if ( mMaxWholeRows != maxWholeRows )
216 214 {
217 215 mMaxWholeRows = maxWholeRows;
218 216 fireRowCountChanged = true;
219 217 }
220 218 int visibleRowCount;
221 - if (mDataToRenderPendingSize != null)
219 + if ( mDataToRenderPendingSize != null )
222 220 {
223 221 int oldModelRowCount = getRowCount();
224 - mModel.setAll(mDataToRenderPendingSize);
222 + mModel.setAll( mDataToRenderPendingSize );
225 223 visibleRowCount = getVisibleRowCount(); // note: calculated using model size
226 - mDetailRowModel.update(mModel.mList, 0, visibleRowCount);
224 + mDetailRowModel.update( mModel.mList, 0, visibleRowCount );
227 225 mDataToRenderPendingSize = null;
228 226 fireRowCountChanged |= getRowCount() != oldModelRowCount;
229 227 fireShowRange = true;
230 - mTable.resizeRows(visibleRowCount);
231 - renderRows(0, visibleRowCount);
228 + mTable.resizeRows( visibleRowCount );
229 + renderRows( 0, visibleRowCount );
232 230 }
233 231 else
234 232 {
235 233 visibleRowCount = getVisibleRowCount();
236 - mTable.resizeRows(visibleRowCount);
237 - if (mDetailRowModel.update(mModel.mList, 0, visibleRowCount) && mDetailRowModel.getDetailRow() != -1)
234 + mTable.resizeRows( visibleRowCount );
235 + if ( mDetailRowModel.update( mModel.mList, 0, visibleRowCount ) && mDetailRowModel.getDetailRow() != -1 )
238 236 {
239 - renderRow(mDetailRowModel.getDetailRow());
237 + renderRow( mDetailRowModel.getDetailRow() );
240 238 }
241 - renderRows(oldVisibleRowCount, visibleRowCount - oldVisibleRowCount);
239 + renderRows( oldVisibleRowCount, visibleRowCount - oldVisibleRowCount );
242 240 }
243 241 fireShowRange |= visibleRowCount != oldVisibleRowCount;
244 - if (fireRowCountChanged && mRowCountCallback != null)
242 + if ( fireRowCountChanged && mRowCountCallback != null )
245 243 {
246 - mRowCountCallback.rowCountChanged(visibleRowCount, mModel.getRowCount(), mMaxWholeRows);
244 + mRowCountCallback.rowCountChanged( visibleRowCount, mModel.getRowCount(), mMaxWholeRows );
247 245 }
248 - if (fireShowRange)
246 + if ( fireShowRange )
249 247 {
250 - ShowRangeEvent.fire(AccordionTable.this, 0, visibleRowCount);
248 + ShowRangeEvent.fire( AccordionTable.this, 0, visibleRowCount );
251 249 }
252 250 }
253 251 }
  @@ -260,62 +258,68 @@
260 258 /**
261 259 * @param pCount negative or 0 will be NOOP
262 260 */
263 - private void renderRows(int pStartRow, int pCount)
261 + private void renderRows( int pStartRow, int pCount )
264 262 {
265 - if (pCount <= 0)
263 + if ( pCount <= 0 )
264 + {
266 265 return;
266 + }
267 267
268 268 AccordionTable.AccordionTableTable.RowView<RowType> rowView = mTable.new RowView<RowType>();
269 - AccordionTable.AccordionTableTable.CellView<RowType> cellView = mTable.new CellView<RowType>(mPrototypeNormalRowHeight, mDetailRowModel);
270 - for (int row = pStartRow, terminus = pStartRow + pCount; row < terminus; row++)
269 + AccordionTable.AccordionTableTable.CellView<RowType> cellView = mTable.new CellView<RowType>( mPrototypeNormalRowHeight, mDetailRowModel );
270 + for ( int row = pStartRow, terminus = pStartRow + pCount; row < terminus; row++ )
271 271 {
272 - RowType rowValue = mModel.get(row);
273 - renderRowImpl(row, rowValue, rowView, cellView);
272 + RowType rowValue = mModel.get( row );
273 + renderRowImpl( row, rowValue, rowView, cellView );
274 274 }
275 275 }
276 276
277 - private void renderRowImpl(int pRowIndex, RowType pRowValue, AccordionTable.AccordionTableTable.RowView<RowType> pRowView, AccordionTable.AccordionTableTable.CellView<RowType> pCellView)
277 + private void renderRowImpl( int pRowIndex, RowType pRowValue, AccordionTable.AccordionTableTable.RowView<RowType> pRowView, AccordionTable.AccordionTableTable.CellView<RowType> pCellView )
278 278 {
279 - setGlassPaneVisible(true);
279 + setGlassPaneVisible( true );
280 280 RowRenderer<RowType> rowRenderer = mTableDefinition.getRowRenderer();
281 281 List<ColumnDefinition<RowType, ?>> colDefs = mTableDefinition.getVisibleColumnDefinitions();
282 - pRowView.setRowIndex(pRowIndex);
283 - rowRenderer.renderRowValue(pRowValue, pRowView);
284 - for (int col = 0, colCount = colDefs.size(); col < colCount; col++)
282 + pRowView.setRowIndex( pRowIndex );
283 + rowRenderer.renderRowValue( pRowValue, pRowView );
284 + for ( int col = 0, colCount = colDefs.size(); col < colCount; col++ )
285 285 {
286 - pCellView.renderAccordionCell(pRowIndex, col, pRowValue, colDefs.get(col));
286 + pCellView.renderAccordionCell( pRowIndex, col, pRowValue, colDefs.get( col ) );
287 287 }
288 - setGlassPaneVisible(false);
288 + setGlassPaneVisible( false );
289 289 }
290 290
291 - public void renderFooter(String[] pValues)
291 + public void renderFooter( String[] pValues )
292 292 {
293 - if (pValues.length > mTable.getColumnCount())
294 - throw new IllegalArgumentException(String.valueOf(pValues.length));
293 + if ( pValues.length > mTable.getColumnCount() )
294 + {
295 + throw new IllegalArgumentException( String.valueOf( pValues.length ) );
296 + }
295 297
296 - if (mTableDefinition == null)
298 + if ( mTableDefinition == null )
299 + {
297 300 throw new IllegalStateException();
301 + }
298 302
299 303 List<ColumnDefinition<RowType, ?>> colDefs = mTableDefinition.getVisibleColumnDefinitions();
300 - for (int col = 0; col < pValues.length; col++)
304 + for ( int col = 0; col < pValues.length; col++ )
301 305 {
302 - ColumnDefinition<RowType, ?> colDef = colDefs.get(col);
306 + ColumnDefinition<RowType, ?> colDef = colDefs.get( col );
303 307 int zPaddingRight = colDef.getColumnProperty( PaddingProperty.RIGHT ).getValue();
304 308 String footerValue = pValues[col];
305 - HorizontalAlignmentConstant alignment = colDef.getColumnProperty( HorizontalAlignmentProperty.TYPE).getValue();
306 - mTable.setFooter(col, footerValue, alignment, zPaddingRight );
309 + HorizontalAlignmentConstant alignment = colDef.getColumnProperty( HorizontalAlignmentProperty.TYPE ).getValue();
310 + mTable.setFooter( col, footerValue, alignment, zPaddingRight );
307 311 }
308 312 }
309 313
310 - private void setGlassPaneVisible(boolean visible)
314 + private void setGlassPaneVisible( boolean visible )
311 315 {
312 - mGlassPane.getStyle().setPropertyPx("height", mViewportHeight);
313 - UIObject.setVisible(mGlassPane, visible);
316 + mGlassPane.getStyle().setPropertyPx( "height", mViewportHeight );
317 + UIObject.setVisible( mGlassPane, visible );
314 318 }
315 319
316 - public void setFooterAlignment(int col, HorizontalAlignmentConstant pAlign)
320 + public void setFooterAlignment( int col, HorizontalAlignmentConstant pAlign )
317 321 {
318 - mTable.setFooterAlignment(col, pAlign);
322 + mTable.setFooterAlignment( col, pAlign );
319 323 }
320 324
321 325 public DetailRowCallback<RowType> getDetailRowCallback()
  @@ -323,9 +327,9 @@
323 327 return mDetailRowModel.getCallback();
324 328 }
325 329
326 - public void setDetailRowCallback(DetailRowCallback<RowType> pDetailRowCallback)
330 + public void setDetailRowCallback( DetailRowCallback<RowType> pDetailRowCallback )
327 331 {
328 - mDetailRowModel.setCallback(pDetailRowCallback);
332 + mDetailRowModel.setCallback( pDetailRowCallback );
329 333 }
330 334
331 335 @Override
  @@ -334,14 +338,14 @@
334 338 return mTableDefinition;
335 339 }
336 340
337 - public RowType getRowValue(int pRow)
341 + public RowType getRowValue( int pRow )
338 342 {
339 - return mModel.get(pRow);
343 + return mModel.get( pRow );
340 344 }
341 345
342 346 public int getVisibleRowCount()
343 347 {
344 - return Math.min(mModel.size(), mMaxWholeRows);
348 + return Math.min( mModel.size(), mMaxWholeRows );
345 349 }
346 350
347 351 public int getRowCount()
  @@ -354,7 +358,7 @@
354 358 return mRowCountCallback;
355 359 }
356 360
357 - public void setRowCountCallback(TableRowCountCallback pRowCountCallback)
361 + public void setRowCountCallback( TableRowCountCallback pRowCountCallback )
358 362 {
359 363 mRowCountCallback = pRowCountCallback;
360 364 }
  @@ -364,26 +368,26 @@
364 368 private final HoverTimer mHoverTimer = new HoverTimer();
365 369
366 370 @Override
367 - public void onHighlight(HighlightEvent<Integer> pEvent)
371 + public void onHighlight( HighlightEvent<Integer> pEvent )
368 372 {
369 - mHoverTimer.setHoverRow(pEvent.getHighlighted());
373 + mHoverTimer.setHoverRow( pEvent.getHighlighted() );
370 374 }
371 375
372 - private void doHighlight(int pNewRow)
376 + private void doHighlight( int pNewRow )
373 377 {
374 378 int oldRow = mDetailRowModel.getDetailRow();
375 - if (mDetailRowModel.maybeSetDetailRow(pNewRow, mModel.get(pNewRow)))
379 + if ( mDetailRowModel.maybeSetDetailRow( pNewRow, mModel.get( pNewRow ) ) )
376 380 {
377 381 // render greater row first to avoid layout settling from incremental rendering
378 - int greaterRow = Math.max(oldRow, pNewRow);
379 - int lesserRow = Math.min(oldRow, pNewRow);
380 - if (greaterRow != -1)
382 + int greaterRow = Math.max( oldRow, pNewRow );
383 + int lesserRow = Math.min( oldRow, pNewRow );
384 + if ( greaterRow != -1 )
381 385 {
382 - renderRows(greaterRow, 1);
386 + renderRows( greaterRow, 1 );
383 387 }
384 - if (lesserRow != -1)
388 + if ( lesserRow != -1 )
385 389 {
386 - renderRows(lesserRow, 1);
390 + renderRows( lesserRow, 1 );
387 391 }
388 392 }
389 393 }
  @@ -395,23 +399,23 @@
395 399 */
396 400 private int mRow = -1;
397 401
398 - public void setHoverRow(int pRow)
402 + public void setHoverRow( int pRow )
399 403 {
400 - if (mRow != -1)
404 + if ( mRow != -1 )
401 405 {
402 406 cancel();
403 407 }
404 408 mRow = pRow;
405 - if (mRow != -1)
409 + if ( mRow != -1 )
406 410 {
407 - schedule(250);
411 + schedule( 250 );
408 412 }
409 413 }
410 414
411 415 @Override
412 416 public void run()
413 417 {
414 - doHighlight(mRow);
418 + doHighlight( mRow );
415 419 mRow = -1;
416 420 }
417 421 }
  @@ -434,25 +438,25 @@
434 438 public AccordionTableTable()
435 439 {
436 440 RowFormatter rowFormatter = new RowFormatter();
437 - setRowFormatter(rowFormatter);
438 - setCellFormatter(new CellFormatter());
439 - UIObject.setStylePrimaryName(rowFormatter.ensureElement(0), "AccordionTable-headerRow");
440 - setCellPadding(0);
441 - setCellSpacing(0);
442 - sinkEvents(Event.ONMOUSEOVER);
443 - sinkEvents(Event.ONMOUSEOUT);
444 - mGridHelper = new TableHelper.GridHelper(this)
441 + setRowFormatter( rowFormatter );
442 + setCellFormatter( new CellFormatter() );
443 + UIObject.setStylePrimaryName( rowFormatter.ensureElement( 0 ), "AccordionTable-headerRow" );
444 + setCellPadding( 0 );
445 + setCellSpacing( 0 );
446 + sinkEvents( Event.ONMOUSEOVER );
447 + sinkEvents( Event.ONMOUSEOUT );
448 + mGridHelper = new TableHelper.GridHelper( this )
445 449 {
446 450 @Override
447 - protected int getRowIndex(com.google.gwt.user.client.Element pRowElement)
451 + protected int getRowIndex( com.google.gwt.user.client.Element pRowElement )
448 452 {
449 - return AccordionTableTable.this.getRowIndex(pRowElement);
453 + return AccordionTableTable.this.getRowIndex( pRowElement );
450 454 }
451 455
452 456 @Override
453 - protected int getCellIndex(Element pRowElement, Element pCellElement)
457 + protected int getCellIndex( Element pRowElement, Element pCellElement )
454 458 {
455 - return AccordionTableTable.this.getCellIndex(pRowElement, pCellElement);
459 + return AccordionTableTable.this.getCellIndex( pRowElement, pCellElement );
456 460 }
457 461 };
458 462 }
  @@ -463,9 +467,9 @@
463 467 }
464 468
465 469 @Override
466 - public HandlerRegistration addHighlightHandler(HighlightHandler<Integer> pHandler)
470 + public HandlerRegistration addHighlightHandler( HighlightHandler<Integer> pHandler )
467 471 {
468 - return addHandler(pHandler, HighlightEvent.getType());
472 + return addHandler( pHandler, HighlightEvent.getType() );
469 473 }
470 474
471 475 public TableHelper.GridHelper getGridHelper()
  @@ -482,73 +486,73 @@
482 486 /**
483 487 * Get the element for the normal row (index is adjusted to account for header row).
484 488 */
485 - public Element getRowElement(int pRow)
489 + public Element getRowElement( int pRow )
486 490 {
487 - return getRowFormatter().getElement(pRow + 1);
491 + return getRowFormatter().getElement( pRow + 1 );
488 492 }
489 493
490 494 public Element getHeaderRowElement()
491 495 {
492 - return getRowFormatter().getElement(HEADER_ROW);
496 + return getRowFormatter().getElement( HEADER_ROW );
493 497 }
494 498
495 499 public Element getFooterRowElement()
496 500 {
497 501 ensureFooter();
498 - return getRowFormatter().getElement(mFooterRow);
502 + return getRowFormatter().getElement( mFooterRow );
499 503 }
500 504
501 - public Element setHeader(int pCol, Object pValue, HorizontalAlignmentConstant pAlign)
505 + public Element setHeader( int pCol, Object pValue, HorizontalAlignmentConstant pAlign )
502 506 {
503 - Element innerTd = ((CellFormatter) getCellFormatter()).ensureElement(HEADER_ROW, pCol);
507 + Element innerTd = ((CellFormatter) getCellFormatter()).ensureElement( HEADER_ROW, pCol );
504 508 Element innerTr = innerTd.getParentElement().cast();
505 509 Element innerTbody = innerTr.getParentElement().cast();
506 510 Element innerTable = innerTbody.getParentElement().cast();
507 511 Element outerTd = innerTable.getParentElement().cast();
508 512
509 513 // set the style name on the containing td so background styles will be 100% row height
510 - UIObject.setStylePrimaryName(outerTd, "AccordionTable-headerCell");
511 - if (pAlign != null)
514 + UIObject.setStylePrimaryName( outerTd, "AccordionTable-headerCell" );
515 + if ( pAlign != null )
512 516 {
513 - innerTd.setPropertyString("align", pAlign.getTextAlignString());
517 + innerTd.setPropertyString( "align", pAlign.getTextAlignString() );
514 518 }
515 - String stringValue = UtilsCommon.noEmpty((String) pValue);
516 - innerTd.setInnerHTML((stringValue != null) ? stringValue : "&nbsp;");
519 + String stringValue = UtilsCommon.noEmpty( (String) pValue );
520 + innerTd.setInnerHTML( (stringValue != null) ? stringValue : "&nbsp;" );
517 521 return innerTd;
518 522 }
519 523
520 - public void setFooter(int pCol, Object pValue, HorizontalAlignmentConstant pAlign, int pPaddingRight)
524 + public void setFooter( int pCol, Object pValue, HorizontalAlignmentConstant pAlign, int pPaddingRight )
521 525 {
522 526 int footerRow = ensureFooter();
523 - Element td = ((CellFormatter) getCellFormatter()).ensureElement(footerRow, pCol);
524 - UIObject.setStylePrimaryName(td, "AccordionTable-footerCell");
525 - if (pAlign != null)
527 + Element td = ((CellFormatter) getCellFormatter()).ensureElement( footerRow, pCol );
528 + UIObject.setStylePrimaryName( td, "AccordionTable-footerCell" );
529 + if ( pAlign != null )
526 530 {
527 - td.setPropertyString("align", pAlign.getTextAlignString());
531 + td.setPropertyString( "align", pAlign.getTextAlignString() );
528 532 }
529 - if( pPaddingRight > 0)
533 + if ( pPaddingRight > 0 )
530 534 {
531 535 Style style = td.getStyle();
532 - style.setPropertyPx("paddingRight", pPaddingRight );
536 + style.setPropertyPx( "paddingRight", pPaddingRight );
533 537 }
534 - String stringValue = UtilsCommon.noEmpty((String) pValue);
535 - td.setInnerHTML((stringValue != null) ? stringValue : "&nbsp;");
538 + String stringValue = UtilsCommon.noEmpty( (String) pValue );
539 + td.setInnerHTML( (stringValue != null) ? stringValue : "&nbsp;" );
536 540 }
537 541
538 - public void setFooterAlignment(int pCol, HorizontalAlignmentConstant pAlign)
542 + public void setFooterAlignment( int pCol, HorizontalAlignmentConstant pAlign )
539 543 {
540 - Element td = ((CellFormatter) getCellFormatter()).ensureElement(mFooterRow, pCol);
541 - td.setPropertyString("align", pAlign.getTextAlignString());
544 + Element td = ((CellFormatter) getCellFormatter()).ensureElement( mFooterRow, pCol );
545 + td.setPropertyString( "align", pAlign.getTextAlignString() );
542 546 }
543 547
544 548 private int ensureFooter()
545 549 {
546 550 int footerRowIndex;
547 551 boolean hasFooterRow = mFooterRow != -1;
548 - if (! hasFooterRow)
552 + if ( !hasFooterRow )
549 553 {
550 554 footerRowIndex = getRowCount();
551 - insertRow(footerRowIndex);
555 + insertRow( footerRowIndex );
552 556 mFooterRow = footerRowIndex;
553 557 }
554 558 else
  @@ -558,27 +562,27 @@
558 562 return footerRowIndex;
559 563 }
560 564
561 - public void resizeRows(int pRowCount)
565 + public void resizeRows( int pRowCount )
562 566 {
563 567 int actualCount = getRowCount() - 1; // subtract header row
564 568 boolean hasFooterRow = mFooterRow != -1;
565 - if (hasFooterRow)
569 + if ( hasFooterRow )
566 570 {
567 571 actualCount--;
568 572 }
569 - while (actualCount > pRowCount)
573 + while ( actualCount > pRowCount )
570 574 {
571 - removeRow(actualCount--);
575 + removeRow( actualCount-- );
572 576 }
573 - while (actualCount < pRowCount)
577 + while ( actualCount < pRowCount )
574 578 {
575 - insertRow(++actualCount);
579 + insertRow( ++actualCount );
576 580 }
577 - if (hasFooterRow)
581 + if ( hasFooterRow )
578 582 {
579 583 mFooterRow = actualCount + 1;
580 584 }
581 - if (mHilightedRow >= actualCount)
585 + if ( mHilightedRow >= actualCount )
582 586 {
583 587 mHilightedRow = -1;
584 588 }
  @@ -588,10 +592,10 @@
588 592 * Have to override super method to append div to td
589 593 */
590 594 @Override
591 - protected void addCells(int pRow, int pNum)
595 + protected void addCells( int pRow, int pNum )
592 596 {
593 597 // Account for ghost row
594 - addCells(getBodyElement(), pRow + 1, pNum);
598 + addCells( getBodyElement(), pRow + 1, pNum );
595 599 clearIdealWidths0();
596 600 }
597 601
  @@ -599,28 +603,28 @@
599 603 this.@com.google.gwt.gen2.table.client.FixedWidthFlexTable::clearIdealWidths()();
600 604 }-*/;
601 605
602 - private static native void addCells(Element table, int row, int num) /*-{
606 + private static native void addCells( Element table, int row, int num ) /*-{
603 607 var rowElem = table.rows[row];
604 - for(var i = 0; i < num; i++)
608 + for ( var i = 0; i < num; i++ )
605 609 {
606 - var cell = $doc.createElement("td");
610 + var cell = $doc.createElement( "td" );
607 611 cell['colSpan'] = 1;
608 612 cell['rowSpan'] = 1;
609 613
610 - var innerCell = $doc.createElement("td");
611 - innerCell.style["overflow"]="hidden";
612 - var tr = $doc.createElement("tr");
613 - tr.appendChild(innerCell);
614 - var tbody = $doc.createElement("tbody");
615 - tbody.appendChild(tr);
616 - var table = $doc.createElement("table");
617 - table.appendChild(tbody);
618 - table.style["width"]="100%";
619 - table["cellSpacing"]=0;
620 - table["cellPadding"]=0;
621 - cell.appendChild(table);
614 + var innerCell = $doc.createElement( "td" );
615 + innerCell.style["overflow"] = "hidden";
616 + var tr = $doc.createElement( "tr" );
617 + tr.appendChild( innerCell );
618 + var tbody = $doc.createElement( "tbody" );
619 + tbody.appendChild( tr );
620 + var table = $doc.createElement( "table" );
621 + table.appendChild( tbody );
622 + table.style["width"] = "100%";
623 + table["cellSpacing"] = 0;
624 + table["cellPadding"] = 0;
625 + cell.appendChild( table );
622 626
623 - rowElem.appendChild(cell);
627 + rowElem.appendChild( cell );
624 628 }
625 629 }-*/;
626 630
  @@ -628,51 +632,51 @@
628 632 public void onBrowserEvent( Event pEvent )
629 633 {
630 634 // the current incubator HTMLTable does not call super()
631 - switch (pEvent.getTypeInt())
635 + switch ( pEvent.getTypeInt() )
632 636 {
633 637 case Event.ONCLICK:
634 638 DomEvent.fireNativeEvent( pEvent, this, getElement() );
635 639 break;
636 640
637 641 case Event.ONMOUSEOVER:
638 - int row = mGridHelper.getRowForEvent(pEvent);
639 - updateHighlightedRow(row);
642 + int row = mGridHelper.getRowForEvent( pEvent );
643 + updateHighlightedRow( row );
640 644 break;
641 645
642 646 case Event.ONMOUSEOUT:
643 647 // only process mouse out if exiting the widget
644 648 Element toElement = pEvent.getRelatedEventTarget().cast();
645 - if (toElement == null || ! getElement().isOrHasChild(toElement))
649 + if ( toElement == null || !getElement().isOrHasChild( toElement ) )
646 650 {
647 - updateHighlightedRow(-1);
651 + updateHighlightedRow( -1 );
648 652 }
649 653 break;
650 654 }
651 655 super.onBrowserEvent( pEvent );
652 656 }
653 657
654 - private void updateHighlightedRow(int pRow)
658 + private void updateHighlightedRow( int pRow )
655 659 {
656 660 assert pRow >= -1;
657 - if (pRow == 0 || pRow == mFooterRow)
661 + if ( pRow == 0 || pRow == mFooterRow )
658 662 {
659 663 pRow = -1;
660 664 }
661 - if (mHilightedRow != pRow)
665 + if ( mHilightedRow != pRow )
662 666 {
663 667 RowFormatter rowFormatter = (RowFormatter) getRowFormatter();
664 - if (mHilightedRow != -1)
668 + if ( mHilightedRow != -1 )
665 669 {
666 - Element tr = rowFormatter.getElement(mHilightedRow);
667 - UIObject.setStyleName(tr, "highlighted", false);
670 + Element tr = rowFormatter.getElement( mHilightedRow );
671 + UIObject.setStyleName( tr, "highlighted", false );
668 672 }
669 673 mHilightedRow = pRow;
670 - if (mHilightedRow != -1)
674 + if ( mHilightedRow != -1 )
671 675 {
672 - Element tr = rowFormatter.getElement(mHilightedRow);
673 - UIObject.setStyleName(tr, "highlighted", true);
676 + Element tr = rowFormatter.getElement( mHilightedRow );
677 + UIObject.setStyleName( tr, "highlighted", true );
674 678 }
675 - HighlightEvent.fire(this, (mHilightedRow == -1) ? -1 : mHilightedRow - 1);
679 + HighlightEvent.fire( this, (mHilightedRow == -1) ? -1 : mHilightedRow - 1 );
676 680 }
677 681 }
678 682
  @@ -682,18 +686,18 @@
682 686 * Override to gain access
683 687 */
684 688 @Override
685 - protected Element ensureElement(int pRow)
689 + protected Element ensureElement( int pRow )
686 690 {
687 - return super.ensureElement(pRow);
691 + return super.ensureElement( pRow );
688 692 }
689 693
690 694 /**
691 695 * Override to gain access
692 696 */
693 697 @Override
694 - protected Element getRawElement(int pRow)
698 + protected Element getRawElement( int pRow )
695 699 {
696 - return super.getRawElement(pRow);
700 + return super.getRawElement( pRow );
697 701 }
698 702 }
699 703
  @@ -703,9 +707,9 @@
703 707 * Override to gain access
704 708 */
705 709 @Override
706 - protected Element getRawElement(int pRow, int pColumn)
710 + protected Element getRawElement( int pRow, int pColumn )
707 711 {
708 - Element outerTd = super.getRawElement(pRow, pColumn);
712 + Element outerTd = super.getRawElement( pRow, pColumn );
709 713 Element table = outerTd.getFirstChildElement().cast();
710 714 Element tbody = table.getFirstChildElement().cast();
711 715 Element tr = tbody.getFirstChildElement().cast();
  @@ -717,9 +721,9 @@
717 721 * Override to gain access
718 722 */
719 723 @Override
720 - protected Element ensureElement(int pRow, int pColumn)
724 + protected Element ensureElement( int pRow, int pColumn )
721 725 {
722 - return super.ensureElement(pRow, pColumn);
726 + return super.ensureElement( pRow, pColumn );
723 727 }
724 728 }
725 729
  @@ -729,7 +733,7 @@
729 733
730 734 public RowView()
731 735 {
732 - super(null);
736 + super( null );
733 737 }
734 738
735 739 @Override
  @@ -738,25 +742,25 @@
738 742 return mRowIndex;
739 743 }
740 744
741 - public void setRowIndex(int pRowIndex)
745 + public void setRowIndex( int pRowIndex )
742 746 {
743 747 mRowIndex = pRowIndex;
744 748 }
745 749
746 750 @Override
747 - public void setStyleAttribute(String attr, String value)
751 + public void setStyleAttribute( String attr, String value )
748 752 {
749 - ((RowFormatter) getRowFormatter()).getRawElement(getRowIndex() + 1).getStyle().setProperty(attr, value);
753 + ((RowFormatter) getRowFormatter()).getRawElement( getRowIndex() + 1 ).getStyle().setProperty( attr, value );
750 754 }
751 755
752 756 @Override
753 - public void setStyleName(String stylename)
757 + public void setStyleName( String stylename )
754 758 {
755 - if (getRowIndex() + 1 == mHilightedRow)
759 + if ( getRowIndex() + 1 == mHilightedRow )
756 760 {
757 761 stylename += " highlighted";
758 762 }
759 - getRowFormatter().setStyleName(getRowIndex() + 1, stylename);
763 + getRowFormatter().setStyleName( getRowIndex() + 1, stylename );
760 764 }
761 765 }
762 766
  @@ -767,96 +771,95 @@
767 771
768 772 private Element mViewTableElement; // the inner TD in each TD
769 773
770 - public CellView(int normalRowHeight, DetailRowModel<RowType> detailRowModel)
774 + public CellView( int normalRowHeight, DetailRowModel<RowType> detailRowModel )
771 775 {
772 - super(null);
776 + super( null );
773 777 mNormalRowHeight = normalRowHeight;
774 778 mDetailRowModel = detailRowModel;
775 779 }
776 780
777 - public void renderAccordionCell(int rowIndex, int cellIndex, RowType rowValue, ColumnDefinition<RowType, ?> columnDef)
781 + public void renderAccordionCell( int rowIndex, int cellIndex, RowType rowValue, ColumnDefinition<RowType, ?> columnDef )
778 782 {
779 783 // ensure element first so we can getRawElement() for all future needs
780 - mViewTableElement = ((CellFormatter) getCellFormatter()).ensureElement(rowIndex + 1, cellIndex);
784 + mViewTableElement = ((CellFormatter) getCellFormatter()).ensureElement( rowIndex + 1, cellIndex );
781 785 Element tr = mViewTableElement.getParentElement().cast();
782 786 Element tbody = tr.getParentElement().cast();
783 787 Element table = tbody.getParentElement().cast();
784 788 Element outerTd = table.getParentElement().cast();
785 - UIObject.setStylePrimaryName(mViewTableElement, "AccordionTable-dataCell");
786 - boolean detailRow = mDetailRowModel.isDetailRow(rowIndex);
789 + UIObject.setStylePrimaryName( mViewTableElement, "AccordionTable-dataCell" );
790 + boolean detailRow = mDetailRowModel.isDetailRow( rowIndex );
787 791 String valign = null;
788 - if (detailRow)
792 + if ( detailRow )
789 793 {
790 794 valign = (mDetailRowModel.getAlign() == DetailRowAlignment.Top) ? "top" : "bottom";
791 795 }
792 - outerTd.getStyle().setProperty("verticalAlign", valign);
793 - super.renderCellImpl(rowIndex, cellIndex, rowValue, columnDef);
796 + outerTd.getStyle().setProperty( "verticalAlign", valign );
797 + super.renderCellImpl( rowIndex, cellIndex, rowValue, columnDef );
794 798 mViewTableElement = null;
795 799 }
796 800
797 - @Override
798 - @SuppressWarnings("unchecked")
799 - protected void renderRowValue(RowType rowValue, ColumnDefinition columnDef)
801 + @Override @SuppressWarnings("unchecked")
802 + protected void renderRowValue( RowType rowValue, ColumnDefinition columnDef )
800 803 {
801 804 CellRenderer cellRenderer = columnDef.getCellRenderer();
802 - boolean detailRow = mDetailRowModel.isDetailRow(getRowIndex());
805 + boolean detailRow = mDetailRowModel.isDetailRow( getRowIndex() );
803 806 boolean maxHeight = false; // typically true for detail cells
804 - if (cellRenderer instanceof DetailCellRenderer)
807 + if ( cellRenderer instanceof DetailCellRenderer )
805 808 {
806 809 DetailCellRenderer<RowType> detailRenderer = (DetailCellRenderer<RowType>) cellRenderer;
807 810 maxHeight = detailRow && detailRenderer.isMaxHeight();
808 - ((DetailCellRenderer) cellRenderer).setDetailRow(detailRow);
811 + ((DetailCellRenderer) cellRenderer).setDetailRow( detailRow );
809 812 }
810 - if (mNormalRowHeight > 0)
813 + if ( mNormalRowHeight > 0 )
811 814 {
812 - mViewTableElement.getStyle().setProperty("height", (detailRow && ! maxHeight) ? mNormalRowHeight + "px" : "");
815 + mViewTableElement.getStyle().setProperty( "height", (detailRow && !maxHeight) ? mNormalRowHeight + "px" : "" );
813 816 }
814 - cellRenderer.renderRowValue(rowValue, columnDef, this);
817 + cellRenderer.renderRowValue( rowValue, columnDef, this );
815 818 }
816 819
817 820 @Override
818 - public void setHorizontalAlignment(HorizontalAlignmentConstant align)
821 + public void setHorizontalAlignment( HorizontalAlignmentConstant align )
819 822 {
820 - mViewTableElement.setPropertyString("align", align.getTextAlignString());
823 + mViewTableElement.setPropertyString( "align", align.getTextAlignString() );
821 824 }
822 825
823 826 @Override
824 - public void setHTML(String html)
827 + public void setHTML( String html )
825 828 {
826 - AccordionTableTable.this.setHTML(getRowIndex() + 1, getCellIndex(), html);
829 + AccordionTableTable.this.setHTML( getRowIndex() + 1, getCellIndex(), html );
827 830 }
828 831
829 832 @Override
830 - public void setStyleAttribute(String attr, String value)
833 + public void setStyleAttribute( String attr, String value )
831 834 {
832 - mViewTableElement.getStyle().setProperty(attr, value != null ? value : ""); // de-null to avoid IE error
835 + mViewTableElement.getStyle().setProperty( attr, value != null ? value : "" ); // de-null to avoid IE error
833 836 }
834 837
835 838 @Override
836 - public void setStyleName(String stylename)
839 + public void setStyleName( String stylename )
837 840 {
838 - if (stylename.length() > 0)
841 + if ( stylename.length() > 0 )
839 842 {
840 - UIObject.setStyleName(mViewTableElement, stylename);
843 + UIObject.setStyleName( mViewTableElement, stylename );
841 844 }
842 845 }
843 846
844 847 @Override
845 - public void setText(String text)
848 + public void setText( String text )
846 849 {
847 - AccordionTableTable.this.setText(getRowIndex() + 1, getCellIndex(), text);
850 + AccordionTableTable.this.setText( getRowIndex() + 1, getCellIndex(), text );
848 851 }
849 852
850 853 @Override
851 - public void setVerticalAlignment(VerticalAlignmentConstant align)
854 + public void setVerticalAlignment( VerticalAlignmentConstant align )
852 855 {
853 - mViewTableElement.getStyle().setProperty("verticalAlign", align.getVerticalAlignString());
856 + mViewTableElement.getStyle().setProperty( "verticalAlign", align.getVerticalAlignString() );
854 857 }
855 858
856 859 @Override
857 - public void setWidget(Widget widget)
860 + public void setWidget( Widget widget )
858 861 {
859 - AccordionTableTable.this.setWidget(getRowIndex() + 1, getCellIndex(), widget);
862 + AccordionTableTable.this.setWidget( getRowIndex() + 1, getCellIndex(), widget );
860 863 }
861 864 }
862 865 }