Have embedded spreadsheets follow the passive view design pattern
Signed-off-by: James Ren <[email protected]>
--- autotest/frontend/client/src/autotest/EmbeddedSpreadsheetClient.gwt.xml
2010-06-09 14:29:53.000000000 -0700
+++ autotest/frontend/client/src/autotest/EmbeddedSpreadsheetClient.gwt.xml
2010-06-09 14:29:53.000000000 -0700
@@ -5,7 +5,7 @@
<source path="tko"/>
<source path="common"/>
- <entry-point class='autotest.tko.EmbeddedSpreadsheetClient'/>
+ <entry-point
class='autotest.tko.embedded_spreadsheet.EmbeddedSpreadsheetClient'/>
<stylesheet src='common.css'/>
<stylesheet src='standard.css'/>
==== (deleted)
//depot/google_vendor_src_branch/autotest/frontend/client/src/autotest/tko/EmbeddedSpreadsheetClient.java
====
--- autotest/frontend/client/src/autotest/tko/EmbeddedSpreadsheetClient.java
2010-06-09 11:05:26.000000000 -0700
+++ /dev/null 2009-12-17 12:29:38.000000000 -0800
@@ -1,172 +0,0 @@
-package autotest.tko;
-
-import autotest.common.JsonRpcCallback;
-import autotest.common.JsonRpcProxy;
-import autotest.common.spreadsheet.Spreadsheet;
-import autotest.common.spreadsheet.Spreadsheet.CellInfo;
-import autotest.common.spreadsheet.Spreadsheet.SpreadsheetListener;
-import autotest.tko.TkoSpreadsheetUtils.DrilldownType;
-
-import com.google.gwt.core.client.EntryPoint;
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.http.client.URL;
-import com.google.gwt.json.client.JSONNumber;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONValue;
-import com.google.gwt.user.client.Command;
-import com.google.gwt.user.client.Window;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.RootPanel;
-
-import java.util.Collections;
-import java.util.List;
-
-public class EmbeddedSpreadsheetClient implements EntryPoint,
SpreadsheetListener {
- private static class SimpleHeaderField extends HeaderField {
- protected SimpleHeaderField(String name) {
- super(name, name);
- }
-
- @Override
- public String getSqlCondition(String value) {
- return getSimpleSqlCondition(name, value);
- }
- }
-
- public static final String ROW_HEADER = "hostname";
- public static final String COLUMN_HEADER = "test_name";
- private static final String NO_RESULTS = "There are no results for this
query (yet?)";
-
- public static final String DRILLDOWN_ROW_HEADER = "job_tag";
- public static final String DRILLDOWN_COLUMN_HEADER = "subdir";
-
- private Label noResults = new Label(NO_RESULTS);
- private Spreadsheet spreadsheet = new Spreadsheet();
- private SpreadsheetDataProcessor spreadsheetProcessor =
- new SpreadsheetDataProcessor(spreadsheet);
- private List<HeaderField> rowHeader =
- Collections.singletonList((HeaderField) new
SimpleHeaderField(ROW_HEADER));
- private List<HeaderField> columnHeader =
- Collections.singletonList((HeaderField) new
SimpleHeaderField(COLUMN_HEADER));
-
- private String afeJobIdStr;
- private JSONObject condition;
-
- @Override
- public void onModuleLoad() {
- JsonRpcProxy.setDefaultBaseUrl(JsonRpcProxy.TKO_BASE_URL);
- afeJobIdStr = Window.Location.getParameter("afe_job_id");
- checkAndRender();
- }
-
- private void checkAndRender() {
- condition = getFilterCondition(afeJobIdStr);
- if (condition == null) {
- showNoResults();
- }
-
- JsonRpcProxy.getProxy().rpcCall("get_num_test_views", condition, new
JsonRpcCallback() {
- @Override
- public void onSuccess(JSONValue result) {
- if (result.isNumber().doubleValue() != 0) {
- renderSpreadsheet(condition);
- } else {
- showNoResults();
- }
- }
- });
- }
-
- private JSONObject getFilterCondition(String afeJobIdStr) {
- if (afeJobIdStr == null) {
- return null;
- }
-
- int afeJobId;
- try {
- afeJobId = Integer.parseInt(afeJobIdStr);
- } catch (NumberFormatException e) {
- return null;
- }
-
- JSONObject condition = new JSONObject();
- condition.put("afe_job_id", new JSONNumber(afeJobId));
- return condition;
- }
-
- private void showNoResults() {
- RootPanel.get().add(noResults);
- notifyParent(noResults.getElement());
- }
-
- private void renderSpreadsheet(JSONObject condition) {
-
spreadsheetProcessor.setDataSource(TestGroupDataSource.getStatusCountDataSource());
- spreadsheetProcessor.setHeaders(rowHeader, columnHeader, new
JSONObject());
-
- spreadsheet.setListener(this);
- RootPanel.get().add(spreadsheet);
- spreadsheetProcessor.refresh(condition, new Command() {
- public void execute() {
- notifyParent(spreadsheet.getElement());
- }
- });
- }
-
- private void notifyParent(Element elem) {
- notifyParent(elem.getClientWidth(), elem.getClientHeight());
- }
-
- private native void notifyParent(int width, int height) /*-{
- $wnd.parent.postMessage(width + 'px ' + height + 'px', '*');
- }-*/;
-
- @Override
- public void onCellClicked(CellInfo cellInfo, boolean isRightClick) {
- TestSet testSet = TkoSpreadsheetUtils.getTestSet(
- cellInfo, condition, rowHeader, columnHeader);
-
- if (testSet.isSingleTest()) {
- openTestDetailView(testSet.getTestIndex());
- } else {
- openSpreadsheetView(testSet.getPartialSqlCondition(),
- TkoSpreadsheetUtils.getDrilldownType(cellInfo));
- }
- }
-
- private void openTestDetailView(int testIdx) {
- openUrl("/new_tko/#tab_id=test_detail_view&object_id=" + testIdx);
- }
-
- private void openSpreadsheetView(String extraCondition, DrilldownType
drilldownType) {
- String drilldownPath;
-
- switch (drilldownType) {
- case DRILLDOWN_ROW:
- drilldownPath = generatePath(DRILLDOWN_ROW_HEADER, COLUMN_HEADER,
extraCondition);
- break;
- case DRILLDOWN_COLUMN:
- drilldownPath = generatePath(ROW_HEADER, DRILLDOWN_COLUMN_HEADER,
extraCondition);
- break;
- case DRILLDOWN_BOTH:
- drilldownPath = generatePath(
- DRILLDOWN_ROW_HEADER, DRILLDOWN_COLUMN_HEADER,
extraCondition);
- break;
- default:
- throw new UnsupportedOperationException(
- "DrilldownType " + drilldownType + " not supported");
- }
-
- openUrl(drilldownPath);
- }
-
- private String generatePath(String rowHeader, String columnHeader, String
extraCondition) {
- String condition = "afe_job_id = " + afeJobIdStr + " AND " +
extraCondition;
-
- return "/new_tko/#tab_id=spreadsheet_view&row=" + rowHeader +
"&column=" + columnHeader +
- "&condition=" + URL.encodeComponent(condition, true) +
"&show_incomplete=true";
- }
-
- private void openUrl(String url) {
- Window.open(url, "_blank", null);
- }
-}
--- autotest/frontend/client/src/autotest/tko/HeaderField.java 2010-06-09
14:29:53.000000000 -0700
+++ autotest/frontend/client/src/autotest/tko/HeaderField.java 2010-06-09
14:29:53.000000000 -0700
@@ -11,15 +11,15 @@
* * sort by this field in table view,
* * group by this field in spreadsheet or table view, and
* * filter on this field in the SQL condition.
- * It's assumed that the name returned by getSqlName() is a field returned by
the server which may
- * also be used for grouping and sorting. Filtering, however, is done
separately (through
- * getSqlCondition()), so HeaderFields may generate arbitrary SQL to perform
filtering.
+ * It's assumed that the name returned by getSqlName() is a field returned by
the server which may
+ * also be used for grouping and sorting. Filtering, however, is done
separately (through
+ * getSqlCondition()), so HeaderFields may generate arbitrary SQL to perform
filtering.
* HeaderFields may also add arbitrary query arguments to support themselves.
- *
- * While the set of HeaderFields active in the application may change at
runtime, HeaderField
+ *
+ * While the set of HeaderFields active in the application may change at
runtime, HeaderField
* objects themselves are immutable.
*/
-abstract class HeaderField implements Comparable<HeaderField> {
+public abstract class HeaderField implements Comparable<HeaderField> {
protected String name;
protected String sqlName;
@@ -31,7 +31,7 @@
this.name = name;
this.sqlName = sqlName;
}
-
+
public int compareTo(HeaderField other) {
return name.compareTo(other.name);
}
@@ -65,7 +65,7 @@
public String getSqlName() {
return sqlName;
}
-
+
/**
* Get a quoted version of getSqlName() safe for use directly in SQL.
*/
@@ -89,7 +89,7 @@
public boolean isUserSelectable() {
return true;
}
-
+
/**
* @return a MultiListSelectPresenter.Item for this HeaderField.
*/
--- autotest/frontend/client/src/autotest/tko/TestGroupDataSource.java
2010-06-09 14:29:53.000000000 -0700
+++ autotest/frontend/client/src/autotest/tko/TestGroupDataSource.java
2010-06-09 14:29:53.000000000 -0700
@@ -13,7 +13,7 @@
import java.util.Arrays;
import java.util.List;
-class TestGroupDataSource extends RpcDataSource {
+public class TestGroupDataSource extends RpcDataSource {
private static final String NUM_GROUPS_RPC = "get_num_groups";
private static final String GROUP_COUNTS_RPC = "get_group_counts";
private static final String STATUS_COUNTS_RPC = "get_status_counts";
--- autotest/frontend/client/src/autotest/tko/TestSet.java 2010-06-09
14:29:53.000000000 -0700
+++ autotest/frontend/client/src/autotest/tko/TestSet.java 2010-06-09
14:29:53.000000000 -0700
@@ -3,7 +3,7 @@
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
-abstract class TestSet {
+public abstract class TestSet {
/**
* Get the full condition args for this test set.
*/
@@ -14,10 +14,10 @@
public abstract String getPartialSqlCondition();
public abstract boolean isSingleTest();
public abstract int getTestIndex();
-
+
public JSONObject getCondition() {
JSONObject condition = getInitialCondition();
- String sqlCondition = TkoUtils.getSqlCondition(condition);
+ String sqlCondition = TkoUtils.getSqlCondition(condition);
sqlCondition = TkoUtils.joinWithParens(" AND ", sqlCondition,
getPartialSqlCondition());
condition.put("extra_where", new JSONString(sqlCondition));
return condition;
--- /dev/null 2009-12-17 12:29:38.000000000 -0800
+++
autotest/frontend/client/src/autotest/tko/embedded_spreadsheet/EmbeddedSpreadsheetClient.java
2010-06-09 14:29:53.000000000 -0700
@@ -0,0 +1,17 @@
+package autotest.tko.embedded_spreadsheet;
+
+import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.RootPanel;
+
+public class EmbeddedSpreadsheetClient implements EntryPoint {
+ private EmbeddedSpreadsheetPresenter presenter = new
EmbeddedSpreadsheetPresenter();
+ private EmbeddedSpreadsheetDisplay display = new
EmbeddedSpreadsheetDisplay();
+
+ @Override
+ public void onModuleLoad() {
+ presenter.bindDisplay(display);
+ presenter.initialize(Window.Location.getParameter("afe_job_id"));
+ RootPanel.get().add(display);
+ }
+}
--- /dev/null 2009-12-17 12:29:38.000000000 -0800
+++
autotest/frontend/client/src/autotest/tko/embedded_spreadsheet/EmbeddedSpreadsheetDisplay.java
2010-06-09 14:29:53.000000000 -0700
@@ -0,0 +1,59 @@
+package autotest.tko.embedded_spreadsheet;
+
+import autotest.common.spreadsheet.Spreadsheet;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.ui.SimplePanel;
+import com.google.gwt.user.client.ui.Widget;
+
+public class EmbeddedSpreadsheetDisplay extends Composite
+ implements EmbeddedSpreadsheetPresenter.Display {
+ private static final String NO_RESULTS = "There are no results for this
query (yet?)";
+
+ private Panel panel = new SimplePanel();
+ private Spreadsheet spreadsheet = new Spreadsheet();
+ private Label noResults = new Label(NO_RESULTS);
+
+ public EmbeddedSpreadsheetDisplay() {
+ initWidget(panel);
+ }
+
+ private void notifyParent(Widget w) {
+ Element elem = w.getElement();
+ notifyParent(elem.getClientWidth(), elem.getClientHeight());
+ }
+
+ private native void notifyParent(int width, int height) /*-{
+ $wnd.parent.postMessage(width + 'px ' + height + 'px', '*');
+ }-*/;
+
+ @Override
+ public Command getOnSpreadsheetRendered() {
+ return new Command() {
+ @Override
+ public void execute() {
+ notifyParent(spreadsheet);
+ }
+ };
+ }
+
+ @Override
+ public Spreadsheet getSpreadsheet() {
+ return spreadsheet;
+ }
+
+ @Override
+ public void showNoResults() {
+ panel.add(noResults);
+ notifyParent(noResults);
+ }
+
+ @Override
+ public void showSpreadsheet() {
+ panel.add(spreadsheet);
+ }
+}
--- autotest/frontend/client/src/autotest/tko/EmbeddedSpreadsheetClient.java
2010-06-09 11:05:26.000000000 -0700
+++
autotest/frontend/client/src/autotest/tko/embedded_spreadsheet/EmbeddedSpreadsheetPresenter.java
2010-06-09 14:29:53.000000000 -0700
@@ -1,27 +1,35 @@
-package autotest.tko;
+package autotest.tko.embedded_spreadsheet;
import autotest.common.JsonRpcCallback;
import autotest.common.JsonRpcProxy;
import autotest.common.spreadsheet.Spreadsheet;
import autotest.common.spreadsheet.Spreadsheet.CellInfo;
import autotest.common.spreadsheet.Spreadsheet.SpreadsheetListener;
+import autotest.tko.HeaderField;
+import autotest.tko.SpreadsheetDataProcessor;
+import autotest.tko.TestGroupDataSource;
+import autotest.tko.TestSet;
+import autotest.tko.TkoSpreadsheetUtils;
import autotest.tko.TkoSpreadsheetUtils.DrilldownType;
-import com.google.gwt.core.client.EntryPoint;
-import com.google.gwt.dom.client.Element;
import com.google.gwt.http.client.URL;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.RootPanel;
import java.util.Collections;
import java.util.List;
-public class EmbeddedSpreadsheetClient implements EntryPoint,
SpreadsheetListener {
+public class EmbeddedSpreadsheetPresenter implements SpreadsheetListener {
+ public interface Display {
+ public void showNoResults();
+ public void showSpreadsheet();
+ public Spreadsheet getSpreadsheet();
+ public Command getOnSpreadsheetRendered();
+ }
+
private static class SimpleHeaderField extends HeaderField {
protected SimpleHeaderField(String name) {
super(name, name);
@@ -35,15 +43,9 @@
public static final String ROW_HEADER = "hostname";
public static final String COLUMN_HEADER = "test_name";
- private static final String NO_RESULTS = "There are no results for this
query (yet?)";
-
public static final String DRILLDOWN_ROW_HEADER = "job_tag";
public static final String DRILLDOWN_COLUMN_HEADER = "subdir";
- private Label noResults = new Label(NO_RESULTS);
- private Spreadsheet spreadsheet = new Spreadsheet();
- private SpreadsheetDataProcessor spreadsheetProcessor =
- new SpreadsheetDataProcessor(spreadsheet);
private List<HeaderField> rowHeader =
Collections.singletonList((HeaderField) new
SimpleHeaderField(ROW_HEADER));
private List<HeaderField> columnHeader =
@@ -52,14 +54,16 @@
private String afeJobIdStr;
private JSONObject condition;
- @Override
- public void onModuleLoad() {
- JsonRpcProxy.setDefaultBaseUrl(JsonRpcProxy.TKO_BASE_URL);
- afeJobIdStr = Window.Location.getParameter("afe_job_id");
- checkAndRender();
+ private Display display;
+
+ public void bindDisplay(Display display) {
+ this.display = display;
}
- private void checkAndRender() {
+ public void initialize(String afeJobIdStr) {
+ JsonRpcProxy.setDefaultBaseUrl(JsonRpcProxy.TKO_BASE_URL);
+ this.afeJobIdStr = afeJobIdStr;
+
condition = getFilterCondition(afeJobIdStr);
if (condition == null) {
showNoResults();
@@ -95,31 +99,20 @@
}
private void showNoResults() {
- RootPanel.get().add(noResults);
- notifyParent(noResults.getElement());
+ display.showNoResults();
}
private void renderSpreadsheet(JSONObject condition) {
+ display.showSpreadsheet();
+ SpreadsheetDataProcessor spreadsheetProcessor =
+ new SpreadsheetDataProcessor(display.getSpreadsheet());
spreadsheetProcessor.setDataSource(TestGroupDataSource.getStatusCountDataSource());
spreadsheetProcessor.setHeaders(rowHeader, columnHeader, new
JSONObject());
- spreadsheet.setListener(this);
- RootPanel.get().add(spreadsheet);
- spreadsheetProcessor.refresh(condition, new Command() {
- public void execute() {
- notifyParent(spreadsheet.getElement());
- }
- });
- }
-
- private void notifyParent(Element elem) {
- notifyParent(elem.getClientWidth(), elem.getClientHeight());
+ display.getSpreadsheet().setListener(this);
+ spreadsheetProcessor.refresh(condition,
display.getOnSpreadsheetRendered());
}
- private native void notifyParent(int width, int height) /*-{
- $wnd.parent.postMessage(width + 'px ' + height + 'px', '*');
- }-*/;
-
@Override
public void onCellClicked(CellInfo cellInfo, boolean isRightClick) {
TestSet testSet = TkoSpreadsheetUtils.getTestSet(
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest