1 /* 2 * Copyright 2010 James Pether Sörling 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 * $Id: ApplicationUserStateHolder.java 5436 2011-04-26 18:25:22Z pether $ 17 * $HeadURL: https://cia.svn.sourceforge.net/svnroot/cia/trunk/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/common/ApplicationUserStateHolder.java $ 18 */ 19 package com.hack23.cia.web.impl.ui.common; 20 21 import com.vaadin.Application; 22 import com.vaadin.terminal.gwt.server.WebApplicationContext; 23 import com.vaadin.terminal.gwt.server.WebBrowser; 24 25 /** 26 * The Class ApplicationUserStateHolder. 27 */ 28 public final class ApplicationUserStateHolder { 29 30 /** The current application. */ 31 private static ThreadLocal<ApplicationUserState> currentApplication = new ThreadLocal<ApplicationUserState>(); 32 33 /** 34 * Adds the current application user state. 35 * 36 * @param applicationUserState 37 * the application user state 38 */ 39 public static void addCurrentApplicationUserState( 40 final ApplicationUserState applicationUserState) { 41 currentApplication.set(applicationUserState); 42 } 43 44 /** 45 * Gets the user state. 46 * 47 * @return the user state 48 */ 49 public static ApplicationUserState getUserState() { 50 return currentApplication.get(); 51 } 52 53 /** 54 * Gets the web browser. 55 * 56 * @return the web browser 57 */ 58 public static WebBrowser getWebBrowser() { 59 return ((WebApplicationContext) ((Application) currentApplication.get()).getContext()).getBrowser(); 60 } 61 62 /** 63 * Removes the current application user state. 64 */ 65 public static void removeCurrentApplicationUserState() { 66 currentApplication.set(null); 67 currentApplication.remove(); 68 } 69 70 /** 71 * Instantiates a new application user state holder. 72 */ 73 private ApplicationUserStateHolder() { 74 super(); 75 } 76 }