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.assemblies;
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.client.components.ComponentsTableButton;
034: import com.bostechcorp.cbesb.console.common.JmxAssemblyInfo;
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.ClickListener;
039: import com.google.gwt.user.client.ui.FlexTable;
040: import com.google.gwt.user.client.ui.HasAlignment;
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.VerticalPanel;
046: import com.google.gwt.user.client.ui.Widget;
047:
048: public abstract class AssembliesDeployBase extends AdminWithTimer {
049:
050: // protected WaitingDialog WaitingDialog = new WaitingDialog();
051:
052: public static final String DEPLOY_ASSEMBLIES_TOKEN = "cbesb_deploy_assembly_";
053:
054: public static final String UNDEPLOY_ASSEMBLIES_TOKEN = "cbesb_undeploy_assembly_";
055:
056: public static final String REMOVE_ASSEMBLIES_TOKEN = "cbesb_remove_assembly_";
057:
058: public static final String PREFIX_TOKEN = "cbesb_assembly_";
059:
060: //VerticalPanel mainPanel;
061:
062: protected VerticalPanel deployPanel;
063:
064: private String[] saNames;
065:
066: private String[] undeploySANames;
067:
068: protected VerticalPanel subPanel;
069:
070: protected boolean readOnly = false;
071:
072: protected TableButtonClickListener tableButtonClickListener = new TableButtonClickListener();
073:
074: protected RefreshListener refreshListener = new RefreshListener(
075: this );
076:
077: protected PollingListener pollingListener = new PollingListener(
078: this );
079:
080: protected FlexTable deployTable;
081:
082: protected void init(boolean ro) {
083: this .readOnly = ro;
084:
085: deployPanel = new VerticalPanel();
086:
087: subPanel = getDeployTable();
088:
089: deployPanel.add(subPanel);
090: deployPanel.setCellWidth(subPanel, "100%");
091: deployPanel.setWidth("100%");
092:
093: initWidget(deployPanel);
094:
095: initTimer();
096: }
097:
098: public void updateContent(boolean isPolling) {
099: if (isPolling)
100: pollingDeployAssemblyList();
101: else
102: getDeployAssemblyList();
103: this .setINTERVAL(INTERVAL);
104: }
105:
106: private void getDeployAssemblyList() {
107: getJmxOperationAsyncFromModule().getDeployServiceAssemblyList(
108: pollingListener);
109: }
110:
111: private void pollingDeployAssemblyList() {
112: getJmxOperationAsyncFromModule()
113: .pollingDeployServiceAssemblyList(pollingListener);
114: }
115:
116: private void deployAssembly(String assemblyZipUrl) {
117: getJmxOperationAsyncFromModule().deployServiceAssembly(
118: assemblyZipUrl, refreshListener);
119: }
120:
121: private void undeployAssembly(String assemblyName) {
122: getJmxOperationAsyncFromModule().undeployServiceAssembly(
123: assemblyName, refreshListener);
124: }
125:
126: protected VerticalPanel getDeployTable() {
127:
128: deployTable = new FlexTable();
129:
130: deployTable.setWidth("100%");
131:
132: deployTable.setHTML(0, 0, ((ConsoleMessages) GWT
133: .create(ConsoleMessages.class)).Updating());
134: deployTable.getFlexCellFormatter().setColSpan(0, 0, 2);
135: deployTable.getCellFormatter().setHorizontalAlignment(0, 0,
136: HasAlignment.ALIGN_CENTER);
137:
138: final VerticalPanel verticalPanel = new VerticalPanel();
139: verticalPanel.add(deployTable);
140:
141: if (!readOnly) {
142: final HorizontalPanel horizontalPanel = new HorizontalPanel();
143: verticalPanel.add(horizontalPanel);
144:
145: final Label label = new Label(((ConsoleMessages) GWT
146: .create(ConsoleMessages.class))
147: .CONSOLE_DEPLOY_CUSTOM());
148: horizontalPanel.add(label);
149:
150: horizontalPanel.setSpacing(10);
151: horizontalPanel
152: .setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
153: verticalPanel.setCellHorizontalAlignment(horizontalPanel,
154: HasHorizontalAlignment.ALIGN_CENTER);
155:
156: FileUploadPanel upload = new FileUploadPanel(this ,
157: FileUploadPanel.ACTION_ASSEMBLY);
158: horizontalPanel.add(upload);
159: }
160: verticalPanel.setWidth("100%");
161: verticalPanel.setCellWidth(deployTable, "100%");
162: return verticalPanel;
163: }
164:
165: // public void onSuccess(Object result) {
166: // if (result instanceof JmxAssemblyInfo) {
167: // JmxAssemblyInfo info = (JmxAssemblyInfo) result;
168: // if (info.isError()) {
169: // waiting.close();
170: // MessageViewDialog.showError(info.getExceptionText(),info
171: // .getExceptionTrace());
172: //
173: // } else {
174: // switch (info.getCallType()) {
175: //
176: // case JmxAssemblyInfo.GET_DEPLOY_SERVICEASSEMBLY_LIST:
177: // saNames = info.getServiceAssemblys();
178: // undeploySANames = info.getUndeployServiceAssemblies();
179: // redrawDeployTable(deployTable);
180: //
181: // break;
182: // case JmxAssemblyInfo.GET_REMOVE_SERVICEASSEMBLY_LIST:
183: // undeploySANames = info.getUndeployServiceAssemblies();
184: //
185: // break;
186: // case JmxAssemblyInfo.DEPLOY_SERVICEASSEMBLY:
187: // case JmxAssemblyInfo.UNDEPLOY_SERVICEASSEMBLY:
188: // try {
189: // getDeployAssemblyList();
190: // } catch (Exception e) {
191: // e.printStackTrace();
192: // break;
193: // }
194: // break;
195: //
196: // case JmxAssemblyInfo.START_SERVICEASSEMBLY:
197: // case JmxAssemblyInfo.STOP_SERVICEASSEMBLY:
198: // case JmxAssemblyInfo.SHOTDOWN_SERVICEASSEMBLY:
199: //
200: // default:
201: //
202: // break;
203: // }
204: //
205: // }
206: // }
207: // waiting.close();
208: // }
209:
210: public void redrawDeployTable(FlexTable tab) {
211: WidgetUtil.clearTable(tab);
212:
213: tab.setWidth("100%");
214: tab.setStyleName(StyleConstants.TABLE_STYLE);
215: tab.getRowFormatter().setStyleName(0,
216: StyleConstants.TABLE_HEADER_STYLE);
217: int curRow = 0;
218:
219: tab.setText(curRow, 0, ((ConsoleMessages) GWT
220: .create(ConsoleMessages.class)).Deploy()
221: + " "
222: + ((ConsoleMessages) GWT.create(ConsoleMessages.class))
223: .Service_Assemblies());
224: tab.getFlexCellFormatter().setVerticalAlignment(curRow, 0,
225: HasVerticalAlignment.ALIGN_MIDDLE);
226: tab.getFlexCellFormatter().setColSpan(curRow, 0, 2);
227: curRow++;
228:
229: for (int i = 0; i < saNames.length; i++) {
230:
231: tab.setText(curRow, 0, saNames[i]);
232: if (!readOnly) {
233: ComponentsTableButton button = new ComponentsTableButton(
234: ((ConsoleMessages) GWT
235: .create(ConsoleMessages.class))
236: .Undeploy());
237: button.setOperation(JmxComponentInfo.UNDEPLOY);
238: button.setComponentName(saNames[i]);
239:
240: button.addClickListener(tableButtonClickListener);
241: tab.setWidget(curRow, 1, button);
242: } else {
243: tab.setText(curRow, 1, ((ConsoleMessages) GWT
244: .create(ConsoleMessages.class)).deployed());
245: }
246: tab.getRowFormatter().setStyleName(curRow,
247: StyleConstants.TABLE_TD_STYLE);
248:
249: curRow++;
250: }
251: for (int i = 0; i < undeploySANames.length; i++) {
252:
253: tab.setText(curRow, 0, undeploySANames[i]);
254:
255: if (!readOnly) {
256: ComponentsTableButton button = new ComponentsTableButton(
257: ((ConsoleMessages) GWT
258: .create(ConsoleMessages.class))
259: .Deploy());
260: button.setOperation(JmxComponentInfo.DEPLOY);
261: button.setComponentName(undeploySANames[i]);
262: button.addClickListener(tableButtonClickListener);
263: tab.setWidget(curRow, 1, button);
264: } else {
265: tab.setText(curRow, 1, ((ConsoleMessages) GWT
266: .create(ConsoleMessages.class)).undeployed());
267: }
268: tab.getRowFormatter().setStyleName(curRow,
269: StyleConstants.TABLE_TD_STYLE);
270:
271: curRow++;
272: }
273: }
274:
275: public void refresh() {
276: this .getDeployAssemblyList();
277: }
278:
279: class RefreshListener extends ConsoleCallback {
280:
281: public RefreshListener(Admin admin) {
282: super (admin);
283: }
284:
285: public void handleSuccess(Object result) {
286: JmxAssemblyInfo info = (JmxAssemblyInfo) result;
287:
288: saNames = info.getServiceAssemblys();
289: undeploySANames = info.getUndeployServiceAssemblies();
290: redrawDeployTable(deployTable);
291: INTERVAL = info.getRefreshRate();
292: }
293: }
294:
295: class PollingListener extends PollingTimerCallback {
296:
297: public PollingListener(AdminWithTimer admin) {
298: super (admin);
299: }
300:
301: public void handleSuccess(Object result) {
302: JmxAssemblyInfo info = (JmxAssemblyInfo) result;
303:
304: saNames = info.getServiceAssemblys();
305: undeploySANames = info.getUndeployServiceAssemblies();
306: redrawDeployTable(deployTable);
307: INTERVAL = info.getRefreshRate();
308: }
309: }
310:
311: class TableButtonClickListener implements ClickListener {
312: /*public TableButtonClickListener(Admin admin) {
313: super(admin);
314: }*/
315:
316: public void onClick(Widget sender) {
317: showWaitingDialog();
318: if (sender instanceof ComponentsTableButton) {
319: ComponentsTableButton button = (ComponentsTableButton) sender;
320: if (button.getOperation().equalsIgnoreCase(
321: JmxComponentInfo.DEPLOY)) {
322: deployAssembly(button.getComponentName());
323: } else if (button.getOperation().equalsIgnoreCase(
324: JmxComponentInfo.UNDEPLOY)) {
325: undeployAssembly(button.getComponentName());
326: }
327: }
328: }
329:
330: /*public void handleSuccess(Object result) {
331: getDeployAssemblyList();
332: JmxAssemblyInfo info = (JmxAssemblyInfo) result;
333:
334: saNames = info.getServiceAssemblys();
335: undeploySANames = info.getUndeployServiceAssemblies();
336: redrawDeployTable(deployTable);
337: INTERVAL=info.getRefreshRate();
338: }*/
339: }
340: }
|