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.admin.system.pagemode;
20  
21  import java.util.Arrays;
22  
23  import org.springframework.security.access.annotation.Secured;
24  import org.springframework.stereotype.Component;
25  import org.springframework.web.context.request.RequestContextHolder;
26  
27  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
28  import com.hack23.cia.service.api.action.admin.SendEmailRequest;
29  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
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.AdminViews;
33  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.SendEmailClickListener;
34  import com.vaadin.data.util.BeanItem;
35  import com.vaadin.ui.Button.ClickListener;
36  import com.vaadin.ui.FormLayout;
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 EmailPageModContentFactoryImpl.
44   */
45  @Component
46  public final class EmailPageModContentFactoryImpl extends AbstractAdminSystemPageModContentFactoryImpl {
47  
48  	/** The Constant ADMIN_EMAIL. */
49  	private static final String ADMIN_EMAIL = "Admin email";
50  
51  	/** The Constant NAME. */
52  	public static final String NAME = AdminViews.ADMIN_EMAIL_VIEW_NAME;
53  
54  	/**
55  	 * Instantiates a new email page mod content factory impl.
56  	 */
57  	public EmailPageModContentFactoryImpl() {
58  		super();
59  	}
60  
61  	@Override
62  	public boolean matches(final String page, final String parameters) {
63  		return NAME.equals(page);
64  	}
65  
66  	@Secured({ "ROLE_ADMIN" })
67  	@Override
68  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
69  		final VerticalLayout content = createPanelContent();
70  
71  		final String pageId = getPageId(parameters);
72  
73  		getMenuItemFactory().createMainPageMenuBar(menuBar);
74  
75  		LabelFactory.createHeader2Label(content, ADMIN_EMAIL);
76  
77  		final VerticalLayout emailLayout = new VerticalLayout();
78  		emailLayout.setSizeFull();
79  
80  		final Panel formPanel = new Panel();
81  		formPanel.setSizeFull();
82  
83  		emailLayout.addComponent(formPanel);
84  
85  		final FormLayout formContent = new FormLayout();
86  		formPanel.setContent(formContent);
87  
88  		final SendEmailRequest sendEmailRequest = new SendEmailRequest();
89  		sendEmailRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
90  		sendEmailRequest.setEmail("");
91  		sendEmailRequest.setSubject("");
92  		sendEmailRequest.setContent("");
93  		final ClickListener sendEmailListener = new SendEmailClickListener(sendEmailRequest);
94  		getFormFactory().addRequestInputFormFields(formContent, new BeanItem<>(sendEmailRequest),
95  				SendEmailRequest.class, Arrays.asList(new String[] { "email", "subject", "content" }), "Email",
96  				sendEmailListener);
97  
98  		content.addComponent(emailLayout);
99  		content.setExpandRatio(emailLayout, ContentRatio.LARGE_FORM);
100 
101 		panel.setCaption("Admin email");
102 		getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_EMAIL_VIEW, ApplicationEventGroup.ADMIN, NAME,
103 				null, pageId);
104 
105 		return content;
106 
107 	}
108 
109 }