Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/GWT/Client/src/com/google/gwt/gen2/table/client/SelectionGrid.java

Diff revisions: vs.
  @@ -15,8 +15,6 @@
15 15 */
16 16 package com.google.gwt.gen2.table.client;
17 17
18 - import java.util.*;
19 -
20 18 import com.google.gwt.dom.client.*;
21 19 import com.google.gwt.gen2.event.shared.*;
22 20 import com.google.gwt.gen2.table.event.client.*;
  @@ -24,6 +22,8 @@
24 22 import com.google.gwt.user.client.*;
25 23 import com.google.gwt.user.client.Element;
26 24
25 + import java.util.*;
26 +
27 27 /**
28 28 * A variation of the {@link Grid} that supports row or cell highlight and row
29 29 * selection.
  @@ -44,18 +44,14 @@
44 44 HasRowUnhighlightHandlers,
45 45 HasCellHighlightHandlers,
46 46 HasCellUnhighlightHandlers,
47 - HasRowSelectionHandlers
48 - {
47 + HasRowSelectionHandlers {
49 48 /**
50 49 * This class contains methods used to format a table's cells.
51 50 */
52 - public class SelectionGridCellFormatter extends CellFormatter
53 - {
51 + public class SelectionGridCellFormatter extends CellFormatter {
54 52 @Override
55 - protected Element getRawElement( int row, int column )
56 - {
57 - if ( selectionPolicy.hasInputColumn() )
58 - {
53 + protected Element getRawElement( int row, int column ) {
54 + if ( selectionPolicy.hasInputColumn() ) {
59 55 column += 1;
60 56 }
61 57 return super.getRawElement( row, column );
  @@ -65,11 +61,9 @@
65 61 /**
66 62 * This class contains methods used to format a table's rows.
67 63 */
68 - public class SelectionGridRowFormatter extends RowFormatter
69 - {
64 + public class SelectionGridRowFormatter extends RowFormatter {
70 65 @Override
71 - protected Element getRawElement( int row )
72 - {
66 + protected Element getRawElement( int row ) {
73 67 return super.getRawElement( row );
74 68 }
75 69 }
  @@ -84,30 +78,26 @@
84 78 * <li>RADIO - one row can be selected using radio buttons</li>
85 79 * </ul>
86 80 */
87 - public static enum SelectionPolicy
88 - {
81 + public static enum SelectionPolicy {
89 82 ONE_ROW( null ), MULTI_ROW( null ), CHECKBOX( "<input type='checkbox'/>" ), RADIO( "<input name='%NAME%' type='radio'/>" );
90 83
91 84 private String inputHtml;
92 85
93 - private SelectionPolicy( String inputHtml )
94 - {
86 + private SelectionPolicy( String inputHtml ) {
95 87 this.inputHtml = inputHtml;
96 88 }
97 89
98 90 /**
99 91 * @return true if the policy requires a selection column
100 92 */
101 - public boolean hasInputColumn()
102 - {
93 + public boolean hasInputColumn() {
103 94 return inputHtml != null;
104 95 }
105 96
106 97 /**
107 98 * @return the HTML string used for this policy
108 99 */
109 - private String getInputHtml()
110 - {
100 + private String getInputHtml() {
111 101 return inputHtml;
112 102 }
113 103 }
  @@ -166,8 +156,7 @@
166 156 /**
167 157 * Construct a new {@link SelectionGrid}.
168 158 */
169 - public SelectionGrid()
170 - {
159 + public SelectionGrid() {
171 160 super();
172 161 id = uniqueID++;
173 162 setCellFormatter( new SelectionGridCellFormatter() );
  @@ -185,47 +174,40 @@
185 174 *
186 175 * @throws IndexOutOfBoundsException
187 176 */
188 - public SelectionGrid( int rows, int columns )
189 - {
177 + public SelectionGrid( int rows, int columns ) {
190 178 this();
191 179 resize( rows, columns );
192 180 }
193 181
194 182 @Override
195 - public HandlerRegistration addCellHighlightHandler( CellHighlightHandler handler )
196 - {
183 + public HandlerRegistration addCellHighlightHandler( CellHighlightHandler handler ) {
197 184 return addHandler( CellHighlightEvent.TYPE, handler );
198 185 }
199 186
200 187 @Override
201 - public HandlerRegistration addCellUnhighlightHandler( CellUnhighlightHandler handler )
202 - {
188 + public HandlerRegistration addCellUnhighlightHandler( CellUnhighlightHandler handler ) {
203 189 return addHandler( CellUnhighlightEvent.TYPE, handler );
204 190 }
205 191
206 192 @Override
207 - public HandlerRegistration addRowHighlightHandler( RowHighlightHandler handler )
208 - {
193 + public HandlerRegistration addRowHighlightHandler( RowHighlightHandler handler ) {
209 194 return addHandler( RowHighlightEvent.TYPE, handler );
210 195 }
211 196
212 197 @Override
213 - public HandlerRegistration addRowSelectionHandler( RowSelectionHandler handler )
214 - {
198 + public HandlerRegistration addRowSelectionHandler( RowSelectionHandler handler ) {
215 199 return addHandler( RowSelectionEvent.TYPE, handler );
216 200 }
217 201
218 202 @Override
219 - public HandlerRegistration addRowUnhighlightHandler( RowUnhighlightHandler handler )
220 - {
203 + public HandlerRegistration addRowUnhighlightHandler( RowUnhighlightHandler handler ) {
221 204 return addHandler( RowUnhighlightEvent.TYPE, handler );
222 205 }
223 206
224 207 /**
225 208 * Deselect all selected rows in the data table.
226 209 */
227 - public void deselectAllRows()
228 - {
210 + public void deselectAllRows() {
229 211 deselectAllRows( true );
230 212 }
231 213
  @@ -235,16 +217,14 @@
235 217 *
236 218 * @param row the row index
237 219 */
238 - public void deselectRow( int row )
239 - {
220 + public void deselectRow( int row ) {
240 221 deselectRow( row, true );
241 222 }
242 223
243 224 /**
244 225 * @return the set of selected row indexes
245 226 */
246 - public Set<Integer> getSelectedRows()
247 - {
227 + public Set<Integer> getSelectedRows() {
248 228 return selectedRows.keySet();
249 229 }
250 230
  @@ -255,8 +235,7 @@
255 235 *
256 236 * @return the FlexTable's cell formatter
257 237 */
258 - public SelectionGridCellFormatter getSelectionGridCellFormatter()
259 - {
238 + public SelectionGridCellFormatter getSelectionGridCellFormatter() {
260 239 return (SelectionGridCellFormatter) getCellFormatter();
261 240 }
262 241
  @@ -267,22 +246,19 @@
267 246 *
268 247 * @return the FlexTable's cell formatter
269 248 */
270 - public SelectionGridRowFormatter getSelectionGridRowFormatter()
271 - {
249 + public SelectionGridRowFormatter getSelectionGridRowFormatter() {
272 250 return (SelectionGridRowFormatter) getRowFormatter();
273 251 }
274 252
275 253 /**
276 254 * @return the selection policy
277 255 */
278 - public SelectionPolicy getSelectionPolicy()
279 - {
256 + public SelectionPolicy getSelectionPolicy() {
280 257 return selectionPolicy;
281 258 }
282 259
283 260 @Override
284 - public int insertRow( int beforeRow )
285 - {
261 + public int insertRow( int beforeRow ) {
286 262 deselectAllRows();
287 263 return super.insertRow( beforeRow );
288 264 }
  @@ -292,33 +268,28 @@
292 268 *
293 269 * @return true if the row is selected, false if not
294 270 */
295 - public boolean isRowSelected( int row )
296 - {
271 + public boolean isRowSelected( int row ) {
297 272 return selectedRows.containsKey( new Integer( row ) );
298 273 }
299 274
300 275 /**
301 276 * @return true if selection is enabled
302 277 */
303 - public boolean isSelectionEnabled()
304 - {
278 + public boolean isSelectionEnabled() {
305 279 return selectionEnabled;
306 280 }
307 281
308 282 @Override
309 - public void onBrowserEvent( Event event )
310 - {
283 + public void onBrowserEvent( Event event ) {
311 284 super.onBrowserEvent( event );
312 285 Element targetRow = null;
313 286 Element targetCell = null;
314 287
315 - switch ( DOM.eventGetType( event ) )
316 - {
288 + switch ( DOM.eventGetType( event ) ) {
317 289 // Highlight the cell on mouse over
318 290 case Event.ONMOUSEOVER:
319 291 Element cellElem = getEventTargetCell( event );
320 - if ( cellElem != null )
321 - {
292 + if ( cellElem != null ) {
322 293 highlightCell( cellElem );
323 294 }
324 295 break;
  @@ -326,8 +297,7 @@
326 297 // Unhighlight on mouse out
327 298 case Event.ONMOUSEOUT:
328 299 Element toElem = DOM.eventGetToElement( event );
329 - if ( highlightedRowElem != null && (toElem == null || !highlightedRowElem.isOrHasChild( toElem )) )
330 - {
300 + if ( highlightedRowElem != null && (toElem == null || !highlightedRowElem.isOrHasChild( toElem )) ) {
331 301 // Check that the coordinates are not directly over the cell
332 302 int clientX = event.getClientX() + Window.getScrollLeft();
333 303 int clientY = event.getClientY() + Window.getScrollTop();
  @@ -337,8 +307,7 @@
337 307 int rowHeight = highlightedRowElem.getOffsetHeight();
338 308 int rowBottom = rowTop + rowHeight;
339 309 int rowRight = rowLeft + rowWidth;
340 - if ( clientX > rowLeft && clientX < rowRight && clientY > rowTop && clientY < rowBottom )
341 - {
310 + if ( clientX > rowLeft && clientX < rowRight && clientY > rowTop && clientY < rowBottom ) {
342 311 return;
343 312 }
344 313
  @@ -348,40 +317,34 @@
348 317 break;
349 318
350 319 // Select a row on click
351 - case Event.ONMOUSEDOWN:
352 - {
320 + case Event.ONMOUSEDOWN: {
353 321 // Ignore if selection is disabled
354 - if ( !selectionEnabled )
355 - {
322 + if ( !selectionEnabled ) {
356 323 return;
357 324 }
358 325
359 326 // Get the target row
360 327 targetCell = getEventTargetCell( event );
361 - if ( targetCell == null )
362 - {
328 + if ( targetCell == null ) {
363 329 return;
364 330 }
365 331 targetRow = DOM.getParent( targetCell );
366 332 int targetRowIndex = getRowIndex( targetRow );
367 333
368 334 // Select the row
369 - if ( selectionPolicy == SelectionPolicy.MULTI_ROW )
370 - {
335 + if ( selectionPolicy == SelectionPolicy.MULTI_ROW ) {
371 336 boolean shiftKey = DOM.eventGetShiftKey( event );
372 337 boolean ctrlKey = DOM.eventGetCtrlKey( event ) || DOM.eventGetMetaKey( event );
373 338
374 339 // Prevent default text selection
375 - if ( ctrlKey || shiftKey )
376 - {
340 + if ( ctrlKey || shiftKey ) {
377 341 event.preventDefault();
378 342 }
379 343
380 344 // Select the rows
381 345 selectRow( targetRowIndex, ctrlKey, shiftKey );
382 - }
383 - else if ( selectionPolicy == SelectionPolicy.ONE_ROW || (selectionPolicy == SelectionPolicy.RADIO && targetCell == targetRow.getFirstChild()) )
384 - {
346 + } else if ( selectionPolicy == SelectionPolicy.ONE_ROW ||
347 + (selectionPolicy == SelectionPolicy.RADIO && targetCell == targetRow.getFirstChild()) ) {
385 348 selectRow( -1, targetRow, true, true );
386 349 lastSelectedRowIndex = targetRowIndex;
387 350 }
  @@ -389,26 +352,22 @@
389 352 break;
390 353
391 354 // Prevent native inputs from being checked
392 - case Event.ONCLICK:
393 - {
355 + case Event.ONCLICK: {
394 356 // Ignore if selection is disabled
395 - if ( !selectionEnabled )
396 - {
357 + if ( !selectionEnabled ) {
397 358 return;
398 359 }
399 360
400 361 // Get the target row
401 362 targetCell = getEventTargetCell( event );
402 - if ( targetCell == null )
403 - {
363 + if ( targetCell == null ) {
404 364 return;
405 365 }
406 366 targetRow = DOM.getParent( targetCell );
407 367 int targetRowIndex = getRowIndex( targetRow );
408 368
409 369 // Select the row
410 - if ( selectionPolicy == SelectionPolicy.CHECKBOX && targetCell == targetRow.getFirstChild() )
411 - {
370 + if ( selectionPolicy == SelectionPolicy.CHECKBOX && targetCell == targetRow.getFirstChild() ) {
412 371 selectRow( targetRowIndex, true, DOM.eventGetShiftKey( event ) );
413 372 }
414 373 }
  @@ -417,8 +376,7 @@
417 376 }
418 377
419 378 @Override
420 - public void removeRow( int row )
421 - {
379 + public void removeRow( int row ) {
422 380 deselectAllRows();
423 381 super.removeRow( row );
424 382 }
  @@ -426,18 +384,15 @@
426 384 /**
427 385 * Select all rows in the table.
428 386 */
429 - public void selectAllRows()
430 - {
387 + public void selectAllRows() {
431 388 // Get the currently selected rows
432 389 Set<Row> oldRowSet = getSelectedRowsSet();
433 390
434 391 // Select all rows
435 392 RowFormatter rowFormatter = getRowFormatter();
436 393 int rowCount = getRowCount();
437 - for ( int i = 0; i < rowCount; i++ )
438 - {
439 - if ( !selectedRows.containsKey( i ) )
440 - {
394 + for ( int i = 0; i < rowCount; i++ ) {
395 + if ( !selectedRows.containsKey( i ) ) {
441 396 selectRow( i, rowFormatter.getElement( i ), false, false );
442 397 }
443 398 }
  @@ -454,8 +409,7 @@
454 409 *
455 410 * @throws IndexOutOfBoundsException
456 411 */
457 - public void selectRow( int row, boolean unselectAll )
458 - {
412 + public void selectRow( int row, boolean unselectAll ) {
459 413 selectRow( row, getRowFormatter().getElement( row ), unselectAll, true );
460 414 }
461 415
  @@ -470,8 +424,7 @@
470 424 *
471 425 * @throws IndexOutOfBoundsException
472 426 */
473 - public void selectRow( int row, boolean ctrlKey, boolean shiftKey )
474 - {
427 + public void selectRow( int row, boolean ctrlKey, boolean shiftKey ) {
475 428 // Check the row bounds
476 429 checkRowBounds( row );
477 430
  @@ -479,27 +432,21 @@
479 432 Set<Row> oldRowList = getSelectedRowsSet();
480 433
481 434 // Deselect all rows
482 - if ( !ctrlKey )
483 - {
435 + if ( !ctrlKey ) {
484 436 deselectAllRows( false );
485 437 }
486 438
487 439 boolean isSelected = selectedRows.containsKey( new Integer( row ) );
488 - if ( shiftKey && (lastSelectedRowIndex > -1) )
489 - {
440 + if ( shiftKey && (lastSelectedRowIndex > -1) ) {
490 441 // Shift+select rows
491 442 SelectionGridRowFormatter formatter = getSelectionGridRowFormatter();
492 443 int firstRow = Math.min( row, lastSelectedRowIndex );
493 444 int lastRow = Math.max( row, lastSelectedRowIndex );
494 445 lastRow = Math.min( lastRow, getRowCount() - 1 );
495 - for ( int curRow = firstRow; curRow <= lastRow; curRow++ )
496 - {
497 - if ( isSelected )
498 - {
446 + for ( int curRow = firstRow; curRow <= lastRow; curRow++ ) {
447 + if ( isSelected ) {
499 448 deselectRow( curRow, false );
500 - }
501 - else
502 - {
449 + } else {
503 450 selectRow( curRow, formatter.getRawElement( curRow ), false, false );
504 451 }
505 452 }
  @@ -507,16 +454,12 @@
507 454 // Fire Event
508 455 lastSelectedRowIndex = row;
509 456 fireRowSelectionEvent( oldRowList );
510 - }
511 - else if ( isSelected )
512 - {
457 + } else if ( isSelected ) {
513 458 // Ctrl+unselect a selected row
514 459 deselectRow( row, false );
515 460 lastSelectedRowIndex = row;
516 461 fireRowSelectionEvent( oldRowList );
517 - }
518 - else
519 - {
462 + } else {
520 463 // Select the row
521 464 SelectionGridRowFormatter formatter = getSelectionGridRowFormatter();
522 465 selectRow( row, formatter.getRawElement( row ), false, false );
  @@ -530,17 +473,14 @@
530 473 *
531 474 * @param enabled true to enable, false to disable
532 475 */
533 - public void setSelectionEnabled( boolean enabled )
534 - {
476 + public void setSelectionEnabled( boolean enabled ) {
535 477 selectionEnabled = enabled;
536 478
537 479 // Update the input elements
538 - if ( selectionPolicy.hasInputColumn() )
539 - {
480 + if ( selectionPolicy.hasInputColumn() ) {
540 481 SelectionGridCellFormatter formatter = getSelectionGridCellFormatter();
541 482 int rowCount = getRowCount();
542 - for ( int i = 0; i < rowCount; i++ )
543 - {
483 + for ( int i = 0; i < rowCount; i++ ) {
544 484 Element td = formatter.getRawElement( i, -1 );
545 485 setInputEnabled( selectionPolicy, td, enabled );
546 486 }
  @@ -553,45 +493,34 @@
553 493 *
554 494 * @param selectionPolicy the selection policy
555 495 */
556 - public void setSelectionPolicy( SelectionPolicy selectionPolicy )
557 - {
558 - if ( this.selectionPolicy == selectionPolicy )
559 - {
496 + public void setSelectionPolicy( SelectionPolicy selectionPolicy ) {
497 + if ( this.selectionPolicy == selectionPolicy ) {
560 498 return;
561 499 }
562 500 deselectAllRows();
563 501
564 502 // Update the input column
565 - if ( selectionPolicy.hasInputColumn() )
566 - {
567 - if ( this.selectionPolicy.hasInputColumn() )
568 - {
503 + if ( selectionPolicy.hasInputColumn() ) {
504 + if ( this.selectionPolicy.hasInputColumn() ) {
569 505 // Update the existing input column
570 506 String inputHtml = getInputHtml( selectionPolicy );
571 - for ( int i = 0; i < numRows; i++ )
572 - {
507 + for ( int i = 0; i < numRows; i++ ) {
573 508 Element tr = getRowFormatter().getElement( i );
574 509 tr.getFirstChildElement().setInnerHTML( inputHtml );
575 510 }
576 - }
577 - else
578 - {
511 + } else {
579 512 // Add an input column to every row
580 513 String inputHtml = getInputHtml( selectionPolicy );
581 514 Element td = createCell();
582 515 td.setInnerHTML( inputHtml );
583 - for ( int i = 0; i < numRows; i++ )
584 - {
516 + for ( int i = 0; i < numRows; i++ ) {
585 517 Element tr = getRowFormatter().getElement( i );
586 518 tr.insertBefore( td.cloneNode( true ), tr.getFirstChildElement() );
587 519 }
588 520 }
589 - }
590 - else if ( this.selectionPolicy.hasInputColumn() )
591 - {
521 + } else if ( this.selectionPolicy.hasInputColumn() ) {
592 522 // Remove the input column from every row
593 - for ( int i = 0; i < numRows; i++ )
594 - {
523 + for ( int i = 0; i < numRows; i++ ) {
595 524 Element tr = getRowFormatter().getElement( i );
596 525 tr.removeChild( tr.getFirstChildElement() );
597 526 }
  @@ -603,17 +532,14 @@
603 532 }
604 533
605 534 @Override
606 - protected Element createRow()
607 - {
535 + protected Element createRow() {
608 536 Element tr = super.createRow();
609 - if ( selectionPolicy.hasInputColumn() )
610 - {
537 + if ( selectionPolicy.hasInputColumn() ) {
611 538 Element td = createCell();
612 539 td.setPropertyString( "align", "center" );
613 540 td.setInnerHTML( getInputHtml( selectionPolicy ) );
614 541 DOM.insertChild( tr, td, 0 );
615 - if ( !selectionEnabled )
616 - {
542 + if ( !selectionEnabled ) {
617 543 setInputEnabled( selectionPolicy, td, false );
618 544 }
619 545 }
  @@ -625,22 +551,18 @@
625 551 *
626 552 * @param fireEvent true to fire events
627 553 */
628 - protected void deselectAllRows( boolean fireEvent )
629 - {
554 + protected void deselectAllRows( boolean fireEvent ) {
630 555 // Get the old list of selected rows
631 556 Set<Row> oldRows = null;
632 - if ( fireEvent )
633 - {
557 + if ( fireEvent ) {
634 558 oldRows = getSelectedRowsSet();
635 559 }
636 560
637 561 // Deselect all rows
638 562 boolean hasInputColumn = selectionPolicy.hasInputColumn();
639 - for ( Element rowElem : selectedRows.values() )
640 - {
563 + for ( Element rowElem : selectedRows.values() ) {
641 564 setStyleName( rowElem, "selected", false );
642 - if ( hasInputColumn )
643 - {
565 + if ( hasInputColumn ) {
644 566 setInputSelected( getSelectionPolicy(), (Element) rowElem.getFirstChildElement(), false );
645 567 }
646 568 }
  @@ -649,8 +571,7 @@
649 571 selectedRows.clear();
650 572
651 573 // Fire event
652 - if ( fireEvent )
653 - {
574 + if ( fireEvent ) {
654 575 fireRowSelectionEvent( oldRows );
655 576 }
656 577 }
  @@ -662,28 +583,23 @@
662 583 * @param row the row index
663 584 * @param fireEvent true to fire events
664 585 */
665 - protected void deselectRow( int row, boolean fireEvent )
666 - {
586 + protected void deselectRow( int row, boolean fireEvent ) {
667 587 Element rowElem = selectedRows.remove( new Integer( row ) );
668 - if ( rowElem != null )
669 - {
588 + if ( rowElem != null ) {
670 589 // Get the old list of selected rows
671 590 Set<Row> oldRows = null;
672 - if ( fireEvent )
673 - {
591 + if ( fireEvent ) {
674 592 oldRows = getSelectedRowsSet();
675 593 }
676 594
677 595 // Deselect the row
678 596 setStyleName( rowElem, "selected", false );
679 - if ( selectionPolicy.hasInputColumn() )
680 - {
597 + if ( selectionPolicy.hasInputColumn() ) {
681 598 setInputSelected( getSelectionPolicy(), (Element) rowElem.getFirstChildElement(), false );
682 599 }
683 600
684 601 // Fire Event
685 - if ( fireEvent )
686 - {
602 + if ( fireEvent ) {
687 603 fireRowSelectionEvent( oldRows );
688 604 }
689 605 }
  @@ -695,33 +611,27 @@
695 611 *
696 612 * @param oldRowSet the set of previously selected rows
697 613 */
698 - protected void fireRowSelectionEvent( Set<Row> oldRowSet )
699 - {
614 + protected void fireRowSelectionEvent( Set<Row> oldRowSet ) {
700 615 Set<Row> newRowList = getSelectedRowsSet();
701 - if ( newRowList.equals( oldRowSet ) )
702 - {
616 + if ( newRowList.equals( oldRowSet ) ) {
703 617 return;
704 618 }
705 619 fireEvent( new RowSelectionEvent( oldRowSet, newRowList ) );
706 620 }
707 621
708 622 @Override
709 - protected int getCellIndex( Element rowElem, Element cellElem )
710 - {
623 + protected int getCellIndex( Element rowElem, Element cellElem ) {
711 624 int index = super.getCellIndex( rowElem, cellElem );
712 - if ( selectionPolicy.hasInputColumn() )
713 - {
625 + if ( selectionPolicy.hasInputColumn() ) {
714 626 index--;
715 627 }
716 628 return index;
717 629 }
718 630
719 631 @Override
720 - protected int getDOMCellCount( int row )
721 - {
632 + protected int getDOMCellCount( int row ) {
722 633 int count = super.getDOMCellCount( row );
723 - if ( getSelectionPolicy().hasInputColumn() )
724 - {
634 + if ( getSelectionPolicy().hasInputColumn() ) {
725 635 count--;
726 636 }
727 637 return count;
  @@ -734,11 +644,9 @@
734 644 *
735 645 * @return the html representation of the input element
736 646 */
737 - protected String getInputHtml( SelectionPolicy selectionPolicy )
738 - {
647 + protected String getInputHtml( SelectionPolicy selectionPolicy ) {
739 648 String inputHtml = selectionPolicy.getInputHtml();
740 - if ( inputHtml != null )
741 - {
649 + if ( inputHtml != null ) {
742 650 inputHtml = inputHtml.replace( "%NAME%", "__gwtSelectionGrid" + id );
743 651 }
744 652 return inputHtml;
  @@ -747,19 +655,16 @@
747 655 /**
748 656 * @return a map or selected row indexes to their elements
749 657 */
750 - protected Map<Integer, Element> getSelectedRowsMap()
751 - {
658 + protected Map<Integer, Element> getSelectedRowsMap() {
752 659 return selectedRows;
753 660 }
754 661
755 662 /**
756 663 * @return a list of selected rows to pass into a {@link RowSelectionEvent}
757 664 */
758 - protected Set<Row> getSelectedRowsSet()
759 - {
665 + protected Set<Row> getSelectedRowsSet() {
760 666 Set<Row> rowSet = new TreeSet<Row>();
761 - for ( Integer rowIndex : selectedRows.keySet() )
762 - {
667 + for ( Integer rowIndex : selectedRows.keySet() ) {
763 668 rowSet.add( new Row( rowIndex.intValue() ) );
764 669 }
765 670 return rowSet;
  @@ -770,32 +675,27 @@
770 675 *
771 676 * @param cellElem the cell element
772 677 */
773 - protected void highlightCell( Element cellElem )
774 - {
678 + protected void highlightCell( Element cellElem ) {
775 679 // Ignore if the cell is already being highlighted
776 - if ( cellElem == highlightedCellElem )
777 - {
680 + if ( cellElem == highlightedCellElem ) {
778 681 return;
779 682 }
780 683
781 684 // Get the row element
782 685 Element rowElem = null;
783 - if ( cellElem != null )
784 - {
686 + if ( cellElem != null ) {
785 687 rowElem = DOM.getParent( cellElem );
786 688 }
787 689
788 690 // Unhighlight the current cell
789 - if ( highlightedCellElem != null )
790 - {
691 + if ( highlightedCellElem != null ) {
791 692 setStyleName( highlightedCellElem, "highlighted", false );
792 693 fireEvent( new CellUnhighlightEvent( highlightedRowIndex, highlightedCellIndex ) );
793 694 highlightedCellElem = null;
794 695 highlightedCellIndex = -1;
795 696
796 697 // Unhighlight the current row if it changed
797 - if ( rowElem != highlightedRowElem )
798 - {
698 + if ( rowElem != highlightedRowElem ) {
799 699 setStyleName( highlightedRowElem, "highlighted", false );
800 700 fireEvent( new RowUnhighlightEvent( highlightedRowIndex ) );
801 701 highlightedRowElem = null;
  @@ -804,15 +704,13 @@
804 704 }
805 705
806 706 // Highlight the cell
807 - if ( cellElem != null )
808 - {
707 + if ( cellElem != null ) {
809 708 setStyleName( cellElem, "highlighted", true );
810 709 highlightedCellElem = cellElem;
811 710 highlightedCellIndex = OverrideDOM.getCellIndex( cellElem );
812 711
813 712 // Highlight the row if it changed
814 - if ( highlightedRowElem == null )
815 - {
713 + if ( highlightedRowElem == null ) {
816 714 setStyleName( rowElem, "highlighted", true );
817 715 highlightedRowElem = rowElem;
818 716 highlightedRowIndex = getRowIndex( highlightedRowElem );
  @@ -832,55 +730,46 @@
832 730 * @param unselectAll true to unselect all currently selected rows
833 731 * @param fireEvent true to fire the select event to listeners
834 732 */
835 - protected void selectRow( int row, Element rowElem, boolean unselectAll, boolean fireEvent )
836 - {
733 + protected void selectRow( int row, Element rowElem, boolean unselectAll, boolean fireEvent ) {
837 734 // Get the row index if needed
838 - if ( row < 0 )
839 - {
735 + if ( row < 0 ) {
840 736 row = getRowIndex( rowElem );
841 737 }
842 738
843 739 // Ignore request if row already selected
844 740 Integer rowI = new Integer( row );
845 - if ( selectedRows.containsKey( rowI ) )
846 - {
741 + if ( selectedRows.containsKey( rowI ) ) {
847 742 return;
848 743 }
849 744
850 745 // Get the old list of selected rows
851 746 Set<Row> oldRowSet = null;
852 - if ( fireEvent )
853 - {
747 + if ( fireEvent ) {
854 748 oldRowSet = getSelectedRowsSet();
855 749 }
856 750
857 751 // Deselect current rows
858 - if ( unselectAll )
859 - {
752 + if ( unselectAll ) {
860 753 deselectAllRows( false );
861 754 }
862 755
863 756 // Select the new row
864 757 selectedRows.put( rowI, rowElem );
865 758 setStyleName( rowElem, "selected", true );
866 - if ( selectionPolicy.hasInputColumn() )
867 - {
759 + if ( selectionPolicy.hasInputColumn() ) {
868 760 setInputSelected( getSelectionPolicy(), (Element) rowElem.getFirstChildElement(), true );
869 761 }
870 762
871 763 // Fire grid listeners
872 - if ( fireEvent )
873 - {
764 + if ( fireEvent ) {
874 765 fireRowSelectionEvent( oldRowSet );
875 766 }
876 767 }
877 768
878 769 @Override
879 - protected void setBodyElement( Element element )
880 - {
770 + protected void setBodyElement( Element element ) {
881 771 super.setBodyElement( element );
882 - if ( !selectionEnabled )
883 - {
772 + if ( !selectionEnabled ) {
884 773 setSelectionEnabled( selectionEnabled );
885 774 }
886 775 }
  @@ -893,8 +782,7 @@
893 782 * @param td the cell containing the element
894 783 * @param enabled true to enable, false to disable
895 784 */
896 - protected void setInputEnabled( SelectionPolicy selectionPolicy, Element td, boolean enabled )
897 - {
785 + protected void setInputEnabled( SelectionPolicy selectionPolicy, Element td, boolean enabled ) {
898 786 ((InputElement) td.getFirstChild()).setDisabled( !enabled );
899 787 }
900 788
  @@ -906,8 +794,7 @@
906 794 * @param td the cell containing the element
907 795 * @param selected true to select, false to deselect
908 796 */
909 - protected void setInputSelected( SelectionPolicy selectionPolicy, Element td, boolean selected )
910 - {
797 + protected void setInputSelected( SelectionPolicy selectionPolicy, Element td, boolean selected ) {
911 798 ((InputElement) td.getFirstChild()).setChecked( selected );
912 799 }
913 800 }