001package votorola.s.gwt.scene.feed; // Copyright 2010, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. 002 003import com.google.gwt.cell.client.*; 004import com.google.gwt.user.cellview.client.*; 005import com.google.gwt.view.client.*; 006import java.util.*; 007import votorola.s.gwt.scene.*; 008 009 010/** A view of a bite feed rendered as a GWT cell list. 011 */ 012public class FeedVCellList extends CellList<BiteJS> 013{ 014 015 016 /** Constructs a FeedVCellList. 017 */ 018 public FeedVCellList( Cell<BiteJS> biteVCell ) 019 { 020 super( biteVCell ); 021 setPageSize( PAGE_SIZE ); 022 addStyleName( "feed-FeedVCellList" ); 023 024 setSelectionModel( Scenes.i().biteSelection() ); 025 setKeyboardSelectionPolicy( HasKeyboardSelectionPolicy.KeyboardSelectionPolicy. 026 // BOUND_TO_SELECTION ); 027 // // To sync keyboard selection with item selection. Note that when a selected 028 // // item drops off the bottom of the list, this policy causes the top item to 029 // // become selected. 030 ///////// won't let you scroll away from selection so: 031 DISABLED ); 032 } 033 034 035 036 // ------------------------------------------------------------------------------------ 037 038 039 /** The maximum height of the viewport, as measured in rows. 040 */ 041 public static final int PAGE_SIZE = 500; // the default is a puny 25 042 043 044 045 // - H a s D a t a -------------------------------------------------------------------- 046 047 048 /** Updates the view from the model. Also adjusts the bite selection to ensure that a 049 * visible bite is selected, and that top selectands are sticky. 050 * 051 * @see Scenes#biteSelection() 052 */ 053 public @Override void setRowData( final int r0, final List<? extends BiteJS> rows ) 054 { 055 056 // Control the selections. Some of this is tied to the view (top selectand) so it's 057 // convenient to code all of it here in the common base class. 058 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 059 assert r0 >= 0; 060 final SingleSelectionModel<BiteJS> selection = Scenes.i().biteSelection(); 061 if( rows.size() > r0 ) 062 { 063 final Object selectand = selection.getSelectedObject(); 064 if( selectand == null || BiteJS.EMPTY_BITE.equals( selectand ) // always have a selectand 065 || getVisibleItemCount() > 0 && selectand.equals( getVisibleItem( 0 )) // make top selectand sticky 066 || !rows.contains( selectand )) // always have a visible selectand 067 { 068 selection.setSelected( rows.get(r0), true ); 069 } 070 } 071 else selection.setSelected( BiteJS.EMPTY_BITE, true ); 072 // so expansion from null list forces selectand to the top, where it probably was 073 074 // - - - 075 super.setRowData( r0, rows ); 076 } 077 078 079 080}