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:
025: package com.bostechcorp.cbesb.console.client.assemblies;
026:
027: import com.bostechcorp.cbesb.console.client.Admin;
028: import com.bostechcorp.cbesb.console.client.AdminWithTimer;
029: import com.bostechcorp.cbesb.console.client.ClientUtils;
030: import com.bostechcorp.cbesb.console.client.ConsoleCallback;
031: import com.bostechcorp.cbesb.console.client.PollingTimerCallback;
032: import com.bostechcorp.cbesb.console.client.StyleConstants;
033: import com.bostechcorp.cbesb.console.client.WidgetUtil;
034: import com.bostechcorp.cbesb.console.client.components.ComponentsTableButton;
035: import com.bostechcorp.cbesb.console.client.dialogs.MessageViewDialog;
036: import com.bostechcorp.cbesb.console.common.ExceptionUtil;
037: import com.bostechcorp.cbesb.console.common.JmxAssemblyInfo;
038: import com.bostechcorp.cbesb.console.common.JmxComponentInfo;
039: import com.bostechcorp.cbesb.console.common.ServerSideException;
040: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
041: import com.google.gwt.core.client.GWT;
042: import com.google.gwt.user.client.ui.ClickListener;
043: import com.google.gwt.user.client.ui.FlexTable;
044: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
045: import com.google.gwt.user.client.ui.HasVerticalAlignment;
046: import com.google.gwt.user.client.ui.HorizontalPanel;
047: import com.google.gwt.user.client.ui.PushButton;
048: import com.google.gwt.user.client.ui.VerticalPanel;
049: import com.google.gwt.user.client.ui.Widget;
050:
051: public abstract class AssembliesCurrentBase extends AdminWithTimer {
052:
053: // protected WaitingDialog waitingDialog = new WaitingDialog();
054:
055: public static final String DEPLOY_ASSEMBLIES_TOKEN = "cbesb_deploy_assembly_";
056:
057: public static final String UNDEPLOY_ASSEMBLIES_TOKEN = "cbesb_undeploy_assembly_";
058:
059: public static final String REMOVE_ASSEMBLIES_TOKEN = "cbesb_remove_assembly_";
060:
061: public static final String PREFIX_TOKEN = "cbesb_assembly_";
062:
063: // VerticalPanel mainPanel;
064:
065: VerticalPanel currentPanel;
066:
067: private String[] saNames;
068:
069: private String[] saStates;
070:
071: private FlexTable currentTable;
072:
073: private boolean readOnly = false;
074: HorizontalPanel currentButtonPanel = new HorizontalPanel();
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: protected TableButtonClickListener tableButtonClickListener = new TableButtonClickListener();
087:
088: protected RefreshListener refreshListener = new RefreshListener(
089: this );
090:
091: protected StartAssemblyListener startAssemblyListener = new StartAssemblyListener(
092: this );
093:
094: protected PollingListener pollingListener = new PollingListener(
095: this );
096:
097: protected void init(boolean b) {
098: this .readOnly = b;
099:
100: currentPanel = new VerticalPanel();
101:
102: // currentTable = getCurrentTable();
103: // currentPanel.add(currentTable);
104: // currentPanel.setCellWidth(currentTable, "100%");
105: // currentPanel.setWidth("100%");
106: createWidget();
107: // initWidget(currentPanel);
108:
109: initTimer();
110: }
111:
112: protected void createWidget() {
113:
114: currentTable = getCurrentTable();
115: if (!readOnly)
116: initialCurrentButtonPanel();
117: currentPanel.add(currentButtonPanel);
118: currentPanel.add(currentTable);
119:
120: currentPanel.setCellWidth(currentButtonPanel, "100%");
121: currentPanel.setCellWidth(currentTable, "100%");
122: currentPanel.setWidth("100%");
123:
124: initWidget(currentPanel);
125: // initTimer();
126: }
127:
128: public void updateContent(boolean isPolling) {
129: if (isPolling)
130: pollingCurrentAssemblyList();
131: else
132: getCurrentAssemblyList();
133: this .setINTERVAL(INTERVAL);
134:
135: }
136:
137: public void getCurrentAssemblyList() {
138: getJmxOperationAsyncFromModule().getCurrentServiceAssemblyList(
139: pollingListener);
140: }
141:
142: public void pollingCurrentAssemblyList() {
143: getJmxOperationAsyncFromModule()
144: .pollingCurrentServiceAssemblyList(pollingListener);
145: }
146:
147: private void startAssembly(String assemblyName) {
148: startAssemblyListener.setAssemblyName(assemblyName);
149: getJmxOperationAsyncFromModule().startServiceAssembly(
150: assemblyName, startAssemblyListener);
151: }
152:
153: /*private void stopAssembly(String assemblyName) {
154: getJmxOperationAsyncFromModule().stopServiceAssembly(assemblyName,
155: tableButtonClickListener);
156: }*/
157:
158: private void shutdownAssembly(String assemblyName) {
159: getJmxOperationAsyncFromModule().shutdownServiceAssembly(
160: assemblyName, refreshListener);
161: }
162:
163: public FlexTable getCurrentTable() {
164: FlexTable orderTable = new FlexTable();
165: orderTable.setWidth("100%");
166: orderTable.setStyleName(StyleConstants.TABLE_STYLE);
167: orderTable.getRowFormatter().setStyleName(0,
168: StyleConstants.TABLE_HEADER_STYLE);
169:
170: return orderTable;
171: }
172:
173: private void setOperation(FlexTable tab, int row, int col,
174: String curState, String assemblyName) {
175:
176: for (int j = 0; j < JmxAssemblyInfo.LifeCycleState.length; j++) {
177: ComponentsTableButton button;
178:
179: if (curState.equals(JmxAssemblyInfo.LifeCycleState[1])) {
180: if (JmxAssemblyInfo.LifeCycleOper[j]
181: .equalsIgnoreCase(JmxAssemblyInfo.LifeCycleOper[1])) {
182: button = new ComponentsTableButton(this .images
183: .startUnableButton().createImage());
184: } else {
185: button = new ComponentsTableButton(this .images
186: .shutdownButton().createImage());
187: button.setTitle(((ConsoleMessages) GWT
188: .create(ConsoleMessages.class)).Shutdown());
189: }
190: } else {
191: if (JmxAssemblyInfo.LifeCycleOper[j]
192: .equalsIgnoreCase(JmxAssemblyInfo.LifeCycleOper[1])) {
193: button = new ComponentsTableButton(this .images
194: .startButton().createImage());
195: button.setTitle(((ConsoleMessages) GWT
196: .create(ConsoleMessages.class)).Start());
197: } else {
198: button = new ComponentsTableButton(this .images
199: .shutdownUnableButton().createImage());
200: }
201: }
202: button.setWidth("24px");
203: button.setHeight("24px");
204: button.setComponentName(assemblyName);
205: button.setOperation(JmxComponentInfo.LifeCycleOper[j]);
206:
207: button.addClickListener(tableButtonClickListener);
208:
209: if (curState.equals(JmxAssemblyInfo.LifeCycleState[j])) {
210: button.setEnabled(false);
211: }
212:
213: tab.setWidget(row, col, button);
214: tab.getCellFormatter().setWidth(row, col, "100%");
215: col++;
216: }
217: }
218:
219: public void redrawCurrentTable(FlexTable tab) {
220: WidgetUtil.clearTable(tab);
221:
222: tab.setWidth("100%");
223: tab.setStyleName(StyleConstants.TABLE_STYLE);
224: tab.getRowFormatter().setStyleName(0,
225: StyleConstants.TABLE_HEADER_STYLE);
226: int curRow = 0;
227: tab.setText(curRow, 0, ((ConsoleMessages) GWT
228: .create(ConsoleMessages.class)).Service_Assemblies());
229: tab.getFlexCellFormatter().setVerticalAlignment(curRow, 0,
230: HasVerticalAlignment.ALIGN_MIDDLE);
231:
232: tab.setText(curRow, 1, ((ConsoleMessages) GWT
233: .create(ConsoleMessages.class)).Status());
234: if (!readOnly)
235: tab.setText(curRow, 2, ((ConsoleMessages) GWT
236: .create(ConsoleMessages.class)).Operation());
237: tab.getFlexCellFormatter().setColSpan(curRow, 2, 2);
238:
239: tab.getRowFormatter().setStyleName(curRow,
240: StyleConstants.TABLE_HEADER_STYLE);
241: curRow++;
242:
243: for (int i = 0; i < saNames.length; i++) {
244: String name = saNames[i];
245: String state = saStates[i];
246: tab.setText(curRow, 0, name);
247: tab.setText(curRow, 1, state);
248: tab.getCellFormatter().setWidth(curRow, 0, "70%");
249: tab.getCellFormatter().setWidth(curRow, 1, "100%");
250: if (!readOnly)
251: setOperation(tab, curRow, 2, state, name);
252: tab.getRowFormatter().setStyleName(curRow,
253: StyleConstants.TABLE_TD_STYLE);
254: if (state
255: .equalsIgnoreCase(JmxComponentInfo.LifeCycleState[1]))
256: tab.getCellFormatter().setStyleName(curRow, 1,
257: StyleConstants.TABLE_C_STARTED_STYLE);
258: else if (state
259: .equalsIgnoreCase(JmxComponentInfo.LifeCycleState[0]))
260: tab.getCellFormatter().setStyleName(curRow, 1,
261: StyleConstants.TABLE_C_SHUTDOWN_STYLE);
262:
263: // tab.getRowFormatter().setStyleName(curRow,
264: // StyleConstants.TABLE_TD_STYLE);
265:
266: curRow++;
267: }
268: }
269:
270: private void initialCurrentButtonPanel() {
271: currentButtonPanel.add(startAll);
272: currentButtonPanel.add(shutdownAll);
273: // currentButtonPanel.add(stopAll);
274:
275: startAll.addClickListener(new ClickListener() {
276: public void onClick(Widget sender) {
277: showWaitingDialog();
278: startAllAssemblies();
279: }
280: });
281: shutdownAll.addClickListener(new ClickListener() {
282: public void onClick(Widget sender) {
283: showWaitingDialog();
284: shutdownAllAssemblies();
285: }
286: });
287: // stopAll.addClickListener(stopAllButtonClickListener);
288: refreshButton.addClickListener(new ClickListener() {
289:
290: public void onClick(Widget sender) {
291: showWaitingDialog();
292: getCurrentAssemblyList();
293:
294: }
295: });
296: currentButtonPanel.add(refreshButton);
297: currentButtonPanel.setWidth("50%");
298: currentButtonPanel.setCellHorizontalAlignment(refreshButton,
299: HasHorizontalAlignment.ALIGN_RIGHT);
300: }
301:
302: protected void startAllAssemblies() {
303: getJmxOperationAsyncFromModule().startAllServiceAssembly(
304: refreshListener);
305:
306: }
307:
308: protected void shutdownAllAssemblies() {
309: getJmxOperationAsyncFromModule().shutdownAllServiceAssembly(
310: refreshListener);
311: }
312:
313: class RefreshListener extends ConsoleCallback {
314:
315: public RefreshListener(Admin admin) {
316: super (admin);
317: }
318:
319: public void handleSuccess(Object result) {
320: if (result instanceof JmxAssemblyInfo) {
321: JmxAssemblyInfo info = (JmxAssemblyInfo) result;
322: saNames = info.getServiceAssemblys();
323: saStates = info.getSaStates();
324: redrawCurrentTable(currentTable);
325: INTERVAL = info.getRefreshRate();
326: }
327: }
328: }
329:
330: class StartAssemblyListener extends RefreshListener {
331:
332: protected String assemblyName;
333:
334: public StartAssemblyListener(Admin admin) {
335: super (admin);
336: }
337:
338: public void setAssemblyName(String assemblyName) {
339: this .assemblyName = assemblyName;
340: }
341:
342: public void handleFailure(String exceptionText,
343: String exceptionTrace) {
344: String errorText = exceptionText
345: + "\n"
346: + ((ConsoleMessages) GWT
347: .create(ConsoleMessages.class))
348: .Start_sa_error();
349:
350: MessageViewDialog.showError(errorText, exceptionTrace);
351:
352: getJmxOperationAsyncFromModule().shutdownServiceAssembly(
353: assemblyName, refreshListener);
354:
355: }
356:
357: }
358:
359: class PollingListener extends PollingTimerCallback {
360:
361: public PollingListener(AdminWithTimer admin) {
362: super (admin);
363: }
364:
365: public void handleSuccess(Object result) {
366: if (result instanceof JmxAssemblyInfo) {
367: JmxAssemblyInfo info = (JmxAssemblyInfo) result;
368:
369: saNames = info.getServiceAssemblys();
370: saStates = info.getSaStates();
371: redrawCurrentTable(currentTable);
372: INTERVAL = info.getRefreshRate();
373: }
374: }
375: }
376:
377: class TableButtonClickListener implements ClickListener {
378: /*public TableButtonClickListener(Admin admin) {
379: super(admin);
380: }*/
381:
382: public void onClick(Widget sender) {
383: // WaitingDialog.show();
384: showWaitingDialog();
385: if (sender instanceof ComponentsTableButton) {
386: ComponentsTableButton button = (ComponentsTableButton) sender;
387: if (button.getOperation().equalsIgnoreCase(
388: JmxComponentInfo.START)) {
389: startAssembly(button.getComponentName());
390: // } else if (button.getOperation().equalsIgnoreCase(
391: // JmxComponentInfo.STOP)) {
392: // stopAssembly(button.getComponentName());
393: } else if (button.getOperation().equalsIgnoreCase(
394: JmxComponentInfo.SHUTDOWN)) {
395: shutdownAssembly(button.getComponentName());
396: }
397: }
398: }
399:
400: /*public void handleSuccess(Object result) {
401: getCurrentAssemblyList();
402: }*/
403: }
404: }
|