Search in sources :

Example 56 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class LevelsClass method fromString.

@Override
public BaseProperty fromString(String value) {
    BaseProperty prop = newProperty();
    prop.setValue(value);
    return prop;
}
Also used : BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 57 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class LevelsClass method displayEdit.

@Override
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    select select = new select(prefix + name, 1);
    select.setAttributeFilter(new XMLAttributeValueFilter());
    select.setMultiple(isMultiSelect());
    select.setSize(getSize());
    select.setName(prefix + name);
    select.setID(prefix + name);
    select.setDisabled(isDisabled());
    List<String> list = getList(context);
    BaseProperty prop = (BaseProperty) object.safeget(name);
    List<String> selectlist = toList(prop);
    // Add options from Set
    for (String value : list) {
        String display = getText(value, context);
        option option = new option(display, value);
        option.setAttributeFilter(new XMLAttributeValueFilter());
        option.addElement(XMLUtils.escape(display));
        // If we don't have this option in the list then add it
        if (!list.contains(value)) {
            list.add(value);
        }
        if (selectlist.contains(value)) {
            option.setSelected(true);
        }
        select.addElement(option);
    }
    buffer.append(select.toString());
    input in = new input();
    in.setAttributeFilter(new XMLAttributeValueFilter());
    in.setType("hidden");
    in.setName(prefix + name);
    in.setDisabled(isDisabled());
    buffer.append(in.toString());
}
Also used : org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) BaseProperty(com.xpn.xwiki.objects.BaseProperty) org.apache.ecs.xhtml.option(org.apache.ecs.xhtml.option)

Example 58 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class ListClass method displayView.

@Override
public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    List<String> selectlist;
    String separator = getSeparator();
    BaseProperty prop = (BaseProperty) object.safeget(name);
    Map<String, ListItem> map = getMap(context);
    // Skip unset values.
    if (prop == null) {
        return;
    }
    if (prop instanceof ListProperty) {
        selectlist = ((ListProperty) prop).getList();
        List<String> newlist = new ArrayList<>();
        for (String value : selectlist) {
            newlist.add(getDisplayValue(value, name, map, context));
        }
        buffer.append(StringUtils.join(newlist, separator));
    } else {
        buffer.append(getDisplayValue(prop.getValue(), name, map, context));
    }
}
Also used : StringListProperty(com.xpn.xwiki.objects.StringListProperty) ListProperty(com.xpn.xwiki.objects.ListProperty) DBStringListProperty(com.xpn.xwiki.objects.DBStringListProperty) ArrayList(java.util.ArrayList) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 59 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class ListClass method fromStringArray.

@Override
public BaseProperty fromStringArray(String[] strings) {
    if (!isMultiSelect()) {
        return fromString(strings[0]);
    }
    BaseProperty prop = newProperty();
    if (prop instanceof StringProperty) {
        return fromString(strings[0]);
    }
    List<String> list = new ArrayList<>();
    if (strings.length == 0) {
        return prop;
    }
    if ((strings.length == 1) && (getDisplayType().equals(DISPLAYTYPE_INPUT) || isMultiSelect())) {
        ((ListProperty) prop).setList(getListFromString(strings[0], getSeparators(), false));
        return prop;
    }
    // If Multiselect and multiple results
    for (String item : strings) {
        if (!item.trim().equals("")) {
            list.add(item);
        }
    }
    // setList will copy the list, so this call must be made last.
    ((ListProperty) prop).setList(list);
    return prop;
}
Also used : StringListProperty(com.xpn.xwiki.objects.StringListProperty) ListProperty(com.xpn.xwiki.objects.ListProperty) DBStringListProperty(com.xpn.xwiki.objects.DBStringListProperty) ArrayList(java.util.ArrayList) StringProperty(com.xpn.xwiki.objects.StringProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 60 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class ListClass method newPropertyfromXML.

@Override
public BaseProperty newPropertyfromXML(Element ppcel) {
    if (!isMultiSelect()) {
        return super.newPropertyfromXML(ppcel);
    }
    @SuppressWarnings("unchecked") List<Element> elist = ppcel.elements(ListXarObjectPropertySerializer.ELEMENT_VALUE);
    BaseProperty lprop = newProperty();
    if (lprop instanceof ListProperty) {
        List<String> llist = ((ListProperty) lprop).getList();
        for (int i = 0; i < elist.size(); i++) {
            Element el = elist.get(i);
            llist.add(el.getText());
        }
    } else {
        for (int i = 0; i < elist.size(); i++) {
            Element el = elist.get(i);
            ((StringProperty) lprop).setValue(el.getText());
        }
    }
    return lprop;
}
Also used : StringListProperty(com.xpn.xwiki.objects.StringListProperty) ListProperty(com.xpn.xwiki.objects.ListProperty) DBStringListProperty(com.xpn.xwiki.objects.DBStringListProperty) Element(org.dom4j.Element) StringProperty(com.xpn.xwiki.objects.StringProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Aggregations

BaseProperty (com.xpn.xwiki.objects.BaseProperty)87 BaseObject (com.xpn.xwiki.objects.BaseObject)26 ArrayList (java.util.ArrayList)16 XWikiException (com.xpn.xwiki.XWikiException)14 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)12 XMLAttributeValueFilter (com.xpn.xwiki.internal.xml.XMLAttributeValueFilter)12 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)11 XWikiContext (com.xpn.xwiki.XWikiContext)10 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)9 DocumentReference (org.xwiki.model.reference.DocumentReference)9 StringProperty (com.xpn.xwiki.objects.StringProperty)8 ListProperty (com.xpn.xwiki.objects.ListProperty)7 XWiki (com.xpn.xwiki.XWiki)5 BaseCollection (com.xpn.xwiki.objects.BaseCollection)5 LargeStringProperty (com.xpn.xwiki.objects.LargeStringProperty)5 List (java.util.List)5 Test (org.junit.Test)5 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)5 DBStringListProperty (com.xpn.xwiki.objects.DBStringListProperty)4 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)4