modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestRemoteServiceStatisticsView.java
| 110 ++++++++--
1 file changed, 95 insertions(+), 15 deletions(-)
New commits:
commit af1289322da7f4173229e8920407e9002965e492
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Feb 25 12:24:56 2011 -0500
be able to export the stats as CSV text. pops up the text in a window so you can
copy-n-paste into your favorite spreadsheet software
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestRemoteServiceStatisticsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestRemoteServiceStatisticsView.java
index 4757ff4..40fae1f 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestRemoteServiceStatisticsView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/i18n/TestRemoteServiceStatisticsView.java
@@ -20,10 +20,15 @@ package org.rhq.enterprise.gui.coregui.client.test.i18n;
import java.util.List;
+import com.smartgwt.client.data.Record;
+import com.smartgwt.client.data.RecordList;
import com.smartgwt.client.data.SortSpecifier;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.SelectionStyle;
import com.smartgwt.client.types.SortDirection;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.events.CloseClickHandler;
+import com.smartgwt.client.widgets.events.CloseClientEvent;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
@@ -32,6 +37,8 @@ import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
import org.rhq.enterprise.gui.coregui.client.util.rpc.RemoteServiceStatistics;
import
org.rhq.enterprise.gui.coregui.client.util.rpc.RemoteServiceStatistics.Record.Summary;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHTMLPane;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableWindow;
/**
* A view that gives a display of statistics for all remote services executed since the
application was loaded.
@@ -40,6 +47,15 @@ import
org.rhq.enterprise.gui.coregui.client.util.rpc.RemoteServiceStatistics.Re
*/
public class TestRemoteServiceStatisticsView extends Table {
+ // these are used both as the name of the fields, titles of the headers and the
columns of the CSV output
+ private static final String FIELD_SERVICENAME = "serviceName";
+ private static final String FIELD_METHODNAME = "methodName";
+ private static final String FIELD_COUNT = "count";
+ private static final String FIELD_SLOWEST = "slowest";
+ private static final String FIELD_AVERAGE = "average";
+ private static final String FIELD_FASTEST = "fastest";
+ private static final String FIELD_STDDEV = "stddev";
+
private static final SortSpecifier[] defaultSorts = new SortSpecifier[] { new
SortSpecifier("average",
SortDirection.DESCENDING) };
@@ -49,23 +65,23 @@ public class TestRemoteServiceStatisticsView extends Table {
@Override
protected void configureTable() {
- ListGridField serviceName = new ListGridField("serviceName",
"Service Name");
- ListGridField methodName = new ListGridField("methodName", "Method
Name");
- ListGridField count = new ListGridField("count", "Count");
+ ListGridField serviceName = new ListGridField(FIELD_SERVICENAME, "Service
Name");
+ ListGridField methodName = new ListGridField(FIELD_METHODNAME, "Method
Name");
+ ListGridField count = new ListGridField(FIELD_COUNT, "Count");
count.setAlign(Alignment.CENTER);
- ListGridField slowest = new ListGridField("slowest", "Slowest
(ms)");
+ ListGridField slowest = new ListGridField(FIELD_SLOWEST, "Slowest
(ms)");
slowest.setAlign(Alignment.RIGHT);
- ListGridField average = new ListGridField("average", "Average
(ms)");
+ ListGridField average = new ListGridField(FIELD_AVERAGE, "Average
(ms)");
average.setAlign(Alignment.RIGHT);
- ListGridField fastest = new ListGridField("fastest", "Fastest
(ms)");
+ ListGridField fastest = new ListGridField(FIELD_FASTEST, "Fastest
(ms)");
fastest.setAlign(Alignment.RIGHT);
- ListGridField stddev = new ListGridField("stddev", "Std
Dev");
+ ListGridField stddev = new ListGridField(FIELD_STDDEV, "Std Dev");
stddev.setAlign(Alignment.RIGHT);
getListGrid().setFields(serviceName, methodName, count, slowest, average,
fastest, stddev);
refresh();
- addTableAction(extendLocatorId("delete"), MSG.common_button_delete(),
MSG.common_msg_areYouSure(),
+ addTableAction(extendLocatorId("deleteAll"),
MSG.common_button_delete_all(), MSG.common_msg_areYouSure(),
new AbstractTableAction(TableActionEnablement.ALWAYS) {
@Override
public void executeAction(ListGridRecord[] selection, Object actionValue)
{
@@ -81,6 +97,37 @@ public class TestRemoteServiceStatisticsView extends Table {
refresh();
}
});
+
+ addTableAction(extendLocatorId("export"), "Export To CSV",
+ new AbstractTableAction(TableActionEnablement.ALWAYS) {
+ @Override
+ public void executeAction(ListGridRecord[] selection, Object actionValue)
{
+ StringBuilder csv = new StringBuilder();
+ csv.append(FIELD_SERVICENAME).append(',') //
+ .append(FIELD_METHODNAME).append(',') //
+ .append(FIELD_COUNT).append(',') //
+ .append(FIELD_SLOWEST).append(',') //
+ .append(FIELD_AVERAGE).append(',') //
+ .append(FIELD_FASTEST).append(',') //
+ .append(FIELD_STDDEV).append('\n');
+
+ RecordList records = getListGrid().getDataAsRecordList();
+ int recordsSize = records.getLength();
+ for (int i = 0; i < recordsSize; i++) {
+ Record record = records.get(i);
+
csv.append(record.getAttribute(FIELD_SERVICENAME)).append(',') //
+
.append(record.getAttribute(FIELD_METHODNAME)).append(',') //
+ .append(record.getAttribute(FIELD_COUNT)).append(',')
//
+
.append(record.getAttribute(FIELD_SLOWEST)).append(',') //
+
.append(record.getAttribute(FIELD_AVERAGE)).append(',') //
+
.append(record.getAttribute(FIELD_FASTEST)).append(',') //
+
.append(record.getAttribute(FIELD_STDDEV)).append('\n');
+ }
+
+ new MessageWindow(extendLocatorId("csv"), "Export To
CSV", "<pre>" + csv.toString() + "</pre>")
+ .show();
+ }
+ });
}
@Override
@@ -109,14 +156,47 @@ public class TestRemoteServiceStatisticsView extends Table {
private ListGridRecord transform(Summary stat) {
ListGridRecord record = new ListGridRecord();
- record.setAttribute("serviceName", stat.serviceName);
- record.setAttribute("methodName", stat.methodName);
- record.setAttribute("count", stat.count);
- record.setAttribute("slowest", stat.slowest);
- record.setAttribute("average", stat.average);
- record.setAttribute("fastest", stat.fastest);
- record.setAttribute("stddev", stat.stddev);
+ record.setAttribute(FIELD_SERVICENAME, stat.serviceName);
+ record.setAttribute(FIELD_METHODNAME, stat.methodName);
+ record.setAttribute(FIELD_COUNT, stat.count);
+ record.setAttribute(FIELD_SLOWEST, stat.slowest);
+ record.setAttribute(FIELD_AVERAGE, stat.average);
+ record.setAttribute(FIELD_FASTEST, stat.fastest);
+ record.setAttribute(FIELD_STDDEV, stat.stddev);
return record;
}
+ class MessageWindow extends LocatableWindow {
+ public MessageWindow(String locatorId, String title, String message) {
+ super(locatorId);
+
+ LocatableHTMLPane htmlPane = new
LocatableHTMLPane(extendLocatorId("winDetailsPane"));
+ htmlPane.setMargin(10);
+ htmlPane.setDefaultWidth(500);
+ htmlPane.setDefaultHeight(400);
+ htmlPane.setContents(message);
+
+ setupWindow(title, htmlPane);
+ }
+
+ private void setupWindow(String title, Canvas item) {
+ setTitle(title);
+ setShowMinimizeButton(false);
+ setShowMaximizeButton(true);
+ setIsModal(true);
+ setShowModalMask(true);
+ setAutoSize(true);
+ setAutoCenter(true);
+ setShowResizer(true);
+ setCanDragResize(true);
+ centerInPage();
+ addCloseClickHandler(new CloseClickHandler() {
+ @Override
+ public void onCloseClick(CloseClientEvent event) {
+ markForDestroy();
+ }
+ });
+ addItem(item);
+ }
+ }
}