001: /**
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * UserLoginPanel
022: * LPS
023: * Oct 24, 2007
024: */package com.bostechcorp.cbesb.console.client.userlogin;
025:
026: import com.bostechcorp.cbesb.console.common.SecurityLoginInfo;
027: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
028: import com.google.gwt.core.client.GWT;
029: import com.google.gwt.user.client.ui.ClickListener;
030: import com.google.gwt.user.client.ui.DeckPanel;
031: import com.google.gwt.user.client.ui.Grid;
032: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
033: import com.google.gwt.user.client.ui.KeyboardListener;
034: import com.google.gwt.user.client.ui.Label;
035: import com.google.gwt.user.client.ui.PasswordTextBox;
036: import com.google.gwt.user.client.ui.PushButton;
037: import com.google.gwt.user.client.ui.TextBox;
038: import com.google.gwt.user.client.ui.VerticalPanel;
039:
040: /**
041: * @author LPS
042: *
043: */
044: public class UserLoginPanel extends DeckPanel {
045: //
046: private VerticalPanel logedIn;
047:
048: private Label logedInCaption;
049:
050: private PushButton logedInPushButton;
051:
052: //
053: private VerticalPanel logedOut;
054:
055: private Label logedOutCaption;
056:
057: //private TextBox loginPortNumber;
058:
059: private TextBox loginName;
060:
061: private PasswordTextBox loginPassword;
062:
063: private PushButton logedOutPushButton;
064:
065: //
066: private SecurityLoginInfo user;
067:
068: //private Label portNumberLabel;
069:
070: private Label userLabel;
071:
072: private Label passwordLabel;
073:
074: private Label logedOutLabel;
075:
076: private Label logedInLabel;
077:
078: /**
079: *
080: */
081: public UserLoginPanel(ClickListener loginButtonCliskListener,
082: ClickListener logoutButtonClickListener,
083: KeyboardListener loginKeyboardListener) {
084: // TODO: implement i18n
085: // panel displayed when logged in
086: logedIn = new VerticalPanel();
087: logedInCaption = new Label(((ConsoleMessages) GWT
088: .create(ConsoleMessages.class)).welcome(), true);
089: logedInLabel = new Label();
090: logedInPushButton = new PushButton(((ConsoleMessages) GWT
091: .create(ConsoleMessages.class)).Logout());
092: logedInPushButton.addClickListener(logoutButtonClickListener);
093: logedIn.add(logedInCaption);
094: logedIn.setCellHorizontalAlignment(logedInCaption,
095: HasHorizontalAlignment.ALIGN_CENTER);
096: logedIn.add(logedInLabel);
097: logedIn.add(logedInPushButton);
098:
099: // panel displayed when not logged in
100: logedOut = new VerticalPanel();
101: logedOutCaption = new Label(((ConsoleMessages) GWT
102: .create(ConsoleMessages.class)).please_Log_In(), true);
103: logedOutLabel = new Label("");
104:
105: // creating labels and login fields and
106: // putting them into the panel
107: //portNumberLabel = new Label(((ConsoleMessages)GWT.create(ConsoleMessages.class)).PortNumber());
108: userLabel = new Label(((ConsoleMessages) GWT
109: .create(ConsoleMessages.class)).User());
110: passwordLabel = new Label(((ConsoleMessages) GWT
111: .create(ConsoleMessages.class)).Password());
112: //loginPortNumber = new TextBox();
113: //loginPortNumber.setText(Constants.DEFAULT_JMX_PORT);
114: loginName = new TextBox();
115:
116: // loginName.setText("cbesb");
117:
118: loginPassword = new PasswordTextBox();
119:
120: // loginPassword.setText("cbesb");
121:
122: Grid fieldsPanel = new Grid(4, 1);
123:
124: fieldsPanel.setWidth("100%");
125: fieldsPanel.setWidget(0, 0, userLabel);
126: fieldsPanel.setWidget(1, 0, loginName);
127: fieldsPanel.setWidget(2, 0, passwordLabel);
128: fieldsPanel.setWidget(3, 0, loginPassword);
129: // fieldsPanel.setWidget(4, 0, portNumberLabel);
130: // fieldsPanel.setWidget(5, 0, loginPortNumber);
131:
132: logedOutPushButton = new PushButton(((ConsoleMessages) GWT
133: .create(ConsoleMessages.class)).Login());
134: logedOutPushButton.addClickListener(loginButtonCliskListener);
135:
136: loginName.addKeyboardListener(loginKeyboardListener);
137: loginPassword.addKeyboardListener(loginKeyboardListener);
138: logedOut.add(logedOutCaption);
139: logedOut.setCellHorizontalAlignment(logedOutCaption,
140: HasHorizontalAlignment.ALIGN_CENTER);
141: logedOut.add(logedOutLabel);
142: logedOut.add(fieldsPanel);
143: logedOut.add(logedOutPushButton);
144: //styling
145: setSyles();
146: // adding to self the two pannels
147: this .add(logedIn);
148: this .add(logedOut);
149: this .display();
150: }
151:
152: private void setSyles() {
153: logedIn.setStyleName("adm-List");
154: logedOut.setStyleName("adm-List");
155: logedInCaption.setStyleName("adm-Caption");
156: logedOutCaption.setStyleName("adm-Caption");
157:
158: logedInLabel.setStyleName("adm-Label-Small");
159: }
160:
161: public void display() {
162: if (isLogedIn()) {
163: setWelcomeLabel();
164: this .showWidget(0);
165: } else {
166: this .showWidget(1);
167: }
168: }
169:
170: private void setWelcomeLabel() {
171: logedInLabel.setText("Welcome " + user.getLogin()
172: + ". You have the '" + user.getType() + "' role.");
173: }
174:
175: public boolean isLogedIn() {
176: if (user == null)
177: return false;
178: return !(user.isError());
179: }
180:
181: /**
182: * @return the user
183: */
184: public SecurityLoginInfo getUserInfo() {
185: return user;
186: }
187:
188: /**
189: * @param user the user to set
190: */
191: public void setUser(SecurityLoginInfo user) {
192: this .user = user;
193: this .display();
194: }
195:
196: public String getLoginUser() {
197: if (this .loginName == null)
198: return "";
199: return this .loginName.getText();
200: }
201:
202: public String getLoginPassword() {
203: if (this .loginPassword == null)
204: return "";
205: return this.loginPassword.getText();
206: }
207: }
|