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.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   * The Class MinistryOverviewPageModContentFactoryImpl.
43   */
44  @Component
45  public final class MinistryOverviewPageModContentFactoryImpl extends AbstractMinistryPageModContentFactoryImpl {
46  
47  	/** The Constant OVERVIEW. */
48  	private static final String OVERVIEW = "overview";
49  
50  	/** The Constant MINISTRY. */
51  	private static final String MINISTRY = "Ministry:";
52  
53  	/**
54  	 * Instantiates a new ministry overview page mod content factory impl.
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 }