001package votorola.s.gwt.stage.vote; // Copyright 2012, 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.web.bindery.event.shared.HandlerRegistration; 004import votorola.g.hold.*; 005import votorola.g.web.gwt.*; 006import votorola.g.web.gwt.event.*; 007 008 009/** A modeller for component views that suspends remodelling while the parent view is 010 * {@linkplain VoteTrackV#isMoving() in motion}. 011 */ 012abstract class SuspendedModeller implements ChangeHandler, PropertyChangeHandler 013{ 014 015 016 /** Creates a SuspendedModeller. 017 * 018 * @param _spool the spool for the release of associated holds. When unwound it 019 * releases the holds of the modeller and thereby disables it. 020 */ 021 SuspendedModeller( final VoteTrackV trackV, Spool _spool ) 022 { 023 this.trackV = trackV; // instead of trackV = _trackV, which causes GWT compiler error (2.4) 024 spool = _spool; 025 spool.add( new Hold() 026 { 027 final HandlerRegistration hR = GWTX.i().bus().addHandlerToSource( 028 Change.TYPE, /*source*/trackV.track(), SuspendedModeller.this ); 029 public void release() { hR.removeHandler(); } 030 }); 031 spool.add( new Hold() 032 { 033 final HandlerRegistration hR = trackV.addHandler( SuspendedModeller.this, 034 PropertyChange.TYPE ); 035 public void release() { hR.removeHandler(); } 036 }); 037 } 038 039 040 041 // ------------------------------------------------------------------------------------ 042 043 044 /** Reshapes the view according to the current model state. 045 */ 046 abstract void remodel(); 047 048 049 050 /** Calls <code>remodel()</code> unless the parent view is {@linkplain 051 * VoteTrackV#isMoving() moving}, in which case it does nothing. 052 */ 053 final void remodelUnlessMoving() { if( !trackV.isMoving() ) remodel(); } 054 055 056 057 /** The parent view. 058 */ 059 final VoteTrackV trackV() { return trackV; } 060 061 062 private final VoteTrackV trackV; 063 064 065 066 // - C h a n g e - H a n d l e r - ---------------------------------------------------- 067 068 069 public final void onChange( Change _e ) { if( !spool.isUnwinding() ) remodelUnlessMoving(); } 070 071 072 073 // - P r o p e r t y - C h a n g e - H a n d l e r - ---------------------------------- 074 075 076 public final void onPropertyChange( final PropertyChange e ) 077 { 078 if( spool.isUnwinding() ) return; 079 080 if( e.propertyName().equals( "moving" )) remodelUnlessMoving(); 081 } 082 083 084 085//// P r i v a t e /////////////////////////////////////////////////////////////////////// 086 087 088 private final Spool spool; 089 090 091}