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.admin.system.pagemode;
20
21 import java.util.Arrays;
22 import java.util.List;
23
24 import org.springframework.security.access.annotation.Secured;
25 import org.springframework.stereotype.Component;
26
27 import com.hack23.cia.model.internal.application.system.impl.Agency;
28 import com.hack23.cia.model.internal.application.system.impl.Agency_;
29 import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
30 import com.hack23.cia.model.internal.application.system.impl.Portal;
31 import com.hack23.cia.service.api.DataContainer;
32 import com.hack23.cia.web.impl.ui.application.action.ViewAction;
33 import com.hack23.cia.web.impl.ui.application.views.common.converters.ListPropertyConverter;
34 import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
35 import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
36 import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentSize;
37 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.AdminViews;
38 import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
39 import com.vaadin.data.util.BeanItem;
40 import com.vaadin.data.util.BeanItemContainer;
41 import com.vaadin.ui.HorizontalLayout;
42 import com.vaadin.ui.Layout;
43 import com.vaadin.ui.MenuBar;
44 import com.vaadin.ui.Panel;
45 import com.vaadin.ui.VerticalLayout;
46
47
48
49
50 @Component
51 public final class AdminAgencyPageModContentFactoryImpl extends AbstractAdminSystemPageModContentFactoryImpl {
52
53
54 private static final String ADMIN_AGENCY = "Admin Agency";
55
56
57 public static final String NAME = AdminViews.ADMIN_AGENCY_VIEW_NAME;
58
59
60
61
62 public AdminAgencyPageModContentFactoryImpl() {
63 super();
64 }
65
66 @Override
67 public boolean matches(final String page, final String parameters) {
68 return NAME.equals(page);
69 }
70
71 @Secured({ "ROLE_ADMIN" })
72 @Override
73 public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
74 final VerticalLayout content = createPanelContent();
75
76 final String pageId = getPageId(parameters);
77 final int pageNr= getPageNr(parameters);
78
79 getMenuItemFactory().createMainPageMenuBar(menuBar);
80
81
82 LabelFactory.createHeader2Label(content,ADMIN_AGENCY);
83
84 final DataContainer<Agency, Long> dataContainer = getApplicationManager().getDataContainer(Agency.class);
85
86 final BeanItemContainer<Agency> politicianDocumentDataSource = new BeanItemContainer<>(Agency.class,
87 dataContainer.getPageOrderBy(pageNr,DEFAULT_RESULTS_PER_PAGE,Agency_.agencyName));
88
89 createPagingControls(content,NAME,pageId, dataContainer.getSize(), pageNr, DEFAULT_RESULTS_PER_PAGE);
90
91 getGridFactory().createBasicBeanItemGrid(content,
92 politicianDocumentDataSource, "Agency",
93 new String[] { "hjid", "agencyName", "description", "portals", "modelObjectVersion" }, new String[] { "hjid","modelObjectId", "modelObjectVersion" },
94 new PageItemPropertyClickListener(AdminViews.ADMIN_AGENCY_VIEW_NAME, "hjid"), null, new ListPropertyConverter[] { new ListPropertyConverter(List.class, "portalName", "portals")});
95
96 if (pageId != null && !pageId.isEmpty()) {
97
98 final VerticalLayout leftLayout = new VerticalLayout();
99 leftLayout.setSizeFull();
100 final VerticalLayout rightLayout = new VerticalLayout();
101 rightLayout.setSizeFull();
102 final HorizontalLayout horizontalLayout = new HorizontalLayout();
103 horizontalLayout.setWidth(ContentSize.FULL_SIZE);
104 content.addComponent(horizontalLayout);
105
106 content.setExpandRatio(horizontalLayout, ContentRatio.LARGE_FORM);
107
108
109 horizontalLayout.addComponent(leftLayout);
110 horizontalLayout.addComponent(rightLayout);
111
112 final Agency agency = dataContainer.load(Long.valueOf(pageId));
113 agency.getPortals().getClass();
114 if (agency != null) {
115
116 getFormFactory().addFormPanelTextFields(leftLayout, new BeanItem<>(agency), Agency.class,
117 Arrays.asList(new String[] { "agencyName", "description"}));
118
119 final BeanItemContainer<Portal> portalItemContainer = new BeanItemContainer<>(Portal.class,
120 agency.getPortals());
121
122 getGridFactory().createBasicBeanItemGrid(rightLayout, portalItemContainer,
123 "Portal",
124 new String[] { "hjid", "portalName", "description", "portalType", "googleMapApiKey",
125 "modelObjectVersion" }, new String[] { "hjid","modelObjectId", "modelObjectVersion", "googleMapApiKey" },
126 new PageItemPropertyClickListener(AdminViews.ADMIN_PORTAL_VIEW_NAME, "hjid"), null, null);
127 }
128
129 }
130
131 getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_AGENCY_VIEW, ApplicationEventGroup.ADMIN,
132 NAME, null, pageId);
133
134 return content;
135
136 }
137
138 }