Search in sources :

Example 1 with XMLAttributeValueFilter

use of com.xpn.xwiki.internal.xml.XMLAttributeValueFilter in project xwiki-platform by xwiki.

the class BooleanClass method displaySelectEdit.

public void displaySelectEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    select select = new select(prefix + name, 1);
    select.setAttributeFilter(new XMLAttributeValueFilter());
    select.setName(prefix + name);
    select.setID(prefix + name);
    select.setDisabled(isDisabled());
    String String0 = getDisplayValue(context, 0);
    String String1 = getDisplayValue(context, 1);
    int nb1 = 1;
    int nb2 = 2;
    option[] options;
    if (getDefaultValue() == -1) {
        options = new option[] { new option("---", ""), new option(String1, "1"), new option(String0, "0") };
        options[0].addElement("---");
        options[1].addElement(XMLUtils.escape(String1));
        options[2].addElement(XMLUtils.escape(String0));
    } else {
        options = new option[] { new option(String1, "1"), new option(String0, "0") };
        options[0].addElement(XMLUtils.escape(String1));
        options[1].addElement(XMLUtils.escape(String0));
        nb1 = 0;
        nb2 = 1;
    }
    for (option option : options) {
        option.setAttributeFilter(new XMLAttributeValueFilter());
    }
    try {
        IntegerProperty prop = (IntegerProperty) object.safeget(name);
        Integer ivalue = (prop == null) ? null : (Integer) prop.getValue();
        if (ivalue != null) {
            int value = ivalue.intValue();
            if (value == 1) {
                options[nb1].setSelected(true);
            } else if (value == 0) {
                options[nb2].setSelected(true);
            }
        } else {
            int value = getDefaultValue();
            if (value == 1) {
                options[nb1].setSelected(true);
            } else if (value == 0) {
                options[nb2].setSelected(true);
            } else if (value == -1) {
                options[0].setSelected(true);
            }
        }
    } catch (Exception e) {
        // This should not happen
        e.printStackTrace();
    }
    select.addElement(options);
    buffer.append(select.toString());
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) org.apache.ecs.xhtml.option(org.apache.ecs.xhtml.option)

Example 2 with XMLAttributeValueFilter

use of com.xpn.xwiki.internal.xml.XMLAttributeValueFilter in project xwiki-platform by xwiki.

the class BooleanClass method displayRadioEdit.

public void displayRadioEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    String StringNone = getDisplayValue(context, 2);
    String StringTrue = getDisplayValue(context, 1);
    String StringFalse = getDisplayValue(context, 0);
    div[] inputs;
    input radioNone = new input(input.radio, prefix + name, "");
    radioNone.setAttributeFilter(new XMLAttributeValueFilter());
    input radioTrue = new input(input.radio, prefix + name, "1");
    radioTrue.setAttributeFilter(new XMLAttributeValueFilter());
    input radioFalse = new input(input.radio, prefix + name, "0");
    radioFalse.setAttributeFilter(new XMLAttributeValueFilter());
    radioNone.setDisabled(isDisabled());
    radioTrue.setDisabled(isDisabled());
    radioFalse.setDisabled(isDisabled());
    label labelNone = new label();
    label labelTrue = new label();
    label labelFalse = new label();
    div divNone = new div();
    div divTrue = new div();
    div divFalse = new div();
    labelNone.addElement(radioNone);
    labelNone.addElement(StringNone);
    divNone.addElement(labelNone);
    labelTrue.addElement(radioTrue);
    labelTrue.addElement(StringTrue);
    divTrue.addElement(labelTrue);
    labelFalse.addElement(radioFalse);
    labelFalse.addElement(StringFalse);
    divFalse.addElement(labelFalse);
    radioNone.setID(prefix + name + "_none");
    labelNone.setFor(prefix + name + "_none");
    radioTrue.setID(prefix + name);
    labelTrue.setFor(prefix + name);
    radioFalse.setID(prefix + name + "_false");
    labelFalse.setFor(prefix + name + "_false");
    if (getDefaultValue() == -1) {
        inputs = new div[] { divNone, divTrue, divFalse };
    } else {
        inputs = new div[] { divTrue, divFalse };
    }
    try {
        IntegerProperty prop = (IntegerProperty) object.safeget(name);
        Integer ivalue = (prop == null) ? null : (Integer) prop.getValue();
        if (ivalue != null) {
            int value = ivalue.intValue();
            if (value == 1) {
                radioTrue.setChecked(true);
            } else if (value == 0) {
                radioFalse.setChecked(true);
            }
        } else {
            int value = getDefaultValue();
            if (value == 1) {
                radioTrue.setChecked(true);
            } else if (value == 0) {
                radioFalse.setChecked(true);
            } else if (value == -1) {
                radioNone.setChecked(true);
            }
        }
    } catch (Exception e) {
        // This should not happen
        e.printStackTrace();
    }
    for (div input : inputs) {
        buffer.append(input.toString());
    }
}
Also used : org.apache.ecs.xhtml.div(org.apache.ecs.xhtml.div) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) org.apache.ecs.xhtml.label(org.apache.ecs.xhtml.label)

Example 3 with XMLAttributeValueFilter

use of com.xpn.xwiki.internal.xml.XMLAttributeValueFilter in project xwiki-platform by xwiki.

the class PasswordClass method displayEdit.

@Override
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    input input = new input();
    input.setAttributeFilter(new XMLAttributeValueFilter());
    BaseProperty prop = (BaseProperty) object.safeget(name);
    // the property is set.
    if (prop != null && !StringUtils.isEmpty(prop.toText())) {
        input.setValue(FORM_PASSWORD_PLACEHODLER);
    }
    input.setType("password");
    input.setName(prefix + name);
    input.setID(prefix + name);
    input.setSize(getSize());
    input.setDisabled(isDisabled());
    buffer.append(input.toString());
}
Also used : org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 4 with XMLAttributeValueFilter

use of com.xpn.xwiki.internal.xml.XMLAttributeValueFilter in project xwiki-platform by xwiki.

the class PropertyClass method displayHidden.

@Override
public void displayHidden(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    input input = new input();
    input.setAttributeFilter(new XMLAttributeValueFilter());
    BaseProperty prop = (BaseProperty) object.safeget(name);
    if (prop != null) {
        input.setValue(prop.toText());
    }
    input.setType("hidden");
    input.setName(prefix + name);
    input.setID(prefix + name);
    buffer.append(input.toString());
}
Also used : org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 5 with XMLAttributeValueFilter

use of com.xpn.xwiki.internal.xml.XMLAttributeValueFilter in project xwiki-platform by xwiki.

the class StaticListClass method displayEdit.

@Override
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    if (getDisplayType().equals(DISPLAYTYPE_INPUT)) {
        input input = new input();
        input.setAttributeFilter(new XMLAttributeValueFilter());
        BaseProperty prop = (BaseProperty) object.safeget(name);
        if (prop != null) {
            input.setValue(this.toFormString(prop));
        }
        input.setType("text");
        input.setSize(getSize());
        input.setName(prefix + name);
        input.setID(prefix + name);
        input.setDisabled(isDisabled());
        if (isPicker()) {
            input.setClass("suggested");
            String path = "";
            XWiki xwiki = context.getWiki();
            path = xwiki.getURL("Main.WebHome", "view", context);
            String classname = this.getObject().getName();
            String fieldname = this.getName();
            String secondCol = "-", firstCol = "-";
            String script = "\"" + path + "?xpage=suggest&classname=" + classname + "&fieldname=" + fieldname + "&firCol=" + firstCol + "&secCol=" + secondCol + "&\"";
            String varname = "\"input\"";
            String seps = "\"" + this.getSeparators() + "\"";
            if (isMultiSelect()) {
                input.setOnFocus("new ajaxSuggest(this, {script:" + script + ", varname:" + varname + ", seps:" + seps + "} )");
            } else {
                input.setOnFocus("new ajaxSuggest(this, {script:" + script + ", varname:" + varname + "} )");
            }
        }
        buffer.append(input.toString());
    } else if (getDisplayType().equals(DISPLAYTYPE_RADIO) || getDisplayType().equals(DISPLAYTYPE_CHECKBOX)) {
        displayRadioEdit(buffer, name, prefix, object, context);
    } else {
        displaySelectEdit(buffer, name, prefix, object, context);
        // We need a hidden input with an empty value to be able to clear the selected values from the above select
        // when it has multiple selection enabled and no value selected.
        org.apache.ecs.xhtml.input hidden = new input(input.hidden, prefix + name, "");
        hidden.setAttributeFilter(new XMLAttributeValueFilter());
        hidden.setDisabled(isDisabled());
        buffer.append(hidden);
    }
}
Also used : org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) XWiki(com.xpn.xwiki.XWiki) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Aggregations

XMLAttributeValueFilter (com.xpn.xwiki.internal.xml.XMLAttributeValueFilter)16 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)13 BaseProperty (com.xpn.xwiki.objects.BaseProperty)12 org.apache.ecs.xhtml.select (org.apache.ecs.xhtml.select)4 XWiki (com.xpn.xwiki.XWiki)3 IntegerProperty (com.xpn.xwiki.objects.IntegerProperty)3 org.apache.ecs.xhtml.option (org.apache.ecs.xhtml.option)3 ListProperty (com.xpn.xwiki.objects.ListProperty)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 org.apache.ecs.xhtml.div (org.apache.ecs.xhtml.div)1 org.apache.ecs.xhtml.label (org.apache.ecs.xhtml.label)1