001: package com.bostechcorp.cbesb.console.client.log;
002:
003: import com.bostechcorp.cbesb.console.client.Admin;
004: import com.bostechcorp.cbesb.console.client.ConsoleCallback;
005: import com.bostechcorp.cbesb.console.client.dialogs.MessageViewDialog;
006: import com.bostechcorp.cbesb.console.common.Constants;
007: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
008: import com.bostechcorp.cbesb.console.pub.LogConfigItem;
009: import com.bostechcorp.cbesb.console.rpc.LogConfig;
010: import com.bostechcorp.cbesb.console.rpc.LogConfigAsync;
011: import com.google.gwt.core.client.GWT;
012: import com.google.gwt.user.client.rpc.ServiceDefTarget;
013: import com.google.gwt.user.client.ui.ClickListener;
014: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
015: import com.google.gwt.user.client.ui.HasVerticalAlignment;
016: import com.google.gwt.user.client.ui.HorizontalPanel;
017: import com.google.gwt.user.client.ui.Label;
018: import com.google.gwt.user.client.ui.ListBox;
019: import com.google.gwt.user.client.ui.PushButton;
020: import com.google.gwt.user.client.ui.VerticalPanel;
021: import com.google.gwt.user.client.ui.Widget;
022:
023: public class LogHelp extends Admin {
024: private ListBox logListBox = new ListBox();
025: private PushButton applyButton = new PushButton(
026: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
027: .Apply());
028: // private List lognameList=new ArrayList<E>();
029: private int selectedIndex;
030:
031: public LogHelp() {
032: createWidget();
033: setApplyOperation();
034: }
035:
036: private void setApplyOperation() {
037: applyButton.setEnabled(false);
038: applyButton.addClickListener(new ButtonClickListener(this ));
039: // logListBox.addChangeListener(new ChangeListener(){
040: //
041: // public void onChange(Widget sender) {
042: // if(logListBox.getSelectedIndex()==selectedIndex)
043: // applyButton.setEnabled(false);
044: // else
045: // applyButton.setEnabled(true);
046: // }});
047: }
048:
049: public static LogConfigAsync getLogConfigAsyncFromModule() {
050:
051: LogConfigAsync logConfig;
052: logConfig = (LogConfigAsync) GWT.create(LogConfig.class);
053: ServiceDefTarget logConnectTarget = (ServiceDefTarget) logConfig;
054: String relativeUrl = GWT.getModuleBaseURL()
055: + Constants.LOG_CONFIG;
056: logConnectTarget.setServiceEntryPoint(relativeUrl);
057: return logConfig;
058: }
059:
060: public void onHide() {
061: }
062:
063: public void onShow() {
064: refresh();
065: }
066:
067: public void refresh() {
068: getLogConfigAsyncFromModule().getConfigNameArray(
069: new GetLogConfigListener(this ));
070: }
071:
072: protected void createWidget() {
073: final VerticalPanel verticalPanel = new VerticalPanel();
074: initWidget(verticalPanel);
075: verticalPanel.setSize("100%", "100%");
076:
077: final Label welcomeToChainbuilderLabel = new Label(
078: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
079: .welcomeESBLogs1());
080: verticalPanel.add(welcomeToChainbuilderLabel);
081: verticalPanel.add(welcomeToChainbuilderLabel);
082: verticalPanel.setCellWidth(welcomeToChainbuilderLabel, "100%");
083: verticalPanel.setCellHorizontalAlignment(
084: welcomeToChainbuilderLabel,
085: HasHorizontalAlignment.ALIGN_CENTER);
086: verticalPanel.setCellVerticalAlignment(
087: welcomeToChainbuilderLabel,
088: HasVerticalAlignment.ALIGN_TOP);
089: verticalPanel.setCellHeight(welcomeToChainbuilderLabel, "3 em");
090: welcomeToChainbuilderLabel
091: .setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
092:
093: final Label fellFreeToLabel = new Label(((ConsoleMessages) GWT
094: .create(ConsoleMessages.class)).welcomeESBLogs2());
095: verticalPanel.add(fellFreeToLabel);
096: verticalPanel.setCellHorizontalAlignment(fellFreeToLabel,
097: HasHorizontalAlignment.ALIGN_CENTER);
098: verticalPanel.setCellWidth(fellFreeToLabel, "100%");
099: verticalPanel.setCellVerticalAlignment(fellFreeToLabel,
100: HasVerticalAlignment.ALIGN_TOP);
101:
102: final Label label = new Label(((ConsoleMessages) GWT
103: .create(ConsoleMessages.class)).welcomeESBLogs3());
104: verticalPanel.add(label);
105: verticalPanel.setCellWidth(label, "100%");
106: verticalPanel.setCellVerticalAlignment(label,
107: HasVerticalAlignment.ALIGN_TOP);
108:
109: final Label logChooseLabel = new Label(((ConsoleMessages) GWT
110: .create(ConsoleMessages.class)).chooseLogPrompt());
111: final HorizontalPanel logChoosePanel = new HorizontalPanel();
112: logChoosePanel.add(logChooseLabel);
113: logChoosePanel.add(logListBox);
114: logChoosePanel.add(applyButton);
115: verticalPanel.add(logChoosePanel);
116: verticalPanel.setCellWidth(logChoosePanel, "100%");
117: verticalPanel.setCellVerticalAlignment(logChoosePanel,
118: HasVerticalAlignment.ALIGN_TOP);
119:
120: }
121:
122: class ButtonClickListener extends ConsoleCallback implements
123: ClickListener {
124:
125: public ButtonClickListener(Admin admin) {
126: super (admin);
127: }
128:
129: public void handleSuccess(Object result) {
130: refresh();
131: MessageViewDialog
132: .showInfo(((ConsoleMessages) GWT
133: .create(ConsoleMessages.class))
134: .applySuccessfully());
135: }
136:
137: public void onClick(Widget sender) {
138: getLogConfigAsyncFromModule().setLogLevel(
139: logListBox.getItemText(logListBox
140: .getSelectedIndex()), this );
141: }
142:
143: }
144:
145: class GetLogConfigListener extends ConsoleCallback {
146:
147: public GetLogConfigListener(Admin admin) {
148: super (admin);
149: }
150:
151: public void handleSuccess(Object result) {
152: if (result instanceof LogConfigItem[]) {
153: LogConfigItem[] logConfigItems = (LogConfigItem[]) result;
154: int count = 0;
155: logListBox.clear();
156: for (int i = 0; i < logConfigItems.length; i++) {
157:
158: // lognameList.add(log.getName());
159: logListBox.addItem(logConfigItems[i].getName());
160: if (logConfigItems[i].isSelected()) {
161: logListBox.setSelectedIndex(count);
162: selectedIndex = count;
163: }
164: count++;
165: }
166: }
167: applyButton.setEnabled(true);
168: }
169: }
170: }
|