Revision: 7755
Author: r...@google.com
Date: Mon Mar 22 05:11:01 2010
Log: Add 'view data' to cell, column, and updater classes.
Make the Validation example work with view data.
Review at http://gwt-code-reviews.appspot.com/248801
http://code.google.com/p/google-web-toolkit/source/detail?r=7755
Deleted:
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/validation/client/ValidatableColumn.java
Modified:
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/ButtonCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/Cell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/CheckboxCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/CurrencyCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/EllipsisCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/FieldUpdater.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/ProfitLossCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/TextCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/TextInputCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/ValueUpdater.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/Column.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/Header.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/PagingTableListView.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/SimpleCellList.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/BuySellPopup.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/ChangeCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/Columns.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/HighlightingTextCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/PlayerScoresWidget.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQuoteCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockSample.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/TransactionTreeViewModel.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/tree/client/MyTreeViewModel.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/validation/client/ValidatableField.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/validation/client/ValidatableInputCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/validation/client/Validation.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/SideBySideTreeNodeView.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/StandardTreeNodeView.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/TreeNodeView.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/TreeViewModel.java
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/validation/client/ValidatableColumn.java
Wed Mar 17 11:08:23 2010
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
- * use this file except in compliance with the License. You may obtain a
copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
under
- * the License.
- */
-package com.google.gwt.bikeshed.sample.validation.client;
-
-import com.google.gwt.bikeshed.cells.client.Cell;
-import com.google.gwt.bikeshed.cells.client.FieldUpdater;
-import com.google.gwt.bikeshed.cells.client.ValueUpdater;
-import com.google.gwt.bikeshed.list.client.Column;
-import
com.google.gwt.bikeshed.sample.validation.client.ValidatableField.DefaultValidatableField;
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.dom.client.NativeEvent;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * A column that support validation.
- *
- * @param <T> the row type
- * @param <C> the column type
- */
-// TODO - avoid wrapping cells that are never modified
-public abstract class ValidatableColumn<T, C> extends Column<T,
ValidatableField<C>> {
-
- Map<T, ValidatableField<C>> fieldMap = new HashMap<T,
ValidatableField<C>>();
-
- public ValidatableColumn(Cell<ValidatableField<C>> cell) {
- super(cell);
- }
-
- // Override onBrowserEvent to copy the ValueUpdater value into our copy
- @Override
- public void onBrowserEvent(Element elem, final int index, final T object,
- NativeEvent event) {
- final FieldUpdater<T, ValidatableField<C>> fieldUpdater =
getFieldUpdater();
- final ValidatableField<C> field = getValue(object);
- getCell().onBrowserEvent(elem, field, event,
- fieldUpdater == null ? null : new
ValueUpdater<ValidatableField<C>>() {
- public void update(ValidatableField<C> value) {
- // Copy pending value from value (copy) to field (original)
- field.setPendingValue(value.getPendingValue());
- fieldUpdater.update(index, object, field);
- }
- });
- }
-
- /**
- * Returns the value of the field with the underlying object that is to
be
- * validated.
- *
- * @param object the underlying data transfer object, of type T
- * @return a value of type C
- */
- protected abstract C getValidatableValue(T object);
-
- @Override
- protected ValidatableField<C> getValue(T object) {
- ValidatableField<C> vfield = fieldMap.get(object);
- if (vfield == null) {
- C validatableValue = getValidatableValue(object);
- vfield = new DefaultValidatableField<C>(validatableValue);
- fieldMap.put(object, vfield);
- }
-
- return vfield;
- }
-}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/ButtonCell.java
Fri Feb 26 09:32:06 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/ButtonCell.java
Mon Mar 22 05:11:01 2010
@@ -21,22 +21,20 @@
/**
* A {...@link Cell} used to render a button.
*/
-public class ButtonCell extends Cell<String> {
+public class ButtonCell extends Cell<String, Void> {
@Override
- public void onBrowserEvent(Element parent, String value, NativeEvent
event,
- ValueUpdater<String> valueUpdater) {
- if (valueUpdater == null) {
- return;
+ public Void onBrowserEvent(Element parent, String value, Void viewData,
+ NativeEvent event, ValueUpdater<String, Void> valueUpdater) {
+ if (valueUpdater != null && "mouseup".equals(event.getType())) {
+ valueUpdater.update(value, viewData);
}
- if ("mouseup".equals(event.getType())) {
- valueUpdater.update(value);
- }
+ return viewData;
}
@Override
- public void render(String data, StringBuilder sb) {
+ public void render(String data, Void viewData, StringBuilder sb) {
sb.append("<button>");
if (data != null) {
sb.append(data);
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/Cell.java Fri
Feb 26 09:32:06 2010
+++ /trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/Cell.java Mon
Mar 22 05:11:01 2010
@@ -22,25 +22,40 @@
* A light weight representation of a renderable object.
*
* @param <C> the type that this Cell represents
+ * @param <V> the type of view data that this cell consumes
*/
-public abstract class Cell<C> {
+public abstract class Cell<C, V> {
/**
- * @param parent
- * @param value
- * @param event
+ * Handle a browser event that took place within the cell. The default
+ * implementation returns null.
+ *
+ * @param parent the parent Element
+ * @param value the value associated with the cell
+ * @param viewData the view data associated with the cell, or null
+ * @param event the native browser event
* @param valueUpdater a {...@link ValueUpdater}, or null
+ * @return a view data object which may be the one passed in or a new
object
*/
- public void onBrowserEvent(Element parent, C value, NativeEvent event,
- ValueUpdater<C> valueUpdater) {
+ public V onBrowserEvent(Element parent, C value, V viewData,
+ NativeEvent event, ValueUpdater<C, V> valueUpdater) {
+ return null;
}
- // TODO: render needs a way of assuming text by default, but allowing
HTML.
- public abstract void render(C value, StringBuilder sb);
-
- public void setValue(Element parent, C value) {
+ /**
+ * Render a cell as HTML into a StringBuilder, suitable for passing
+ * to setInnerHTML on a container element.
+ *
+ * @param value the cell value to be rendered
+ * @param viewData view data associated with the cell
+ * @param sb the StringBuilder to be written to
+ */
+ // TODO: render needs a way of assuming text by default, but allowing
HTML
+ public abstract void render(C value, V viewData, StringBuilder sb);
+
+ public void setValue(Element parent, C value, V viewData) {
StringBuilder sb = new StringBuilder();
- render(value, sb);
+ render(value, viewData, sb);
parent.setInnerHTML(sb.toString());
}
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/CheckboxCell.java
Wed Mar 10 08:48:25 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/CheckboxCell.java
Mon Mar 22 05:11:01 2010
@@ -22,23 +22,21 @@
/**
* A {...@link Cell} used to render a checkbox.
*/
-public class CheckboxCell extends Cell<Boolean> {
+public class CheckboxCell extends Cell<Boolean, Void> {
@Override
- public void onBrowserEvent(Element parent, Boolean value, NativeEvent
event,
- ValueUpdater<Boolean> valueUpdater) {
- if (valueUpdater == null) {
- return;
- }
-
- if ("change".equals(event.getType())) {
+ public Void onBrowserEvent(Element parent, Boolean value, Void viewData,
+ NativeEvent event, ValueUpdater<Boolean, Void> valueUpdater) {
+ if (valueUpdater != null && "change".equals(event.getType())) {
InputElement input = parent.getFirstChild().cast();
- valueUpdater.update(input.isChecked());
- }
+ valueUpdater.update(input.isChecked(), viewData);
+ }
+
+ return viewData;
}
@Override
- public void render(Boolean data, StringBuilder sb) {
+ public void render(Boolean data, Void viewData, StringBuilder sb) {
sb.append("<input type=\"checkbox\"");
if ((data != null) && (data == true)) {
sb.append(" checked");
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/CurrencyCell.java
Thu Mar 11 03:44:25 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/CurrencyCell.java
Mon Mar 22 05:11:01 2010
@@ -18,10 +18,10 @@
/**
* A {...@link Cell} used to render currency.
*/
-public class CurrencyCell extends Cell<Integer> {
+public class CurrencyCell extends Cell<Integer, Void> {
@Override
- public void render(Integer price, StringBuilder sb) {
+ public void render(Integer price, Void viewData, StringBuilder sb) {
boolean negative = price < 0;
if (negative) {
price = -price;
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/EllipsisCell.java
Thu Mar 11 09:45:33 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/EllipsisCell.java
Mon Mar 22 05:11:01 2010
@@ -18,10 +18,10 @@
/**
* Call that displays overflow using an ellipsis.
*/
-public class EllipsisCell extends Cell<String> {
+public class EllipsisCell extends Cell<String, Void> {
@Override
- public void render(String value, StringBuilder sb) {
+ public void render(String value, Void viewData, StringBuilder sb) {
sb.append("<div style='overflow:hidden; white-space:nowrap;
text-overflow:ellipsis;'>");
sb.append(value);
sb.append("</div>");
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/FieldUpdater.java
Wed Mar 17 11:08:23 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/FieldUpdater.java
Mon Mar 22 05:11:01 2010
@@ -21,14 +21,16 @@
*
* @param <T> the data type that will be modified
* @param <C> the data type of the modified field
+ * @param <V> the data type of the view data for the field
*/
-public interface FieldUpdater<T, C> {
+public interface FieldUpdater<T, C, V> {
/**
* Announces a new value for a field within a base object.
- * @param index TODO
+ * @param index the current row index of the object
* @param object the base object to be updated
- * @param value the new value of the field being updated.
+ * @param value the new value of the field being updated
+ * @param viewData the view data associated with the field
*/
- void update(int index, T object, C value);
-}
+ void update(int index, T object, C value, V viewData);
+}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/ProfitLossCell.java
Tue Mar 16 10:24:13 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/ProfitLossCell.java
Mon Mar 22 05:11:01 2010
@@ -19,10 +19,10 @@
* A {...@link Cell} used to render profit and loss. Positive values are
shown in
* green with a "+" sign and negative values are shown in red with a "-"
sign.
*/
-public class ProfitLossCell extends Cell<Integer> {
+public class ProfitLossCell extends Cell<Integer, Void> {
@Override
- public void render(Integer priceDelta, StringBuilder sb) {
+ public void render(Integer priceDelta, Void viewData, StringBuilder sb) {
boolean negative = priceDelta < 0;
if (negative) {
priceDelta = -priceDelta;
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/TextCell.java
Fri Feb 26 09:32:06 2010
+++ /trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/TextCell.java
Mon Mar 22 05:11:01 2010
@@ -18,10 +18,10 @@
/**
* A {...@link Cell} used to render text.
*/
-public class TextCell extends Cell<String> {
+public class TextCell extends Cell<String, Void> {
@Override
- public void render(String value, StringBuilder sb) {
+ public void render(String value, Void viewData, StringBuilder sb) {
if (value != null) {
sb.append(value);
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/TextInputCell.java
Fri Feb 26 09:32:06 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/TextInputCell.java
Mon Mar 22 05:11:01 2010
@@ -22,23 +22,21 @@
/**
* A {...@link Cell} used to render a text input.
*/
-public class TextInputCell extends Cell<String> {
+public class TextInputCell extends Cell<String, Void> {
@Override
- public void onBrowserEvent(Element parent, String value, NativeEvent
event,
- ValueUpdater<String> valueUpdater) {
- if (valueUpdater == null) {
- return;
- }
-
- if ("change".equals(event.getType())) {
+ public Void onBrowserEvent(Element parent, String value, Void viewData,
+ NativeEvent event, ValueUpdater<String, Void> valueUpdater) {
+ if (valueUpdater != null && "change".equals(event.getType())) {
InputElement input = parent.getFirstChild().cast();
- valueUpdater.update(input.getValue());
- }
+ valueUpdater.update(input.getValue(), viewData);
+ }
+
+ return viewData;
}
@Override
- public void render(String data, StringBuilder sb) {
+ public void render(String data, Void viewData, StringBuilder sb) {
sb.append("<input type='text'");
if (data != null) {
sb.append(" value='" + data + "'");
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/ValueUpdater.java
Fri Feb 26 09:32:06 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/ValueUpdater.java
Mon Mar 22 05:11:01 2010
@@ -19,13 +19,14 @@
* A {...@link ValueUpdater} may be added to a Cell to provide updated data.
*
* @param <C> the data type of the cell
+ * @param <V> the data type of view data associated with the cell
*/
-public interface ValueUpdater<C> {
+public interface ValueUpdater<C, V> {
/**
* Announces a new value.
*
* @param value the updated value.
*/
- void update(C value);
-}
+ void update(C value, V viewData);
+}
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/Column.java Wed
Mar 17 11:08:23 2010
+++ /trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/Column.java Mon
Mar 22 05:11:01 2010
@@ -21,44 +21,59 @@
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
+import java.util.HashMap;
+import java.util.Map;
+
/**
- * A representation of a column in a table.
+ * A representation of a column in a table. The column may maintain view
data
+ * for each cell on demand. New view data, if needed, is created by the
+ * cell's onBrowserEvent method, stored in the Column, and passed to future
+ * calls to Cell's {...@link Cell#onBrowserEvent} and @link{Cell#render}
methods.
*
* @param <T> the row type
* @param <C> the column type
+ * @param <V> the view data type
*/
-public abstract class Column<T, C> {
- private final Cell<C> cell;
- private FieldUpdater<T, C> fieldUpdater;
-
- public Column(Cell<C> cell) {
+// TODO - when can we get rid of a view data object?
+// TODO - should viewData implement some interface? (e.g., with
commit/rollback/dispose)
+public abstract class Column<T, C, V> {
+ protected final Cell<C, V> cell;
+ protected Map<T, V> viewDataMap = new HashMap<T, V>();
+ protected FieldUpdater<T, C, V> fieldUpdater;
+
+ public Column(Cell<C, V> cell) {
this.cell = cell;
}
public void onBrowserEvent(Element elem, final int index, final T object,
NativeEvent event) {
- cell.onBrowserEvent(elem, getValue(object), event,
- fieldUpdater == null ? null : new ValueUpdater<C>() {
- public void update(C value) {
- fieldUpdater.update(index, object, value);
- }
- });
+ V viewData = viewDataMap.get(object);
+ V newViewData = cell.onBrowserEvent(elem,
+ getValue(object), viewData, event, fieldUpdater == null ? null
+ : new ValueUpdater<C, V>() {
+ public void update(C value, V viewData) {
+ fieldUpdater.update(index, object, value, viewData);
+ }
+ });
+ if (newViewData != viewData) {
+ viewDataMap.put(object, newViewData);
+ }
}
public void render(T object, StringBuilder sb) {
C value = getValue(object);
- cell.render(value, sb);
+ cell.render(value, viewDataMap.get(object), sb);
}
- public void setFieldUpdater(FieldUpdater<T, C> fieldUpdater) {
+ public void setFieldUpdater(FieldUpdater<T, C, V> fieldUpdater) {
this.fieldUpdater = fieldUpdater;
}
- protected Cell<C> getCell() {
+ protected Cell<C, V> getCell() {
return cell;
}
- protected FieldUpdater<T, C> getFieldUpdater() {
+ protected FieldUpdater<T, C, V> getFieldUpdater() {
return fieldUpdater;
}
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/Header.java Thu
Mar 11 03:44:25 2010
+++ /trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/Header.java Mon
Mar 22 05:11:01 2010
@@ -26,11 +26,11 @@
* @param <H> the {#link Cell} type
*/
public class Header<H> {
- private final Cell<H> cell;
- private ValueUpdater<H> updater;
+ private final Cell<H, Void> cell;
+ private ValueUpdater<H, Void> updater;
private H value;
- public Header(Cell<H> cell) {
+ public Header(Cell<H, Void> cell) {
this.cell = cell;
}
@@ -39,14 +39,14 @@
}
public void onBrowserEvent(Element elem, NativeEvent event) {
- cell.onBrowserEvent(elem, value, event, updater);
+ cell.onBrowserEvent(elem, value, null, event, updater);
}
public void render(StringBuilder sb) {
- cell.render(value, sb);
+ cell.render(value, null, sb);
}
- public void setUpdater(ValueUpdater<H> updater) {
+ public void setUpdater(ValueUpdater<H, Void> updater) {
this.updater = updater;
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/PagingTableListView.java
Wed Mar 17 11:08:23 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/PagingTableListView.java
Mon Mar 22 05:11:01 2010
@@ -49,7 +49,7 @@
private int numPages;
private ListRegistration listReg;
private int totalSize;
- private List<Column<T, ?>> columns = new ArrayList<Column<T, ?>>();
+ private List<Column<T, ?, ?>> columns = new ArrayList<Column<T, ?, ?>>();
private ArrayList<T> data = new ArrayList<T>();
private List<Header<?>> headers = new ArrayList<Header<?>>();
@@ -92,16 +92,16 @@
listReg.setRangeOfInterest(0, pageSize);
}
- public void addColumn(Column<T, ?> col) {
+ public void addColumn(Column<T, ?, ?> col) {
addColumn(col, null, null);
}
- public void addColumn(Column<T, ?> col, Header<?> header) {
+ public void addColumn(Column<T, ?, ?> col, Header<?> header) {
addColumn(col, header, null);
}
// TODO: remove(Column)
- public void addColumn(Column<T, ?> col, Header<?> header, Header<?>
footer) {
+ public void addColumn(Column<T, ?, ?> col, Header<?> header, Header<?>
footer) {
headers.add(header);
footers.add(footer);
createHeadersAndFooters(); // TODO: defer header recreation
@@ -148,7 +148,7 @@
} else if (section == tbody) {
int row = tr.getSectionRowIndex();
T value = data.get(row);
- Column<T, ?> column = columns.get(col);
+ Column<T, ?, ?> column = columns.get(col);
column.onBrowserEvent(cell, curPage * pageSize + row, value, event);
}
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/SimpleCellList.java
Sat Mar 20 17:18:42 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/SimpleCellList.java
Mon Mar 22 05:11:01 2010
@@ -40,7 +40,7 @@
*/
public class SimpleCellList<T> extends Widget {
- private final Cell<T> cell;
+ private final Cell<T, Void> cell;
private final ArrayList<T> data = new ArrayList<T>();
private int increment;
private int maxSize;
@@ -48,9 +48,10 @@
private final Element showMoreElem;
private final Element tmpElem;
private ListRegistration reg;
- private ValueUpdater<T> valueUpdater;
-
- public SimpleCellList(ListModel<T> model, Cell<T> cell, int maxSize, int
increment) {
+ private ValueUpdater<T, Void> valueUpdater;
+
+ public SimpleCellList(ListModel<T> model, Cell<T, Void> cell, int
maxSize,
+ int increment) {
this.maxSize = maxSize;
this.increment = increment;
this.model = model;
@@ -82,11 +83,11 @@
}
if (idxString.length() > 0) {
int idx = Integer.parseInt(idxString);
- cell.onBrowserEvent(target, data.get(idx), event, valueUpdater);
+ cell.onBrowserEvent(target, data.get(idx), null, event,
valueUpdater);
}
}
- public void setValueUpdater(ValueUpdater<T> valueUpdater) {
+ public void setValueUpdater(ValueUpdater<T, Void> valueUpdater) {
this.valueUpdater = valueUpdater;
}
@@ -162,7 +163,7 @@
int totalToAdd = 0;
for (int i = childCount; i < start; ++i) {
html.append("<div __idx='" + i + "'>");
- cell.render(null, html);
+ cell.render(null, null, html);
html.append("</div>");
++totalToAdd;
}
@@ -170,7 +171,7 @@
// Items rendered from data.
for (int i = start; i < end; ++i) {
html.append("<div __idx='" + i + "'>");
- cell.render(values.get(i - start), html);
+ cell.render(values.get(i - start), null, html);
html.append("</div>");
++totalToAdd;
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/BuySellPopup.java
Fri Mar 12 06:22:00 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/BuySellPopup.java
Mon Mar 22 05:11:01 2010
@@ -164,7 +164,7 @@
layout.setText(NAME, 1, quote.getName());
layout.setText(PRICE, 1, quote.getDisplayPrice());
if (isBuying) {
- layout.setText(MAX_QUANTITY, 1, "" + (int) Math.floor(cash /
quote.getPrice()));
+ layout.setText(MAX_QUANTITY, 1, "" + cash / quote.getPrice());
} else {
layout.setText(MAX_QUANTITY, 1, "" + quote.getSharesOwned());
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/ChangeCell.java
Fri Mar 12 06:22:00 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/ChangeCell.java
Mon Mar 22 05:11:01 2010
@@ -20,10 +20,10 @@
/**
* A cell that represents a {...@link StockQuote}.
*/
-public class ChangeCell extends Cell<String> {
+public class ChangeCell extends Cell<String, Void> {
@Override
- public void render(String value, StringBuilder sb) {
+ public void render(String value, Void viewData, StringBuilder sb) {
if (value == null || value.length() == 0) {
return;
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/Columns.java
Thu Mar 11 09:45:33 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/Columns.java
Mon Mar 22 05:11:01 2010
@@ -29,7 +29,7 @@
*/
public class Columns {
- static Column<StockQuote, String> buyColumn = new Column<StockQuote,
String>(
+ static Column<StockQuote, String, Void> buyColumn = new
Column<StockQuote, String, Void>(
new ButtonCell()) {
@Override
protected String getValue(StockQuote object) {
@@ -37,93 +37,93 @@
}
};
- static Column<StockQuote, String> changeColumn =
- new Column<StockQuote, String>(new ChangeCell()) {
+ static Column<StockQuote, String, Void> changeColumn = new
Column<StockQuote, String, Void>(
+ new ChangeCell()) {
@Override
protected String getValue(StockQuote object) {
return object.getChange();
}
};
- static Column<StockQuote, Integer> dollarsColumn =
- new Column<StockQuote, Integer>(new CurrencyCell()) {
+ static Column<StockQuote, Integer, Void> dollarsColumn = new
Column<StockQuote, Integer, Void>(
+ new CurrencyCell()) {
@Override
protected Integer getValue(StockQuote object) {
return object.getPrice() * object.getSharesOwned();
}
};
-
- static Column<StockQuote, Boolean> favoriteColumn =
- new Column<StockQuote, Boolean>(new CheckboxCell()) {
+
+ static Column<StockQuote, Boolean, Void> favoriteColumn = new
Column<StockQuote, Boolean, Void>(
+ new CheckboxCell()) {
@Override
protected Boolean getValue(StockQuote object) {
return object.isFavorite();
}
};
- // TODO - use an ellipsis cell
+ // TODO - use an ellipsis cell
static HighlightingTextCell nameCell = new HighlightingTextCell();
- static Column<StockQuote, String> nameColumn =
- new Column<StockQuote, String>(nameCell) {
+ static Column<StockQuote, String, Void> nameColumn = new
Column<StockQuote, String, Void>(
+ nameCell) {
@Override
protected String getValue(StockQuote object) {
return object.getName();
}
};
- static Column<StockQuote, Integer> priceColumn =
- new Column<StockQuote, Integer>(new CurrencyCell()) {
+ static Column<StockQuote, Integer, Void> priceColumn = new
Column<StockQuote, Integer, Void>(
+ new CurrencyCell()) {
@Override
protected Integer getValue(StockQuote object) {
return object.getPrice();
}
};
- static Column<StockQuote, Integer> profitLossColumn =
- new Column<StockQuote, Integer>(new ProfitLossCell()) {
+ static Column<StockQuote, Integer, Void> profitLossColumn = new
Column<StockQuote, Integer, Void>(
+ new ProfitLossCell()) {
@Override
protected Integer getValue(StockQuote object) {
return object.getValue() - object.getTotalPaid();
}
};
- static Column<StockQuote, String> sellColumn =
- new Column<StockQuote, String>(new ButtonCell()) {
+ static Column<StockQuote, String, Void> sellColumn = new
Column<StockQuote, String, Void>(
+ new ButtonCell()) {
@Override
protected String getValue(StockQuote object) {
return "Sell";
}
};
- static Column<StockQuote, String> sharesColumn =
- new Column<StockQuote, String>(new TextCell()) {
+ static Column<StockQuote, String, Void> sharesColumn = new
Column<StockQuote, String, Void>(
+ new TextCell()) {
@Override
protected String getValue(StockQuote object) {
return "" + object.getSharesOwned();
}
};
- static Column<Transaction, String> subtotalColumn =
- new Column<Transaction, String>(new TextCell()) {
+ static Column<Transaction, String, Void> subtotalColumn = new
Column<Transaction, String, Void>(
+ new TextCell()) {
@Override
protected String getValue(Transaction object) {
int price = object.getActualPrice() * object.getQuantity();
- return (object.isBuy() ? " (" : " ") +
StockSample.getFormattedPrice(price) +
- (object.isBuy() ? ")" : "");
+ return (object.isBuy() ? " (" : " ")
+ + StockSample.getFormattedPrice(price) +
(object.isBuy() ? ")" : "");
}
};
-
- static Column<StockQuote, String> tickerColumn =
- new Column<StockQuote, String>(new TextCell()) {
+
+ static Column<StockQuote, String, Void> tickerColumn = new
Column<StockQuote, String, Void>(
+ new TextCell()) {
@Override
protected String getValue(StockQuote object) {
return object.getTicker();
}
};
-
- static Column<Transaction, String> transactionColumn =
- new Column<Transaction, String>(new TextCell()) {
+
+ static Column<Transaction, String, Void> transactionColumn = new
Column<Transaction, String, Void>(
+ new TextCell()) {
@Override
protected String getValue(Transaction object) {
return object.toString();
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/HighlightingTextCell.java
Fri Mar 12 06:22:00 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/HighlightingTextCell.java
Mon Mar 22 05:11:01 2010
@@ -23,12 +23,12 @@
* A {...@link Cell} used to render text, with portions matching a given
* regular expression highlighted.
*/
-public class HighlightingTextCell extends Cell<String> {
+public class HighlightingTextCell extends Cell<String, Void> {
private RegExp highlightRegex;
@Override
- public void render(String value, StringBuilder sb) {
+ public void render(String value, Void viewData, StringBuilder sb) {
// sb.append("<div style='overflow:hidden; white-space:nowrap;
text-overflow:ellipsis;'>");
sb.append("<div>");
if (highlightRegex == null) {
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/PlayerScoresWidget.java
Fri Mar 19 07:22:04 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/PlayerScoresWidget.java
Mon Mar 22 05:11:01 2010
@@ -41,9 +41,9 @@
/**
* A {...@link Cell} that displays the status of a single player.
*/
- private static final class PlayerInfoCell extends Cell<PlayerInfo> {
+ private static final class PlayerInfoCell extends Cell<PlayerInfo, Void>
{
@Override
- public void render(PlayerInfo value, StringBuilder sb) {
+ public void render(PlayerInfo value, Void viewData, StringBuilder sb) {
sb.append("<div class='playerScoreBox'>");
sb.append("<b>Name: </b>");
sb.append(value.getDisplayName());
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQuoteCell.java
Fri Feb 26 09:32:06 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQuoteCell.java
Mon Mar 22 05:11:01 2010
@@ -21,10 +21,10 @@
/**
* A cell that represents a {...@link StockQuote}.
*/
-public class StockQuoteCell extends Cell<StockQuote> {
+public class StockQuoteCell extends Cell<StockQuote, Void> {
@Override
- public void render(StockQuote value, StringBuilder sb) {
+ public void render(StockQuote value, Void viewData, StringBuilder sb) {
sb.append(value.getTicker() + " (" + value.getName() + "): "
+ value.getDisplayPrice());
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockSample.java
Fri Mar 19 07:22:04 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockSample.java
Mon Mar 22 05:11:01 2010
@@ -65,6 +65,7 @@
static String getFormattedPrice(int price) {
return NumberFormat.getCurrencyFormat("USD").format(price / 100.0);
}
+
@UiField Label cashLabel;
@UiField FavoritesWidget favoritesWidget;
@@ -140,20 +141,20 @@
RootLayoutPanel.get().add(binder.createAndBindUi(this));
// Hook up handlers to columns and the buy/sell popup.
- Columns.favoriteColumn.setFieldUpdater(new FieldUpdater<StockQuote,
Boolean>() {
- public void update(int index, StockQuote object, Boolean value) {
+ Columns.favoriteColumn.setFieldUpdater(new FieldUpdater<StockQuote,
Boolean, Void>() {
+ public void update(int index, StockQuote object, Boolean value, Void
viewData) {
setFavorite(object.getTicker(), value);
}
});
- Columns.buyColumn.setFieldUpdater(new FieldUpdater<StockQuote,
String>() {
- public void update(int index, StockQuote quote, String value) {
+ Columns.buyColumn.setFieldUpdater(new FieldUpdater<StockQuote, String,
Void>() {
+ public void update(int index, StockQuote quote, String value, Void
viewData) {
buy(quote);
}
});
- Columns.sellColumn.setFieldUpdater(new FieldUpdater<StockQuote,
String>() {
- public void update(int index, StockQuote quote, String value) {
+ Columns.sellColumn.setFieldUpdater(new FieldUpdater<StockQuote,
String, Void>() {
+ public void update(int index, StockQuote quote, String value, Void
viewData) {
sell(quote);
}
});
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/TransactionTreeViewModel.java
Fri Mar 19 07:22:04 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/TransactionTreeViewModel.java
Mon Mar 22 05:11:01 2010
@@ -56,21 +56,21 @@
}
}
- static class TransactionCell extends Cell<Transaction> {
+ static class TransactionCell extends Cell<Transaction, Void> {
@Override
- public void render(Transaction value, StringBuilder sb) {
+ public void render(Transaction value, Void viewData, StringBuilder sb)
{
sb.append(value.toString());
}
}
- private static final Cell<StockQuote> STOCK_QUOTE_CELL = new
Cell<StockQuote>() {
+ private static final Cell<StockQuote, Void> STOCK_QUOTE_CELL = new
Cell<StockQuote, Void>() {
@Override
- public void render(StockQuote value, StringBuilder sb) {
+ public void render(StockQuote value, Void viewData, StringBuilder sb) {
sb.append(value.getTicker() + " - " + value.getDisplayPrice());
}
};
- private static final Cell<Transaction> TRANSACTION_CELL =
+ private static final Cell<Transaction, Void> TRANSACTION_CELL =
new TransactionCell();
private Map<String, SectorListModel> sectorListModels = new
HashMap<String, SectorListModel>();
@@ -120,8 +120,8 @@
list.add("Buy");
list.add("Sell");
return new TreeViewModel.DefaultNodeInfo<String>(listModel, new
ButtonCell(),
- new ValueUpdater<String>() {
- public void update(String value) {
+ new ValueUpdater<String, Void>() {
+ public void update(String value, Void viewData) {
StockQuote stockQuote = (StockQuote)
treeNode.getParentNode().getValue();
if ("Buy".equals(value)) {
updater.buy(stockQuote);
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/tree/client/MyTreeViewModel.java
Fri Mar 19 07:22:04 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/tree/client/MyTreeViewModel.java
Mon Mar 22 05:11:01 2010
@@ -92,9 +92,9 @@
/**
* The cell used to render integers.
*/
- private static final Cell<Integer> INTEGER_CELL = new Cell<Integer>() {
+ private static final Cell<Integer, Void> INTEGER_CELL = new
Cell<Integer, Void>() {
@Override
- public void render(Integer value, StringBuilder sb) {
+ public void render(Integer value, Void viewData, StringBuilder sb) {
sb.append(value);
}
};
@@ -117,16 +117,16 @@
if (value.endsWith("...")) {
ListModel<String> listModel = new StringListModel(value.toString());
return new DefaultNodeInfo<String>(listModel, new ButtonCell(),
- new ValueUpdater<String>() {
- public void update(String value) {
+ new ValueUpdater<String, Void>() {
+ public void update(String value, Void viewData) {
Window.alert("Clicked: " + value);
}
});
} else {
ListModel<Integer> listModel = new IntegerListModel(value.length());
return new DefaultNodeInfo<Integer>(listModel, INTEGER_CELL,
- new ValueUpdater<Integer>() {
- public void update(Integer value) {
+ new ValueUpdater<Integer, Void>() {
+ public void update(Integer value, Void viewData) {
Window.alert("Integer = " + value);
}
});
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/validation/client/ValidatableField.java
Wed Mar 17 11:08:23 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/validation/client/ValidatableField.java
Mon Mar 22 05:11:01 2010
@@ -16,16 +16,14 @@
package com.google.gwt.bikeshed.sample.validation.client;
/**
- * A field value with a pending future value and a valid flag.
+ * A field with a pending value and an 'is invalid' flag.
*
* @param <T> the value type of the field
*/
public interface ValidatableField<T> {
- T getPendingValue();
T getValue();
boolean isInvalid();
void setInvalid(boolean isInvalid);
- void setPendingValue(T pendingValue);
void setValue(T value);
/**
@@ -34,10 +32,9 @@
* @param <T> the value type of the field
*/
public static class DefaultValidatableField<T> implements
ValidatableField<T> {
- static int genserial = 0;
- int serial;
+ static int genserial = 0; // debugging
+ int serial; // debugging
boolean isInvalid;
- T pendingValue;
T value;
public DefaultValidatableField(T value) {
@@ -50,13 +47,8 @@
this.serial = ((DefaultValidatableField<T>) other).serial;
}
this.value = other.getValue();
- this.pendingValue = other.getPendingValue();
this.isInvalid = other.isInvalid();
}
-
- public T getPendingValue() {
- return pendingValue;
- }
public T getValue() {
return value;
@@ -69,10 +61,6 @@
public void setInvalid(boolean isInvalid) {
this.isInvalid = isInvalid;
}
-
- public void setPendingValue(T pendingValue) {
- this.pendingValue = pendingValue;
- }
public void setValue(T value) {
this.value = value;
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/validation/client/ValidatableInputCell.java
Wed Mar 17 11:08:23 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/validation/client/ValidatableInputCell.java
Mon Mar 22 05:11:01 2010
@@ -23,34 +23,47 @@
import com.google.gwt.dom.client.NativeEvent;
/**
- * A String Cell that supports validation.
+ * A String {...@link Cell} that supports validation using a
+ * {...@link ValidatableField}.
*/
-public class ValidatableInputCell extends Cell<ValidatableField<String>> {
+public class ValidatableInputCell extends Cell<String,
ValidatableField<String>> {
@Override
- public void onBrowserEvent(Element parent, ValidatableField<String>
value, NativeEvent event,
- ValueUpdater<ValidatableField<String>> valueUpdater) {
+ public ValidatableField<String> onBrowserEvent(Element parent, String
value,
+ ValidatableField<String> viewData, NativeEvent event,
+ ValueUpdater<String, ValidatableField<String>> valueUpdater) {
if (event.getType().equals("change")) {
InputElement input = parent.getFirstChild().cast();
- // Mark as pending
+ // Mark cell as containing a pending change
input.getStyle().setColor("blue");
- ValidatableField<String> field = new
DefaultValidatableField<String>(value);
- field.setPendingValue(input.getValue());
- valueUpdater.update(field);
- }
+ // Create a new ValidatableField if needed
+ if (viewData == null) {
+ viewData = new DefaultValidatableField<String>(input.getValue());
+ }
+ viewData.setValue(input.getValue());
+ valueUpdater.update(value, viewData);
+ }
+
+ return viewData;
}
@Override
- public void render(ValidatableField<String> value, StringBuilder sb) {
- String pendingValue = value.getPendingValue();
+ public void render(String value, ValidatableField<String> viewData,
StringBuilder sb) {
+ /*
+ * If viewData is null, just paint the contents black. If it is
non-null,
+ * show the pending value and paint the contents red if they are known
to be
+ * invalid.
+ */
+ String pendingValue = viewData == null ? null : viewData.getValue();
+ boolean invalid = viewData == null ? false : viewData.isInvalid();
+
sb.append("<input type=\"text\" value=\"");
- boolean invalid = value.isInvalid();
if (pendingValue != null) {
sb.append(pendingValue);
} else {
- sb.append(value.getValue());
+ sb.append(value);
}
sb.append("\" style=\"color:");
if (pendingValue != null) {
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/validation/client/Validation.java
Wed Mar 17 11:08:23 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/validation/client/Validation.java
Mon Mar 22 05:11:01 2010
@@ -1,12 +1,12 @@
/*
* Copyright 2010 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may
not
* use this file except in compliance with the License. You may obtain a
copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -30,11 +30,10 @@
* Validation demo.
*/
public class Validation implements EntryPoint {
-
+
static class Address {
static int genkey = 0;
int key;
- String message;
String state;
String zip;
boolean zipInvalid;
@@ -44,13 +43,13 @@
this.state = address.state;
this.zip = address.zip;
}
-
+
public Address(String state, String zip) {
this.key = genkey++;
this.state = state;
this.zip = zip;
}
-
+
@Override
public boolean equals(Object other) {
if (!(other instanceof Address)) {
@@ -64,7 +63,7 @@
return key;
}
}
-
+
public static boolean zipInvalid(int zip) {
return zip % 3 == 0;
}
@@ -76,54 +75,58 @@
if (zipInvalid(30000 + i)) {
continue;
}
-
+
String zip = "300" + i;
list.add(new Address("GA", zip));
}
-
- PagingTableListView<Address> table = new
PagingTableListView<Address>(listModel, 10);
- Column<Address, String> stateColumn = new Column<Address, String>(new
TextCell()) {
+
+ PagingTableListView<Address> table = new PagingTableListView<Address>(
+ listModel, 10);
+ Column<Address, String, Void> stateColumn = new Column<Address,
String, Void>(
+ new TextCell()) {
@Override
protected String getValue(Address object) {
return object.state;
}
};
-
- ValidatableColumn<Address, String> zipColumn =
- new ValidatableColumn<Address, String>(new ValidatableInputCell()) {
- @Override
- protected String getValidatableValue(Address object) {
- return object.zip;
- }
+
+ Column<Address, String, ValidatableField<String>> zipColumn =
+ new Column<Address, String, ValidatableField<String>>(
+ new ValidatableInputCell()) {
+ @Override
+ protected String getValue(Address object) {
+ return object.zip;
+ }
};
- zipColumn.setFieldUpdater(new FieldUpdater<Address,
ValidatableField<String>>() {
- public void update(final int index, final Address object, final
ValidatableField<String> value) {
+ zipColumn.setFieldUpdater(new FieldUpdater<Address, String,
ValidatableField<String>>() {
+ public void update(final int index, final Address object,
+ final String value, final ValidatableField<String> viewData) {
// Perform validation after a 2-second delay
new Timer() {
@Override
public void run() {
- String pendingValue = value.getPendingValue();
-
+ String pendingValue = viewData.getValue();
+
int zip = Integer.parseInt(pendingValue);
boolean zipInvalid = Validation.zipInvalid(zip);
final Address newValue = new Address(object);
- newValue.zip = pendingValue == null ? value.getValue() :
pendingValue;
+ newValue.zip = pendingValue == null ? value : pendingValue;
newValue.zipInvalid = zipInvalid;
-
- value.setInvalid(zipInvalid);
+
+ viewData.setInvalid(zipInvalid);
if (!zipInvalid) {
- value.setValue(pendingValue);
- value.setPendingValue(null);
- }
-
+ viewData.setValue(null);
+ }
+
list.set(index, newValue);
}
}.schedule(2000);
}
});
-
- Column<Address, String> messageColumn = new Column<Address,
String>(new TextCell()) {
+
+ Column<Address, String, Void> messageColumn = new Column<Address,
String, Void>(
+ new TextCell()) {
@Override
protected String getValue(Address object) {
return object.zipInvalid ? "Please fix the zip code" : "";
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/SideBySideTreeNodeView.java
Fri Mar 12 11:27:24 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/SideBySideTreeNodeView.java
Mon Mar 22 05:11:01 2010
@@ -66,14 +66,14 @@
@Override
protected <C> TreeNodeView<C> createTreeNodeView(NodeInfo<C> nodeInfo,
- Element childElem, C childValue, int idx) {
+ Element childElem, C childValue, Void viewData, int idx) {
return new SideBySideTreeNodeView<C>(getTree(), this, nodeInfo,
childElem,
childValue, level + 1, path + "-" + idx, columnWidth,
columnHeight);
}
@Override
protected <C> void emitHtml(StringBuilder sb, List<C> childValues,
- List<TreeNodeView<?>> savedViews, Cell<C> cell) {
+ List<TreeNodeView<?>> savedViews, Cell<C, Void> cell) {
TreeView tree = getTree();
TreeViewModel model = tree.getTreeViewModel();
int imageWidth = tree.getImageWidth();
@@ -94,7 +94,7 @@
sb.append(tree.getClosedImageHtml(imageLeft));
}
sb.append("<div class=\"gwt-sstree-cell\">");
- cell.render(childValue, sb);
+ cell.render(childValue, null, sb);
sb.append("</div></div>");
idx++;
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/StandardTreeNodeView.java
Fri Mar 12 11:27:24 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/StandardTreeNodeView.java
Mon Mar 22 05:11:01 2010
@@ -54,14 +54,14 @@
@Override
protected <C> TreeNodeView<C> createTreeNodeView(NodeInfo<C> nodeInfo,
- Element childElem, C childValue, int idx) {
+ Element childElem, C childValue, Void viewData, int idx) {
return new StandardTreeNodeView<C>(getTree(), this, nodeInfo,
childElem,
childValue);
}
@Override
protected <C> void emitHtml(StringBuilder sb, List<C> childValues,
- List<TreeNodeView<?>> savedViews, Cell<C> cell) {
+ List<TreeNodeView<?>> savedViews, Cell<C, Void> cell) {
TreeView tree = getTree();
TreeViewModel model = tree.getTreeViewModel();
int imageWidth = tree.getImageWidth();
@@ -79,7 +79,7 @@
sb.append(tree.getClosedImageHtml(0));
}
sb.append("<div>");
- cell.render(childValue, sb);
+ cell.render(childValue, null, sb);
sb.append("</div></div>");
}
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/TreeNodeView.java
Fri Mar 19 07:22:04 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/TreeNodeView.java
Mon Mar 22 05:11:01 2010
@@ -236,29 +236,30 @@
* Returns an instance of TreeNodeView of the same subclass as the
* calling object.
*
- * @param <C> the data type of the node's children.
- * @param nodeInfo a NodeInfo object describing the child nodes.
- * @param childElem the DOM element used to parent the new TreeNodeView.
- * @param childValue the child's value.
- * @param idx the index of the child within its parent node.
- * @return a TreeNodeView of suitable type.
+ * @param <C> the data type of the node's children
+ * @param nodeInfo a NodeInfo object describing the child nodes
+ * @param childElem the DOM element used to parent the new TreeNodeView
+ * @param childValue the child's value
+ * @param viewData view data associated with the node
+ * @param idx the index of the child within its parent node
+ * @return a TreeNodeView of suitable type
*/
protected abstract <C> TreeNodeView<C> createTreeNodeView(NodeInfo<C>
nodeInfo,
- Element childElem, C childValue, int idx);
+ Element childElem, C childValue, Void viewData, int idx);
/**
* Write the HTML for a list of child values into the given
StringBuilder.
*
- * @param <C> the data type of the child nodes.
- * @param sb a StringBuilder to write to.
- * @param childValues a List of child node values.
+ * @param <C> the data type of the child nodes
+ * @param sb a StringBuilder to write to
+ * @param childValues a List of child node values
* @param savedViews a List of TreeNodeView instances corresponding to
* the child values; a non-null value indicates a TreeNodeView
previously
- * associated with a given child value.
- * @param cell the Cell to use for rendering each child value.
+ * associated with a given child value
+ * @param cell the Cell to use for rendering each child value
*/
protected abstract <C> void emitHtml(StringBuilder sb, List<C>
childValues,
- List<TreeNodeView<?>> savedViews, Cell<C> cell);
+ List<TreeNodeView<?>> savedViews, Cell<C, Void> cell);
/**
* Ensure that the animation frame exists and return it.
@@ -344,7 +345,7 @@
*
* @param nodeInfo the {...@link NodeInfo} that provides information about
the
* child values
- * @param <C> the child data type of the node.
+ * @param <C> the child data type of the node
*/
protected <C> void onOpen(final NodeInfo<C> nodeInfo) {
// Add a loading message.
@@ -396,7 +397,7 @@
int idx = 0;
for (C childValue : event.getValues()) {
TreeNodeView<C> child = createTreeNodeView(nodeInfo, childElem,
- childValue, idx);
+ childValue, null, idx);
TreeNodeView<?> savedChild =
map.get(nodeInfo.getKey(childValue));
// Copy the saved child's state into the new child
if (savedChild != null) {
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/TreeViewModel.java
Fri Mar 12 11:27:24 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/tree/client/TreeViewModel.java
Mon Mar 22 05:11:01 2010
@@ -35,7 +35,7 @@
*
* @return the cell
*/
- Cell<C> getCell();
+ Cell<C, Void> getCell();
/**
* Return a key that may be used to identify values that should
@@ -69,9 +69,9 @@
*/
class DefaultNodeInfo<C> implements NodeInfo<C> {
- private Cell<C> cell;
+ private Cell<C, Void> cell;
private ListModel<C> listModel;
- private ValueUpdater<C> valueUpdater;
+ private ValueUpdater<C, Void> valueUpdater;
/**
* Construct a new {...@link DefaultNodeInfo}.
@@ -79,7 +79,7 @@
* @param listModel the {...@link ListModel} that provides the child
values
* @param cell the {...@link Cell} used to render the child values
*/
- public DefaultNodeInfo(ListModel<C> listModel, Cell<C> cell) {
+ public DefaultNodeInfo(ListModel<C> listModel, Cell<C, Void> cell) {
this.cell = cell;
this.listModel = listModel;
}
@@ -91,13 +91,13 @@
* @param cell the {...@link Cell} used to render the child values
* @param valueUpdater the {...@link ValueUpdater}
*/
- public DefaultNodeInfo(ListModel<C> listModel, Cell<C> cell,
- ValueUpdater<C> valueUpdater) {
+ public DefaultNodeInfo(ListModel<C> listModel, Cell<C, Void> cell,
+ ValueUpdater<C, Void> valueUpdater) {
this(listModel, cell);
this.valueUpdater = valueUpdater;
}
- public Cell<C> getCell() {
+ public Cell<C, Void> getCell() {
return cell;
}
@@ -110,7 +110,7 @@
}
public void onBrowserEvent(Element elem, final C object, NativeEvent
event) {
- cell.onBrowserEvent(elem, object, event, valueUpdater);
+ cell.onBrowserEvent(elem, object, null, event, valueUpdater);
}
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
To unsubscribe from this group, send email to
google-web-toolkit-contributors+unsubscribegooglegroups.com or reply to this email with
the words "REMOVE ME" as the subject.