001package 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. 002 003import com.google.gwt.dom.client.*; 004import com.google.gwt.user.client.Window; 005import votorola.a.diff.*; 006import votorola.a.web.gwt.*; 007import votorola.g.web.gwt.*; 008import votorola.s.gwt.stage.*; 009 010 011/** A targeter for a difference link in a link track. 012 */ 013class DifferenceTargeter extends LinkTrackV.Targeter1 014{ 015 016 017 /** Creates a DifferenceTargeter. 018 */ 019 DifferenceTargeter( final LinkTrackV trackV, final AnchorElement diffLink ) 020 { 021 trackV.super( diffLink, "difference" ); 022 } 023 024 025 026 // ------------------------------------------------------------------------------------ 027 028 029 /** Returns the target location for the specified difference look, or null if the 030 * current page is already at that location. 031 */ 032 static final String href( final DiffLook look ) 033 { 034 if( DiffLookJS.EQUATOR.equals( look, href_lookLast )) return href_hrefLast; // cached 035 036 final String key = look.key(); 037 final String selectand = look.selectand(); 038 final String sEffective; 039 { 040 final String s = Window.Location.getParameter( "s" ); 041 if( s == null ) sEffective = "a"; 042 else if( s.equals( "" )) sEffective = "b"; 043 else sEffective = s; 044 } 045 String href = null; 046 final StringBuilder b = GWTX.stringBuilderClear(); 047 b.append( App.getServletContextLocation() ).append( "/w/D?" ); 048 final boolean alreadyAtLocation = Window.Location.getHref().startsWith( b.toString() ) 049 && key.equals( Window.Location.getParameter( "k" )) 050 && selectand.equals( sEffective ); 051 if( !alreadyAtLocation ) 052 { 053 b.append( "k=" ).append( key ); 054 if( !"a".equals( selectand )) 055 { 056 assert "b".equals( selectand ); 057 b.append( "&s" ); 058 } 059 href = b.toString(); 060 } 061 href_lookLast = look; 062 href_hrefLast = href; 063 return href; 064 } 065 066 067 private static DiffLook href_lookLast; 068 069 070 private static String href_hrefLast; // cached for sake of NominalDifferenceTargeter 071 072 073 074 // - T a r g e t t e r ---------------------------------------------------------------- 075 076 077 @Override void retarget() 078 { 079 final DiffLook look = Stage.i().getDifference(); 080 final String href; 081 if( look == null ) href = null; 082 else href = href( look ); 083 setTarget( adjustedTarget( href )); 084 } 085 086 087}