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.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
43
44 @Component
45 public final class MinistryCurrentMembersPageModContentFactoryImpl extends AbstractMinistryPageModContentFactoryImpl {
46
47
48 private static final String CURRENT_MEMBERS = "Current Members";
49
50
51 private static final String MINISTRY = "Ministry:";
52
53
54
55
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 }