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