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.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.PartyDataSeriesFactory;
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.Layout;
34  import com.vaadin.ui.MenuBar;
35  import com.vaadin.ui.Panel;
36  import com.vaadin.ui.VerticalLayout;
37  
38  /**
39   * The Class PoliticianRankingChartsAllPartiesPageModContentFactoryImpl.
40   */
41  @Service
42  public final class PoliticianRankingChartsAllPartiesPageModContentFactoryImpl
43  		extends AbstractPoliticianRankingPageModContentFactoryImpl {
44  
45  	/** The Constant NAME. */
46  	public static final String NAME = UserViews.POLITICIAN_RANKING_VIEW_NAME;
47  
48  	/** The Constant CHARTS. */
49  	private static final String CHARTS = "Charts:All parties";
50  
51  	/** The chart data manager. */
52  	@Autowired
53  	private ChartDataManager chartDataManager;
54  
55  	/** The data series factory. */
56  	@Autowired
57  	private PartyDataSeriesFactory dataSeriesFactory;
58  
59  	/**
60  	 * Instantiates a new politician ranking charts all parties page mod content
61  	 * factory impl.
62  	 */
63  	public PoliticianRankingChartsAllPartiesPageModContentFactoryImpl() {
64  		super();
65  	}
66  
67  	@Override
68  	public boolean matches(final String page, final String parameters) {
69  		return NAME.equals(page)
70  				&& (!StringUtils.isEmpty(parameters) && parameters.contains(PageMode.CHARTS.toString()) && parameters.contains(ChartIndicators.ALLPARTIES.toString()));
71  	}
72  
73  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
74  	@Override
75  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
76  		final VerticalLayout panelContent = createPanelContent();
77  
78  		final String pageId = getPageId(parameters);
79  
80  		getPoliticianRankingMenuItemFactory().createPoliticianRankingMenuBar(menuBar);
81  
82  		chartDataManager
83  				.createChartPanel(panelContent,dataSeriesFactory.createPartyChartTimeSeriesAll(), "All");
84  
85  
86  		panel.setCaption(CHARTS);
87  
88  		getPageActionEventHelper().createPageEvent(ViewAction.VISIT_POLITICIAN_RANKING_VIEW, ApplicationEventGroup.USER,
89  				NAME, parameters, pageId);
90  
91  		return panelContent;
92  
93  	}
94  
95  }