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: * UserEditReadOnlyPanel
022: * LPS
023: * Oct 30, 2007
024: */package com.bostechcorp.cbesb.console.client.useredit;
025:
026: import com.bostechcorp.cbesb.console.client.Admin;
027: import com.bostechcorp.cbesb.console.client.ConsoleCallback;
028: import com.bostechcorp.cbesb.console.client.ICallbackHandler;
029: import com.bostechcorp.cbesb.console.client.Validators;
030: import com.bostechcorp.cbesb.console.common.ConsoleUserInfo;
031: import com.bostechcorp.cbesb.console.common.Constants;
032: import com.bostechcorp.cbesb.console.common.SecurityLoginInfo;
033: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
034: import com.bostechcorp.cbesb.console.rpc.SecurityOperations;
035: import com.bostechcorp.cbesb.console.rpc.SecurityOperationsAsync;
036: import com.google.gwt.core.client.GWT;
037: import com.google.gwt.user.client.rpc.ServiceDefTarget;
038: import com.google.gwt.user.client.ui.ChangeListener;
039: import com.google.gwt.user.client.ui.ClickListener;
040: import com.google.gwt.user.client.ui.DisclosurePanel;
041: import com.google.gwt.user.client.ui.FlexTable;
042: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
043: import com.google.gwt.user.client.ui.HorizontalPanel;
044: import com.google.gwt.user.client.ui.KeyboardListener;
045: import com.google.gwt.user.client.ui.Label;
046: import com.google.gwt.user.client.ui.ListBox;
047: import com.google.gwt.user.client.ui.PasswordTextBox;
048: import com.google.gwt.user.client.ui.PushButton;
049: import com.google.gwt.user.client.ui.TextArea;
050: import com.google.gwt.user.client.ui.TextBox;
051: import com.google.gwt.user.client.ui.VerticalPanel;
052: import com.google.gwt.user.client.ui.Widget;
053:
054: /**
055: * @author LPS
056: *
057: */
058: public class UserEditReadOnlyPanel extends Admin {
059:
060: protected SecurityLoginInfo logedInUser;
061: //we must have it here to be able to operate db operations
062: private ConsoleUserInfo currentUser;
063:
064: private ConsoleUserInfo backupCurrentUser;
065:
066: private TextBox userLoginTextBox = new TextBox();
067:
068: private TextBox userNameTextBox = new TextBox();
069:
070: private ListBox userTypesListBox = new ListBox();
071:
072: private TextArea userNotesTextArea = new TextArea();
073:
074: private TextBox userIdTextBox = new TextBox();
075:
076: private TextBox userEmailTextBox = new TextBox();
077:
078: private PasswordTextBox userPasswordTextBox = new PasswordTextBox();
079:
080: private PasswordTextBox userComfirmTextBox = new PasswordTextBox();
081:
082: private PushButton okSavePushButton = new PushButton();
083:
084: private PushButton cancelHideFieldsPushButton = new PushButton();
085:
086: private HorizontalPanel okCancelButtonsPanel = new HorizontalPanel();
087:
088: private TextArea errorTextArea = new TextArea();
089:
090: private DisclosurePanel errorContainer = new DisclosurePanel();
091:
092: private Label userComfirmLabel = new Label(((ConsoleMessages) GWT
093: .create(ConsoleMessages.class)).ConfirmPassword(), true);
094:
095: private Label userPasswordLabel = new Label(((ConsoleMessages) GWT
096: .create(ConsoleMessages.class)).InputPassword(), true);
097:
098: private Label userLastUpdateLabel = new Label(
099: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
100: .LastUpdate(), true);
101:
102: private Label userNotesLabel = new Label(((ConsoleMessages) GWT
103: .create(ConsoleMessages.class)).Notes(), true);
104:
105: private Label userEmailLabel = new Label(((ConsoleMessages) GWT
106: .create(ConsoleMessages.class)).Email(), true);
107:
108: private Label userTypeLabel = new Label(((ConsoleMessages) GWT
109: .create(ConsoleMessages.class)).Type(), true);
110:
111: private Label userNameLabel = new Label(((ConsoleMessages) GWT
112: .create(ConsoleMessages.class)).Name(), true);
113:
114: private Label userLoginLabel = new Label(((ConsoleMessages) GWT
115: .create(ConsoleMessages.class)).Nickname(), true);
116:
117: private Label userIdLabel = new Label(((ConsoleMessages) GWT
118: .create(ConsoleMessages.class)).UserId(), true);
119:
120: private VerticalPanel userInformationContainer = new VerticalPanel();
121:
122: private Label errorContainerHeader = new Label(
123: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
124: .Errorview(), true);
125:
126: private TextBox userLastUpdateTextBox = new TextBox();
127:
128: private Label userTimeoutLabel = new Label(((ConsoleMessages) GWT
129: .create(ConsoleMessages.class)).Timeout(), true);
130:
131: private TextBox userTimeoutTextBox = new TextBox();
132:
133: private Label userTimeoutUnitLabel = new Label(
134: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
135: .TimeoutUnit(), true);
136: private HorizontalPanel timeoutPanel = new HorizontalPanel();
137:
138: /**
139: * @wbp.parser.constructor
140: */
141: public UserEditReadOnlyPanel(SecurityLoginInfo user) {
142: this .logedInUser = user;
143: createUserEditWidget();
144: setStyles();
145: initWidget(userInformationContainer);
146: userInformationContainer.setWidth("100%");
147: //
148: extractCurrentUser(user);
149: }
150:
151: /**
152: * goes back to database to extract the user's details in VO bean object
153: * @param user
154: */
155: private void extractCurrentUser(SecurityLoginInfo user) {
156: //get the operations servlet
157: SecurityOperationsAsync operations;
158: operations = (SecurityOperationsAsync) GWT
159: .create(SecurityOperations.class);
160: ServiceDefTarget consoleUserOperation = (ServiceDefTarget) operations;
161: String relativeUrl = GWT.getModuleBaseURL()
162: + Constants.JMX_CONSOLE_USER_SERVLET;
163: consoleUserOperation.setServiceEntryPoint(relativeUrl);
164: //
165: operations.getUserByNickname(user.getLogin(),
166: new ExtractCurrentUserCallback(this ));
167: }
168:
169: private void createUserEditWidget() {
170: // Buttons
171: okSavePushButton.setText(((ConsoleMessages) GWT
172: .create(ConsoleMessages.class)).Save());
173: cancelHideFieldsPushButton.setText(((ConsoleMessages) GWT
174: .create(ConsoleMessages.class)).Cancel());
175: okCancelButtonsPanel.add(okSavePushButton);
176: okCancelButtonsPanel.add(cancelHideFieldsPushButton);
177: okCancelButtonsPanel.setCellHorizontalAlignment(
178: okSavePushButton, HasHorizontalAlignment.ALIGN_RIGHT);
179: okCancelButtonsPanel.setCellHorizontalAlignment(
180: cancelHideFieldsPushButton,
181: HasHorizontalAlignment.ALIGN_RIGHT);
182: okSavePushButton
183: .addClickListener(new OkSaveButtonClickListener(this ));
184: cancelHideFieldsPushButton
185: .addClickListener(new CancelHideFieldsButtonClickListener());
186: //
187: userTypesListBox.addItem(SecurityLoginInfo.administrator);
188: userTypesListBox.addItem(SecurityLoginInfo.operator);
189: userTypesListBox.addItem(SecurityLoginInfo.user);
190:
191: userNotesTextArea.setVisibleLines(3);
192: userNotesTextArea.setWidth("100%");
193: // userNotesTextArea.setCharacterWidth("40");
194: userIdTextBox.setEnabled(false);
195: userLastUpdateTextBox.setEnabled(false);
196: userLoginTextBox.setEnabled(false);
197: userTimeoutTextBox.setEnabled(false);
198: userTypesListBox.setEnabled(false);
199: timeoutPanel.add(userTimeoutTextBox);
200: timeoutPanel.add(userTimeoutUnitLabel);
201: //
202: FlexTable grid = new FlexTable();// Grid(9, 2);
203: grid.setWidget(0, 0, userIdLabel);
204: grid.getCellFormatter().setWidth(0, 0, "20%");
205: grid.setWidget(1, 0, userLoginLabel);
206: grid.setWidget(2, 0, userNameLabel);
207: grid.setWidget(3, 0, userEmailLabel);
208: grid.setWidget(4, 0, userTypeLabel);
209: grid.setWidget(5, 0, userTimeoutLabel);
210: grid.setWidget(6, 0, userLastUpdateLabel);
211: grid.setWidget(7, 0, userNotesLabel);
212: grid.setWidget(8, 0, userPasswordLabel);
213: grid.setWidget(9, 0, userComfirmLabel);
214: grid.setWidget(0, 1, userIdTextBox);
215: grid.setWidget(1, 1, userLoginTextBox);
216: grid.setWidget(2, 1, userNameTextBox);
217: grid.setWidget(3, 1, userEmailTextBox);
218: grid.setWidget(4, 1, userTypesListBox);
219: grid.setWidget(5, 1, timeoutPanel);
220: grid.setWidget(6, 1, userLastUpdateTextBox);
221: grid.setWidget(7, 1, userNotesTextArea);
222: grid.setWidget(8, 1, userPasswordTextBox);
223: grid.setWidget(9, 1, userComfirmTextBox);
224:
225: // listening for any changes
226: FieldsModificationListener modif = new FieldsModificationListener();
227: userIdTextBox.addChangeListener(modif);
228: userLastUpdateTextBox.addChangeListener(modif);
229: userEmailTextBox.addChangeListener(modif);
230: userLoginTextBox.addChangeListener(modif);
231: userNotesTextArea.addChangeListener(modif);
232: userPasswordTextBox.addChangeListener(modif);
233: userComfirmTextBox.addChangeListener(modif);
234: userNameTextBox.addChangeListener(modif);
235: userTypesListBox.addChangeListener(modif);
236:
237: userIdTextBox.addKeyboardListener(modif);
238: userLastUpdateTextBox.addKeyboardListener(modif);
239: userEmailTextBox.addKeyboardListener(modif);
240: userLoginTextBox.addKeyboardListener(modif);
241: userNotesTextArea.addKeyboardListener(modif);
242: userPasswordTextBox.addKeyboardListener(modif);
243: userComfirmTextBox.addKeyboardListener(modif);
244: userNameTextBox.addKeyboardListener(modif);
245: userTypesListBox.addKeyboardListener(modif);
246: // some more layouting
247: userIdTextBox.setWidth("100%");
248: userTypesListBox.setWidth("100%");
249: userNotesTextArea.setWidth("100%");
250: userPasswordTextBox.setWidth("100%");
251: userNameTextBox.setWidth("100%");
252: userLastUpdateTextBox.setWidth("100%");
253: userLoginTextBox.setWidth("100%");
254: userComfirmTextBox.setWidth("100%");
255: userEmailTextBox.setWidth("100%");
256:
257: // Error Area
258: errorContainer.setHeader(errorContainerHeader);
259: errorContainer.setWidth("100%");
260: errorTextArea.setWidth("100%");
261: errorTextArea.setVisibleLines(5);
262: errorContainer.add(errorTextArea);
263: errorContainer.setOpen(false);
264: //
265: userInformationContainer.add(okCancelButtonsPanel);
266: userInformationContainer.add(grid);
267: userInformationContainer.setCellWidth(grid, "100%");
268: grid.setWidth("100%");
269: userInformationContainer.add(errorContainer);
270: userInformationContainer.setCellHorizontalAlignment(
271: okCancelButtonsPanel,
272: HasHorizontalAlignment.ALIGN_RIGHT);
273: }
274:
275: private void setStyles() {
276:
277: okSavePushButton.setStyleName("gwt-PushButton");
278: cancelHideFieldsPushButton.setStyleName("gwt-PushButton");
279:
280: //labels
281: userIdLabel.setStyleName("gwt-Label");
282: userComfirmLabel.setStyleName("gwt-Label");
283: userTimeoutLabel.setStyleName("gwt-Label");
284: userEmailLabel.setStyleName("gwt-Label");
285: userLastUpdateLabel.setStyleName("gwt-Label");
286: userLoginLabel.setStyleName("gwt-Label");
287: userNameLabel.setStyleName("gwt-Label");
288: userNotesLabel.setStyleName("gwt-Label");
289: userPasswordLabel.setStyleName("gwt-Label");
290: userTypeLabel.setStyleName("gwt-Label");
291: //
292: userIdTextBox.setStyleName("gwt-TextField");
293: userComfirmTextBox.setStyleName("gwt-TextField");
294: userTimeoutTextBox.setStyleName("gwt-TextField");
295: userEmailTextBox.setStyleName("gwt-TextField");
296: userLastUpdateTextBox.setStyleName("gwt-TextField");
297: userLoginTextBox.setStyleName("gwt-TextField");
298: userNameTextBox.setStyleName("gwt-TextField");
299: userNotesTextArea.setStyleName("gwt-TextField");
300: userPasswordTextBox.setStyleName("gwt-TextField");
301: userTypesListBox.setStyleName("gwt-TextField");
302: //
303: //errorContainerHeader.setStyleName("body-userEdit-gwt-CaptionLabel");
304: //
305: }
306:
307: /**
308: * @param logedInUser
309: * the logedInUser to set
310: */
311: public void setLogedInUser(SecurityLoginInfo logedInUser) {
312: this .logedInUser = logedInUser;
313: }
314:
315: class OkSaveButtonClickListener extends ConsoleCallback implements
316: ClickListener {
317:
318: public OkSaveButtonClickListener(ICallbackHandler handler) {
319: super (handler);
320: }
321:
322: public void onClick(Widget sender) {
323: controlToModel();
324: //get the operations servlet
325: SecurityOperationsAsync operations;
326: operations = (SecurityOperationsAsync) GWT
327: .create(SecurityOperations.class);
328: ServiceDefTarget consoleUserOperation = (ServiceDefTarget) operations;
329: String relativeUrl = GWT.getModuleBaseURL()
330: + Constants.JMX_CONSOLE_USER_SERVLET;
331: consoleUserOperation.setServiceEntryPoint(relativeUrl);
332: //
333: operations.update(currentUser,
334: OkSaveButtonClickListener.this );
335: setSaveCancelButtonsEnabled(false);
336: }
337:
338: public void handleSuccess(Object result) {
339: if (result instanceof Boolean) {
340: if (((Boolean) result).booleanValue()) {
341: UserEditReadOnlyPanel.this .backupCurrentUser = UserEditReadOnlyPanel.this .currentUser;
342: } else {
343: setErrorMessage(((ConsoleMessages) GWT
344: .create(ConsoleMessages.class))
345: .saveOperationError(), true);
346: }
347: } else {
348: setErrorMessage(((ConsoleMessages) GWT
349: .create(ConsoleMessages.class))
350: .saveOperationErrorForNotBoolean(), true);
351: }
352: }
353: }
354:
355: class CancelHideFieldsButtonClickListener implements ClickListener {
356:
357: public void onClick(Widget sender) {
358: setCurrentUser(UserEditReadOnlyPanel.this .backupCurrentUser);
359: setSaveCancelButtonsEnabled(false);
360: }
361: }
362:
363: class FieldsModificationListener implements ChangeListener,
364: KeyboardListener {
365: public void onChange(Widget sender) {
366: controlToModel();
367: }
368:
369: public void onKeyDown(Widget sender, char keyCode, int modifiers) {
370: }
371:
372: public void onKeyPress(Widget sender, char keyCode,
373: int modifiers) {
374: //controlToModel();
375: }
376:
377: public void onKeyUp(Widget sender, char keyCode, int modifiers) {
378: }
379: }
380:
381: private void controlToModel() {
382: boolean valid = areUserInfoValid();
383: if (valid) {
384: Long l = new Long(userIdTextBox.getText());
385: Long timeout = new Long(userTimeoutTextBox.getText());
386: currentUser.setUserId(l.longValue());
387: currentUser.setTimeout(timeout.longValue());
388: currentUser.setLogin(userLoginTextBox.getText());
389: currentUser.setName(userNameTextBox.getText());
390: currentUser.setEmail(userEmailTextBox.getText());
391: currentUser.setNotes(userNotesTextArea.getText());
392: currentUser.setPassword(userPasswordTextBox.getText());
393: currentUser.setType(userTypesListBox
394: .getItemText(userTypesListBox.getSelectedIndex()));
395: }
396: setSaveCancelButtonsEnabled(valid);
397: }
398:
399: /**
400: * @param saveCancelButtonsEnabled
401: * the saveCancelButtonsEnabled to set
402: */
403: public void setSaveCancelButtonsEnabled(
404: boolean saveCancelButtonsEnabled) {
405: // this.saveCancelButtonsEnabled = saveCancelButtonsEnabled;
406: okSavePushButton.setEnabled(saveCancelButtonsEnabled);
407: cancelHideFieldsPushButton.setEnabled(saveCancelButtonsEnabled);
408: }
409:
410: private boolean areUserInfoValid() {
411: if (!Validators.isLogin(userLoginTextBox.getText())) {
412: setErrorMessage(((ConsoleMessages) GWT
413: .create(ConsoleMessages.class)).invalidLogin(),
414: true);
415: return false;
416: } else if (!Validators.isAlfanumeric(userNameTextBox.getText())) {
417: setErrorMessage(((ConsoleMessages) GWT
418: .create(ConsoleMessages.class)).invalidName(), true);
419: return false;
420: } else if (!Validators.isEmail(userEmailTextBox.getText())) {
421: setErrorMessage(((ConsoleMessages) GWT
422: .create(ConsoleMessages.class)).invalidEmail(),
423: true);
424: return false;
425: } else if (!Validators
426: .isPassword(userPasswordTextBox.getText())) {
427: setErrorMessage(((ConsoleMessages) GWT
428: .create(ConsoleMessages.class)).invalidPassword(),
429: true);
430: return false;
431: } else if (!Validators.isPasswordConfirmed(userPasswordTextBox
432: .getText(), userComfirmTextBox.getText())) {
433: setErrorMessage(((ConsoleMessages) GWT
434: .create(ConsoleMessages.class))
435: .invalidPasswordConfirm(), true);
436: return false;
437: }
438: return true;
439: }
440:
441: /**
442: * sets the message into ErrorTextArea, in the bottom of the userInformation
443: * panel, and opens the disclosure panel.
444: *
445: * @param message
446: * @param append,
447: * if tru the message will be appended to the current content
448: */
449: public void setErrorMessage(String message, boolean append) {
450: errorContainer.setOpen(true);
451: String s = "";
452: if (append) {
453: s = errorTextArea.getText();
454: }
455: s += "\n";
456: errorTextArea.setText(s + message);
457: errorTextArea.setCursorPos(errorTextArea.getText().length());
458: }
459:
460: /**
461: * @param currentUser
462: * the currentUser to disply
463: */
464: public void setCurrentUser(ConsoleUserInfo currentUser) {
465: if (this .currentUser != null) {
466: this .backupCurrentUser = this .currentUser.clone();
467: } else {
468: this .backupCurrentUser = null;
469: }
470: this .currentUser = currentUser;
471:
472: setSaveCancelButtonsEnabled(false);
473: displayCurrentUser();
474: }
475:
476: private void displayCurrentUser() {
477: userIdTextBox.setText("" + currentUser.getUserId());
478: userLoginTextBox.setText("" + currentUser.getLogin());
479: userNameTextBox.setText("" + currentUser.getName());
480: userEmailTextBox.setText("" + currentUser.getEmail());
481: userNotesTextArea.setText("" + currentUser.getNotes());
482: userPasswordTextBox.setText("" + currentUser.getPassword());
483: userComfirmTextBox.setText("" + currentUser.getPassword());
484: userLastUpdateTextBox
485: .setText("" + currentUser.getLastUpdated());
486: userTimeoutTextBox.setText("" + currentUser.getTimeout());
487:
488: if (currentUser.getType().equals(
489: SecurityLoginInfo.administrator)) {
490: userTypesListBox.setSelectedIndex(0);
491: } else if (currentUser.getType().equals(
492: SecurityLoginInfo.operator)) {
493: userTypesListBox.setSelectedIndex(1);
494: } else if (currentUser.getType().equals(SecurityLoginInfo.user)) {
495: userTypesListBox.setSelectedIndex(2);
496: }
497: }
498:
499: class ExtractCurrentUserCallback extends ConsoleCallback {
500:
501: public ExtractCurrentUserCallback(ICallbackHandler handler) {
502: super (handler);
503: // TODO Auto-generated constructor stub
504: }
505:
506: public void handleSuccess(Object result) {
507: if (result instanceof ConsoleUserInfo) {
508: setCurrentUser((ConsoleUserInfo) result);
509: } else {
510: setErrorMessage(((ConsoleMessages) GWT
511: .create(ConsoleMessages.class))
512: .resultNotConsoleUserInfo()
513: + result.toString(), true);
514: }
515: }
516: }
517:
518: public void onHide() {
519:
520: }
521:
522: public void onShow() {
523:
524: }
525:
526: public void refresh() {
527:
528: }
529: }
|