View Javadoc
1   /*
2    * Copyright 2014 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$
17   *  $HeadURL$
18  */
19  package com.hack23.cia.web.impl.ui.application.views.common.pagemode;
20  
21  import org.springframework.beans.factory.annotation.Autowired;
22  
23  import com.hack23.cia.service.api.ApplicationManager;
24  import com.hack23.cia.web.impl.ui.application.action.PageActionEventHelper;
25  import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.AdminChartDataManager;
26  import com.hack23.cia.web.impl.ui.application.views.common.formfactory.api.FormFactory;
27  import com.hack23.cia.web.impl.ui.application.views.common.gridfactory.api.GridFactory;
28  import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.ApplicationMenuItemFactory;
29  import com.hack23.cia.web.impl.ui.application.views.common.pagelinks.api.PageLinkFactory;
30  import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
31  import com.vaadin.server.Sizeable.Unit;
32  import com.vaadin.ui.HorizontalLayout;
33  import com.vaadin.ui.TabSheet;
34  import com.vaadin.ui.TabSheet.Tab;
35  import com.vaadin.ui.VerticalLayout;
36  
37  /**
38   * The Class AbstractPageModContentFactoryImpl.
39   */
40  public abstract class AbstractPageModContentFactoryImpl implements PageModeContentFactory {
41  
42  	/** The Constant GENERAL_PAGE_MODE_PAGE_VISIT. */
43  	public static final String GENERAL_PAGE_MODE_PAGE_VISIT = "General Page Mode Page Visit";
44  
45  	/** The Constant CURRENT_PAGE_VISIT_HISTORY. */
46  	public static final String CURRENT_PAGE_VISIT_HISTORY = "Current Page Visit History";
47  
48  	/** The application manager. */
49  	@Autowired
50  	private ApplicationManager applicationManager;
51  
52  	/** The menu item factory. */
53  	@Autowired
54  	private ApplicationMenuItemFactory menuItemFactory;
55  
56  	/** The grid factory. */
57  	@Autowired
58  	private GridFactory gridFactory;
59  
60  	/** The form factory. */
61  	@Autowired
62  	private FormFactory formFactory;
63  
64  	/** The page link factory. */
65  	@Autowired
66  	private PageLinkFactory pageLinkFactory;
67  
68  	/** The page action event helper. */
69  	@Autowired
70  	private PageActionEventHelper pageActionEventHelper;
71  
72  	/** The admin chart data manager. */
73  	@Autowired
74  	private AdminChartDataManager adminChartDataManager;
75  
76  	/**
77  	 * Instantiates a new abstract page mod content factory impl.
78  	 */
79  	protected AbstractPageModContentFactoryImpl() {
80  		super();
81  	}
82  
83  	/**
84  	 * Gets the page id.
85  	 *
86  	 * @param parameters
87  	 *            the parameters
88  	 * @return the page id
89  	 */
90  	protected final String getPageId(final String parameters) {
91  		if (parameters != null) {
92  			final int pageNr = getPageNr(parameters);
93  			final String cleanedString = parameters.replace("[" + pageNr + "]", "");
94  
95  			return cleanedString.substring(cleanedString.lastIndexOf('/') + "/".length(), cleanedString.length());
96  		} else {
97  			return "";
98  		}
99  	}
100 
101 	/**
102 	 * Gets the page nr.
103 	 *
104 	 * @param parameters
105 	 *            the parameters
106 	 * @return the page nr
107 	 */
108 	protected final int getPageNr(final String parameters) {
109 		String pageNrValue;
110 		if (parameters != null && parameters.contains("[") && parameters.contains("]")) {
111 			pageNrValue = parameters.substring(parameters.indexOf('[') + 1, parameters.lastIndexOf(']'));
112 		} else {
113 			pageNrValue = "";
114 		}
115 
116 		int pageNr = 1;
117 
118 		if (pageNrValue.length() > 0) {
119 			pageNr = Integer.parseInt(pageNrValue);
120 		}
121 		return pageNr;
122 	}
123 
124 	/**
125 	 * Gets the application manager.
126 	 *
127 	 * @return the application manager
128 	 */
129 	protected final ApplicationManager getApplicationManager() {
130 		return applicationManager;
131 	}
132 
133 	/**
134 	 * Gets the menu item factory.
135 	 *
136 	 * @return the menu item factory
137 	 */
138 	protected final ApplicationMenuItemFactory getMenuItemFactory() {
139 		return menuItemFactory;
140 	}
141 
142 	/**
143 	 * Gets the grid factory.
144 	 *
145 	 * @return the grid factory
146 	 */
147 	protected final GridFactory getGridFactory() {
148 		return gridFactory;
149 	}
150 
151 	/**
152 	 * Gets the form factory.
153 	 *
154 	 * @return the form factory
155 	 */
156 	protected final FormFactory getFormFactory() {
157 		return formFactory;
158 	}
159 
160 	/**
161 	 * Gets the page link factory.
162 	 *
163 	 * @return the page link factory
164 	 */
165 	protected final PageLinkFactory getPageLinkFactory() {
166 		return pageLinkFactory;
167 	}
168 
169 	/**
170 	 * Gets the page action event helper.
171 	 *
172 	 * @return the page action event helper
173 	 */
174 	protected final PageActionEventHelper getPageActionEventHelper() {
175 		return pageActionEventHelper;
176 	}
177 
178 	/**
179 	 * Creates the panel content.
180 	 *
181 	 * @return the vertical layout
182 	 */
183 	protected final VerticalLayout createPanelContent() {
184 		final VerticalLayout panelContent = new VerticalLayout();
185 		panelContent.setMargin(true);
186 		panelContent.setWidth(100, Unit.PERCENTAGE);
187 		panelContent.setHeight(100, Unit.PERCENTAGE);
188 		panelContent.setStyleName("Header");
189 		return panelContent;
190 	}
191 
192 	/**
193 	 * Creates the page visit history.
194 	 *
195 	 * @param pageName
196 	 *            the page name
197 	 * @param pageId
198 	 *            the page id
199 	 * @param panelContent
200 	 *            the panel content
201 	 */
202 	protected final void createPageVisitHistory(final String pageName, final String pageId,
203 			final VerticalLayout panelContent) {
204 
205 		final TabSheet tabsheet = new TabSheet();
206 		tabsheet.setWidth(100, Unit.PERCENTAGE);
207 		tabsheet.setHeight(100, Unit.PERCENTAGE);
208 
209 		panelContent.addComponent(tabsheet);
210 		panelContent.setExpandRatio(tabsheet, ContentRatio.LARGE);
211 
212 		final HorizontalLayout tabContentPageItemRankHistory = new HorizontalLayout();
213 		tabContentPageItemRankHistory.setWidth(100, Unit.PERCENTAGE);
214 		tabContentPageItemRankHistory.setHeight(100, Unit.PERCENTAGE);
215 		final Tab tabPageItemRankHistory = tabsheet.addTab(tabContentPageItemRankHistory);
216 
217 		tabPageItemRankHistory.setCaption(CURRENT_PAGE_VISIT_HISTORY);
218 		adminChartDataManager.createApplicationActionEventPageElementDailySummaryChart(tabContentPageItemRankHistory,
219 				pageName, pageId);
220 
221 		final HorizontalLayout tabContentPageModeSummary = new HorizontalLayout();
222 		tabContentPageModeSummary.setWidth(100, Unit.PERCENTAGE);
223 		tabContentPageModeSummary.setHeight(100, Unit.PERCENTAGE);
224 		final Tab tabPageModeSummary = tabsheet.addTab(tabContentPageModeSummary);
225 		tabPageModeSummary.setCaption(GENERAL_PAGE_MODE_PAGE_VISIT);
226 
227 		adminChartDataManager.createApplicationActionEventPageModeDailySummaryChart(tabContentPageModeSummary,
228 				pageName);
229 
230 	}
231 
232 }