01: package com.bostechcorp.cbesb.console.client.preference;
02:
03: import com.bostechcorp.cbesb.console.client.Admin;
04: import com.bostechcorp.cbesb.console.client.Console;
05: import com.bostechcorp.cbesb.console.client.ConsoleCallback;
06: import com.bostechcorp.cbesb.console.client.dialogs.MessageViewDialog;
07: import com.bostechcorp.cbesb.console.common.ConsoleSettingResult;
08: import com.bostechcorp.cbesb.console.common.ConsoleUserSettingInfo;
09: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
10: import com.google.gwt.core.client.GWT;
11: import com.google.gwt.user.client.ui.ClickListener;
12: import com.google.gwt.user.client.ui.Widget;
13:
14: public class UserPreferencesPanel extends PreferencesPanelBase {
15:
16: private ConsoleUserSettingInfo consoleSetting;
17:
18: public UserPreferencesPanel(String userId) {
19: super ();
20: init(userId, true);
21: }
22:
23: public void refresh() {
24: getConsoleSettingAsyncFromModule().getConsoleUserSetting(
25: userId, new RefreshCallback(this ));
26: }
27:
28: public void addSaveButtonClickListener() {
29: saveButton.addClickListener(new SaveButtonClickListener(this ));
30:
31: }
32:
33: class SaveButtonClickListener extends ConsoleCallback implements
34: ClickListener {
35: public SaveButtonClickListener(Admin admin) {
36: super (admin);
37:
38: }
39:
40: public void onClick(Widget sender) {
41: if (sender == saveButton) {
42: ConsoleUserSettingInfo consoleSetting = new ConsoleUserSettingInfo();
43: consoleSetting.setUserId(userId);
44: if (setConsoleUserSetting(consoleSetting))
45: saveConsoleSetting(consoleSetting);
46: }
47: }
48:
49: public void handleSuccess(Object result) {
50: MessageViewDialog.showInfo(((ConsoleMessages) GWT
51: .create(ConsoleMessages.class)).saveSuccessfully());
52: if (result instanceof ConsoleSettingResult) {
53: ConsoleSettingResult settingResult = (ConsoleSettingResult) result;
54: if (settingResult.isSaInEndpointViewChanged()) {
55: Console.instance.reloadEndpointView(settingResult
56: .getSaInEndpointView());
57: }
58:
59: }
60: }
61: }
62:
63: class RefreshCallback extends ConsoleCallback {
64:
65: public RefreshCallback(Admin admin) {
66: super (admin);
67: }
68:
69: public void handleSuccess(Object result) {
70: if (result instanceof ConsoleUserSettingInfo) {
71: displayUserProperties((ConsoleUserSettingInfo) result);
72:
73: }
74:
75: }
76: }
77:
78: public void saveConsoleSetting(ConsoleUserSettingInfo consoleSetting) {
79: this .consoleSetting = consoleSetting;
80: saveProperties();
81: }
82:
83: public void saveProperties() {
84: if (consoleSetting == null) {
85: consoleSetting = new ConsoleUserSettingInfo();
86: consoleSetting.setUserId(userId);
87: super .saveProperties(consoleSetting);
88: }
89: getConsoleSettingAsyncFromModule().saveConsoleUserSetting(
90: userId, consoleSetting,
91: new SaveButtonClickListener(this));
92:
93: }
94:
95: }
|