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$
023: */
024: package com.bostechcorp.cbesb.console.client.components;
025:
026: import com.bostechcorp.cbesb.console.client.Admin;
027: import com.bostechcorp.cbesb.console.client.AdminWithTimer;
028: import com.bostechcorp.cbesb.console.client.ConsoleCallback;
029: import com.bostechcorp.cbesb.console.client.ConsoleVersion;
030: import com.bostechcorp.cbesb.console.client.PollingTimerCallback;
031: import com.bostechcorp.cbesb.console.client.StyleConstants;
032: import com.bostechcorp.cbesb.console.client.WidgetUtil;
033: import com.bostechcorp.cbesb.console.client.dialogs.ComponentsVersionDialog;
034: import com.bostechcorp.cbesb.console.client.dialogs.UninstallConfirmDialog;
035: import com.bostechcorp.cbesb.console.common.JmxComponentInfo;
036: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
037: import com.google.gwt.core.client.GWT;
038: import com.google.gwt.user.client.ui.Button;
039: import com.google.gwt.user.client.ui.ClickListener;
040: import com.google.gwt.user.client.ui.FlexTable;
041: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
042: import com.google.gwt.user.client.ui.HasVerticalAlignment;
043: import com.google.gwt.user.client.ui.HorizontalPanel;
044: import com.google.gwt.user.client.ui.Label;
045: import com.google.gwt.user.client.ui.PushButton;
046: import com.google.gwt.user.client.ui.VerticalPanel;
047: import com.google.gwt.user.client.ui.Widget;
048:
049: public abstract class ComponentsCurrentBase extends AdminWithTimer {
050:
051: // private WaitingDialog WaitingDialog = new WaitingDialog();
052:
053: UninstallConfirmDialog confirm = null;
054:
055: public static final String PREFIX_TOKEN = "cbesb_component_";
056:
057: VerticalPanel mainPanel = new VerticalPanel();
058:
059: VerticalPanel currentPanel = new VerticalPanel();
060:
061: HorizontalPanel currentButtonPanel = new HorizontalPanel();
062:
063: private String[] bcNames;
064:
065: private String[] seNames;
066:
067: private String[] slNames;
068:
069: private String[] bcStates;
070:
071: private String[] seStates;
072:
073: private FlexTable currentTable = new FlexTable();
074:
075: private PushButton refreshButton = new PushButton(
076: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
077: .Refresh());
078:
079: private PushButton startAll = new PushButton(((ConsoleMessages) GWT
080: .create(ConsoleMessages.class)).StartAll());
081:
082: private PushButton shutdownAll = new PushButton(
083: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
084: .ShutdownAll());
085:
086: // private PushButton stopAll = new PushButton(((ConsoleMessages) GWT
087: // .create(ConsoleMessages.class)).StopAll());
088:
089: protected boolean readOnly = false;
090:
091: // protected StartAllButtonClickListener startAllButtonClickListener = new StartAllButtonClickListener(this);
092:
093: // protected ShutdownAllButtonClickListener shutdownAllButtonClickListener = new ShutdownAllButtonClickListener(this);
094:
095: // protected StopAllButtonClickListener stopAllButtonClickListener = new StopAllButtonClickListener(this);
096:
097: protected ButtonClickListener buttonClickListener = new ButtonClickListener(
098: this );
099:
100: protected PollingListener pollingListener = new PollingListener(
101: this );
102:
103: protected ComponentClickListener componentClickListener = new ComponentClickListener(
104: this );
105:
106: protected LibraryClickListener libraryClickListener = new LibraryClickListener(
107: this );
108:
109: protected void init(boolean ro) {
110: readOnly = ro;
111: createWidget();
112: setStyles();
113: }
114:
115: private void setStyles() {
116: // for (int row = 0; row < currentTable.getRowCount(); row++) {
117: // if("New".equals(alert.getFlag())){
118: // currentTable.getRowFormatter().addStyleName(row, StyleConstants.TABLE_C_STA_STYLE);
119: // } else {
120: // currentTable.getRowFormatter().removeStyleName(row, StyleConstants.TABLE_C_STO_STYLE);
121: // }
122: // }
123: }
124:
125: protected void createWidget() {
126:
127: currentTable = getCurrentTable();
128: if (!readOnly)
129: initialCurrentButtonPanel();
130: currentPanel.add(currentButtonPanel);
131: currentPanel.add(currentTable);
132:
133: currentPanel.setCellWidth(currentButtonPanel, "100%");
134: currentPanel.setCellWidth(currentTable, "100%");
135: currentPanel.setWidth("100%");
136:
137: initWidget(currentPanel);
138: initTimer();
139: }
140:
141: public void updateContent(boolean isPolling) {
142: if (isPolling)
143: pollingCurrentComponentList();
144: else
145: getCurrentComponentList();
146:
147: currentTimer.scheduleRepeating(INTERVAL);
148: }
149:
150: public void pollingCurrentComponentList() {
151: getJmxOperationAsyncFromModule().pollingCurrentComponentList(
152: pollingListener);
153: }
154:
155: public void getCurrentComponentList() {
156: getJmxOperationAsyncFromModule().getCurrentComponentList(
157: pollingListener);
158: }
159:
160: private void startComponent(String componentName) {
161: getJmxOperationAsyncFromModule().startComponent(componentName,
162: buttonClickListener);
163: }
164:
165: private void shutdownComponent(String componentName) {
166: getJmxOperationAsyncFromModule().shutdownComponent(
167: componentName, buttonClickListener);
168: }
169:
170: private void startAllComponent() {
171: getJmxOperationAsyncFromModule().startAllComponent(
172: buttonClickListener);
173: }
174:
175: private void shutdownAllComponent() {
176: getJmxOperationAsyncFromModule().shutdownAllComponent(
177: buttonClickListener);
178: }
179:
180: public void delConfirmDlg() {
181: if (confirm == null) {
182: } else {
183: confirm.delete();
184: confirm = null;
185: }
186: }
187:
188: public void continueOperation(String action, String name) {
189: if (action.startsWith(((ConsoleMessages) GWT
190: .create(ConsoleMessages.class)).UninstallComponent())) {
191: } else if (action.startsWith(((ConsoleMessages) GWT
192: .create(ConsoleMessages.class))
193: .UninstallSharedLibrary())) {
194: }
195: delConfirmDlg();
196: }
197:
198: private void setOperation(FlexTable tab, int row, int col,
199: String curState, String componentName) {
200: for (int j = 0; j < JmxComponentInfo.LifeCycleState.length; j++) {
201: ComponentsTableButton button;
202: if (curState.equals(JmxComponentInfo.LifeCycleState[1])) {
203: if (JmxComponentInfo.LifeCycleOper[j]
204: .equalsIgnoreCase(JmxComponentInfo.LifeCycleOper[1])) {
205: button = new ComponentsTableButton(this .images
206: .startUnableButton().createImage());
207: } else {
208: button = new ComponentsTableButton(this .images
209: .shutdownButton().createImage());
210: button.setTitle(((ConsoleMessages) GWT
211: .create(ConsoleMessages.class)).Shutdown());
212: }
213: } else {
214: if (JmxComponentInfo.LifeCycleOper[j]
215: .equalsIgnoreCase(JmxComponentInfo.LifeCycleOper[1])) {
216: button = new ComponentsTableButton(this .images
217: .startButton().createImage());
218: button.setTitle(((ConsoleMessages) GWT
219: .create(ConsoleMessages.class)).Start());
220: } else {
221: button = new ComponentsTableButton(this .images
222: .shutdownUnableButton().createImage());
223: }
224: }
225: button.setWidth("24px");
226: button.setHeight("24px");
227: button.setComponentName(componentName);
228: button.setOperation(JmxComponentInfo.LifeCycleOper[j]);
229:
230: button.addClickListener(buttonClickListener);
231:
232: if (curState.equals(JmxComponentInfo.LifeCycleState[j])) {
233: button.setEnabled(false);
234: }
235: tab.setWidget(row, col, button);
236: tab.getCellFormatter().setWidth(row, col, "100%");
237: col++;
238: }
239: }
240:
241: // -------------------------------------------
242: public FlexTable getCurrentTable() {
243: FlexTable orderTable = new FlexTable();
244:
245: orderTable.setWidth("100%");
246: orderTable.setStyleName(StyleConstants.TABLE_STYLE);
247: orderTable.getRowFormatter().setStyleName(0,
248: StyleConstants.TABLE_HEADER_STYLE);
249: orderTable.setText(0, 0, ((ConsoleMessages) GWT
250: .create(ConsoleMessages.class)).Updating());
251:
252: return orderTable;
253: }
254:
255: public void redrawCurrentTable(FlexTable tab) {
256: WidgetUtil.clearTable(tab);
257: tab.setWidth("100%");
258: tab.setStyleName(StyleConstants.TABLE_STYLE);
259: tab.getRowFormatter().setStyleName(0,
260: StyleConstants.TABLE_HEADER_STYLE);
261: int curRow = 0;
262: tab.setText(curRow, 0, ((ConsoleMessages) GWT
263: .create(ConsoleMessages.class)).Installed()
264: + " "
265: + ((ConsoleMessages) GWT.create(ConsoleMessages.class))
266: .Binding_Components());
267:
268: tab.setText(curRow, 1, ((ConsoleMessages) GWT
269: .create(ConsoleMessages.class)).Status());
270: if (!readOnly)
271: tab.setText(curRow, 2, ((ConsoleMessages) GWT
272: .create(ConsoleMessages.class)).Operation());
273: tab.getFlexCellFormatter().setColSpan(curRow, 2, 2);
274:
275: curRow++;
276:
277: for (int i = 0; i < bcNames.length; i++) {
278: String name = bcNames[i];
279: String state = bcStates[i];
280: Button comName = new Button(name);
281: comName.setWidth("100%");
282: comName
283: .setStyleName(StyleConstants.TABLE_COMPONENTNAME_STYLE);
284: tab.setWidget(curRow, 0, comName);
285: comName.addClickListener(componentClickListener);
286: tab.getCellFormatter().setWidth(curRow, 0, "70%");
287:
288: tab.setText(curRow, 1, state);
289: tab.getCellFormatter().setWidth(curRow, 1, "100%");
290:
291: if (!readOnly)
292: setOperation(tab, curRow, 2, state, name);
293: tab.getRowFormatter().setStyleName(curRow,
294: StyleConstants.TABLE_TD_STYLE);
295: if (state
296: .equalsIgnoreCase(JmxComponentInfo.LifeCycleState[1]))
297: tab.getCellFormatter().setStyleName(curRow, 1,
298: StyleConstants.TABLE_C_STARTED_STYLE);
299: else if (state
300: .equalsIgnoreCase(JmxComponentInfo.LifeCycleState[0]))
301: tab.getCellFormatter().setStyleName(curRow, 1,
302: StyleConstants.TABLE_C_SHUTDOWN_STYLE);
303: curRow++;
304: }
305:
306: tab.setText(curRow, 0, ((ConsoleMessages) GWT
307: .create(ConsoleMessages.class)).Installed()
308: + " "
309: + ((ConsoleMessages) GWT.create(ConsoleMessages.class))
310: .Service_Engines());
311: tab.setText(curRow, 1, ((ConsoleMessages) GWT
312: .create(ConsoleMessages.class)).Status());
313:
314: if (!readOnly)
315: tab.setText(curRow, 2, ((ConsoleMessages) GWT
316: .create(ConsoleMessages.class)).Operation());
317: tab.getFlexCellFormatter().setColSpan(curRow, 2, 2);
318: tab.getFlexCellFormatter().setVerticalAlignment(curRow, 0,
319: HasVerticalAlignment.ALIGN_MIDDLE);
320: tab.getRowFormatter().setStyleName(curRow,
321: StyleConstants.TABLE_HEADER_STYLE);
322:
323: curRow++;
324: for (int i = 0; i < seNames.length; i++) {
325: String name = seNames[i];
326: String state = seStates[i];
327: Button comName = new Button(name);
328: comName
329: .setStyleName(StyleConstants.TABLE_COMPONENTNAME_STYLE);
330: tab.setWidget(curRow, 0, comName);
331: comName.addClickListener(componentClickListener);
332: tab.getCellFormatter().setWidth(curRow, 0, "70%");
333: tab.setText(curRow, 1, state);
334: tab.getCellFormatter().setWidth(curRow, 1, "100%");
335: // Label stateLabel = new Label(state);
336: // tab.setWidget(curRow, 1, stateLabel);
337: if (!readOnly)
338: setOperation(tab, curRow, 2, state, name);
339: tab.getRowFormatter().setStyleName(curRow,
340: StyleConstants.TABLE_TD_STYLE);
341: if (state
342: .equalsIgnoreCase(JmxComponentInfo.LifeCycleState[1]))
343: tab.getCellFormatter().setStyleName(curRow, 1,
344: StyleConstants.TABLE_C_STARTED_STYLE);
345: else if (state
346: .equalsIgnoreCase(JmxComponentInfo.LifeCycleState[0]))
347: tab.getCellFormatter().setStyleName(curRow, 1,
348: StyleConstants.TABLE_C_SHUTDOWN_STYLE);
349: // tab.getRowFormatter().setStyleName(curRow, StyleConstants.TABLE_TD_STYLE);
350:
351: curRow++;
352: }
353:
354: tab.setText(curRow, 0, ((ConsoleMessages) GWT
355: .create(ConsoleMessages.class)).Installed()
356: + " "
357: + ((ConsoleMessages) GWT.create(ConsoleMessages.class))
358: .SharedLibrary());
359: tab.getFlexCellFormatter().setColSpan(curRow, 0, 6);
360: tab.getFlexCellFormatter().setVerticalAlignment(curRow, 0,
361: HasVerticalAlignment.ALIGN_MIDDLE);
362: tab.getRowFormatter().setStyleName(curRow,
363: StyleConstants.TABLE_HEADER_STYLE);
364:
365: curRow++;
366: for (int i = 0; i < slNames.length; i++) {
367: Button sln = new Button(slNames[i]);
368: sln.setStyleName(StyleConstants.TABLE_COMPONENTNAME_STYLE);
369: sln.addClickListener(libraryClickListener);
370: tab.setWidget(curRow, 0, sln);
371: tab.getFlexCellFormatter().setColSpan(curRow, 0, 6);
372: // tab.getRowFormatter().setStyleName(curRow, StyleConstants.TABLE_TD_STYLE);
373:
374: curRow++;
375: }
376: }
377:
378: private void initialCurrentButtonPanel() {
379: currentButtonPanel.add(startAll);
380: currentButtonPanel.add(shutdownAll);
381: // currentButtonPanel.add(stopAll);
382:
383: startAll.addClickListener(new ClickListener() {
384: public void onClick(Widget sender) {
385: showWaitingDialog();
386: startAllComponent();
387: }
388: });
389: shutdownAll.addClickListener(new ClickListener() {
390: public void onClick(Widget sender) {
391: showWaitingDialog();
392: shutdownAllComponent();
393: }
394: });
395: // stopAll.addClickListener(stopAllButtonClickListener);
396: refreshButton.addClickListener(buttonClickListener);
397: currentButtonPanel.add(refreshButton);
398: currentButtonPanel.setWidth("50%");
399: currentButtonPanel.setCellHorizontalAlignment(refreshButton,
400: HasHorizontalAlignment.ALIGN_RIGHT);
401: }
402:
403: class ButtonClickListener extends ConsoleCallback implements
404: ClickListener {
405:
406: public ButtonClickListener(Admin admin) {
407: super (admin);
408: }
409:
410: public void onClick(Widget sender) {
411: showWaitingDialog();
412: if (sender instanceof ComponentsTableButton) {
413: ComponentsTableButton button = (ComponentsTableButton) sender;
414: if (button.getOperation().equalsIgnoreCase(
415: JmxComponentInfo.START)) {
416: startComponent(button.getComponentName());
417: } else if (button.getOperation().equalsIgnoreCase(
418: JmxComponentInfo.SHUTDOWN)) {
419: shutdownComponent(button.getComponentName());
420: }
421: } else if (sender instanceof PushButton) {
422: PushButton button = (PushButton) sender;
423: if (button.getText().equals(
424: ((ConsoleMessages) GWT
425: .create(ConsoleMessages.class))
426: .Refresh())) {
427: getCurrentComponentList();
428: }
429: }
430: }
431:
432: public void handleSuccess(Object result) {
433: if (result instanceof JmxComponentInfo) {
434: JmxComponentInfo info = (JmxComponentInfo) result;
435:
436: bcNames = info.getBindingComponents();
437: seNames = info.getServiceEngines();
438: slNames = info.getSharedLibraries();
439: bcStates = info.getBcStates();
440: seStates = info.getSeStates();
441: // System.out.println("\nBC components: = "+ bcNames);
442: redrawCurrentTable(currentTable);
443: INTERVAL = info.getRefreshRate();
444: }
445: }
446: }
447:
448: class PollingListener extends PollingTimerCallback {
449:
450: public PollingListener(AdminWithTimer admin) {
451: super (admin);
452: }
453:
454: public void handleSuccess(Object result) {
455: if (result instanceof JmxComponentInfo) {
456: JmxComponentInfo info = (JmxComponentInfo) result;
457:
458: bcNames = info.getBindingComponents();
459: seNames = info.getServiceEngines();
460: slNames = info.getSharedLibraries();
461: bcStates = info.getBcStates();
462: seStates = info.getSeStates();
463: // System.out.println("\nBC components: = "+ bcNames);
464: redrawCurrentTable(currentTable);
465: INTERVAL = info.getRefreshRate();
466: }
467: }
468: }
469:
470: class CurrentListListener extends ConsoleCallback {
471:
472: public CurrentListListener(Admin admin) {
473: super (admin);
474: }
475:
476: public void handleSuccess(Object result) {
477: getCurrentComponentList();
478: }
479: }
480:
481: class ComponentClickListener extends ConsoleCallback implements
482: ClickListener {
483:
484: public ComponentClickListener(Admin admin) {
485: super (admin);
486: }
487:
488: public void onClick(Widget sender) {
489: getJmxOperationAsyncFromModule().getVersionInfo(
490: ((Button) sender).getText(), this );
491: }
492:
493: public void handleSuccess(Object result) {
494: if (result instanceof ConsoleVersion) {
495: ConsoleVersion consoleVersion = (ConsoleVersion) result;
496: ComponentsVersionDialog.showVertion(consoleVersion);
497: }
498: }
499: }
500:
501: class LibraryClickListener extends ConsoleCallback implements
502: ClickListener {
503:
504: public LibraryClickListener(Admin admin) {
505: super (admin);
506: }
507:
508: public void onClick(Widget sender) {
509: getJmxOperationAsyncFromModule().getCCSLVersionInfo(
510: ((Button) sender).getText(), this );
511: }
512:
513: public void handleSuccess(Object result) {
514: if (result instanceof ConsoleVersion) {
515: ConsoleVersion consoleVersion = (ConsoleVersion) result;
516: ComponentsVersionDialog.showVertion(consoleVersion);
517: }
518: }
519: }
520:
521: }
|