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 java.util.Arrays;
22
23 import org.apache.commons.lang3.StringUtils;
24 import org.springframework.security.access.annotation.Secured;
25 import org.springframework.stereotype.Component;
26
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.sizing.ContentRatio;
33 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PageMode;
34 import com.vaadin.data.util.BeanItem;
35 import com.vaadin.ui.Layout;
36 import com.vaadin.ui.Link;
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 MinistryOverviewPageModContentFactoryImpl extends AbstractMinistryPageModContentFactoryImpl {
46
47
48 private static final String OVERVIEW = "overview";
49
50
51 private static final String MINISTRY = "Ministry:";
52
53
54
55
56 public MinistryOverviewPageModContentFactoryImpl() {
57 super();
58 }
59
60 @Override
61 public boolean matches(final String page, final String parameters) {
62 final String pageId = getPageId(parameters);
63 return NAME.equals(page) && (StringUtils.isEmpty(parameters) || parameters.equals(pageId)
64 || parameters.contains(PageMode.OVERVIEW.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,OVERVIEW);
84
85 final VerticalLayout overviewLayout = new VerticalLayout();
86 overviewLayout.setSizeFull();
87
88 panelContent.addComponent(overviewLayout);
89 panelContent.setExpandRatio(overviewLayout, ContentRatio.LARGE_FORM);
90
91 getMinistryMenuItemFactory().createOverviewPage(overviewLayout, pageId);
92
93 final Link addMinistryPageLink = getPageLinkFactory().addMinistryPageLink(viewRiksdagenMinistry);
94 panelContent.addComponent(addMinistryPageLink);
95
96 getFormFactory().addFormPanelTextFields(panelContent, new BeanItem<>(viewRiksdagenMinistry),
97 ViewRiksdagenMinistry.class, Arrays.asList(new String[] { "nameId", "active", "firstAssignmentDate",
98 "lastAssignmentDate", "totalAssignments", "totalDaysServed", "currentMemberSize" }));
99
100 panelContent.setExpandRatio(addMinistryPageLink, ContentRatio.SMALL);
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 }