Java tutorial
/** * Sencha GXT 3.1.2 - Sencha for GWT * Copyright(c) 2007-2014, Sencha, Inc. * licensing@sencha.com * * http://www.sencha.com/products/gxt/license/ */ package org.ringstephanais.theme.gestionclub.base.client.base.field; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.InputElement; import com.google.gwt.dom.client.LabelElement; import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.sencha.gxt.cell.core.client.form.CheckBoxCell; import com.sencha.gxt.core.client.dom.XDOM; import com.sencha.gxt.core.client.dom.XElement; public class Css3CheckBoxAppearance extends Css3ValueBaseFieldAppearance implements CheckBoxCell.CheckBoxAppearance { public interface Css3CheckBoxResources extends Css3ValueBaseFieldResources, ClientBundle { @Source({ "Css3ValueBaseField.css", "Css3CheckBox.css" }) Css3CheckBoxStyle style(); } public interface Css3CheckBoxStyle extends Css3ValueBaseFieldStyle { String checkBoxLabel(); } protected final Css3CheckBoxResources resources; protected final Css3CheckBoxStyle style; protected String type = "checkbox"; public Css3CheckBoxAppearance() { this(GWT.<Css3CheckBoxResources>create(Css3CheckBoxResources.class)); } public Css3CheckBoxAppearance(Css3CheckBoxResources resources) { super(resources); this.resources = resources; this.style = resources.style(); } @Override public void render(SafeHtmlBuilder sb, Boolean value, CheckBoxCell.CheckBoxCellOptions options) { String checkBoxId = XDOM.getUniqueId(); String nameParam = options.getName() != null ? " name='" + options.getName() + "' " : ""; String disabledParam = options.isDisabled() ? " disabled=true" : ""; String readOnlyParam = options.isReadonly() ? " readonly" : ""; String idParam = " id=" + checkBoxId; String typeParam = " type=" + type; String checkedParam = value ? " checked" : ""; sb.appendHtmlConstant("<div class=" + style.wrap() + ">"); sb.appendHtmlConstant( "<input " + typeParam + nameParam + disabledParam + readOnlyParam + idParam + checkedParam + " />"); sb.appendHtmlConstant("<label for=" + checkBoxId + " class=" + style.checkBoxLabel() + ">"); if (options.getBoxLabel() != null) { sb.appendHtmlConstant(options.getBoxLabel()); } sb.appendHtmlConstant("</label></div>"); } @Override public void setBoxLabel(String boxLabel, XElement parent) { parent.selectNode("." + resources.style().checkBoxLabel()).<LabelElement>cast().setInnerHTML(boxLabel); } @Override public XElement getInputElement(Element parent) { return parent.<XElement>cast().selectNode("input"); } @Override public void setReadOnly(Element parent, boolean readOnly) { getInputElement(parent).<InputElement>cast().setReadOnly(readOnly); } @Override public void onEmpty(Element parent, boolean empty) { } @Override public void onFocus(Element parent, boolean focus) { // Override method to prevent outline from being applied to check boxes on // focus } @Override public void onValid(Element parent, boolean valid) { // no-op, cb is true or false... } }