Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Very useful. Here is my take on a conditionally rendered <code>CheckboxCell<code></p> <pre> import com.google.gwt.cell.client.AbstractCell; import com.google.gwt.cell.client.CheckboxCell; import com.google.gwt.cell.client.ValueUpdater; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.EventTarget; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; /** * <code>CheckboxCell</code> that is conditionally rendered if the enclosing column's * Boolean com.google.gwt.user.cellview.client.Column.getValue(T object)</code> method returns true</code>. */ public class ConditionallyRenderedCheckboxCell extends AbstractCell { public ConditionallyRenderedCheckboxCell() { //We handle the same events as CheckboxCell super("change", "keydown"); } private CheckboxCell cell = null; @Override public void render(Context context, Boolean renderCheckboxCell, SafeHtmlBuilder sb) { if (renderCheckboxCell) { this.cell = new CheckboxCell(false,true); //Render the checkbox cell unchecked this.cell.render(context, false, sb); } } @Override public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context, Element parent, Boolean value, NativeEvent event, ValueUpdater valueUpdater) { //If we have created a checkbox cell, do event handling, otherwise, ignore it. if( this.cell != null ){ super.onBrowserEvent(context, parent, value, event, valueUpdater); // Handle the change event. if ("change".equals(event.getType())) { // Ignore events that occur outside of the outermost element. EventTarget eventTarget = event.getEventTarget(); if (parent.isOrHasChild(Element.as(eventTarget))) { // Use this to get the selected element!! Element el = Element.as(eventTarget); //Check if we really clicked on the checkbox if (el.getNodeName().equalsIgnoreCase("input") && el.getPropertyString("type").equalsIgnoreCase("checkbox")) { //If an value updater was defined, invoke it if(valueUpdater != null) valueUpdater.update(el.getPropertyBoolean("checked")); } } } } } } </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload