View Javadoc

1   package org.kuali.student.common.ui.client.util;
2   
3   import com.google.gwt.user.client.Window;
4   
5   /**
6    * Provides a variety of helper methods to manipulate page title based on location
7    * 
8    * @author Kuali Student Team
9    *
10   */
11  public class WindowTitleUtils {
12  	
13  	private static String contextTitle = "";
14  	private static String appTitle = "";
15  	private static String subTitle = "";
16  	
17  	public static void setApplicationTitle(String title){
18  		appTitle = title;
19  		contextTitle = "";
20  		subTitle = "";
21  		Window.setTitle(generateWindowTitle());
22  	}
23  	
24  	/**
25  	 * Call this when scope of the application changes to make this be the new
26  	 * preceding title for the window, followed by last breadcrumb name
27  	 */
28  	public static void setContextTitle(String title){
29  		contextTitle = title;
30  		subTitle = "";
31  		Window.setTitle(generateWindowTitle());
32  	}
33  	
34  	/**
35  	 * Call this to change the subtitle
36  	 */
37  	public static void setSubtitle(String title){
38  		subTitle = title;
39  		Window.setTitle(generateWindowTitle());
40  	}
41  	
42  	private static String generateWindowTitle(){
43  		String title = null;
44  		if(appTitle != null && !appTitle.equals("")){
45  			title = appTitle;
46  		}
47  		
48  		if(contextTitle != null && !contextTitle.equals("")){
49  			if(title != null){
50  				if(!contextTitle.equals(appTitle)){
51  					title = title + ": " + contextTitle;
52  				}
53  			}
54  			else{
55  				title = contextTitle;
56  			}
57  		}
58  		
59  		if(subTitle != null && !subTitle.equals("")){
60  			if(title != null){
61  				if(!subTitle.equals(contextTitle)){
62  					title = title + " - " + subTitle;
63  				}
64  			}
65  			else{
66  				title = subTitle;
67  			}
68  		}
69  		
70  		if(title == null){
71  			title = "KS";
72  		}
73  		
74  		return title;
75  	}
76  }