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.common.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.ejt.vaadin.loginform.DefaultVerticalLoginForm;
26  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
27  import com.hack23.cia.service.api.action.application.LoginRequest;
28  import com.hack23.cia.web.impl.ui.application.action.ApplicationAction;
29  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
30  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.ApplicationPageMode;
31  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.CommonsViews;
32  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.ApplicationLoginListener;
33  import com.vaadin.data.fieldgroup.BeanFieldGroup;
34  import com.vaadin.data.util.BeanItem;
35  import com.vaadin.server.FontAwesome;
36  import com.vaadin.ui.Field;
37  import com.vaadin.ui.Layout;
38  import com.vaadin.ui.MenuBar;
39  import com.vaadin.ui.Panel;
40  import com.vaadin.ui.VerticalLayout;
41  
42  /**
43   * The Class MainViewLoginPageModContentFactoryImpl.
44   */
45  @Component
46  public final class MainViewLoginPageModContentFactoryImpl extends AbstractPageModContentFactoryImpl {
47  
48  	/** The Constant CITIZEN_INTELLIGENCE_AGENCY_MAIN. */
49  	private static final String CITIZEN_INTELLIGENCE_AGENCY_MAIN = "Citizen Intelligence Agency::Main";
50  
51  	/** The Constant NAME. */
52  	public static final String NAME = CommonsViews.MAIN_VIEW_NAME;
53  
54  	/**
55  	 * Instantiates a new main view login page mod content factory impl.
56  	 */
57  	public MainViewLoginPageModContentFactoryImpl() {
58  		super();
59  	}
60  
61  	@Override
62  	public boolean matches(final String page, final String parameters) {
63  		return NAME.equals(page)
64  				&& (!StringUtils.isEmpty(parameters) && parameters.contains(ApplicationPageMode.LOGIN.toString()));
65  	}
66  
67  	@Secured({ "ROLE_ANONYMOUS" })
68  	@Override
69  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
70  		final VerticalLayout content = createPanelContent();
71  		final String pageId = getPageId(parameters);
72  
73  		panel.setCaption(CITIZEN_INTELLIGENCE_AGENCY_MAIN);
74  
75  		getMenuItemFactory().createMainPageMenuBar(menuBar);
76  
77  		final DefaultVerticalLoginForm loginForm = new EmailPasswordLoginForm();
78  		final LoginRequest loginRequest = new LoginRequest();
79  		loginRequest.setOtpCode("");
80  		loginForm.addLoginListener(new ApplicationLoginListener(loginRequest));
81  		loginForm.setId(ApplicationAction.LOGIN.toString());
82  		loginForm.setIcon(FontAwesome.SIGN_IN);
83  
84  		final BeanFieldGroup<LoginRequest> fieldGroup = new BeanFieldGroup<>(LoginRequest.class);
85  		fieldGroup.setItemDataSource(new BeanItem<>(loginRequest));
86  		fieldGroup.setReadOnly(true);
87  		fieldGroup.setBuffered(false);
88  		final Field<?> buildAndBind = fieldGroup.buildAndBind("otpCode");
89  		buildAndBind.setReadOnly(false);
90  		content.addComponent(buildAndBind);
91  
92  		content.addComponent(loginForm);
93  
94  		panel.setCaption(CITIZEN_INTELLIGENCE_AGENCY_MAIN);
95  		getPageActionEventHelper().createPageEvent(ViewAction.VISIT_MAIN_VIEW, ApplicationEventGroup.USER,
96  				CommonsViews.MAIN_VIEW_NAME, parameters, pageId);
97  
98  
99  		return content;
100 
101 	}
102 
103 }