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.Component;
25  
26  import com.hack23.cia.model.internal.application.data.ministry.impl.ViewRiksdagenMinistry;
27  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
28  import com.hack23.cia.service.api.DataContainer;
29  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
30  import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.GovernmentBodyChartDataManager;
31  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
32  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.MinistryPageMode;
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 MinistryGovernmentBodiesModContentFactoryImpl.
40   */
41  @Component
42  public final class MinistryGovernmentBodiesModContentFactoryImpl extends AbstractMinistryPageModContentFactoryImpl {
43  
44  	private static final String GOVERNMENT_BODIES = "Government bodies";
45  
46  	/** The Constant MINISTRY. */
47  	private static final String MINISTRY = "Ministry:";
48  
49  	@Autowired
50  	private GovernmentBodyChartDataManager governmentBodyChartDataManager;
51  
52  	/**
53  	 * Instantiates a new ministry government bodies mod content factory impl.
54  	 */
55  	public MinistryGovernmentBodiesModContentFactoryImpl() {
56  		super();
57  	}
58  
59  	@Override
60  	public boolean matches(final String page, final String parameters) {
61  		return NAME.equals(page) && (!StringUtils.isEmpty(parameters) && parameters.contains(MinistryPageMode.GOVERNMENT_BODIES.toString()));
62  	}
63  
64  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
65  	@Override
66  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
67  		final VerticalLayout panelContent = createPanelContent();
68  
69  		final String pageId = getPageId(parameters);
70  
71  		final DataContainer<ViewRiksdagenMinistry, String> dataContainer = getApplicationManager()
72  				.getDataContainer(ViewRiksdagenMinistry.class);
73  
74  		final ViewRiksdagenMinistry viewRiksdagenMinistry = dataContainer.load(pageId);
75  
76  		if (viewRiksdagenMinistry != null) {
77  
78  			getMinistryMenuItemFactory().createMinistryMenuBar(menuBar, pageId);
79  
80  			LabelFactory.createHeader2Label(panelContent,GOVERNMENT_BODIES);
81  
82  			governmentBodyChartDataManager.createMinistryGovernmentBodyHeadcountSummaryChart(panelContent, viewRiksdagenMinistry.getNameId());
83  
84  			panel.setCaption(MINISTRY + viewRiksdagenMinistry.getNameId());
85  			getPageActionEventHelper().createPageEvent(ViewAction.VISIT_MINISTRY_VIEW, ApplicationEventGroup.USER, NAME,
86  					parameters, pageId);
87  
88  		}
89  
90  		return panelContent;
91  
92  	}
93  
94  }