Reviewers: pdr,
Description:
Making rendered Cells in CellWidgets fill the root element of the widget
so that setting the height/width of the Widget applies to the Cell.
Also making TextButton implement HasText so it can be used in UiBinder
files with a default string.
Please review this at http://gwt-code-reviews.appspot.com/1383807/
Affected files:
M user/src/com/google/gwt/user/cellview/client/CellWidget.java
M user/src/com/google/gwt/widget/client/TextButton.java
Index: user/src/com/google/gwt/user/cellview/client/CellWidget.java
===================================================================
--- user/src/com/google/gwt/user/cellview/client/CellWidget.java (revision
9879)
+++ user/src/com/google/gwt/user/cellview/client/CellWidget.java (working
copy)
@@ -20,6 +20,7 @@
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
@@ -36,8 +37,7 @@
*
* @param <C> the type that the Cell represents
*/
-public class CellWidget<C> extends Widget implements HasKeyProvider<C>,
- HasValue<C> {
+public class CellWidget<C> extends Widget implements HasKeyProvider<C>,
HasValue<C> {
/**
* Create the default element used to wrap the Cell. The default element
is a
@@ -128,8 +128,7 @@
* @param keyProvider the key provider used to get keys from values
* @param elem the browser element to use
*/
- protected CellWidget(Cell<C> cell, C initialValue,
- ProvidesKey<C> keyProvider, Element elem) {
+ protected CellWidget(Cell<C> cell, C initialValue, ProvidesKey<C>
keyProvider, Element elem) {
this.cell = cell;
this.keyProvider = keyProvider;
setElement(elem);
@@ -166,8 +165,7 @@
// Forward the event to the cell.
String eventType = event.getType();
if (cell.getConsumedEvents().contains(eventType)) {
- cell.onBrowserEvent(createContext(), getElement(), value, event,
- valueUpdater);
+ cell.onBrowserEvent(createContext(), getElement(), value, event,
valueUpdater);
}
}
@@ -178,6 +176,16 @@
SafeHtmlBuilder sb = new SafeHtmlBuilder();
cell.render(createContext(), value, sb);
getElement().setInnerHTML(sb.toSafeHtml().asString());
+
+ /*
+ * The rendered Cell should fill the root element so height and width
styles
+ * applied to the widget also apply to the Cell.
+ */
+ Element child = getElement().getFirstChildElement();
+ if (child != null) {
+ child.getStyle().setHeight(100, Unit.PCT);
+ child.getStyle().setWidth(100, Unit.PCT);
+ }
}
/**
@@ -240,7 +248,6 @@
* @return the key
*/
private Object getKey(C value) {
- return (keyProvider == null || value == null) ? value
- : keyProvider.getKey(value);
+ return (keyProvider == null || value == null) ? value :
keyProvider.getKey(value);
}
}
\ No newline at end of file
Index: user/src/com/google/gwt/widget/client/TextButton.java
===================================================================
--- user/src/com/google/gwt/widget/client/TextButton.java (revision 9879)
+++ user/src/com/google/gwt/widget/client/TextButton.java (working copy)
@@ -17,11 +17,12 @@
import com.google.gwt.cell.client.TextButtonCell;
import com.google.gwt.cell.client.TextButtonCell.Appearance;
+import com.google.gwt.user.client.ui.HasText;
/**
* A button that displays text and an optional icon.
*/
-public class TextButton extends ButtonBase<String> {
+public class TextButton extends ButtonBase<String> implements HasText {
/**
* Construct a new {@link TextButton} using the default {@link
Appearance}.
@@ -71,4 +72,12 @@
protected TextButton(TextButtonCell cell, String text) {
super(cell, text);
}
+
+ public String getText() {
+ return getValue();
+ }
+
+ public void setText(String text) {
+ setValue(text);
+ }
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors