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: EndpointLifeCycle.java 10517 2007-12-04 04:55:41Z lzheng $
023: */
024: package com.bostechcorp.cbesb.console.client.endpoint;
025:
026: import com.bostechcorp.cbesb.console.client.Admin;
027: import com.bostechcorp.cbesb.console.client.ConsoleCallback;
028: import com.bostechcorp.cbesb.console.pub.JmxAssemblyExtObj;
029: import com.bostechcorp.cbesb.console.pub.JmxAssemblyObj;
030: import com.google.gwt.user.client.ui.ChangeListener;
031: import com.google.gwt.user.client.ui.ListBox;
032: import com.google.gwt.user.client.ui.PushButton;
033: import com.google.gwt.user.client.ui.Widget;
034:
035: abstract public class EndpointBaseOne extends EndpointBase {
036: protected ListBox saListBox = new ListBox();
037: protected PushButton retrieveButton = new PushButton();
038: protected String currentSaName = "";
039: protected JmxAssemblyObj currentAssembly;
040: protected PollingCallback pollingCallback = new PollingCallback(
041: this );
042: protected RefreshCallback refreshCallback = new RefreshCallback(
043: this );
044: SaListChangeListener saListChangeLister = new SaListChangeListener();
045:
046: protected String[] saNameList = null;
047:
048: public EndpointBaseOne() {
049: super ();
050:
051: }
052:
053: class SaListChangeListener implements ChangeListener {
054:
055: public void onChange(Widget sender) {
056: currentSaName = saListBox.getItemText(saListBox
057: .getSelectedIndex());
058: refresh();
059:
060: }
061:
062: }
063:
064: class PollingCallback extends ConsoleCallback {
065:
066: public PollingCallback(Admin admin) {
067: super (admin);
068: }
069:
070: public void handleSuccess(Object result) {
071: if (!canPolling())
072: return;
073:
074: if (result instanceof JmxAssemblyObj) {
075:
076: JmxAssemblyObj sa = (JmxAssemblyObj) result;
077: if (sa.getName().equals(currentSaName)) {
078: currentAssembly = (JmxAssemblyObj) result;
079: if (isChanged(sa))
080: drawTree();
081: polling();
082: }
083:
084: } else {
085: System.out
086: .println("unexpected callback object, expecting JmxEndpointInfo");
087: }
088: }
089: }
090:
091: protected abstract boolean isChanged(JmxAssemblyObj sa);
092:
093: class RefreshCallback extends ConsoleCallback {
094:
095: public RefreshCallback(Admin admin) {
096: super (admin);
097: }
098:
099: public void handleSuccess(Object result) {
100: if (result instanceof JmxAssemblyExtObj) {
101: JmxAssemblyExtObj info = (JmxAssemblyExtObj) result;
102:
103: saNameList = info.getSaList();
104: saListBox.removeChangeListener(saListChangeLister);
105: saListBox.clear();
106: int selIndex = 0;
107: for (int i = 0; i < saNameList.length; i++) {
108: saListBox.addItem(saNameList[i]);
109: if (currentSaName != null
110: && saNameList[i].equals(currentSaName)) {
111: selIndex = i;
112: }
113: }
114: if (saListBox.getItemCount() > 0) {
115:
116: saListBox.setItemSelected(selIndex, true);
117: currentSaName = saListBox.getItemText(saListBox
118: .getSelectedIndex());
119:
120: } else {
121: clearTree();
122: }
123: JmxAssemblyObj sa = info.getSaObj();
124:
125: if (sa != null && sa.getName().equals(currentSaName)) {
126: currentAssembly = (JmxAssemblyObj) sa;
127: drawTree();
128: saListBox.addChangeListener(saListChangeLister);
129: startPollingFlag();
130: polling();
131: }
132:
133: } else if (result instanceof JmxAssemblyObj) {
134: JmxAssemblyObj sa = (JmxAssemblyObj) result;
135:
136: if (sa.getName().equals(currentSaName)) {
137: startPollingFlag();
138: currentAssembly = sa;
139: drawTree();
140: polling();
141: }
142:
143: } else {
144: System.out
145: .println("unexpected callback object, expecting JmxEndpointInfo");
146: }
147: }
148:
149: }
150:
151: abstract protected void getAssemblyInfo();
152:
153: abstract protected void getSANameList();
154:
155: public void refresh() {
156: stopPollingFlag();
157: showWaitingDialog();
158: getAssemblyInfo();
159: }
160:
161: public void initRefresh() {
162: stopPollingFlag();
163: showWaitingDialog();
164: getSANameList();
165: }
166: }
|