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 org.apache.commons.lang3.StringUtils;
22  import org.springframework.security.access.annotation.Secured;
23  import org.springframework.stereotype.Component;
24  
25  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommittee;
26  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
27  import com.hack23.cia.service.api.DataContainer;
28  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
29  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PageMode;
30  import com.vaadin.ui.Layout;
31  import com.vaadin.ui.MenuBar;
32  import com.vaadin.ui.Panel;
33  import com.vaadin.ui.VerticalLayout;
34  
35  /**
36   * The Class CommitteePageVisitHistoryPageModContentFactoryImpl.
37   */
38  @Component
39  public final class CommitteePageVisitHistoryPageModContentFactoryImpl extends AbstractCommitteePageModContentFactoryImpl {
40  
41  	/** The Constant COMMITTEE. */
42  	private static final String COMMITTEE = "Committee:";
43  
44  	/**
45  	 * Instantiates a new committee page visit history page mod content factory
46  	 * impl.
47  	 */
48  	public CommitteePageVisitHistoryPageModContentFactoryImpl() {
49  		super();
50  	}
51  
52  	@Override
53  	public boolean matches(final String page, final String parameters) {
54  		return NAME.equals(page) && (!StringUtils.isEmpty(parameters) && parameters.contains(PageMode.PAGEVISITHISTORY.toString()));
55  	}
56  
57  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
58  	@Override
59  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
60  		final VerticalLayout panelContent = createPanelContent();
61  
62  		final String pageId = getPageId(parameters);
63  
64  
65  		final DataContainer<ViewRiksdagenCommittee, String> dataContainer = getApplicationManager()
66  				.getDataContainer(ViewRiksdagenCommittee.class);
67  
68  		final ViewRiksdagenCommittee viewRiksdagenCommittee = dataContainer.load(pageId);
69  
70  		if (viewRiksdagenCommittee != null) {
71  
72  			getCommitteeMenuItemFactory().createCommitteeeMenuBar(menuBar, pageId);
73  
74  				createPageVisitHistory(NAME,pageId,panelContent);
75  
76  				panel.setCaption(COMMITTEE + viewRiksdagenCommittee.getEmbeddedId().getDetail());
77  				getPageActionEventHelper().createPageEvent(ViewAction.VISIT_COMMITTEE_VIEW, ApplicationEventGroup.USER, NAME, parameters, pageId);
78  		}
79  		return panelContent;
80  
81  	}
82  
83  }