2 * Copyright (C) 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.DecoratedPopupPanel;
26 import com.google.gwt.user.client.ui.FlexTable;
27 import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
28 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
29 import com.google.gwt.user.client.ui.Label;
30 import com.google.gwt.user.client.ui.PasswordTextBox;
31 import com.google.gwt.user.client.ui.TextBox;
34 * @author Ben Konrath <ben@bagu.org>
37 public class AuthenticationPopup extends DecoratedPopupPanel {
38 private TextBox usernameTextBox = new TextBox();
39 private PasswordTextBox passwordTextBox = new PasswordTextBox();
40 private Label errorMessage = new Label("Username and/or password not correct.");
41 private Button okButton = new Button("OK");
42 FlexTable flexTable = new FlexTable();
44 private HandlerRegistration authOkHandlerRegistration;
46 public AuthenticationPopup() {
48 flexTable.setCellSpacing(10);
49 FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
50 flexTable.setHTML(0, 0, "<b>Enter the PostgreSQL username and password.</b>");
51 cellFormatter.setColSpan(0, 0, 2);
52 cellFormatter.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
53 flexTable.setHTML(1, 0, "Username");
54 flexTable.setWidget(1, 1, usernameTextBox);
55 cellFormatter.setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_RIGHT);
56 flexTable.setHTML(2, 0, "Password");
57 flexTable.setWidget(2, 1, passwordTextBox);
58 cellFormatter.setHorizontalAlignment(2, 1, HasHorizontalAlignment.ALIGN_RIGHT);
59 flexTable.setWidget(3, 1, okButton);
60 cellFormatter.setHorizontalAlignment(3, 1, HasHorizontalAlignment.ALIGN_RIGHT);
63 setGlassEnabled(true);
66 // setup properties for the error messsage
67 errorMessage.getElement().getStyle().setColor("Red");
70 public void setClickOkHandler(ClickHandler clickHandler) {
71 authOkHandlerRegistration = okButton.addClickHandler(clickHandler);
74 public String getUsername() {
75 return usernameTextBox.getValue();
78 public String getPassword() {
79 return passwordTextBox.getValue();
85 if (authOkHandlerRegistration != null) {
86 authOkHandlerRegistration.removeHandler();
87 authOkHandlerRegistration = null;
89 usernameTextBox.setText("");
90 passwordTextBox.setText("");
91 setTextFieldsEnabled(true);
95 public void setTextFieldsEnabled(boolean enabled) {
96 usernameTextBox.setEnabled(enabled);
97 passwordTextBox.setEnabled(enabled);
100 public void setError() {
101 flexTable.setWidget(4, 0, errorMessage);
102 FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
103 cellFormatter.setColSpan(4, 0, 2);
104 cellFormatter.setHorizontalAlignment(4, 0, HasHorizontalAlignment.ALIGN_CENTER);
107 public void clearError() {
108 if (flexTable.getRowCount() == 5)
109 flexTable.removeRow(4);