View Javadoc

1   /*
2    * Copyright 2010 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: LoginPage.java 5582 2012-01-04 20:03:13Z pether $
17   *  $HeadURL: https://cia.svn.sourceforge.net/svnroot/cia/trunk/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/page/user/LoginPage.java $
18  */
19  package com.hack23.cia.web.impl.ui.page.user;
20  
21  import org.vaadin.navigator7.NavigableApplication;
22  import org.vaadin.navigator7.Page;
23  
24  import com.hack23.cia.web.impl.ui.page.common.MenuState;
25  import com.vaadin.ui.Button;
26  import com.vaadin.ui.Button.ClickEvent;
27  import com.vaadin.ui.Component;
28  import com.vaadin.ui.PasswordField;
29  import com.vaadin.ui.TextField;
30  import com.vaadin.ui.VerticalLayout;
31  
32  /**
33   * The Class LoginPage.
34   */
35  @Page(uriName = "login",crawlable=true)
36  @SuppressWarnings("serial")
37  public final class LoginPage extends AbstractUserPage implements Button.ClickListener {
38  
39  	/** The content. */
40  	private final VerticalLayout content = new VerticalLayout();
41  
42  	/** The username. */
43  	private final TextField username;
44  
45  	/** The password. */
46  	private final PasswordField password;
47  
48  	/** The login button. */
49  	private final Button loginButton;
50  
51  	/**
52  	 * Instantiates a new login page.
53  	 */
54  	public LoginPage() {
55  		super();
56  		username = new TextField(translateFromEnglish("User"));
57  		username.setWidth(100, Component.UNITS_PERCENTAGE);
58  		username.setNullRepresentation("");
59  		content.addComponent(username);
60  
61  		password = new PasswordField(translateFromEnglish("Password"));
62  		password.setWidth(100, Component.UNITS_PERCENTAGE);
63  		password.setNullRepresentation("");
64  		content.addComponent(password);
65  
66  		loginButton = new Button(translateFromEnglish("Login"), this);
67  		content.addComponent(loginButton);
68  		content.setSizeFull();
69  		content.setMargin(false);
70  		content.setSpacing(true);
71  
72  		final VisitorPanel visitorPanel = new VisitorPanel();
73  		content.addComponent(visitorPanel);
74  		visitorPanel.setSizeFull();
75  
76  		setCompositionRoot(content);
77  		setHeight(getScreenHeight());
78  	}
79  
80  	/* (non-Javadoc)
81  	 * @see com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.Button.ClickEvent)
82  	 */
83  	@Override
84  	public void buttonClick(final ClickEvent event) {
85  		try {
86  			getApplicationManager().authenticate((String) username.getValue(),(String) password.getValue());
87  			final MenuState menuState = (MenuState) NavigableApplication.getCurrentNavigableAppLevelWindow();
88  			menuState.setupMenu();
89  			navigateTo(WelcomePage.class);
90  		}catch (final Exception e) {
91  		 getApplication().getMainWindow().showNotification(e.getMessage());
92  		 }
93  	}
94  
95  	/* (non-Javadoc)
96  	 * @see com.hack23.cia.web.impl.ui.page.common.AbstractPage#getPageTitle()
97  	 */
98  	@Override
99  	public String getPageTitle() {
100 		return "";
101 	}
102 
103 
104 }