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: *
022: * $Id: Console.java 12024 2008-02-19 08:32:23Z rhou $
023: */
024: package com.bostechcorp.cbesb.console.client;
025:
026: import com.bostechcorp.cbesb.console.client.dialogs.MessageViewDialog;
027: import com.bostechcorp.cbesb.console.client.dialogs.WaitingDialog;
028: import com.bostechcorp.cbesb.console.client.userlogin.UserLoginPanel;
029: import com.bostechcorp.cbesb.console.common.Constants;
030: import com.bostechcorp.cbesb.console.common.SecurityLoginInfo;
031: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
032: import com.bostechcorp.cbesb.console.rpc.SecurityLogin;
033: import com.bostechcorp.cbesb.console.rpc.SecurityLoginAsync;
034: import com.google.gwt.core.client.EntryPoint;
035: import com.google.gwt.core.client.GWT;
036: import com.google.gwt.user.client.History;
037: import com.google.gwt.user.client.HistoryListener;
038: import com.google.gwt.user.client.Window;
039: import com.google.gwt.user.client.rpc.ServiceDefTarget;
040: import com.google.gwt.user.client.ui.ClickListener;
041: import com.google.gwt.user.client.ui.HorizontalPanel;
042: import com.google.gwt.user.client.ui.KeyboardListener;
043: import com.google.gwt.user.client.ui.RootPanel;
044: import com.google.gwt.user.client.ui.TreeItem;
045: import com.google.gwt.user.client.ui.TreeListener;
046: import com.google.gwt.user.client.ui.VerticalPanel;
047: import com.google.gwt.user.client.ui.Widget;
048:
049: /**
050: * Entry point classes define <code>onModuleLoad()</code>.
051: *
052: * The Console is now a base class. the Entry point has been moved to the Alertmonitor
053: * and the AdminConsole module.
054: *
055: * The Console becomes a shared libray project. You can not run it as a seperate application any more.
056: *
057: */
058: public class Console implements EntryPoint, HistoryListener,
059: ICallbackHandler {
060:
061: protected boolean isAlertMonitor = false;
062:
063: private AdminInfo curInfo = null;
064:
065: private Admin curAdmin = null;
066:
067: // private HTML description = new HTML();
068: // protected AdminList menuList = new AdminList();
069: public AdminTree menuList = new AdminTree(new MenuTreeListener());
070:
071: public VerticalPanel adminContainer = new VerticalPanel();
072:
073: public HorizontalPanel headerPanel = null;
074:
075: protected UserLoginPanel loginPanel = new UserLoginPanel(
076: new LogInPushButtonClickListener(this ),
077: new LogOutPushButtonClickListener(this ),
078: new LoginKeyboardListener(this ));
079:
080: // public WaitingDialog waitDialog = new WaitingDialog();
081:
082: public static Console instance;
083: public WaitingDialog waiting = new WaitingDialog();
084: // = new WaitingDialog(this);
085: private static SecurityLoginAsync login = null;
086:
087: public void onHistoryChanged(String token) {
088: // Find the AdminInfo associated with the history context. If one is
089: // found, show it (It may not be found, for example, when the user mis-
090: // types a URL, or on startup, when the first context will be "").
091:
092: // System.out.println("\n++Console++History token=" + token);
093: if (!token.startsWith("console:")) {
094: return;
095: }
096: String adminName = token.substring(8);
097: AdminInfo info = (AdminInfo) (menuList.findTitle(adminName)
098: .getUserObject());
099: if (info == null) {
100: return;
101: }
102: show(info, false);
103: }
104:
105: // private JmxConnectDialog jmxDlg;
106:
107: public void onModuleLoad() {
108: instance = this ;
109: initWidgets();
110: }
111:
112: public void initWidgets() {
113: History.addHistoryListener(this );
114: createHeader();
115: adminContainer.setStyleName("adm-Admin");
116: createLoginPanel();
117:
118: RootPanel.get("body").add(adminContainer);
119: RootPanel.get("header").add(headerPanel);
120: RootPanel.get("login").add(loginPanel);
121: }
122:
123: private void createLoginPanel() {
124: // loginPanel = new UserLoginPanel(new LogInPushButtonClickListener(),
125: // new LogOutPushButtonClickListener());
126: // display the initial page
127: curInfo = AdminInfoFactory.getUserStartup();
128: curAdmin = curInfo.getInstance();
129: adminContainer.add(curAdmin);
130: curAdmin.onShow();
131: }
132:
133: public void setConnected() {
134:
135: loadAdmins();
136: postLoadAdmins();
137: RootPanel.get("menu").add(menuList);
138:
139: // Show the initial screen.
140: String initToken = History.getToken();
141: if (initToken.length() > 0)
142: onHistoryChanged(initToken);
143:
144: }
145:
146: private void createHeader() {
147: if (headerPanel == null) {
148: headerPanel = new HorizontalPanel();
149: // Image image = new Image("ChainBuilderESB.jpeg");
150: // headerPanel.add(image);
151: //
152: // HorizontalPanel languages = new HorizontalPanel();
153: // languages.setBorderWidth(1);
154: // languages.setSpacing(3);
155: // Label english = new Label("English");
156: // Label chinese = new Label("Chinese");
157: // languages.add(chinese);
158: // languages.add(english);
159: // headerPanel.add(languages);
160: }
161: }
162:
163: public void show(AdminInfo info, boolean affectHistory) {
164: // Don'currentTimer bother re-displaying the existing admin. This can be
165: // an issue
166: // in practice, because when the history context is set, our
167: // onHistoryChanged() handler will attempt to show the currently-visible
168: // admin.
169: if (info == curInfo)
170: return;
171: curInfo = info;
172:
173: // Remove the old admin from the display area.
174: if (curAdmin != null) {
175: curAdmin.onHide();
176: adminContainer.remove(curAdmin);
177: }
178:
179: // Get the new admin instance, and display its description in the
180: // admin list.
181: curAdmin = info.getInstance();
182:
183: // XXX
184: // menuList.setAdminSelection(info.getName());
185:
186: // description.setHTML("<strong><em>"+info.getDescription());
187: // If affectHistory is set, create a new item on the history stack. This
188: // will ultimately result in onHistoryChanged() being called. It will
189: // call
190: // show() again, but nothing will happen because it will request the
191: // exact
192: // same admin we're already showing.
193: if (affectHistory)
194: History.newItem("console:" + info.getName());
195:
196: // Display the new admin.
197: adminContainer.add(curAdmin);
198: curAdmin.onShow();
199: }
200:
201: /**
202: * Adds all admins to the list. Note that this does not create actual
203: * instances of all admins yet (they are created on-demand). This can make a
204: * significant difference in startup time.
205: */
206: protected void loadAdmins() {
207: menuList.addAdmin(AdminInfoFactory.getComponentsHelp(loginPanel
208: .getUserInfo()), menuList.images.components());
209: menuList.addAdmin(AdminInfoFactory
210: .getComponentsCurrent(loginPanel.getUserInfo()),
211: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
212: .Components(), menuList.images
213: .defaultMenuItem());
214: menuList.addAdmin(AdminInfoFactory
215: .getComponentsInstall(loginPanel.getUserInfo()),
216: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
217: .Components(), menuList.images
218: .defaultMenuItem());
219: menuList.addAdmin(AdminInfoFactory.getAssembliesHelp(loginPanel
220: .getUserInfo()), menuList.images.assemblies());
221: menuList.addAdmin(AdminInfoFactory
222: .getAssembliesCurrent(loginPanel.getUserInfo()),
223: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
224: .Assemblies(), menuList.images.assemblies());
225: menuList.addAdmin(AdminInfoFactory
226: .getAssembliesDeploy(loginPanel.getUserInfo()),
227: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
228: .Assemblies(), menuList.images.assemblies());
229: //
230: menuList.addAdmin(AdminInfoFactory.getEndpointHelp(loginPanel
231: .getUserInfo()), menuList.images.endpoints());
232: menuList.addAdmin(AdminInfoFactory.getEndpointStatus(loginPanel
233: .getUserInfo()), ((ConsoleMessages) GWT
234: .create(ConsoleMessages.class)).Endpoints(),
235: menuList.images.endpoints());
236:
237: menuList.addAdmin(AdminInfoFactory
238: .getEndpointStatistics(loginPanel.getUserInfo()),
239: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
240: .Endpoints(), menuList.images.endpoints());
241:
242: menuList.addAdmin(AdminInfoFactory.getLogHelp(loginPanel
243: .getUserInfo()), menuList.images.log());
244: menuList.addAdmin(AdminInfoFactory.getServerLogView(loginPanel
245: .getUserInfo()), ((ConsoleMessages) GWT
246: .create(ConsoleMessages.class)).Log(), menuList.images
247: .log());
248: menuList.addAdmin(AdminInfoFactory.getSmLogView(loginPanel
249: .getUserInfo()), ((ConsoleMessages) GWT
250: .create(ConsoleMessages.class)).Log(), menuList.images
251: .log());
252: menuList.addAdmin(AdminInfoFactory.getTcLogView(loginPanel
253: .getUserInfo()), ((ConsoleMessages) GWT
254: .create(ConsoleMessages.class)).Log(), menuList.images
255: .log());
256: //
257: menuList.addAdmin(AdminInfoFactory.getErrorDBPanel(loginPanel
258: .getUserInfo()), menuList.images.defaultMenuItem());
259:
260: }
261:
262: public void reloadEndpointView(String saInEndpointView) {
263: SecurityLoginInfo userInfo = loginPanel.getUserInfo();
264: userInfo.setSaInEndpointView(saInEndpointView);
265: TreeItem statisticItem = menuList
266: .findTitle(AdminInfoFactory.STATISTIC);
267: if (statisticItem != null) {
268: statisticItem.setUserObject(AdminInfoFactory
269: .getEndpointStatistics(userInfo));
270: }
271: TreeItem statusItem = menuList
272: .findTitle(AdminInfoFactory.STATUS);
273: if (statusItem != null) {
274: statusItem.setUserObject(AdminInfoFactory
275: .getEndpointStatus(userInfo));
276: }
277:
278: }
279:
280: /**
281: * Adds all admins to the list. Note that this does not create actual
282: * instances of all admins yet (they are created on-demand). This can make a
283: * significant difference in startup time.
284: */
285: protected void postLoadAdmins() {
286:
287: // Setup menu
288: menuList.addAdmin(AdminInfoFactory.getSetup(loginPanel
289: .getUserInfo()), menuList.images.preferences());
290: menuList.addAdmin(AdminInfoFactory.getUserEdit(loginPanel
291: .getUserInfo()), ((ConsoleMessages) GWT
292: .create(ConsoleMessages.class)).Setup(),
293: menuList.images.editUser());
294: // menuList.addAdmin(AdminInfoFactory.getLogViewProperties(loginPanel
295: // .getUserInfo()), ((ConsoleMessages) GWT
296: // .create(ConsoleMessages.class)).Setup(), menuList.images.log());
297: if (loginPanel.getUserInfo().getType().equals(
298: SecurityLoginInfo.administrator)) {
299: menuList.addAdmin(
300: AdminInfoFactory
301: .getDefaultPreferencePanel(loginPanel
302: .getUserInfo()),
303: ((ConsoleMessages) GWT
304: .create(ConsoleMessages.class)).Setup(),
305: menuList.images.log());
306: }
307: menuList.addAdmin(AdminInfoFactory
308: .getUserPreferencePanel(loginPanel.getUserInfo()),
309: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
310: .Setup(), menuList.images.log());
311: menuList.addAdmin(AdminInfoFactory.getAboutPanel(loginPanel
312: .getUserInfo()), ((ConsoleMessages) GWT
313: .create(ConsoleMessages.class)).Setup(),
314: menuList.images.log());
315:
316: // menuList.addAdmin(AdminInfoFactory.getVersionPanel(loginPanel
317: // .getUserInfo()), ((ConsoleMessages) GWT
318: // .create(ConsoleMessages.class)).About(), menuList.images.log());
319: // menuList.addAdmin(AdminInfoFactory.getLicensePanel(loginPanel
320: // .getUserInfo()), ((ConsoleMessages) GWT
321: // .create(ConsoleMessages.class)).About(), menuList.images.log());
322: // menuList.addAdmin(AdminInfoFactory.getSupportPanel(loginPanel
323: // .getUserInfo()), ((ConsoleMessages) GWT
324: // .create(ConsoleMessages.class)).About(), menuList.images.log());
325:
326: }
327:
328: // Some Click Listeners
329: class LogInPushButtonClickListener extends ConsoleCallback
330: implements ClickListener {
331: public LogInPushButtonClickListener(ICallbackHandler handler) {
332: super (handler);
333:
334: }
335:
336: public void onClick(Widget sender) {
337: waiting.show();
338:
339: getSecurityLoginAsyncFromModule().login(
340: /*loginPanel.getLoginPort()*/null,
341: loginPanel.getLoginUser(),
342: loginPanel.getLoginPassword(),
343: LogInPushButtonClickListener.this );
344: }
345:
346: public void handleExtFailure(Object result) {
347: loginPanel.setUser(null);
348: super .handleExtFailure(result);
349: }
350:
351: public void handleSuccess(Object result) {
352: if (result instanceof SecurityLoginInfo) {
353: SecurityLoginInfo info = (SecurityLoginInfo) result;
354: loginPanel.setUser(info);
355: setConnected();// display the menu , etc
356: } else
357:
358: MessageViewDialog
359: .showWarning("Login result is not expected");
360:
361: }
362: }
363:
364: public static SecurityLoginAsync getSecurityLoginAsyncFromModule() {
365: if (login == null) {
366: login = (SecurityLoginAsync) GWT
367: .create(SecurityLogin.class);
368: ServiceDefTarget jmxConnectTarget = (ServiceDefTarget) login;
369: String relativeUrl = GWT.getModuleBaseURL()
370: + Constants.JMX_SECURITY_LOGIN_SERVLET;
371: jmxConnectTarget.setServiceEntryPoint(relativeUrl);
372: }
373: return login;
374:
375: }
376:
377: class LogOutPushButtonClickListener extends ConsoleCallback
378: implements ClickListener {
379: public LogOutPushButtonClickListener(ICallbackHandler handler) {
380: super (handler);
381:
382: }
383:
384: public void onClick(Widget w) {
385:
386: waiting.show();
387:
388: getSecurityLoginAsyncFromModule().logout(
389: LogOutPushButtonClickListener.this );
390: }
391:
392: public void handleSuccess(Object result) {
393: refreshPage();
394:
395: }
396:
397: public void handleExtFailure(Object result) {
398:
399: refreshPage();
400: }
401:
402: }
403:
404: class LoginKeyboardListener extends ConsoleCallback implements
405: KeyboardListener {
406:
407: public LoginKeyboardListener(ICallbackHandler handler) {
408: super (handler);
409:
410: }
411:
412: public void handleExtFailure(Object result) {
413: loginPanel.setUser(null);
414: super .handleExtFailure(result);
415: }
416:
417: public void handleSuccess(Object result) {
418: if (result instanceof SecurityLoginInfo) {
419: SecurityLoginInfo info = (SecurityLoginInfo) result;
420: loginPanel.setUser(info);
421: setConnected();// display the menu , etc
422: } else
423:
424: MessageViewDialog
425: .showWarning("Login result is not expected");
426:
427: }
428:
429: public void onKeyDown(Widget sender, char keyCode, int modifiers) {
430: // TODO Auto-generated method stub
431:
432: }
433:
434: public void onKeyPress(Widget sender, char keyCode,
435: int modifiers) {
436:
437: if ((!Character.isDigit(keyCode))
438: && (keyCode == (char) KEY_ENTER)) {
439: // Window.alert("Test for enter.");
440: waiting.show();
441: getSecurityLoginAsyncFromModule().login(
442: /*loginPanel.getLoginPort()*/null,
443: loginPanel.getLoginUser(),
444: loginPanel.getLoginPassword(),
445: LoginKeyboardListener.this );
446: }
447:
448: }
449:
450: public void onKeyUp(Widget sender, char keyCode, int modifiers) {
451: // TODO Auto-generated method stub
452:
453: }
454:
455: }
456:
457: public boolean isAlertMonitor() {
458: return isAlertMonitor;
459: }
460:
461: public void setAlertMonitor(boolean isAlertMonitor) {
462: this .isAlertMonitor = isAlertMonitor;
463: }
464:
465: public static Console getInstance() {
466: return instance;
467: }
468:
469: public static native void refreshPage() /*-{
470: var baseurl = @com.google.gwt.core.client.GWT::getModuleBaseURL()();
471: parent.location.href = parent.location.href;
472: }-*/;
473:
474: // End Click Listeners
475: //
476: class MenuTreeListener implements TreeListener {
477:
478: public void onTreeItemSelected(TreeItem item) {
479: show(((AdminInfo) (item.getUserObject())), false);
480: }
481:
482: public void onTreeItemStateChanged(TreeItem item) {
483: // TODO Auto-generated method stub
484: }
485:
486: }
487: }
|