package 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. import com.google.gwt.cell.client.*; import com.google.gwt.user.cellview.client.*; import com.google.gwt.view.client.*; import java.util.*; import votorola.s.gwt.scene.*; /** A view of a bite feed rendered as a GWT cell list. */ public class FeedVCellList extends CellList { /** Constructs a FeedVCellList. */ public FeedVCellList( Cell biteVCell ) { super( biteVCell ); setPageSize( PAGE_SIZE ); addStyleName( "feed-FeedVCellList" ); setSelectionModel( Scenes.i().biteSelection() ); setKeyboardSelectionPolicy( HasKeyboardSelectionPolicy.KeyboardSelectionPolicy. // BOUND_TO_SELECTION ); // // To sync keyboard selection with item selection. Note that when a selected // // item drops off the bottom of the list, this policy causes the top item to // // become selected. ///////// won't let you scroll away from selection so: DISABLED ); } // ------------------------------------------------------------------------------------ /** The maximum height of the viewport, as measured in rows. */ public static final int PAGE_SIZE = 500; // the default is a puny 25 // - H a s D a t a -------------------------------------------------------------------- /** Updates the view from the model. Also adjusts the bite selection to ensure that a * visible bite is selected, and that top selectands are sticky. * * @see Scenes#biteSelection() */ public @Override void setRowData( final int r0, final List rows ) { // Control the selections. Some of this is tied to the view (top selectand) so it's // convenient to code all of it here in the common base class. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - assert r0 >= 0; final SingleSelectionModel selection = Scenes.i().biteSelection(); if( rows.size() > r0 ) { final Object selectand = selection.getSelectedObject(); if( selectand == null || BiteJS.EMPTY_BITE.equals( selectand ) // always have a selectand || getVisibleItemCount() > 0 && selectand.equals( getVisibleItem( 0 )) // make top selectand sticky || !rows.contains( selectand )) // always have a visible selectand { selection.setSelected( rows.get(r0), true ); } } else selection.setSelected( BiteJS.EMPTY_BITE, true ); // so expansion from null list forces selectand to the top, where it probably was // - - - super.setRowData( r0, rows ); } }