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.party.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.party.impl.ViewRiksdagenParty;
28  import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenPartySummary;
29  import com.hack23.cia.service.api.DataContainer;
30  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
31  import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
32  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PageMode;
33  import com.vaadin.data.util.BeanItem;
34  import com.vaadin.ui.Layout;
35  import com.vaadin.ui.Link;
36  import com.vaadin.ui.MenuBar;
37  import com.vaadin.ui.Panel;
38  import com.vaadin.ui.VerticalLayout;
39  
40  /**
41   * The Class OverviewPageModContentFactoryImpl.
42   */
43  @Component
44  public final class PartyOverviewPageModContentFactoryImpl extends AbstractPartyPageModContentFactoryImpl {
45  
46  	/** The Constant OVERVIEW. */
47  	private static final String OVERVIEW = "overview";
48  
49  	/**
50  	 * Instantiates a new party overview page mod content factory impl.
51  	 */
52  	public PartyOverviewPageModContentFactoryImpl() {
53  		super();
54  	}
55  
56  	@Override
57  	public boolean matches(final String page, final String parameters) {
58  		final String pageId = getPageId(parameters);
59  		return NAME.equals(page) && (StringUtils.isEmpty(parameters) || parameters.equals(pageId)
60  				|| parameters.contains(PageMode.OVERVIEW.toString()));
61  	}
62  
63  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
64  	@Override
65  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
66  		final VerticalLayout panelContent = createPanelContent();
67  
68  		final String pageId = getPageId(parameters);
69  
70  
71  		final DataContainer<ViewRiksdagenParty, String> dataContainer = getApplicationManager()
72  				.getDataContainer(ViewRiksdagenParty.class);
73  
74  		final DataContainer<ViewRiksdagenPartySummary, String> partySummarydataContainer = getApplicationManager()
75  				.getDataContainer(ViewRiksdagenPartySummary.class);
76  
77  		final ViewRiksdagenParty viewRiksdagenParty = dataContainer
78  				.load(pageId);
79  
80  		if (viewRiksdagenParty != null) {
81  
82  			getPartyMenuItemFactory().createPartyMenuBar(menuBar, pageId);
83  
84  
85  			LabelFactory.createHeader2Label(panelContent,OVERVIEW);
86  
87  			final VerticalLayout overviewLayout = new VerticalLayout();
88  			overviewLayout.setSizeFull();
89  
90  			panelContent.addComponent(overviewLayout);
91  			panelContent.setExpandRatio(overviewLayout, ContentRatio.LARGE_FORM);
92  
93  			getPartyMenuItemFactory().createOverviewPage(overviewLayout, pageId);
94  
95  			final Link addPartyPageLink = getPageLinkFactory().addPartyPageLink(viewRiksdagenParty);
96  			panelContent.addComponent(addPartyPageLink);
97  
98  			panelContent.setExpandRatio(addPartyPageLink, ContentRatio.SMALL);
99  
100 			getFormFactory().addFormPanelTextFields(
101 					panelContent,
102 					new BeanItem<>(viewRiksdagenParty),
103 					ViewRiksdagenParty.class,
104 					Arrays.asList(new String[] { "partyName", "partyId",
105 							"headCount", "partyNumber", "registeredDate",
106 					"website" }));
107 
108 			final ViewRiksdagenPartySummary viewRiksdagenPartySummary = partySummarydataContainer
109 					.load(pageId);
110 
111 			if (viewRiksdagenPartySummary != null) {
112 
113 
114 
115 				getFormFactory().addFormPanelTextFields(panelContent,
116 						new BeanItem<>(
117 								viewRiksdagenPartySummary),
118 								ViewRiksdagenPartySummary.class,
119 								Arrays.asList(new String[] { "active",
120 										"firstAssignmentDate", "lastAssignmentDate",
121 										"currentAssignments", "totalAssignments",
122 										"totalDaysServed", "activeEu", "totalActiveEu",
123 										"totalDaysServedEu", "activeGovernment",
124 										"totalActiveGovernment",
125 										"totalDaysServedGovernment", "activeCommittee",
126 										"totalActiveCommittee",
127 										"totalDaysServedCommittee", "activeParliament",
128 										"totalActiveParliament",
129 								"totalDaysServedParliament" }));
130 
131 			}
132 
133 
134 			pageCompleted(parameters, panel, pageId, viewRiksdagenParty);
135 		}
136 		return panelContent;
137 
138 	}
139 
140 
141 }