package 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. import com.google.web.bindery.event.shared.HandlerRegistration; import votorola.g.hold.*; import votorola.g.web.gwt.*; import votorola.g.web.gwt.event.*; /** A modeller for component views that suspends remodelling while the parent view is * {@linkplain VoteTrackV#isMoving() in motion}. */ abstract class SuspendedModeller implements ChangeHandler, PropertyChangeHandler { /** Creates a SuspendedModeller. * * @param _spool the spool for the release of associated holds. When unwound it * releases the holds of the modeller and thereby disables it. */ SuspendedModeller( final VoteTrackV trackV, Spool _spool ) { this.trackV = trackV; // instead of trackV = _trackV, which causes GWT compiler error (2.4) spool = _spool; spool.add( new Hold() { final HandlerRegistration hR = GWTX.i().bus().addHandlerToSource( Change.TYPE, /*source*/trackV.track(), SuspendedModeller.this ); public void release() { hR.removeHandler(); } }); spool.add( new Hold() { final HandlerRegistration hR = trackV.addHandler( SuspendedModeller.this, PropertyChange.TYPE ); public void release() { hR.removeHandler(); } }); } // ------------------------------------------------------------------------------------ /** Reshapes the view according to the current model state. */ abstract void remodel(); /** Calls remodel() unless the parent view is {@linkplain * VoteTrackV#isMoving() moving}, in which case it does nothing. */ final void remodelUnlessMoving() { if( !trackV.isMoving() ) remodel(); } /** The parent view. */ final VoteTrackV trackV() { return trackV; } private final VoteTrackV trackV; // - C h a n g e - H a n d l e r - ---------------------------------------------------- public final void onChange( Change _e ) { if( !spool.isUnwinding() ) remodelUnlessMoving(); } // - P r o p e r t y - C h a n g e - H a n d l e r - ---------------------------------- public final void onPropertyChange( final PropertyChange e ) { if( spool.isUnwinding() ) return; if( e.propertyName().equals( "moving" )) remodelUnlessMoving(); } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private final Spool spool; }