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.goverment.pagemode;
20  
21  import org.apache.commons.lang3.StringUtils;
22  import org.springframework.beans.factory.annotation.Autowired;
23  import org.springframework.security.access.annotation.Secured;
24  import org.springframework.stereotype.Service;
25  
26  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
27  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
28  import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.ChartDataManager;
29  import com.hack23.cia.web.impl.ui.application.views.common.dataseriesfactory.api.MinistryDataSeriesFactory;
30  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.ChartIndicators;
31  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PageMode;
32  import com.vaadin.ui.HorizontalLayout;
33  import com.vaadin.ui.Layout;
34  import com.vaadin.ui.MenuBar;
35  import com.vaadin.ui.Panel;
36  import com.vaadin.ui.VerticalLayout;
37  
38  /**
39   * The Class MinistryRankingAllPartiesChartsPageModContentFactoryImpl.
40   */
41  @Service
42  public final class MinistryRankingAllPartiesChartsPageModContentFactoryImpl
43  		extends AbstractMinistryRankingPageModContentFactoryImpl {
44  
45  	/** The Constant CHARTS. */
46  	private static final String CHARTS = "Charts: All Parties, total days served";
47  
48  	/** The chart data manager. */
49  	@Autowired
50  	private ChartDataManager chartDataManager;
51  
52  	/** The data series factory. */
53  	@Autowired
54  	private MinistryDataSeriesFactory dataSeriesFactory;
55  
56  	/**
57  	 * Instantiates a new ministry ranking all parties charts page mod content
58  	 * factory impl.
59  	 */
60  	public MinistryRankingAllPartiesChartsPageModContentFactoryImpl() {
61  		super();
62  	}
63  
64  	@Override
65  	public boolean matches(final String page, final String parameters) {
66  		return NAME.equals(page) && !StringUtils.isEmpty(parameters) && parameters.contains(PageMode.CHARTS.toString())
67  				&& parameters.contains(ChartIndicators.ALLMINISTRIESPARTYBYTOTALDAYS.toString());
68  	}
69  
70  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
71  	@Override
72  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
73  		final VerticalLayout panelContent = createPanelContent();
74  
75  		getMinistryRankingMenuItemFactory().createMinistryRankingMenuBar(menuBar);
76  
77  		final String pageId = getPageId(parameters);
78  
79  		final HorizontalLayout chartLayout = new HorizontalLayout();
80  		chartLayout.setSizeFull();
81  
82  		chartDataManager.createChartPanel(chartLayout,
83  				dataSeriesFactory.createChartTimeSeriesTotalDaysServedGovernmentByParty(),
84  				"All Parties, total days served");
85  
86  		panelContent.addComponent(chartLayout);
87  
88  		panel.setCaption(CHARTS + parameters);
89  
90  		getPageActionEventHelper().createPageEvent(ViewAction.VISIT_MINISTRY_RANKING_VIEW, ApplicationEventGroup.USER,
91  				NAME, parameters, pageId);
92  
93  		return panelContent;
94  
95  	}
96  
97  }