1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
41
42 @Component
43 public final class PartyVoteHistoryPageModContentFactoryImpl extends AbstractPartyPageModContentFactoryImpl {
44
45
46 private static final String VOTE_HISTORY = "VoteHistory";
47
48
49 @Autowired
50 private GenericChartDataManager<ViewRiksdagenVoteDataBallotPartySummary> viewRiksdagenVoteDataBallotPartySummaryChartDataManager;
51
52
53
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 }