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.List;
22  
23  import org.springframework.beans.factory.annotation.Autowired;
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.ViewRiksdagenPartyRoleMember;
29  import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenPartyRoleMember_;
30  import com.hack23.cia.service.api.DataContainer;
31  import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.PartyGhantChartManager;
32  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
33  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PartyPageMode;
34  import com.vaadin.ui.Layout;
35  import com.vaadin.ui.MenuBar;
36  import com.vaadin.ui.Panel;
37  import com.vaadin.ui.VerticalLayout;
38  
39  /**
40   * The Class PartyRoleGhantPageModContentFactoryImpl.
41   */
42  @Component
43  public final class PartyRoleGhantPageModContentFactoryImpl extends AbstractPartyPageModContentFactoryImpl {
44  
45  	/** The Constant ROLE_GHANT. */
46  	private static final String ROLE_GHANT = "Role chart";
47  
48  	@Autowired
49  	private PartyGhantChartManager partyGhantChartManager;
50  
51  	/**
52  	 * Instantiates a new party role ghant page mod content factory impl.
53  	 */
54  	public PartyRoleGhantPageModContentFactoryImpl() {
55  		super();
56  	}
57  
58  	@Override
59  	public boolean matches(final String page, final String parameters) {
60  		return NAME.equals(page) && parameters.contains(PartyPageMode.ROLEGHANT.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  		final DataContainer<ViewRiksdagenParty, String> dataContainer = getApplicationManager()
71  				.getDataContainer(ViewRiksdagenParty.class);
72  
73  		final ViewRiksdagenParty viewRiksdagenParty = dataContainer.load(pageId);
74  
75  		if (viewRiksdagenParty != null) {
76  
77  			getPartyMenuItemFactory().createPartyMenuBar(menuBar, pageId);
78  
79  			LabelFactory.createHeader2Label(panelContent, ROLE_GHANT);
80  
81  			final DataContainer<ViewRiksdagenPartyRoleMember, String> partyRoleMemberDataContainer = getApplicationManager()
82  					.getDataContainer(ViewRiksdagenPartyRoleMember.class);
83  
84  			final List<ViewRiksdagenPartyRoleMember> allMembers = partyRoleMemberDataContainer
85  					.getAllBy(ViewRiksdagenPartyRoleMember_.party, viewRiksdagenParty.getPartyId());
86  
87  			partyGhantChartManager.createRoleGhant(panelContent, allMembers);
88  
89  			pageCompleted(parameters, panel, pageId, viewRiksdagenParty);
90  		}
91  		return panelContent;
92  
93  	}
94  
95  }