2 * Copyright (C) 2010, 2011 Openismus GmbH
4 * This file is part of GWT-Glom.
6 * GWT-Glom is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
11 * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with GWT-Glom. If not, see <http://www.gnu.org/licenses/>.
20 package org.glom.web.client.ui;
22 import com.google.gwt.event.dom.client.ClickHandler;
23 import com.google.gwt.event.shared.HandlerRegistration;
24 import com.google.gwt.user.client.ui.Button;
25 import com.google.gwt.user.client.ui.Composite;
26 import com.google.gwt.user.client.ui.FlexTable;
27 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
28 import com.google.gwt.user.client.ui.Label;
29 import com.google.gwt.user.client.ui.PasswordTextBox;
30 import com.google.gwt.user.client.ui.TextBox;
31 import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
33 public class DocumentLoginViewImpl extends Composite implements DocumentLoginView {
35 //final private FlowPanel mainPanel = new FlowPanel();
36 private final TextBox usernameTextBox = new TextBox();
37 private final PasswordTextBox passwordTextBox = new PasswordTextBox();
38 private final Label errorMessage = new Label("Username and/or password not correct."); //TODO: Translate
39 private final Button loginButton = new Button("Login"); //TODO: Translate
40 private final Button cancelButton = new Button("Cancel"); //TODO: Translate
41 //TODO: ForgotPassword button.
42 FlexTable flexTable = new FlexTable();
43 private Presenter presenter;
45 private HandlerRegistration authLoginButtonHandlerRegistration;
46 private HandlerRegistration authCancelButtonHandlerRegistration;
48 public DocumentLoginViewImpl() {
49 initWidget(flexTable);
51 flexTable.setCellSpacing(10);
52 final FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
53 flexTable.setHTML(0, 0, "<b>Enter the PostgreSQL username and password.</b>");
54 cellFormatter.setColSpan(0, 0, 2);
55 cellFormatter.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
56 flexTable.setHTML(1, 0, "Username");
57 flexTable.setWidget(1, 1, usernameTextBox);
58 cellFormatter.setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_RIGHT);
59 flexTable.setHTML(2, 0, "Password");
60 flexTable.setWidget(2, 1, passwordTextBox);
61 cellFormatter.setHorizontalAlignment(2, 1, HasHorizontalAlignment.ALIGN_RIGHT);
62 flexTable.setWidget(3, 0, cancelButton);
63 cellFormatter.setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_RIGHT);
64 flexTable.setWidget(3, 1, loginButton);
65 cellFormatter.setHorizontalAlignment(3, 1, HasHorizontalAlignment.ALIGN_RIGHT);
69 public void setPresenter(final Presenter presenter) {
70 this.presenter = presenter;
74 public void setClickLoginHandler(final ClickHandler clickHandler) {
75 authLoginButtonHandlerRegistration = loginButton.addClickHandler(clickHandler);
79 public void setClickCancelHandler(final ClickHandler clickHandler) {
80 authCancelButtonHandlerRegistration = cancelButton.addClickHandler(clickHandler);
84 public String getUsername() {
85 return usernameTextBox.getValue();
89 public String getPassword() {
90 return passwordTextBox.getValue();
96 if (authLoginButtonHandlerRegistration != null) {
97 authLoginButtonHandlerRegistration.removeHandler();
98 authLoginButtonHandlerRegistration = null;
101 if (authCancelButtonHandlerRegistration != null) {
102 authCancelButtonHandlerRegistration.removeHandler();
103 authCancelButtonHandlerRegistration = null;
106 usernameTextBox.setText("");
107 passwordTextBox.setText("");
108 setTextFieldsEnabled(true);
113 public void setTextFieldsEnabled(final boolean enabled) {
114 usernameTextBox.setEnabled(enabled);
115 passwordTextBox.setEnabled(enabled);
119 public void setError() {
120 flexTable.setWidget(4, 0, errorMessage);
121 final FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
122 cellFormatter.setColSpan(4, 0, 2);
123 cellFormatter.setHorizontalAlignment(4, 0, HasHorizontalAlignment.ALIGN_CENTER);
127 public void clearError() {
128 if (flexTable.getRowCount() == 5) {
129 flexTable.removeRow(4);