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.beans.factory.annotation.Autowired;
22  import org.springframework.security.access.annotation.Secured;
23  import org.springframework.stereotype.Component;
24  
25  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummary;
26  import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenParty;
27  import com.hack23.cia.service.api.DataContainer;
28  import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.GenericChartDataManager;
29  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
30  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PartyPageMode;
31  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
32  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
33  import com.vaadin.data.util.BeanItemContainer;
34  import com.vaadin.ui.Layout;
35  import com.vaadin.ui.MenuBar;
36  import com.vaadin.ui.Panel;
37  import com.vaadin.ui.VerticalLayout;
38  
39  /**
40   * The Class VoteHistoryPageModContentFactoryImpl.
41   */
42  @Component
43  public final class PartyVoteHistoryPageModContentFactoryImpl extends AbstractPartyPageModContentFactoryImpl {
44  
45  	/** The Constant VOTE_HISTORY. */
46  	private static final String VOTE_HISTORY = "VoteHistory";
47  
48  	/** The view riksdagen vote data ballot party summary chart data manager. */
49  	@Autowired
50  	private GenericChartDataManager<ViewRiksdagenVoteDataBallotPartySummary> viewRiksdagenVoteDataBallotPartySummaryChartDataManager;
51  
52  	/**
53  	 * Instantiates a new party vote history page mod content factory impl.
54  	 */
55  	public PartyVoteHistoryPageModContentFactoryImpl() {
56  		super();
57  	}
58  
59  	@Override
60  	public boolean matches(final String page, final String parameters) {
61  		return NAME.equals(page) && parameters.contains(PartyPageMode.VOTEHISTORY.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<ViewRiksdagenParty, String> dataContainer = getApplicationManager()
72  				.getDataContainer(ViewRiksdagenParty.class);
73  
74  		final ViewRiksdagenParty viewRiksdagenParty = dataContainer.load(pageId);
75  
76  		if (viewRiksdagenParty != null) {
77  
78  			getPartyMenuItemFactory().createPartyMenuBar(menuBar, pageId);
79  
80  			LabelFactory.createHeader2Label(panelContent, VOTE_HISTORY);
81  
82  			final BeanItemContainer<ViewRiksdagenVoteDataBallotPartySummary> partyBallotDataSource = new BeanItemContainer<>(
83  					ViewRiksdagenVoteDataBallotPartySummary.class,
84  					viewRiksdagenVoteDataBallotPartySummaryChartDataManager.findByValue(pageId));
85  
86  			getGridFactory().createBasicBeanItemNestedPropertiesGrid(panelContent, partyBallotDataSource, "Ballots",
87  					new String[] { "embeddedId.ballotId", "embeddedId.concern", "embeddedId.issue",
88  							"embeddedId.party" },
89  					new String[] { "embeddedId.party", "voteDate", "rm", "label", "embeddedId.concern",
90  							"embeddedId.issue", "approved", "partyApproved", "totalVotes", "partyTotalVotes",
91  							"yesVotes", "partyYesVotes", "noVotes", "partyNoVotes", "partyAbstainVotes", "abstainVotes",
92  							"partyAbsentVotes", "absentVotes", "partyAvgBornYear", "avgBornYear", "partyPercentageMale",
93  							"percentageMale", "ballotType", "embeddedId.ballotId" },
94  					new String[] { "embeddedId", "partyNoWinner", "partyPercentageYes", "partyPercentageNo",
95  							"partyPercentageAbsent", "partyPercentageAbstain", "percentageYes", "percentageNo",
96  							"percentageAbsent", "percentageAbstain", "ballotType", "embeddedId.party",
97  							"embeddedId.ballotId", "partyAvgBornYear", "avgBornYear", "partyPercentageMale",
98  							"percentageMale", "noWinner" },
99  					new PageItemPropertyClickListener(UserViews.BALLOT_VIEW_NAME, "embeddedId.ballotId"),
100 					"embeddedId.ballotId", null);
101 
102 			pageCompleted(parameters, panel, pageId, viewRiksdagenParty);
103 		}
104 		return panelContent;
105 
106 	}
107 
108 }