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.security.access.annotation.Secured;
23  import org.springframework.stereotype.Component;
24  
25  import com.hack23.cia.model.internal.application.data.ministry.impl.ViewRiksdagenGovermentRoleMember;
26  import com.hack23.cia.model.internal.application.data.ministry.impl.ViewRiksdagenGovermentRoleMember_;
27  import com.hack23.cia.model.internal.application.data.ministry.impl.ViewRiksdagenMinistry;
28  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
29  import com.hack23.cia.service.api.DataContainer;
30  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
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.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
34  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
35  import com.vaadin.data.util.BeanItemContainer;
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 MinistryCurrentMembersPageModContentFactoryImpl.
43   */
44  @Component
45  public final class MinistryCurrentMembersPageModContentFactoryImpl extends AbstractMinistryPageModContentFactoryImpl {
46  
47  	/** The Constant CURRENT_MEMBERS. */
48  	private static final String CURRENT_MEMBERS = "Current Members";
49  
50  	/** The Constant MINISTRY. */
51  	private static final String MINISTRY = "Ministry:";
52  
53  	/**
54  	 * Instantiates a new ministry current members page mod content factory
55  	 * impl.
56  	 */
57  	public MinistryCurrentMembersPageModContentFactoryImpl() {
58  		super();
59  	}
60  
61  	@Override
62  	public boolean matches(final String page, final String parameters) {
63  		return NAME.equals(page) && (!StringUtils.isEmpty(parameters)
64  				&& parameters.contains(MinistryPageMode.CURRENTMEMBERS.toString()));
65  	}
66  
67  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
68  	@Override
69  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
70  		final VerticalLayout panelContent = createPanelContent();
71  
72  		final String pageId = getPageId(parameters);
73  
74  		final DataContainer<ViewRiksdagenMinistry, String> dataContainer = getApplicationManager()
75  				.getDataContainer(ViewRiksdagenMinistry.class);
76  
77  		final ViewRiksdagenMinistry viewRiksdagenMinistry = dataContainer.load(pageId);
78  
79  		if (viewRiksdagenMinistry != null) {
80  
81  			getMinistryMenuItemFactory().createMinistryMenuBar(menuBar, pageId);
82  
83  			LabelFactory.createHeader2Label(panelContent,CURRENT_MEMBERS);
84  
85  
86  			final DataContainer<ViewRiksdagenGovermentRoleMember, String> govermentRoleMemberDataContainer = getApplicationManager()
87  					.getDataContainer(ViewRiksdagenGovermentRoleMember.class);
88  
89  			final BeanItemContainer<ViewRiksdagenGovermentRoleMember> currentMembersMemberDataSource = new BeanItemContainer<>(
90  					ViewRiksdagenGovermentRoleMember.class,
91  					govermentRoleMemberDataContainer.findListByProperty(
92  							new Object[] { viewRiksdagenMinistry.getNameId(), Boolean.TRUE },
93  							ViewRiksdagenGovermentRoleMember_.detail, ViewRiksdagenGovermentRoleMember_.active));
94  
95  			getGridFactory().createBasicBeanItemGrid(
96  					panelContent, currentMembersMemberDataSource,
97  					CURRENT_MEMBERS,
98  					new String[] { "roleCode", "roleId", "personId", "firstName", "lastName", "party", "active", "totalDaysServed", "detail",
99  							"fromDate", "toDate" }, new String[] { "roleId", "personId", "detail", "active" },
100 					new PageItemPropertyClickListener(UserViews.POLITICIAN_VIEW_NAME, "personId"), null, null);
101 
102 			panel.setCaption(MINISTRY + viewRiksdagenMinistry.getNameId());
103 			getPageActionEventHelper().createPageEvent(ViewAction.VISIT_MINISTRY_VIEW, ApplicationEventGroup.USER, NAME,
104 					parameters, pageId);
105 
106 		}
107 
108 		return panelContent;
109 
110 	}
111 
112 }