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.user.politician.pagemode;
20  
21  import org.springframework.beans.factory.annotation.Autowired;
22  
23  import com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician;
24  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
25  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
26  import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.PoliticianMenuItemFactory;
27  import com.hack23.cia.web.impl.ui.application.views.common.pagemode.AbstractPageModContentFactoryImpl;
28  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
29  import com.vaadin.ui.Component;
30  
31  /**
32   * The Class AbstractPoliticianPageModContentFactoryImpl.
33   */
34  abstract class AbstractPoliticianPageModContentFactoryImpl extends AbstractPageModContentFactoryImpl {
35  
36  	/** The Constant NAME. */
37  	public static final String NAME = UserViews.POLITICIAN_VIEW_NAME;
38  
39  	/** The Constant POLITICIAN. */
40  	private static final String POLITICIAN = "Politician:";
41  
42  	/** The Constant DAYS_PER_STANDARD_YEAR. */
43  	private static final long DAYS_PER_STANDARD_YEAR = 365L;
44  
45  	/** The politician ranking menu item factory. */
46  	@Autowired
47  	private PoliticianMenuItemFactory politicianMenuItemFactory;
48  
49  
50  	/**
51  	 * Instantiates a new abstract politician page mod content factory impl.
52  	 */
53  	AbstractPoliticianPageModContentFactoryImpl() {
54  		super();
55  	}
56  
57  	/**
58  	 * Convert to years string.
59  	 *
60  	 * @param totalDays
61  	 *            the total days
62  	 * @return the string
63  	 */
64  	protected final String convertToYearsString(final long totalDays) {
65  		final long years = totalDays / DAYS_PER_STANDARD_YEAR;
66  		final long days = totalDays - years * DAYS_PER_STANDARD_YEAR;
67  
68  		return years + " Years " + days + " days";
69  	}
70  
71  	/**
72  	 * Page completed.
73  	 *
74  	 * @param parameters
75  	 *            the parameters
76  	 * @param panel
77  	 *            the panel
78  	 * @param pageId
79  	 *            the page id
80  	 * @param viewRiksdagenPolitician
81  	 *            the view riksdagen politician
82  	 */
83  	protected final void pageCompleted(final String parameters, final Component panel, final String pageId,
84  			final ViewRiksdagenPolitician viewRiksdagenPolitician) {
85  		getPageActionEventHelper().createPageEvent(ViewAction.VISIT_POLITICIAN_VIEW, ApplicationEventGroup.USER,
86  				UserViews.POLITICIAN_VIEW_NAME, parameters, pageId);
87  
88  		panel.setCaption(POLITICIAN + viewRiksdagenPolitician.getFirstName() + ' '
89  				+ viewRiksdagenPolitician.getLastName() + '(' + viewRiksdagenPolitician.getParty() + ')');
90  	}
91  
92  	/**
93  	 * Gets the politician ranking menu item factory.
94  	 *
95  	 * @return the politician ranking menu item factory
96  	 */
97  	protected final PoliticianMenuItemFactory getPoliticianMenuItemFactory() {
98  		return politicianMenuItemFactory;
99  	}
100 
101 }