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.party.pagemode;
20  
21  import org.springframework.security.access.annotation.Secured;
22  import org.springframework.stereotype.Component;
23  
24  import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenParty;
25  import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenPartyRoleMember;
26  import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenPartyRoleMember_;
27  import com.hack23.cia.service.api.DataContainer;
28  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
29  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PartyPageMode;
30  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
31  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
32  import com.vaadin.data.util.BeanItemContainer;
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 CurrentLeadersPageModContentFactoryImpl.
40   */
41  @Component
42  public final class PartyCurrentLeadersPageModContentFactoryImpl extends AbstractPartyPageModContentFactoryImpl {
43  
44  	/** The Constant CURRENT_LEADERS. */
45  	private static final String CURRENT_LEADERS = "Current Leaders";
46  
47  	/**
48  	 * Instantiates a new party current leaders page mod content factory impl.
49  	 */
50  	public PartyCurrentLeadersPageModContentFactoryImpl() {
51  		super();
52  	}
53  
54  	@Override
55  	public boolean matches(final String page, final String parameters) {
56  		return NAME.equals(page) && parameters.contains(PartyPageMode.CURRENTLEADERS.toString());
57  	}
58  
59  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
60  	@Override
61  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
62  		final VerticalLayout panelContent = createPanelContent();
63  
64  		final String pageId = getPageId(parameters);
65  
66  		final DataContainer<ViewRiksdagenParty, String> dataContainer = getApplicationManager()
67  				.getDataContainer(ViewRiksdagenParty.class);
68  
69  		final ViewRiksdagenParty viewRiksdagenParty = dataContainer.load(pageId);
70  
71  		if (viewRiksdagenParty != null) {
72  
73  			getPartyMenuItemFactory().createPartyMenuBar(menuBar, pageId);
74  
75  			LabelFactory.createHeader2Label(panelContent,CURRENT_LEADERS);
76  
77  
78  			final DataContainer<ViewRiksdagenPartyRoleMember, String> partyRoleMemberDataContainer = getApplicationManager()
79  					.getDataContainer(ViewRiksdagenPartyRoleMember.class);
80  
81  			final BeanItemContainer<ViewRiksdagenPartyRoleMember> currentPartyMemberDataSource = new BeanItemContainer<>(
82  					ViewRiksdagenPartyRoleMember.class,
83  					partyRoleMemberDataContainer.findListByProperty(
84  							new Object[] { viewRiksdagenParty.getPartyId(), Boolean.TRUE },
85  							ViewRiksdagenPartyRoleMember_.party, ViewRiksdagenPartyRoleMember_.active));
86  
87  			getGridFactory().createBasicBeanItemGrid(panelContent,
88  					currentPartyMemberDataSource,
89  					CURRENT_LEADERS,
90  					new String[] { "roleCode","roleId", "personId", "firstName", "lastName", "party","totalDaysServed", "active", "detail",
91  							 "fromDate", "toDate" }, new String[] { "roleId", "personId", "detail" , "active", "party"},
92  					new PageItemPropertyClickListener(UserViews.POLITICIAN_VIEW_NAME, "personId"), null, null);
93  
94  
95  			pageCompleted(parameters, panel, pageId, viewRiksdagenParty);
96  		}
97  		return panelContent;
98  
99  	}
100 
101 }