|
@@ -15,25 +15,23 @@ |
15 |
15 |
|
*/ |
16 |
16 |
|
package com.google.gwt.gen2.table.client; |
17 |
17 |
|
|
18 |
|
- |
import java.util.*; |
19 |
|
- |
|
20 |
18 |
|
import com.google.gwt.gen2.table.client.FixedWidthTableImpl.*; |
21 |
19 |
|
import com.google.gwt.user.client.*; |
22 |
20 |
|
import com.google.gwt.user.client.ui.*; |
23 |
21 |
|
|
|
22 |
+ |
import java.util.*; |
|
23 |
+ |
|
24 |
24 |
|
/** |
25 |
25 |
|
* A variation of the {@link FlexTable} that supports smarter column resizing |
26 |
26 |
|
* options. Unlike the {@link FlexTable}, columns resized in the |
27 |
27 |
|
* {@link FixedWidthFlexTable} class are guaranteed to be resized correctly. |
28 |
28 |
|
*/ |
29 |
|
- |
public class FixedWidthFlexTable extends FlexTable |
30 |
|
- |
{ |
|
29 |
+ |
public class FixedWidthFlexTable extends FlexTable { |
31 |
30 |
|
/** |
32 |
31 |
|
* FlexTable-specific implementation of |
33 |
32 |
|
* {@link com.google.gwt.user.client.ui.HTMLTable.CellFormatter}. |
34 |
33 |
|
*/ |
35 |
|
- |
public class FixedWidthFlexCellFormatter extends FlexCellFormatter |
36 |
|
- |
{ |
|
34 |
+ |
public class FixedWidthFlexCellFormatter extends FlexCellFormatter { |
37 |
35 |
|
/** |
38 |
36 |
|
* Sets the column span for the given cell. This is the number of logical |
39 |
37 |
|
* columns covered by the cell. |
|
@@ -45,16 +43,14 @@ |
45 |
43 |
|
* @throws IndexOutOfBoundsException |
46 |
44 |
|
*/ |
47 |
45 |
|
@Override |
48 |
|
- |
public void setColSpan( int row, int column, int colSpan ) |
49 |
|
- |
{ |
|
46 |
+ |
public void setColSpan( int row, int column, int colSpan ) { |
50 |
47 |
|
colSpan = Math.max( 1, colSpan ); |
51 |
48 |
|
int colSpanDelta = colSpan - getColSpan( row, column ); |
52 |
49 |
|
super.setColSpan( row, column, colSpan ); |
53 |
50 |
|
|
54 |
51 |
|
// Update the column counts |
55 |
52 |
|
int rowSpan = getRowSpan( row, column ); |
56 |
|
- |
for ( int i = row; i < row + rowSpan; i++ ) |
57 |
|
- |
{ |
|
53 |
+ |
for ( int i = row; i < row + rowSpan; i++ ) { |
58 |
54 |
|
setNumColumnsPerRow( i, getNumColumnsPerRow( i ) + colSpanDelta ); |
59 |
55 |
|
} |
60 |
56 |
|
} |
|
@@ -70,25 +66,19 @@ |
70 |
66 |
|
* @throws IndexOutOfBoundsException |
71 |
67 |
|
*/ |
72 |
68 |
|
@Override |
73 |
|
- |
public void setRowSpan( int row, int column, int rowSpan ) |
74 |
|
- |
{ |
|
69 |
+ |
public void setRowSpan( int row, int column, int rowSpan ) { |
75 |
70 |
|
rowSpan = Math.max( 1, rowSpan ); |
76 |
71 |
|
int curRowSpan = getRowSpan( row, column ); |
77 |
72 |
|
super.setRowSpan( row, column, rowSpan ); |
78 |
73 |
|
|
79 |
74 |
|
// Update the column counts |
80 |
75 |
|
int colSpan = getColSpan( row, column ); |
81 |
|
- |
if ( rowSpan > curRowSpan ) |
82 |
|
- |
{ |
83 |
|
- |
for ( int i = row + curRowSpan; i < row + rowSpan; i++ ) |
84 |
|
- |
{ |
|
76 |
+ |
if ( rowSpan > curRowSpan ) { |
|
77 |
+ |
for ( int i = row + curRowSpan; i < row + rowSpan; i++ ) { |
85 |
78 |
|
setNumColumnsPerRow( i, getNumColumnsPerRow( i ) + colSpan ); |
86 |
79 |
|
} |
87 |
|
- |
} |
88 |
|
- |
else if ( rowSpan < curRowSpan ) |
89 |
|
- |
{ |
90 |
|
- |
for ( int i = row + rowSpan; i < row + curRowSpan; i++ ) |
91 |
|
- |
{ |
|
80 |
+ |
} else if ( rowSpan < curRowSpan ) { |
|
81 |
+ |
for ( int i = row + rowSpan; i < row + curRowSpan; i++ ) { |
92 |
82 |
|
setNumColumnsPerRow( i, getNumColumnsPerRow( i ) - colSpan ); |
93 |
83 |
|
} |
94 |
84 |
|
} |
|
@@ -105,8 +95,7 @@ |
105 |
95 |
|
* @throws UnsupportedOperationException |
106 |
96 |
|
*/ |
107 |
97 |
|
@Override |
108 |
|
- |
public void setWidth( int row, int column, String width ) |
109 |
|
- |
{ |
|
98 |
+ |
public void setWidth( int row, int column, String width ) { |
110 |
99 |
|
throw new UnsupportedOperationException( "setWidth is not supported. " + "Use ExtendedGrid.setColumnWidth(int, int) instead." ); |
111 |
100 |
|
} |
112 |
101 |
|
|
|
@@ -120,8 +109,7 @@ |
120 |
109 |
|
* @return the column's TD element |
121 |
110 |
|
*/ |
122 |
111 |
|
@Override |
123 |
|
- |
protected Element getRawElement( int row, int column ) |
124 |
|
- |
{ |
|
112 |
+ |
protected Element getRawElement( int row, int column ) { |
125 |
113 |
|
return super.getRawElement( row + 1, column ); |
126 |
114 |
|
} |
127 |
115 |
|
} |
|
@@ -130,8 +118,7 @@ |
130 |
118 |
|
* This class contains methods used to format a table's columns. It is limited |
131 |
119 |
|
* by the support cross-browser HTML support for column formatting. |
132 |
120 |
|
*/ |
133 |
|
- |
public class FixedWidthFlexColumnFormatter extends ColumnFormatter |
134 |
|
- |
{ |
|
121 |
+ |
public class FixedWidthFlexColumnFormatter extends ColumnFormatter { |
135 |
122 |
|
/** |
136 |
123 |
|
* UnsupportedOperation. Use ExtendedGrid.setColumnWidth(column, width) |
137 |
124 |
|
* instead. |
|
@@ -142,8 +129,7 @@ |
142 |
129 |
|
* @throws UnsupportedOperationException |
143 |
130 |
|
*/ |
144 |
131 |
|
@Override |
145 |
|
- |
public void setWidth( int column, String width ) |
146 |
|
- |
{ |
|
132 |
+ |
public void setWidth( int column, String width ) { |
147 |
133 |
|
throw new UnsupportedOperationException( "setWidth is not supported. " + "Use ExtendedGrid.setColumnWidth(int, int) instead." ); |
148 |
134 |
|
} |
149 |
135 |
|
} |
|
@@ -151,8 +137,7 @@ |
151 |
137 |
|
/** |
152 |
138 |
|
* This class contains methods used to format a table's rows. |
153 |
139 |
|
*/ |
154 |
|
- |
public class FixedWidthFlexRowFormatter extends RowFormatter |
155 |
|
- |
{ |
|
140 |
+ |
public class FixedWidthFlexRowFormatter extends RowFormatter { |
156 |
141 |
|
/** |
157 |
142 |
|
* Unsafe method to get a row element. |
158 |
143 |
|
* |
|
@@ -161,8 +146,7 @@ |
161 |
146 |
|
* @return the row element |
162 |
147 |
|
*/ |
163 |
148 |
|
@Override |
164 |
|
- |
protected Element getRawElement( int row ) |
165 |
|
- |
{ |
|
149 |
+ |
protected Element getRawElement( int row ) { |
166 |
150 |
|
return super.getRawElement( row + 1 ); |
167 |
151 |
|
} |
168 |
152 |
|
} |
|
@@ -225,8 +209,7 @@ |
225 |
209 |
|
/** |
226 |
210 |
|
* Constructor. |
227 |
211 |
|
*/ |
228 |
|
- |
public FixedWidthFlexTable() |
229 |
|
- |
{ |
|
212 |
+ |
public FixedWidthFlexTable() { |
230 |
213 |
|
super(); |
231 |
214 |
|
Element tableElem = getElement(); |
232 |
215 |
|
DOM.setStyleAttribute( tableElem, "tableLayout", "fixed" ); |
|
@@ -242,8 +225,7 @@ |
242 |
225 |
|
} |
243 |
226 |
|
|
244 |
227 |
|
@Override |
245 |
|
- |
public void clear() |
246 |
|
- |
{ |
|
228 |
+ |
public void clear() { |
247 |
229 |
|
super.clear(); |
248 |
230 |
|
clearIdealWidths(); |
249 |
231 |
|
} |
|
@@ -251,8 +233,7 @@ |
251 |
233 |
|
/** |
252 |
234 |
|
* @return the raw number of columns in this table. |
253 |
235 |
|
*/ |
254 |
|
- |
public int getColumnCount() |
255 |
|
- |
{ |
|
236 |
+ |
public int getColumnCount() { |
256 |
237 |
|
return maxRawColumnCount; |
257 |
238 |
|
} |
258 |
239 |
|
|
|
@@ -264,15 +245,11 @@ |
264 |
245 |
|
* |
265 |
246 |
|
* @return the column width in pixels |
266 |
247 |
|
*/ |
267 |
|
- |
public int getColumnWidth( int column ) |
268 |
|
- |
{ |
|
248 |
+ |
public int getColumnWidth( int column ) { |
269 |
249 |
|
Object colWidth = colWidths.get( new Integer( column ) ); |
270 |
|
- |
if ( colWidth == null ) |
271 |
|
- |
{ |
|
250 |
+ |
if ( colWidth == null ) { |
272 |
251 |
|
return DEFAULT_COLUMN_WIDTH; |
273 |
|
- |
} |
274 |
|
- |
else |
275 |
|
- |
{ |
|
252 |
+ |
} else { |
276 |
253 |
|
return ((Integer) colWidth).intValue(); |
277 |
254 |
|
} |
278 |
255 |
|
} |
|
@@ -291,11 +268,9 @@ |
291 |
268 |
|
* |
292 |
269 |
|
* @return the ideal column width, or -1 if it is not applicable |
293 |
270 |
|
*/ |
294 |
|
- |
public int getIdealColumnWidth( int column ) |
295 |
|
- |
{ |
|
271 |
+ |
public int getIdealColumnWidth( int column ) { |
296 |
272 |
|
maybeRecalculateIdealColumnWidths(); |
297 |
|
- |
if ( idealWidths.length > column ) |
298 |
|
- |
{ |
|
273 |
+ |
if ( idealWidths.length > column ) { |
299 |
274 |
|
return idealWidths[column]; |
300 |
275 |
|
} |
301 |
276 |
|
return -1; |
|
@@ -305,8 +280,7 @@ |
305 |
280 |
|
* @see FlexTable |
306 |
281 |
|
*/ |
307 |
282 |
|
@Override |
308 |
|
- |
public Element insertCell( int beforeRow, int beforeColumn ) |
309 |
|
- |
{ |
|
283 |
+ |
public Element insertCell( int beforeRow, int beforeColumn ) { |
310 |
284 |
|
clearIdealWidths(); |
311 |
285 |
|
Element td = super.insertCell( beforeRow, beforeColumn ); |
312 |
286 |
|
DOM.setStyleAttribute( td, "overflow", "hidden" ); |
|
@@ -318,24 +292,20 @@ |
318 |
292 |
|
* @see FlexTable |
319 |
293 |
|
*/ |
320 |
294 |
|
@Override |
321 |
|
- |
public int insertRow( int beforeRow ) |
322 |
|
- |
{ |
|
295 |
+ |
public int insertRow( int beforeRow ) { |
323 |
296 |
|
// Get the affected colSpan, which is the number of raw cells created by |
324 |
297 |
|
// row spanning cells in rows above the new row. |
325 |
298 |
|
FlexCellFormatter formatter = getFlexCellFormatter(); |
326 |
299 |
|
int affectedColSpan = getNumColumnsPerRow( beforeRow ); |
327 |
|
- |
if ( beforeRow != getRowCount() ) |
328 |
|
- |
{ |
|
300 |
+ |
if ( beforeRow != getRowCount() ) { |
329 |
301 |
|
int numCellsInRow = getCellCount( beforeRow ); |
330 |
|
- |
for ( int cell = 0; cell < numCellsInRow; cell++ ) |
331 |
|
- |
{ |
|
302 |
+ |
for ( int cell = 0; cell < numCellsInRow; cell++ ) { |
332 |
303 |
|
affectedColSpan -= formatter.getColSpan( beforeRow, cell ); |
333 |
304 |
|
} |
334 |
305 |
|
} |
335 |
306 |
|
|
336 |
307 |
|
// Specifically allow the row count as an insert position. |
337 |
|
- |
if ( beforeRow != getRowCount() ) |
338 |
|
- |
{ |
|
308 |
+ |
if ( beforeRow != getRowCount() ) { |
339 |
309 |
|
checkRowBounds( beforeRow ); |
340 |
310 |
|
} |
341 |
311 |
|
Element tr = DOM.createTR(); |
|
@@ -345,21 +315,17 @@ |
345 |
315 |
|
// Make sure the column counts are still correct by iterating backward |
346 |
316 |
|
// through the rows looking for cells that span down into the newly |
347 |
317 |
|
// inserted row. Stop iterating when every raw column is accounted for. |
348 |
|
- |
for ( int curRow = beforeRow - 1; curRow >= 0; curRow-- ) |
349 |
|
- |
{ |
|
318 |
+ |
for ( int curRow = beforeRow - 1; curRow >= 0; curRow-- ) { |
350 |
319 |
|
// No more affect of rowspan, so we are done |
351 |
|
- |
if ( affectedColSpan <= 0 ) |
352 |
|
- |
{ |
|
320 |
+ |
if ( affectedColSpan <= 0 ) { |
353 |
321 |
|
break; |
354 |
322 |
|
} |
355 |
323 |
|
|
356 |
324 |
|
// Look for cells that span into the new row |
357 |
325 |
|
int numCells = getCellCount( curRow ); |
358 |
|
- |
for ( int curCell = 0; curCell < numCells; curCell++ ) |
359 |
|
- |
{ |
|
326 |
+ |
for ( int curCell = 0; curCell < numCells; curCell++ ) { |
360 |
327 |
|
int affectedRow = curRow + formatter.getRowSpan( curRow, curCell ); |
361 |
|
- |
if ( affectedRow > beforeRow ) |
362 |
|
- |
{ |
|
328 |
+ |
if ( affectedRow > beforeRow ) { |
363 |
329 |
|
int colSpan = formatter.getColSpan( curRow, curCell ); |
364 |
330 |
|
affectedColSpan -= colSpan; |
365 |
331 |
|
setNumColumnsPerRow( beforeRow, getNumColumnsPerRow( beforeRow ) + colSpan ); |
|
@@ -373,10 +339,8 @@ |
373 |
339 |
|
} |
374 |
340 |
|
|
375 |
341 |
|
@Override |
376 |
|
- |
public boolean remove( Widget widget ) |
377 |
|
- |
{ |
378 |
|
- |
if ( super.remove( widget ) ) |
379 |
|
- |
{ |
|
342 |
+ |
public boolean remove( Widget widget ) { |
|
343 |
+ |
if ( super.remove( widget ) ) { |
380 |
344 |
|
clearIdealWidths(); |
381 |
345 |
|
return true; |
382 |
346 |
|
} |
|
@@ -387,16 +351,14 @@ |
387 |
351 |
|
* @see FlexTable |
388 |
352 |
|
*/ |
389 |
353 |
|
@Override |
390 |
|
- |
public void removeCell( int row, int column ) |
391 |
|
- |
{ |
|
354 |
+ |
public void removeCell( int row, int column ) { |
392 |
355 |
|
clearIdealWidths(); |
393 |
356 |
|
int colSpan = getFlexCellFormatter().getColSpan( row, column ); |
394 |
357 |
|
int rowSpan = getFlexCellFormatter().getRowSpan( row, column ); |
395 |
358 |
|
super.removeCell( row, column ); |
396 |
359 |
|
|
397 |
360 |
|
// Update the column counts |
398 |
|
- |
for ( int i = row; i < row + rowSpan; i++ ) |
399 |
|
- |
{ |
|
361 |
+ |
for ( int i = row; i < row + rowSpan; i++ ) { |
400 |
362 |
|
setNumColumnsPerRow( i, getNumColumnsPerRow( i ) - colSpan ); |
401 |
363 |
|
} |
402 |
364 |
|
} |
|
@@ -405,14 +367,12 @@ |
405 |
367 |
|
* @see FlexTable |
406 |
368 |
|
*/ |
407 |
369 |
|
@Override |
408 |
|
- |
public void removeRow( int row ) |
409 |
|
- |
{ |
|
370 |
+ |
public void removeRow( int row ) { |
410 |
371 |
|
// Set the rowspan of everything in this row to 1 |
411 |
372 |
|
FlexCellFormatter formatter = getFlexCellFormatter(); |
412 |
373 |
|
int affectedColSpan = getNumColumnsPerRow( row ); |
413 |
374 |
|
int numCellsInRow = getCellCount( row ); |
414 |
|
- |
for ( int cell = 0; cell < numCellsInRow; cell++ ) |
415 |
|
- |
{ |
|
375 |
+ |
for ( int cell = 0; cell < numCellsInRow; cell++ ) { |
416 |
376 |
|
formatter.setRowSpan( row, cell, 1 ); |
417 |
377 |
|
affectedColSpan -= formatter.getColSpan( row, cell ); |
418 |
378 |
|
} |
|
@@ -426,21 +386,17 @@ |
426 |
386 |
|
// Make sure the column counts are still correct by iterating backward |
427 |
387 |
|
// through the rows looking for cells that span down into the newly |
428 |
388 |
|
// inserted row. Stop iterating when every raw column is accounted for. |
429 |
|
- |
for ( int curRow = row - 1; curRow >= 0; curRow-- ) |
430 |
|
- |
{ |
|
389 |
+ |
for ( int curRow = row - 1; curRow >= 0; curRow-- ) { |
431 |
390 |
|
// No more affects from rowspan, so we are done |
432 |
|
- |
if ( affectedColSpan <= 0 ) |
433 |
|
- |
{ |
|
391 |
+ |
if ( affectedColSpan <= 0 ) { |
434 |
392 |
|
break; |
435 |
393 |
|
} |
436 |
394 |
|
|
437 |
395 |
|
// Look for cells that span into the removed row |
438 |
396 |
|
int numCells = getCellCount( curRow ); |
439 |
|
- |
for ( int curCell = 0; curCell < numCells; curCell++ ) |
440 |
|
- |
{ |
|
397 |
+ |
for ( int curCell = 0; curCell < numCells; curCell++ ) { |
441 |
398 |
|
int affectedRow = curRow + formatter.getRowSpan( curRow, curCell ) - 1; |
442 |
|
- |
if ( affectedRow >= row ) |
443 |
|
- |
{ |
|
399 |
+ |
if ( affectedRow >= row ) { |
444 |
400 |
|
int colSpan = formatter.getColSpan( curRow, curCell ); |
445 |
401 |
|
affectedColSpan -= colSpan; |
446 |
402 |
|
setNumColumnsPerRow( affectedRow, getNumColumnsPerRow( affectedRow ) + colSpan ); |
|
@@ -450,25 +406,21 @@ |
450 |
406 |
|
} |
451 |
407 |
|
|
452 |
408 |
|
@Override |
453 |
|
- |
public void setCellPadding( int padding ) |
454 |
|
- |
{ |
|
409 |
+ |
public void setCellPadding( int padding ) { |
455 |
410 |
|
super.setCellPadding( padding ); |
456 |
411 |
|
|
457 |
412 |
|
// Reset the width of all columns |
458 |
|
- |
for ( Map.Entry<Integer, Integer> entry : colWidths.entrySet() ) |
459 |
|
- |
{ |
|
413 |
+ |
for ( Map.Entry<Integer, Integer> entry : colWidths.entrySet() ) { |
460 |
414 |
|
setColumnWidth( entry.getKey(), entry.getValue() ); |
461 |
415 |
|
} |
462 |
416 |
|
} |
463 |
417 |
|
|
464 |
418 |
|
@Override |
465 |
|
- |
public void setCellSpacing( int spacing ) |
466 |
|
- |
{ |
|
419 |
+ |
public void setCellSpacing( int spacing ) { |
467 |
420 |
|
super.setCellSpacing( spacing ); |
468 |
421 |
|
|
469 |
422 |
|
// Reset the width of all columns |
470 |
|
- |
for ( Map.Entry<Integer, Integer> entry : colWidths.entrySet() ) |
471 |
|
- |
{ |
|
423 |
+ |
for ( Map.Entry<Integer, Integer> entry : colWidths.entrySet() ) { |
472 |
424 |
|
setColumnWidth( entry.getKey(), entry.getValue() ); |
473 |
425 |
|
} |
474 |
426 |
|
} |
|
@@ -481,11 +433,9 @@ |
481 |
433 |
|
* |
482 |
434 |
|
* @throws IndexOutOfBoundsException |
483 |
435 |
|
*/ |
484 |
|
- |
public void setColumnWidth( int column, int width ) |
485 |
|
- |
{ |
|
436 |
+ |
public void setColumnWidth( int column, int width ) { |
486 |
437 |
|
// Ensure that the indices are not negative. |
487 |
|
- |
if ( column < 0 ) |
488 |
|
- |
{ |
|
438 |
+ |
if ( column < 0 ) { |
489 |
439 |
|
throw new IndexOutOfBoundsException( "Cannot access a column with a negative index: " + column ); |
490 |
440 |
|
} |
491 |
441 |
|
|
|
@@ -495,8 +445,7 @@ |
495 |
445 |
|
|
496 |
446 |
|
// Update the cell width if possible |
497 |
447 |
|
int numGhosts = getGhostColumnCount(); |
498 |
|
- |
if ( column >= numGhosts ) |
499 |
|
- |
{ |
|
448 |
+ |
if ( column >= numGhosts ) { |
500 |
449 |
|
return; |
501 |
450 |
|
} |
502 |
451 |
|
|
|
@@ -505,22 +454,19 @@ |
505 |
454 |
|
} |
506 |
455 |
|
|
507 |
456 |
|
@Override |
508 |
|
- |
public void setHTML( int row, int column, String html ) |
509 |
|
- |
{ |
|
457 |
+ |
public void setHTML( int row, int column, String html ) { |
510 |
458 |
|
super.setHTML( row, column, html ); |
511 |
459 |
|
clearIdealWidths(); |
512 |
460 |
|
} |
513 |
461 |
|
|
514 |
462 |
|
@Override |
515 |
|
- |
public void setText( int row, int column, String text ) |
516 |
|
- |
{ |
|
463 |
+ |
public void setText( int row, int column, String text ) { |
517 |
464 |
|
super.setText( row, column, text ); |
518 |
465 |
|
clearIdealWidths(); |
519 |
466 |
|
} |
520 |
467 |
|
|
521 |
468 |
|
@Override |
522 |
|
- |
public void setWidget( int row, int column, Widget widget ) |
523 |
|
- |
{ |
|
469 |
+ |
public void setWidget( int row, int column, Widget widget ) { |
524 |
470 |
|
super.setWidget( row, column, widget ); |
525 |
471 |
|
clearIdealWidths(); |
526 |
472 |
|
} |
|
@@ -529,23 +475,20 @@ |
529 |
475 |
|
* @see FlexTable |
530 |
476 |
|
*/ |
531 |
477 |
|
@Override |
532 |
|
- |
protected void addCells( int row, int num ) |
533 |
|
- |
{ |
|
478 |
+ |
protected void addCells( int row, int num ) { |
534 |
479 |
|
// Account for ghost row |
535 |
480 |
|
super.addCells( row + 1, num ); |
536 |
481 |
|
clearIdealWidths(); |
537 |
482 |
|
} |
538 |
483 |
|
|
539 |
484 |
|
@Override |
540 |
|
- |
protected int getDOMCellCount( int row ) |
541 |
|
- |
{ |
|
485 |
+ |
protected int getDOMCellCount( int row ) { |
542 |
486 |
|
// Account for ghost row |
543 |
487 |
|
return super.getDOMCellCount( row + 1 ); |
544 |
488 |
|
} |
545 |
489 |
|
|
546 |
490 |
|
@Override |
547 |
|
- |
protected int getDOMRowCount() |
548 |
|
- |
{ |
|
491 |
+ |
protected int getDOMRowCount() { |
549 |
492 |
|
// Account for ghost row |
550 |
493 |
|
return super.getDOMRowCount() - 1; |
551 |
494 |
|
} |
|
@@ -555,64 +498,54 @@ |
555 |
498 |
|
* |
556 |
499 |
|
* @return the number of ghost columns |
557 |
500 |
|
*/ |
558 |
|
- |
protected int getGhostColumnCount() |
559 |
|
- |
{ |
|
501 |
+ |
protected int getGhostColumnCount() { |
560 |
502 |
|
return super.getDOMCellCount( 0 ); |
561 |
503 |
|
} |
562 |
504 |
|
|
563 |
505 |
|
/** |
564 |
506 |
|
* @return the ghost row element |
565 |
507 |
|
*/ |
566 |
|
- |
protected Element getGhostRow() |
567 |
|
- |
{ |
|
508 |
+ |
protected Element getGhostRow() { |
568 |
509 |
|
return ghostRow; |
569 |
510 |
|
} |
570 |
511 |
|
|
571 |
512 |
|
@Override |
572 |
|
- |
protected int getRowIndex( Element rowElem ) |
573 |
|
- |
{ |
|
513 |
+ |
protected int getRowIndex( Element rowElem ) { |
574 |
514 |
|
int rowIndex = super.getRowIndex( rowElem ); |
575 |
|
- |
if ( rowIndex < 0 ) |
576 |
|
- |
{ |
|
515 |
+ |
if ( rowIndex < 0 ) { |
577 |
516 |
|
return rowIndex; |
578 |
517 |
|
} |
579 |
518 |
|
return rowIndex - 1; |
580 |
519 |
|
} |
581 |
520 |
|
|
582 |
521 |
|
@Override |
583 |
|
- |
protected boolean internalClearCell( Element td, boolean clearInnerHTML ) |
584 |
|
- |
{ |
|
522 |
+ |
protected boolean internalClearCell( Element td, boolean clearInnerHTML ) { |
585 |
523 |
|
clearIdealWidths(); |
586 |
524 |
|
return super.internalClearCell( td, clearInnerHTML ); |
587 |
525 |
|
} |
588 |
526 |
|
|
589 |
527 |
|
@Override |
590 |
|
- |
protected void onAttach() |
591 |
|
- |
{ |
|
528 |
+ |
protected void onAttach() { |
592 |
529 |
|
super.onAttach(); |
593 |
530 |
|
clearIdealWidths(); |
594 |
531 |
|
} |
595 |
532 |
|
|
596 |
533 |
|
@Override |
597 |
|
- |
protected void prepareCell( int row, int column ) |
598 |
|
- |
{ |
|
534 |
+ |
protected void prepareCell( int row, int column ) { |
599 |
535 |
|
int curNumCells = 0; |
600 |
|
- |
if ( getRowCount() > row ) |
601 |
|
- |
{ |
|
536 |
+ |
if ( getRowCount() > row ) { |
602 |
537 |
|
curNumCells = getCellCount( row ); |
603 |
538 |
|
} |
604 |
539 |
|
super.prepareCell( row, column ); |
605 |
540 |
|
|
606 |
541 |
|
// Add ghost columns as needed |
607 |
|
- |
if ( column >= curNumCells ) |
608 |
|
- |
{ |
|
542 |
+ |
if ( column >= curNumCells ) { |
609 |
543 |
|
// Add ghost cells |
610 |
544 |
|
int cellsAdded = column - curNumCells + 1; |
611 |
545 |
|
setNumColumnsPerRow( row, getNumColumnsPerRow( row ) + cellsAdded ); |
612 |
546 |
|
|
613 |
547 |
|
// Set the new cells to hide overflow |
614 |
|
- |
for ( int cell = curNumCells; cell < column; cell++ ) |
615 |
|
- |
{ |
|
548 |
+ |
for ( int cell = curNumCells; cell < column; cell++ ) { |
616 |
549 |
|
Element td = getCellFormatter().getElement( row, cell ); |
617 |
550 |
|
DOM.setStyleAttribute( td, "overflow", "hidden" ); |
618 |
551 |
|
} |
|
@@ -622,12 +555,10 @@ |
622 |
555 |
|
/** |
623 |
556 |
|
* Recalculate the ideal column widths of each column in the data table. |
624 |
557 |
|
*/ |
625 |
|
- |
protected void recalculateIdealColumnWidths() |
626 |
|
- |
{ |
|
558 |
+ |
protected void recalculateIdealColumnWidths() { |
627 |
559 |
|
// We need at least one cell to do any calculations |
628 |
560 |
|
int columnCount = getColumnCount(); |
629 |
|
- |
if ( !isAttached() || getRowCount() == 0 || columnCount < 1 ) |
630 |
|
- |
{ |
|
561 |
+ |
if ( !isAttached() || getRowCount() == 0 || columnCount < 1 ) { |
631 |
562 |
|
idealWidths = new int[0]; |
632 |
563 |
|
return; |
633 |
564 |
|
} |
|
@@ -640,16 +571,14 @@ |
640 |
571 |
|
/** |
641 |
572 |
|
* Clear the idealWidths field when the ideal widths change. |
642 |
573 |
|
*/ |
643 |
|
- |
void clearIdealWidths() |
644 |
|
- |
{ |
|
574 |
+ |
void clearIdealWidths() { |
645 |
575 |
|
idealWidths = null; |
646 |
576 |
|
} |
647 |
577 |
|
|
648 |
578 |
|
/** |
649 |
579 |
|
* @return true if the ideal column widths have already been calculated |
650 |
580 |
|
*/ |
651 |
|
- |
boolean isIdealColumnWidthsCalculated() |
652 |
|
- |
{ |
|
581 |
+ |
boolean isIdealColumnWidthsCalculated() { |
653 |
582 |
|
return idealWidths != null; |
654 |
583 |
|
} |
655 |
584 |
|
|
|
@@ -657,24 +586,21 @@ |
657 |
586 |
|
* Recalculate the ideal column widths of each column in the data table. This |
658 |
587 |
|
* method assumes that the tableLayout has already been changed. |
659 |
588 |
|
*/ |
660 |
|
- |
void recalculateIdealColumnWidthsImpl() |
661 |
|
- |
{ |
|
589 |
+ |
void recalculateIdealColumnWidthsImpl() { |
662 |
590 |
|
idealWidths = FixedWidthTableImpl.get().recalculateIdealColumnWidths( idealColumnWidthInfo ); |
663 |
591 |
|
} |
664 |
592 |
|
|
665 |
593 |
|
/** |
666 |
594 |
|
* Setup to recalculate column widths. |
667 |
595 |
|
*/ |
668 |
|
- |
void recalculateIdealColumnWidthsSetup() |
669 |
|
- |
{ |
|
596 |
+ |
void recalculateIdealColumnWidthsSetup() { |
670 |
597 |
|
idealColumnWidthInfo = FixedWidthTableImpl.get().recalculateIdealColumnWidthsSetup( this, getColumnCount(), 0 ); |
671 |
598 |
|
} |
672 |
599 |
|
|
673 |
600 |
|
/** |
674 |
601 |
|
* Tear down after recalculating column widths. |
675 |
602 |
|
*/ |
676 |
|
- |
void recalculateIdealColumnWidthsTeardown() |
677 |
|
- |
{ |
|
603 |
+ |
void recalculateIdealColumnWidthsTeardown() { |
678 |
604 |
|
FixedWidthTableImpl.get().recalculateIdealColumnWidthsTeardown( idealColumnWidthInfo ); |
679 |
605 |
|
idealColumnWidthInfo = null; |
680 |
606 |
|
} |
|
@@ -684,14 +610,10 @@ |
684 |
610 |
|
* |
685 |
611 |
|
* @return the number of columns |
686 |
612 |
|
*/ |
687 |
|
- |
private int getNumColumnsPerRow( int row ) |
688 |
|
- |
{ |
689 |
|
- |
if ( columnsPerRow.size() <= row ) |
690 |
|
- |
{ |
|
613 |
+ |
private int getNumColumnsPerRow( int row ) { |
|
614 |
+ |
if ( columnsPerRow.size() <= row ) { |
691 |
615 |
|
return 0; |
692 |
|
- |
} |
693 |
|
- |
else |
694 |
|
- |
{ |
|
616 |
+ |
} else { |
695 |
617 |
|
return columnsPerRow.get( row ).intValue(); |
696 |
618 |
|
} |
697 |
619 |
|
} |
|
@@ -700,10 +622,8 @@ |
700 |
622 |
|
* Recalculate the ideal column widths of each column in the data table if |
701 |
623 |
|
* they have changed since the last calculation. |
702 |
624 |
|
*/ |
703 |
|
- |
private void maybeRecalculateIdealColumnWidths() |
704 |
|
- |
{ |
705 |
|
- |
if ( idealWidths == null ) |
706 |
|
- |
{ |
|
625 |
+ |
private void maybeRecalculateIdealColumnWidths() { |
|
626 |
+ |
if ( idealWidths == null ) { |
707 |
627 |
|
recalculateIdealColumnWidths(); |
708 |
628 |
|
} |
709 |
629 |
|
} |
|
@@ -715,68 +635,51 @@ |
715 |
635 |
|
* @param row the row index |
716 |
636 |
|
* @param numColumns the number of columns in the row |
717 |
637 |
|
*/ |
718 |
|
- |
private void setNumColumnsPerRow( int row, int numColumns ) |
719 |
|
- |
{ |
|
638 |
+ |
private void setNumColumnsPerRow( int row, int numColumns ) { |
720 |
639 |
|
// Get the old number of raw columns in the row |
721 |
640 |
|
int oldNumColumns = getNumColumnsPerRow( row ); |
722 |
|
- |
if ( oldNumColumns == numColumns ) |
723 |
|
- |
{ |
|
641 |
+ |
if ( oldNumColumns == numColumns ) { |
724 |
642 |
|
return; |
725 |
643 |
|
} |
726 |
644 |
|
|
727 |
645 |
|
// Update the list of columns per row |
728 |
646 |
|
Integer numColumnsI = new Integer( numColumns ); |
729 |
647 |
|
Integer oldNumColumnsI = new Integer( oldNumColumns ); |
730 |
|
- |
if ( row < columnsPerRow.size() ) |
731 |
|
- |
{ |
|
648 |
+ |
if ( row < columnsPerRow.size() ) { |
732 |
649 |
|
columnsPerRow.set( row, numColumnsI ); |
733 |
|
- |
} |
734 |
|
- |
else |
735 |
|
- |
{ |
|
650 |
+ |
} else { |
736 |
651 |
|
columnsPerRow.add( numColumnsI ); |
737 |
652 |
|
} |
738 |
653 |
|
|
739 |
654 |
|
// Decrement the old number of columns |
740 |
655 |
|
boolean oldNumColumnsRemoved = false; |
741 |
|
- |
if ( columnCountMap.containsKey( oldNumColumnsI ) ) |
742 |
|
- |
{ |
|
656 |
+ |
if ( columnCountMap.containsKey( oldNumColumnsI ) ) { |
743 |
657 |
|
int numRows = columnCountMap.get( oldNumColumnsI ).intValue(); |
744 |
|
- |
if ( numRows == 1 ) |
745 |
|
- |
{ |
|
658 |
+ |
if ( numRows == 1 ) { |
746 |
659 |
|
columnCountMap.remove( oldNumColumnsI ); |
747 |
660 |
|
oldNumColumnsRemoved = true; |
748 |
|
- |
} |
749 |
|
- |
else |
750 |
|
- |
{ |
|
661 |
+ |
} else { |
751 |
662 |
|
columnCountMap.put( oldNumColumnsI, new Integer( numRows - 1 ) ); |
752 |
663 |
|
} |
753 |
664 |
|
} |
754 |
665 |
|
|
755 |
666 |
|
// Increment the new number of columns |
756 |
|
- |
if ( numColumns > 0 ) |
757 |
|
- |
{ |
758 |
|
- |
if ( columnCountMap.containsKey( numColumnsI ) ) |
759 |
|
- |
{ |
|
667 |
+ |
if ( numColumns > 0 ) { |
|
668 |
+ |
if ( columnCountMap.containsKey( numColumnsI ) ) { |
760 |
669 |
|
int numRows = columnCountMap.get( numColumnsI ).intValue(); |
761 |
670 |
|
columnCountMap.put( numColumnsI, new Integer( numRows + 1 ) ); |
762 |
|
- |
} |
763 |
|
- |
else |
764 |
|
- |
{ |
|
671 |
+ |
} else { |
765 |
672 |
|
columnCountMap.put( numColumnsI, new Integer( 1 ) ); |
766 |
673 |
|
} |
767 |
674 |
|
} |
768 |
675 |
|
|
769 |
676 |
|
// Update the maximum number of rows |
770 |
|
- |
if ( numColumns > maxRawColumnCount ) |
771 |
|
- |
{ |
|
677 |
+ |
if ( numColumns > maxRawColumnCount ) { |
772 |
678 |
|
maxRawColumnCount = numColumns; |
773 |
|
- |
} |
774 |
|
- |
else if ( (numColumns < oldNumColumns) && (oldNumColumns == maxRawColumnCount) && oldNumColumnsRemoved ) |
775 |
|
- |
{ |
|
679 |
+ |
} else if ( (numColumns < oldNumColumns) && (oldNumColumns == maxRawColumnCount) && oldNumColumnsRemoved ) { |
776 |
680 |
|
// Column count decreased from max count |
777 |
681 |
|
maxRawColumnCount = 0; |
778 |
|
- |
for ( Integer curNumColumns : columnCountMap.keySet() ) |
779 |
|
- |
{ |
|
682 |
+ |
for ( Integer curNumColumns : columnCountMap.keySet() ) { |
780 |
683 |
|
maxRawColumnCount = Math.max( maxRawColumnCount, curNumColumns.intValue() ); |
781 |
684 |
|
} |
782 |
685 |
|
} |
|
@@ -788,26 +691,20 @@ |
788 |
691 |
|
/** |
789 |
692 |
|
* Add or remove ghost cells when the table size changes. |
790 |
693 |
|
*/ |
791 |
|
- |
private void updateGhostRow() |
792 |
|
- |
{ |
|
694 |
+ |
private void updateGhostRow() { |
793 |
695 |
|
int curNumGhosts = getGhostColumnCount(); |
794 |
|
- |
if ( maxRawColumnCount > curNumGhosts ) |
795 |
|
- |
{ |
|
696 |
+ |
if ( maxRawColumnCount > curNumGhosts ) { |
796 |
697 |
|
// Add ghosts as needed |
797 |
698 |
|
super.addCells( 0, maxRawColumnCount - curNumGhosts ); |
798 |
|
- |
for ( int i = curNumGhosts; i < maxRawColumnCount; i++ ) |
799 |
|
- |
{ |
|
699 |
+ |
for ( int i = curNumGhosts; i < maxRawColumnCount; i++ ) { |
800 |
700 |
|
Element td = FixedWidthTableImpl.get().getGhostCell( ghostRow, i ); |
801 |
701 |
|
FixedWidthTableImpl.get().createGhostCell( td ); |
802 |
702 |
|
setColumnWidth( i, getColumnWidth( i ) ); |
803 |
703 |
|
} |
804 |
|
- |
} |
805 |
|
- |
else if ( maxRawColumnCount < curNumGhosts ) |
806 |
|
- |
{ |
|
704 |
+ |
} else if ( maxRawColumnCount < curNumGhosts ) { |
807 |
705 |
|
// Remove ghost rows as needed |
808 |
706 |
|
int cellsToRemove = curNumGhosts - maxRawColumnCount; |
809 |
|
- |
for ( int i = 0; i < cellsToRemove; i++ ) |
810 |
|
- |
{ |
|
707 |
+ |
for ( int i = 0; i < cellsToRemove; i++ ) { |
811 |
708 |
|
DOM.removeChild( ghostRow, FixedWidthTableImpl.get().getGhostCell( ghostRow, maxRawColumnCount ) ); |
812 |
709 |
|
} |
813 |
710 |
|
} |