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.committee.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.committee.impl.ViewRiksdagenCommittee;
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 CommitteeOverviewPageModContentFactoryImpl.
43   */
44  @Component
45  public final class CommitteeOverviewPageModContentFactoryImpl extends AbstractCommitteePageModContentFactoryImpl {
46  
47  	/** The Constant COMMITTEE. */
48  	private static final String COMMITTEE = "Committee:";
49  
50  	/** The Constant OVERVIEW. */
51  	private static final String OVERVIEW = "overview";
52  
53  	/**
54  	 * Instantiates a new committee overview page mod content factory impl.
55  	 */
56  	public CommitteeOverviewPageModContentFactoryImpl() {
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  
75  		final DataContainer<ViewRiksdagenCommittee, String> dataContainer = getApplicationManager()
76  				.getDataContainer(ViewRiksdagenCommittee.class);
77  
78  		final ViewRiksdagenCommittee viewRiksdagenCommittee = dataContainer.load(pageId);
79  
80  		if (viewRiksdagenCommittee != null) {
81  
82  			getCommitteeMenuItemFactory().createCommitteeeMenuBar(menuBar, pageId);
83  
84  				LabelFactory.createHeader2Label(panelContent,OVERVIEW);
85  
86  				final VerticalLayout overviewLayout = new VerticalLayout();
87  				overviewLayout.setSizeFull();
88  
89  				panelContent.addComponent(overviewLayout);
90  				panelContent.setExpandRatio(overviewLayout, ContentRatio.LARGE_FORM);
91  
92  				getCommitteeMenuItemFactory().createOverviewPage(overviewLayout, pageId);
93  
94  
95  				final Link addCommitteePageLink = getPageLinkFactory().addCommitteePageLink(viewRiksdagenCommittee);
96  				panelContent.addComponent(addCommitteePageLink);
97  
98  				getFormFactory().addFormPanelTextFields(panelContent, new BeanItem<>(viewRiksdagenCommittee),
99  						ViewRiksdagenCommittee.class,
100 						Arrays.asList(new String[] { "embeddedId.detail", "active", "firstAssignmentDate",
101 								"lastAssignmentDate", "totalAssignments", "totalDaysServed",
102 								"currentMemberSize" }));
103 
104 
105 				panelContent.setExpandRatio(addCommitteePageLink,ContentRatio.SMALL);
106 
107 				panel.setCaption(COMMITTEE + viewRiksdagenCommittee.getEmbeddedId().getDetail());
108 				getPageActionEventHelper().createPageEvent(ViewAction.VISIT_COMMITTEE_VIEW, ApplicationEventGroup.USER, NAME, parameters, pageId);
109 		}
110 		return panelContent;
111 
112 	}
113 
114 
115 }