1

How would I go about changing the default MCheckBox state text (currently I/0) to, for example, YES/NO or ON/OFF?

Boris Brudnoy
  • 2,405
  • 18
  • 28

3 Answers3

3

Mr. Daniel Kurka is the author for all the widget classes in MGWT. If the look & feel is not fulfilling our requirement, We can edit those classes and rewrite them according to our requirement.Because they are open source. I done this on many classes like CellList,FormListEntry and MCheckBox. code for ON/OFF instead of I/O

public MyOwnCheckBox(CheckBoxCss css) {
    this.css = css;
    css.ensureInjected();
    setElement(DOM.createDiv());
    addStyleName(css.checkBox());

    onDiv = DOM.createDiv();
    onDiv.setClassName(css.on());
    onDiv.setInnerText("ON");
    getElement().appendChild(onDiv);

    middleDiv = DOM.createDiv();
    middleDiv.setClassName(css.middle());
    Element middleContent = DOM.createDiv();
    middleContent.setClassName(css.content());
    middleDiv.appendChild(middleContent);
    getElement().appendChild(middleDiv);

    offDiv = DOM.createDiv();
    offDiv.setClassName(css.off());
    offDiv.setInnerText("OFF");
    getElement().appendChild(offDiv);

    addTouchHandler(new TouchHandlerImplementation());

    setValue(true, false);

}

Write a new class like MyOwnCheckBox.just copy the code in MCheckBox and paste in your class MyOwnCheckBox, find and replace the MCheckBox with MyOwnCheckBox in the code(change constructor's name). do the following changes.

onDiv.setInnerText("ON");

offDiv.setInnerText("OFF");

and finally create object to MyOwnCheckBox rather MCheckBox, it'll shows MCheckBox with ON/OFF.

1

Right now there is no way to do that, but there is no real reasons that checkbox does not implement HasText other than we might need to update the css so that big text will not break the layout.

If you think mgwt should implement this go and vote for this issue: http://code.google.com/p/mgwt/issues/detail?id=171

Daniel Kurka
  • 7,973
  • 2
  • 24
  • 43
1

Well, an easy way to accomplish the same thing, without creating a new class that mimics MCheckBox, is to do something like the code below:

CheckBoxCss css = MGWTStyle.getTheme().getMGWTClientBundle().getCheckBoxCss();
String offClass = css.off();
String onClass = css.on();
NodeList<Node> checkBoxElems;

mIsSingleSkuBox = new MCheckBox(css);

checkBoxElems = mIsSingleSkuBox.getElement().getChildNodes();
for( int i = 0; i < checkBoxElems.getLength(); i++ )
{
    Element openElem = (Element) checkBoxElems.getItem(i);
    String className = openElem.getClassName();

    if( className.equals( offClass))
    {
        openElem.setInnerText("No" );
    }
    else if( className.equals( onClass))
    {
        openElem.setInnerText("Yes" );
    }
}

It will probably have space problems with anything longer than 3 characters, but it works consistently with "Yes" and "No" for me.

Tony B
  • 915
  • 1
  • 9
  • 24