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.FileUploadPanel;
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.common.JmxComponentInfo;
034: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
035: import com.google.gwt.core.client.GWT;
036: import com.google.gwt.user.client.ui.ClickListener;
037: import com.google.gwt.user.client.ui.FlexTable;
038: import com.google.gwt.user.client.ui.HasAlignment;
039: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
040: import com.google.gwt.user.client.ui.HasVerticalAlignment;
041: import com.google.gwt.user.client.ui.HorizontalPanel;
042: import com.google.gwt.user.client.ui.Label;
043: import com.google.gwt.user.client.ui.PushButton;
044: import com.google.gwt.user.client.ui.VerticalPanel;
045: import com.google.gwt.user.client.ui.Widget;
046:
047: public abstract class ComponentsInstallBase extends AdminWithTimer {
048:
049: // private WaitingDialog WaitingDialog = new WaitingDialog();
050:
051: public static final String REMOVE_COMPONENT_TOKEN = "cbesb_remove_bc_";
052:
053: public static final String REMOVE_SHAREDLIBRARY_TOKEN = "cbesb_remove_sl_";
054:
055: public static final String INSTALL_COMPONENT_TOKEN = "cbesb_install_bc_";
056:
057: public static final String INSTALL_SHAREDLIBRARY_TOKEN = "cbesb_install_sl_";
058:
059: public static final String UNINSTALL_COMPONENT_TOKEN = "cbesb_uninstall_bc_";
060:
061: public static final String UNINSTALL_SHAREDLIBRARY_TOKEN = "cbesb_uninstall_sl_";
062:
063: public static final String PREFIX_TOKEN = "cbesb_component_";
064:
065: VerticalPanel currentPanel;
066:
067: HorizontalPanel currentButtonPanel;
068:
069: private static final String DELIMITER = "#";
070:
071: private String[] bcNames;
072:
073: private String[] seNames;
074:
075: private String[] slNames;
076:
077: private String[] uninstallBCNames;
078:
079: private String[] uninstallSENames;
080:
081: private String[] uninstallSLNames;
082:
083: private FlexTable installTable;
084:
085: boolean installCCSL = false;
086:
087: final PushButton installAll = new PushButton(((ConsoleMessages) GWT
088: .create(ConsoleMessages.class)).InstallAll());
089:
090: final PushButton uninstallAll = new PushButton(
091: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
092: .UninstallAll());
093:
094: //HorizontalPanel mainPanel = new HorizontalPanel();
095:
096: VerticalPanel installPanel = new VerticalPanel();
097:
098: HorizontalPanel installButtonPanel = new HorizontalPanel();
099:
100: private PushButton refreshButton = new PushButton(
101: ((ConsoleMessages) GWT.create(ConsoleMessages.class))
102: .Refresh());
103:
104: protected boolean readOnly = false;
105:
106: // protected InstallAllButtonClickListener installAllButtonClickListener = new InstallAllButtonClickListener(this);
107:
108: // protected UninstallAllButtonClickListener uninstallAllButtonClickListener = new UninstallAllButtonClickListener(this);
109:
110: protected PollingListener pollingListener = new PollingListener(
111: this );
112:
113: protected ButtonClickListener buttonClickListener = new ButtonClickListener(
114: this );
115:
116: protected void init(boolean ro) {
117: readOnly = ro;
118: VerticalPanel subPanel = getInstallPanel();
119: if (!readOnly)
120: initialInstallButtonPanel();
121: installPanel.add(installButtonPanel);
122: installPanel.add(subPanel);
123:
124: installPanel.setCellWidth(installButtonPanel, "100%");
125: installPanel.setCellWidth(installTable, "100%");
126: installPanel.setWidth("100%");
127:
128: initWidget(installPanel);
129:
130: initTimer();
131: }
132:
133: public void updateContent(boolean isPolling) {
134: if (isPolling)
135: pollingInstallComponentList();
136: else
137: getInstallComponentList();
138: currentTimer.scheduleRepeating(INTERVAL);
139: }
140:
141: private void initialInstallButtonPanel() {
142:
143: installButtonPanel.add(installAll);
144: installButtonPanel.add(uninstallAll);
145: installAll.addClickListener(new ClickListener() {
146: public void onClick(Widget sender) {
147: showWaitingDialog();
148: installAllComponents();
149: }
150: });
151: uninstallAll.addClickListener(new ClickListener() {
152: public void onClick(Widget sender) {
153: showWaitingDialog();
154: uninstallAllComponents();
155: }
156: });
157:
158: refreshButton.addClickListener(buttonClickListener);
159: installButtonPanel.add(refreshButton);
160: installButtonPanel.setWidth("50%");
161: installButtonPanel.setCellHorizontalAlignment(refreshButton,
162: HasHorizontalAlignment.ALIGN_RIGHT);
163: }
164:
165: private void getInstallComponentList() {
166: showWaitingDialog();
167: getJmxOperationAsyncFromModule().getInstallComponentList(
168: pollingListener);
169: }
170:
171: private void pollingInstallComponentList() {
172: getJmxOperationAsyncFromModule().pollingInstallComponentList(
173: pollingListener);
174: }
175:
176: private void installComponent(String componentName, String jarName) {
177: getJmxOperationAsyncFromModule().installComponent(
178: componentName, jarName, buttonClickListener);
179: }
180:
181: private void installSharedLibrary(String libName, String jarName) {
182: getJmxOperationAsyncFromModule().installSharedLibrary(libName,
183: jarName, buttonClickListener);
184: }
185:
186: private void uninstallComponent(String componentName) {
187: getJmxOperationAsyncFromModule().uninstallComponent(
188: componentName, buttonClickListener);
189: }
190:
191: private void uninstallSharedLibrary(String libName) {
192: getJmxOperationAsyncFromModule().uninstallSharedLibrary(
193: libName, buttonClickListener);
194: }
195:
196: private void installAllComponents() {
197: getJmxOperationAsyncFromModule().installAllComponents(
198: buttonClickListener);
199: }
200:
201: private void uninstallAllComponents() {
202: getJmxOperationAsyncFromModule().uninstallAllComponents(
203: buttonClickListener);
204: }
205:
206: /*public void continueOperation(String action, String name) {
207: if (action.startsWith(((ConsoleMessages) GWT
208: .create(ConsoleMessages.class)).UninstallComponent())) {
209: this.uninstallComponent(name);
210: } else if (action.startsWith(((ConsoleMessages) GWT
211: .create(ConsoleMessages.class)).UninstallSharedLibrary())) {
212: this.uninstallSharedLibrary(name);
213: }
214:
215: }*/
216:
217: private VerticalPanel getInstallPanel() {
218: installTable = new FlexTable();
219: installTable.setWidth("100%");
220: installTable.setHTML(0, 0, ((ConsoleMessages) GWT
221: .create(ConsoleMessages.class)).Updating());
222: installTable.getFlexCellFormatter().setColSpan(0, 0, 3);
223: installTable.getCellFormatter().setHorizontalAlignment(0, 0,
224: HasAlignment.ALIGN_CENTER);
225:
226: final VerticalPanel verticalPanel = new VerticalPanel();
227: verticalPanel.add(installTable);
228:
229: /*final HTML html = new HTML("<hr/>");
230: verticalPanel.add(html);*/
231: verticalPanel.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT);
232: if (!readOnly) {
233: final HorizontalPanel horizontalPanel = new HorizontalPanel();
234: //horizontalPanel.setWidth("100%");
235: verticalPanel.add(horizontalPanel);
236: horizontalPanel
237: .setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
238: //horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
239: final Label label = new Label(((ConsoleMessages) GWT
240: .create(ConsoleMessages.class)).InstallCustom());
241: horizontalPanel.add(label);
242: horizontalPanel.setSpacing(10);
243: verticalPanel.setCellHorizontalAlignment(horizontalPanel,
244: HasHorizontalAlignment.ALIGN_CENTER);
245: FileUploadPanel upload = new FileUploadPanel(this ,
246: FileUploadPanel.ACTION_COMPONENT);
247: horizontalPanel.add(upload);
248: }
249: verticalPanel.setCellWidth(installTable, "100%");
250: verticalPanel.setWidth("100%");
251: return verticalPanel;
252: }
253:
254: public void redrawInstallTable(FlexTable tab) {
255: WidgetUtil.clearTable(tab);
256:
257: tab.setWidth("100%");
258: tab.setStyleName(StyleConstants.TABLE_STYLE);
259: int curRow = 0;
260:
261: tab.setText(curRow, 0, ((ConsoleMessages) GWT
262: .create(ConsoleMessages.class)).Binding_Components());
263: tab.getFlexCellFormatter().setVerticalAlignment(curRow, 0,
264: HasVerticalAlignment.ALIGN_MIDDLE);
265: tab.getFlexCellFormatter().setColSpan(curRow, 0, 3);
266: tab.getRowFormatter().setStyleName(curRow,
267: StyleConstants.TABLE_HEADER_STYLE);
268:
269: curRow++;
270:
271: String name[];
272: for (int i = 0; i < bcNames.length; i++) {
273: name = bcNames[i].split("#");// name#compoentname.jar
274:
275: tab.setText(curRow, 0, name[0]);
276: if (!readOnly) {
277: ComponentsTableButton button = new ComponentsTableButton(
278: ((ConsoleMessages) GWT
279: .create(ConsoleMessages.class))
280: .Install());
281: button.setOperation(JmxComponentInfo.INSTALL);
282: button.setComponentName(name[0]);
283: button.setJarName(name[1]);
284: button.addClickListener(buttonClickListener);
285: tab.setWidget(curRow, 1, button);
286: } else {
287: tab.setText(curRow, 1, ((ConsoleMessages) GWT
288: .create(ConsoleMessages.class)).unInstalled());
289:
290: }
291: tab.getRowFormatter().setStyleName(curRow,
292: StyleConstants.TABLE_TD_STYLE);
293:
294: curRow++;
295: }
296:
297: for (int i = 0; i < uninstallBCNames.length; i++) {
298:
299: tab.setText(curRow, 0, uninstallBCNames[i]);
300:
301: if (!readOnly) {
302: ComponentsTableButton button = new ComponentsTableButton(
303: ((ConsoleMessages) GWT
304: .create(ConsoleMessages.class))
305: .Uninstall());
306: button.setOperation(JmxComponentInfo.UNINSTALL);
307: button.setComponentName(uninstallBCNames[i]);
308: button.addClickListener(buttonClickListener);
309: tab.setWidget(curRow, 1, button);
310: } else {
311: tab.setText(curRow, 1, ((ConsoleMessages) GWT
312: .create(ConsoleMessages.class)).Installed());
313: }
314:
315: tab.getRowFormatter().setStyleName(curRow,
316: StyleConstants.TABLE_TD_STYLE);
317:
318: curRow++;
319: }
320:
321: tab.setText(curRow, 0, ((ConsoleMessages) GWT
322: .create(ConsoleMessages.class)).Service_Engines());
323: tab.getFlexCellFormatter().setColSpan(curRow, 0, 3);
324:
325: tab.getRowFormatter().setStyleName(curRow,
326: StyleConstants.TABLE_HEADER_STYLE);
327:
328: curRow++;
329:
330: for (int i = 0; i < seNames.length; i++) {
331: name = seNames[i].split(DELIMITER);// name#compoentname.jar
332:
333: tab.setText(curRow, 0, name[0]);
334: if (!readOnly) {
335: ComponentsTableButton button = new ComponentsTableButton(
336: ((ConsoleMessages) GWT
337: .create(ConsoleMessages.class))
338: .Install());
339: button.setOperation(JmxComponentInfo.INSTALL);
340: button.setComponentName(name[0]);
341: button.setJarName(name[1]);
342: button.addClickListener(buttonClickListener);
343: tab.setWidget(curRow, 1, button);
344: } else {
345: tab.setText(curRow, 1, ((ConsoleMessages) GWT
346: .create(ConsoleMessages.class)).unInstalled());
347: }
348: tab.getRowFormatter().setStyleName(curRow,
349: StyleConstants.TABLE_TD_STYLE);
350:
351: curRow++;
352: }
353: for (int i = 0; i < uninstallSENames.length; i++) {
354:
355: tab.setText(curRow, 0, uninstallSENames[i]);
356:
357: if (!readOnly) {
358: ComponentsTableButton button = new ComponentsTableButton(
359: ((ConsoleMessages) GWT
360: .create(ConsoleMessages.class))
361: .Uninstall());
362: button.setOperation(JmxComponentInfo.UNINSTALL);
363: button.setComponentName(uninstallSENames[i]);
364: button.addClickListener(buttonClickListener);
365: tab.setWidget(curRow, 1, button);
366: } else {
367: tab.setText(curRow, 1, ((ConsoleMessages) GWT
368: .create(ConsoleMessages.class)).Installed());
369:
370: }
371: tab.getRowFormatter().setStyleName(curRow,
372: StyleConstants.TABLE_TD_STYLE);
373:
374: curRow++;
375: }
376:
377: Label shared_lib_cat = new Label(((ConsoleMessages) GWT
378: .create(ConsoleMessages.class)).SharedLibrary());
379:
380: tab.setWidget(curRow, 0, shared_lib_cat);
381: tab.getFlexCellFormatter().setColSpan(curRow, 0, 3);
382: tab.getFlexCellFormatter().setVerticalAlignment(curRow, 0,
383: HasVerticalAlignment.ALIGN_MIDDLE);
384: tab.getRowFormatter().setStyleName(curRow,
385: StyleConstants.TABLE_HEADER_STYLE);
386:
387: curRow++;
388:
389: for (int i = 0; i < slNames.length; i++) {
390: name = slNames[i].split(DELIMITER);// name#compoentname.jar
391:
392: tab.setText(curRow, 0, name[0]);
393:
394: installCCSL = false;
395: if (!readOnly) {
396: SharedLibraryTableButton button = new SharedLibraryTableButton(
397: ((ConsoleMessages) GWT
398: .create(ConsoleMessages.class))
399: .Install());
400: button.setOperation(JmxComponentInfo.INSTALL);
401: button.setSharedLibraryName(name[0]);
402: button.setJarName(name[1]);
403: button.addClickListener(buttonClickListener);
404: tab.setWidget(curRow, 1, button);
405: } else {
406: tab.setText(curRow, 1, ((ConsoleMessages) GWT
407: .create(ConsoleMessages.class)).unInstalled());
408: }
409: tab.getRowFormatter().setStyleName(curRow,
410: StyleConstants.TABLE_TD_STYLE);
411:
412: curRow++;
413: }
414: for (int i = 0; i < uninstallSLNames.length; i++) {
415:
416: Label libName = new Label(uninstallSLNames[i]);
417: tab.setWidget(curRow, 0, libName);
418: //Label jarName = new Label("");
419: //tab.setWidget(curRow, 1, jarName);// jarName
420: installCCSL = true;
421: if (!readOnly) {
422: SharedLibraryTableButton button = new SharedLibraryTableButton(
423: ((ConsoleMessages) GWT
424: .create(ConsoleMessages.class))
425: .Uninstall());
426: button.setOperation(JmxComponentInfo.UNINSTALL);
427: button.setSharedLibraryName(uninstallSLNames[i]);
428: button.addClickListener(buttonClickListener);
429: tab.setWidget(curRow, 1, button);
430: } else {
431: tab.setText(curRow, 1, ((ConsoleMessages) GWT
432: .create(ConsoleMessages.class)).Installed());
433: }
434: tab.getRowFormatter().setStyleName(curRow,
435: StyleConstants.TABLE_TD_STYLE);
436:
437: curRow++;
438: }
439: }
440:
441: public void refresh() {
442: getInstallComponentList();
443: }
444:
445: class ButtonClickListener extends ConsoleCallback implements
446: ClickListener {
447:
448: public ButtonClickListener(Admin admin) {
449: super (admin);
450: }
451:
452: public void onClick(Widget sender) {
453: showWaitingDialog();
454: if (sender instanceof ComponentsTableButton) {
455: ComponentsTableButton button = (ComponentsTableButton) sender;
456: if (button.getOperation().equalsIgnoreCase(
457: JmxComponentInfo.INSTALL)) {
458: installComponent(button.getComponentName(), button
459: .getJarName());
460: } else if (button.getOperation().equalsIgnoreCase(
461: JmxComponentInfo.UNINSTALL)) {
462: uninstallComponent(button.getComponentName());
463: }
464: } else if (sender instanceof SharedLibraryTableButton) {
465: SharedLibraryTableButton button = (SharedLibraryTableButton) sender;
466: if (button.getOperation().equalsIgnoreCase(
467: JmxComponentInfo.INSTALL)) {
468: installSharedLibrary(button.getSharedLibraryName(),
469: button.getJarName());
470: } else if (button.getOperation().equalsIgnoreCase(
471: JmxComponentInfo.UNINSTALL)) {
472: uninstallSharedLibrary(button
473: .getSharedLibraryName());
474: }
475: } else if (sender instanceof PushButton) {
476: PushButton button = (PushButton) sender;
477: if (button.getText().equals(
478: ((ConsoleMessages) GWT
479: .create(ConsoleMessages.class))
480: .Refresh())) {
481: getInstallComponentList();
482: }
483: }
484: }
485:
486: public void handleSuccess(Object result) {
487: if (result instanceof JmxComponentInfo) {
488: JmxComponentInfo info = (JmxComponentInfo) result;
489:
490: bcNames = info.getBindingComponents();
491: seNames = info.getServiceEngines();
492: slNames = info.getSharedLibraries();
493:
494: uninstallBCNames = info.getUninstallBC();
495: uninstallSENames = info.getUninstallSE();
496: uninstallSLNames = info.getUninstallSL();
497:
498: redrawInstallTable(installTable);
499: INTERVAL = info.getRefreshRate();
500: }
501: }
502: }
503:
504: class PollingListener extends PollingTimerCallback {
505:
506: public PollingListener(AdminWithTimer admin) {
507: super (admin);
508: }
509:
510: public void handleSuccess(Object result) {
511: if (result instanceof JmxComponentInfo) {
512: JmxComponentInfo info = (JmxComponentInfo) result;
513:
514: bcNames = info.getBindingComponents();
515: seNames = info.getServiceEngines();
516: slNames = info.getSharedLibraries();
517:
518: uninstallBCNames = info.getUninstallBC();
519: uninstallSENames = info.getUninstallSE();
520: uninstallSLNames = info.getUninstallSL();
521:
522: redrawInstallTable(installTable);
523: INTERVAL = info.getRefreshRate();
524: }
525: }
526: }
527:
528: }
|