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.committee.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.CommitteeDataSeriesFactory;
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.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
33  import com.vaadin.ui.HorizontalLayout;
34  import com.vaadin.ui.Layout;
35  import com.vaadin.ui.MenuBar;
36  import com.vaadin.ui.Panel;
37  import com.vaadin.ui.VerticalLayout;
38  
39  /**
40   * The Class CommitteeRankingCommitteeByPartyChartsPageModContentFactoryImpl.
41   */
42  @Service
43  public final class CommitteeRankingCommitteeByPartyChartsPageModContentFactoryImpl
44  		extends AbstractCommitteeRankingPageModContentFactoryImpl {
45  
46  	/** The Constant NAME. */
47  	public static final String NAME = UserViews.COMMITTEE_RANKING_VIEW_NAME;
48  
49  	/** The Constant ALL_PARTIES_TOTAL_DAYS_SERVED. */
50  	private static final String ALL_PARTIES_TOTAL_DAYS_SERVED = "All Parties, total days served";
51  
52  	/** The Constant CHARTS. */
53  	private static final String CHARTS = "Charts:";
54  
55  	/** The chart data manager. */
56  	@Autowired
57  	private ChartDataManager chartDataManager;
58  
59  	/** The data series factory. */
60  	@Autowired
61  	private CommitteeDataSeriesFactory dataSeriesFactory;
62  
63  	/**
64  	 * Instantiates a new committee ranking committee by party charts page mod
65  	 * content factory impl.
66  	 */
67  	public CommitteeRankingCommitteeByPartyChartsPageModContentFactoryImpl() {
68  		super();
69  	}
70  
71  	@Override
72  	public boolean matches(final String page, final String parameters) {
73  		return NAME.equals(page) && !StringUtils.isEmpty(parameters) && parameters.contains(PageMode.CHARTS.toString())
74  				&& parameters.contains(ChartIndicators.COMMITTEESBYPARTY.toString());
75  	}
76  
77  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
78  	@Override
79  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
80  		final VerticalLayout panelContent = createPanelContent();
81  
82  		getCommitteeRankingMenuItemFactory().createCommitteeeRankingMenuBar(menuBar);
83  
84  		final String pageId = getPageId(parameters);
85  
86  		final HorizontalLayout chartLayout = new HorizontalLayout();
87  		chartLayout.setSizeFull();
88  
89  		chartDataManager.createChartPanel(chartLayout,
90  				dataSeriesFactory.createChartTimeSeriesTotalDaysServedCommitteeByParty(),
91  				ALL_PARTIES_TOTAL_DAYS_SERVED);
92  
93  		panelContent.addComponent(chartLayout);
94  
95  		panel.setCaption(CHARTS + parameters);
96  
97  		getPageActionEventHelper().createPageEvent(ViewAction.VISIT_COMMITTEE_RANKING_VIEW, ApplicationEventGroup.USER,
98  				NAME, parameters, pageId);
99  
100 		return panelContent;
101 
102 	}
103 
104 }