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: * DaemonPanel.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 supplies access to the daemons running in Coadunation.
043: *
044: * @author brett chaldecott
045: */
046: public class DaemonPanel 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 DaemonManagerAsync 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 DaemonPanel() {
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: initDaemonManager();
097:
098: // Create an asynchronous callback to handle the result.
099: service.getDaemons(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 initDaemonManager() {
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 = (DaemonManagerAsync) GWT.create(DaemonManager.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()
130: + "daemonmanager";
131: endpoint.setServiceEntryPoint(moduleRelativeURL);
132: }
133:
134: /**
135: * This method is responsible for dealing with the entry selected events.
136: *
137: * @param key The key identifying the selected entry.
138: */
139: public void objectSelected(String key) {
140: daemon = key;
141: // Create an asynchronous callback to handle the result.
142: service.getMethods(daemon, new AsyncCallback() {
143: public void onSuccess(Object result) {
144: methodPanel.resetMethod();
145: methodsPanel.setMethods((String[]) result);
146: }
147:
148: public void onFailure(Throwable caught) {
149: Window.alert("Failed to load the list of objects :"
150: + caught.getMessage());
151: }
152: });
153: }
154:
155: /**
156: * This method deals with selected methods
157: *
158: * @param key The key identifying the selected method
159: */
160: public void methodSelected(String key) {
161: method = key;
162: // Create an asynchronous callback to handle the result.
163: service.getMethod(daemon, method, new AsyncCallback() {
164: public void onSuccess(Object result) {
165: methodPanel.setMethod((MethodDef) result);
166: }
167:
168: public void onFailure(Throwable caught) {
169: Window
170: .alert("Failed to retrieve the method information : "
171: + caught.getMessage());
172: }
173: });
174: }
175:
176: /**
177: * This method is invoked to handle a method being called.
178: *
179: * @param method The method being invoked.
180: */
181: public void methodInvoked(MethodDef method) {
182: // Create an asynchronous callback to handle the result.
183: service.invokeMethod(daemon, method, new AsyncCallback() {
184: public void onSuccess(Object result) {
185: resultPanel.setResult((String) result);
186: }
187:
188: public void onFailure(Throwable caught) {
189: Window.alert("Failed to invoke the method : "
190: + caught.getMessage());
191: }
192: });
193: }
194:
195: /**
196: * This method is responsible for displaying the help information.
197: */
198: public void onClick(Widget widget) {
199: if (help == widget) {
200: HelpDialog
201: .getInstance()
202: .setContent(
203: "The Daemon Admin Panel enables users to interact directly "
204: + "<br>with the deployed Daemons. This means it is possible to"
205: + "<br>manage the daemons without deploying a custom frontend."
206: + "<br>"
207: + "<br>To interact with a deployed daemon follow these steps."
208: + "<br>"
209: + "<br><b>Step 1:</b>"
210: + "<br>Select the daemon to interact with by selecting the "
211: + "<br>name from the objects panel."
212: + "<br><img src='images/Objects.gif'/>"
213: + "<br>"
214: + "<br><b>Step 2:</b>"
215: + "<br>Select the method to invoke by selecting the method"
216: + "<br>name from the methods option panel."
217: + "<br><img src='images/Methods.gif'/>"
218: + "<br>"
219: + "<br><b>Step 3:</b>"
220: + "<br>Enter the parameter information need to invoke the call"
221: + "<br>and invoke the method by clicking on the invoke button."
222: + "<br><i>Note:</i> Array values can be passed as comma "
223: + "<br>delimated strings."
224: + "<br><img src='images/Method.gif'/>"
225: + "<br>"
226: + "<br><b>Step 4:</b>"
227: + "<br>View the result in the result panel. If an error occurs"
228: + "<br>a full stack trace will be printed."
229: + "<br><img src='images/Result.gif'/>");
230: //HelpDialog.getInstance().show();
231: }
232: }
233: }
|