001: /*
002: * CoadunationAdmin: The admin frontend for coadunation.
003: * Copyright (C) 2007 - 2008 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * MXPanel.java
020: */
021:
022: // package path
023: package com.rift.coad.web.admin.client;
024:
025: // imports
026: import com.google.gwt.user.client.Window;
027: import com.google.gwt.user.client.ui.AbstractImagePrototype;
028: import com.google.gwt.user.client.ui.Composite;
029: import com.google.gwt.user.client.ui.ImageBundle;
030: import com.google.gwt.user.client.ui.ScrollPanel;
031: import com.google.gwt.user.client.ui.VerticalPanel;
032: import com.google.gwt.user.client.ui.DockPanel;
033: import com.google.gwt.user.client.ui.HTML;
034: import com.google.gwt.user.client.ui.Label;
035: import com.google.gwt.user.client.ui.ClickListener;
036: import com.google.gwt.core.client.GWT;
037: import com.google.gwt.user.client.rpc.AsyncCallback;
038: import com.google.gwt.user.client.rpc.ServiceDefTarget;
039: import com.google.gwt.user.client.ui.Widget;
040:
041: /**
042: * This panel provides a means to access and manage the mx beans.
043: *
044: * @author brett chaldecott
045: */
046: public class MXPanel extends Composite implements ObjectsListener,
047: MethodsListener, MethodListener, ClickListener {
048:
049: // private member variables
050: private DockPanel dockPanel = null;
051: private ObjectsPanel objectsPanel = null;
052: private MethodsPanel methodsPanel = null;
053: private MethodPanel methodPanel = null;
054: private ResultPanel resultPanel = null;
055: private MXManagerAsync service = null;
056: private Label help = null;
057:
058: // member variables
059: private String daemon = null;
060: private String method = null;
061:
062: /**
063: * Creates a new instance of DaemonPanel
064: */
065: public MXPanel() {
066: VerticalPanel lhs = new VerticalPanel();
067: lhs.setSpacing(2);
068: objectsPanel = new ObjectsPanel(this );
069: lhs.add(objectsPanel);
070: methodsPanel = new MethodsPanel(this );
071: lhs.add(methodsPanel);
072:
073: help = new Label("Help");
074: help.addClickListener(this );
075: help.setStyleName("click-Label");
076: help.setWidth("100%");
077: lhs.add(help);
078:
079: VerticalPanel rhs = new VerticalPanel();
080: rhs.setWidth("100%");
081: rhs.setSpacing(2);
082: methodPanel = new MethodPanel(this );
083: rhs.add(methodPanel);
084: resultPanel = new ResultPanel();
085: resultPanel.setWidth("100%");
086: rhs.add(resultPanel);
087:
088: dockPanel = new DockPanel();
089: dockPanel.setWidth("100%");
090: dockPanel.add(lhs, DockPanel.WEST);
091: dockPanel.add(rhs, DockPanel.CENTER);
092: dockPanel.setSpacing(2);
093: dockPanel.setCellWidth(rhs, "100%");
094:
095: // init the daemon manager
096: initMXManager();
097:
098: // Create an asynchronous callback to handle the result.
099: service.getMXBeans(new AsyncCallback() {
100: public void onSuccess(Object result) {
101: objectsPanel.setObjects((String[]) result);
102: }
103:
104: public void onFailure(Throwable caught) {
105: Window.alert("Failed to load the list of objects : "
106: + caught.getMessage());
107: }
108: });
109:
110: // init the widget
111: initWidget(dockPanel);
112: }
113:
114: /**
115: * init the daemon manager
116: */
117: private void initMXManager() {
118: // Create the client proxy. Note that although you are creating the
119: // service interface proper, you cast the result to the asynchronous
120: // version of
121: // the interface. The cast is always safe because the generated proxy
122: // implements the asynchronous interface automatically.
123: service = (MXManagerAsync) GWT.create(MXManager.class);
124: // Specify the URL at which our service implementation is running.
125: // Note that the target URL must reside on the same domain and port from
126: // which the host page was served.
127: //
128: ServiceDefTarget endpoint = (ServiceDefTarget) service;
129: String moduleRelativeURL = GWT.getModuleBaseURL() + "mxmanager";
130: endpoint.setServiceEntryPoint(moduleRelativeURL);
131: }
132:
133: /**
134: * This method is responsible for dealing with the entry selected events.
135: *
136: * @param key The key identifying the selected entry.
137: */
138: public void objectSelected(String key) {
139: daemon = key;
140: // Create an asynchronous callback to handle the result.
141: service.getMethods(daemon, new AsyncCallback() {
142: public void onSuccess(Object result) {
143: methodPanel.resetMethod();
144: methodsPanel.setMethods((String[]) result);
145: }
146:
147: public void onFailure(Throwable caught) {
148: Window.alert("Failed to load the list of objects :"
149: + caught.getMessage());
150: }
151: });
152: }
153:
154: /**
155: * This method deals with selected methods
156: *
157: * @param key The key identifying the selected method
158: */
159: public void methodSelected(String key) {
160: method = key;
161: // Create an asynchronous callback to handle the result.
162: service.getMethod(daemon, method, new AsyncCallback() {
163: public void onSuccess(Object result) {
164: methodPanel.setMethod((MethodDef) result);
165: }
166:
167: public void onFailure(Throwable caught) {
168: Window
169: .alert("Failed to retrieve the method information : "
170: + caught.getMessage());
171: }
172: });
173: }
174:
175: /**
176: * This method is invoked to handle a method being called.
177: *
178: * @param method The method being invoked.
179: */
180: public void methodInvoked(MethodDef method) {
181: // Create an asynchronous callback to handle the result.
182: service.invokeMethod(daemon, method, new AsyncCallback() {
183: public void onSuccess(Object result) {
184: resultPanel.setResult((String) result);
185: }
186:
187: public void onFailure(Throwable caught) {
188: Window.alert("Failed to invoke the method : "
189: + caught.getMessage());
190: }
191: });
192: }
193:
194: /**
195: * This method is responsible for displaying the help information.
196: */
197: public void onClick(Widget widget) {
198: if (help == widget) {
199: HelpDialog
200: .getInstance()
201: .setContent(
202: "The MX Admin Panel enables users to interact directly with"
203: + "<br>the deployed MX Beans. This means it is possible to"
204: + "<br>manage the beans without deploying a custom frontend."
205: + "<br>"
206: + "<br>To interact with a deployed MX Bean follow these steps."
207: + "<br>"
208: + "<br><b>Step 1:</b>"
209: + "<br>Select the bean to interact with by selecting the bean"
210: + "<br>name from the objects panel."
211: + "<br><img src='images/Objects.gif'/>"
212: + "<br>"
213: + "<br><b>Step 2:</b>"
214: + "<br>Select the method to invoke by selecting the method"
215: + "<br>name from the methods option panel."
216: + "<br><img src='images/Methods.gif'/>"
217: + "<br>"
218: + "<br><b>Step 3:</b>"
219: + "<br>Enter the parameter information need to invoke the call"
220: + "<br>and invoke the method by clicking on the invoke button."
221: + "<br><i>Note:</i> Array values can be passed as comma "
222: + "<br>delimated strings."
223: + "<br><img src='images/Method.gif'/>"
224: + "<br>"
225: + "<br><b>Step 4:</b>"
226: + "<br>View the result in the result panel. If an error occurs"
227: + "<br>a full stack trace will be printed."
228: + "<br><img src='images/Result.gif'/>");
229: //HelpDialog.getInstance().show();
230: }
231: }
232:
233: }
|