package votorola.s.gwt.stage.link; // Copyright 2012-2013, 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.dom.client.*; import com.google.gwt.user.client.Window; import votorola.a.diff.*; import votorola.a.web.gwt.*; import votorola.g.web.gwt.*; import votorola.s.gwt.stage.*; /** A targeter for a difference link in a link track. */ class DifferenceTargeter extends LinkTrackV.Targeter1 { /** Creates a DifferenceTargeter. */ DifferenceTargeter( final LinkTrackV trackV, final AnchorElement diffLink ) { trackV.super( diffLink, "difference" ); } // ------------------------------------------------------------------------------------ /** Returns the target location for the specified difference look, or null if the * current page is already at that location. */ static final String href( final DiffLook look ) { if( DiffLookJS.EQUATOR.equals( look, href_lookLast )) return href_hrefLast; // cached final String key = look.key(); final String selectand = look.selectand(); final String sEffective; { final String s = Window.Location.getParameter( "s" ); if( s == null ) sEffective = "a"; else if( s.equals( "" )) sEffective = "b"; else sEffective = s; } String href = null; final StringBuilder b = GWTX.stringBuilderClear(); b.append( App.getServletContextLocation() ).append( "/w/D?" ); final boolean alreadyAtLocation = Window.Location.getHref().startsWith( b.toString() ) && key.equals( Window.Location.getParameter( "k" )) && selectand.equals( sEffective ); if( !alreadyAtLocation ) { b.append( "k=" ).append( key ); if( !"a".equals( selectand )) { assert "b".equals( selectand ); b.append( "&s" ); } href = b.toString(); } href_lookLast = look; href_hrefLast = href; return href; } private static DiffLook href_lookLast; private static String href_hrefLast; // cached for sake of NominalDifferenceTargeter // - T a r g e t t e r ---------------------------------------------------------------- @Override void retarget() { final DiffLook look = Stage.i().getDifference(); final String href; if( look == null ) href = null; else href = href( look ); setTarget( adjustedTarget( href )); } }