View Javadoc

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: AbstractPage.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/page/common/AbstractPage.java $
18  */
19  package com.hack23.cia.web.impl.ui.page.common;
20  
21  import org.slf4j.Logger;
22  import org.slf4j.LoggerFactory;
23  import org.vaadin.navigator7.NavigableApplication;
24  
25  import com.hack23.cia.service.api.ApplicationManager;
26  import com.hack23.cia.service.api.ConfigurationManager;
27  import com.hack23.cia.web.impl.ui.common.ApplicationUserState;
28  import com.hack23.cia.web.impl.ui.common.ApplicationUserStateHolder;
29  import com.vaadin.Application;
30  import com.vaadin.terminal.gwt.server.WebApplicationContext;
31  import com.vaadin.terminal.gwt.server.WebBrowser;
32  import com.vaadin.ui.Component;
33  import com.vaadin.ui.CustomComponent;
34  
35  /**
36   * The Class AbstractPage.
37   */
38  public abstract class AbstractPage extends CustomComponent implements Page {
39  
40  	/** The Constant serialVersionUID. */
41  	private static final long serialVersionUID = 1L;
42  
43  	/** The user state. */
44  	private final transient ApplicationUserState userState;
45  
46  	/** The configuration manager. */
47  	private final transient ConfigurationManager configurationManager;
48  
49  	/** The application manager. */
50  	private final transient ApplicationManager applicationManager;
51  
52  	/** The Constant LOGGER. */
53  	private static final Logger LOGGER = LoggerFactory
54  			.getLogger(AbstractPage.class);
55  
56  	/** The screen height. */
57  	private final String screenHeight;
58  
59  	/**
60  	 * Instantiates a new abstract page.
61  	 */
62  	protected AbstractPage() {
63  		super();
64  		userState = ApplicationUserStateHolder.getUserState();
65  		configurationManager = userState.getConfigurationManager();
66  		applicationManager = userState.getApplicationManager();
67  		screenHeight=calculateScreenHeightFromBrowser();
68  	}
69  
70  	/**
71  	 * Calculate screen height from browser.
72  	 *
73  	 * @return the string
74  	 */
75  	private String calculateScreenHeightFromBrowser() {
76  		return (((((WebApplicationContext) ((Application) userState).getContext()).getBrowser().getScreenHeight()-120)  * 75) / 100) +"px";
77  	}
78  
79  	/**
80  	 * Gets the application manager.
81  	 *
82  	 * @return the application manager
83  	 */
84  	protected final ApplicationManager getApplicationManager() {
85  		return applicationManager;
86  	}
87  
88  	/**
89  	 * Gets the browser.
90  	 *
91  	 * @return the browser
92  	 */
93  	protected final WebBrowser getBrowser() {
94  		return ((WebApplicationContext) ((Application) userState).getContext()).getBrowser();
95  	}
96  
97  	/**
98  	 * Gets the configuration manager.
99  	 *
100 	 * @return the configuration manager
101 	 */
102 	protected final ConfigurationManager getConfigurationManager() {
103 		return configurationManager;
104 	}
105 
106 	/* (non-Javadoc)
107 	 * @see com.hack23.cia.web.impl.ui.page.Page#getLogger()
108 	 */
109 	@Override
110 	public final Logger getLogger() {
111 		return LOGGER;
112 	}
113 
114 	/* (non-Javadoc)
115 	 * @see com.hack23.cia.web.impl.ui.page.common.Page#getPageTitle()
116 	 */
117 	@Override
118 	public abstract String getPageTitle();
119 
120 	/**
121 	 * Gets the screen height.
122 	 *
123 	 * @return the screen height
124 	 */
125 	protected final String getScreenHeight() {
126 		return screenHeight;
127 	}
128 
129 	/* (non-Javadoc)
130 	 * @see com.hack23.cia.web.impl.ui.page.Page#getUserState()
131 	 */
132 	/**
133 	 * Gets the user state.
134 	 *
135 	 * @return the user state
136 	 */
137 	protected final ApplicationUserState getUserState() {
138 		return userState;
139 	}
140 
141 	/* (non-Javadoc)
142 	 * @see com.hack23.cia.web.impl.ui.page.Page#navigateTo(java.lang.Class)
143 	 */
144 	@Override
145 	public final void navigateTo(final Class<? extends Component> page) {
146 		NavigableApplication.getCurrentNavigableAppLevelWindow().getNavigator().navigateTo(page);
147 
148 	}
149 
150 	/* (non-Javadoc)
151 	 * @see com.hack23.cia.web.impl.ui.page.Page#navigateTo(java.lang.Class, java.lang.String)
152 	 */
153 	@Override
154 	public final void navigateTo(final Class<? extends Component> page,final String params) {
155 		NavigableApplication.getCurrentNavigableAppLevelWindow().getNavigator().navigateTo(page,params);
156 	}
157 
158 	/**
159 	 * Translate from english.
160 	 *
161 	 * @param string
162 	 *            the string
163 	 * @return the string
164 	 */
165 	protected final String translateFromEnglish(final String string) {
166 		return userState.translateFromEnglish(string);
167 	}
168 
169 }