Search in sources :

Example 6 with ListProperty

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

the class DBTreeListClass method displayView.

@Override
public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    List<String> selectlist;
    BaseProperty prop = (BaseProperty) object.safeget(name);
    if (prop == null) {
        selectlist = new ArrayList<String>();
    } else if (prop instanceof ListProperty) {
        selectlist = ((ListProperty) prop).getList();
    } else {
        selectlist = new ArrayList<String>();
        selectlist.add(String.valueOf(prop.getValue()));
    }
    String result = displayFlatView(selectlist, context);
    if (result.equals("")) {
        super.displayView(buffer, name, prefix, object, context);
    } else {
        buffer.append(result);
    }
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) ArrayList(java.util.ArrayList) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 7 with ListProperty

use of com.xpn.xwiki.objects.ListProperty 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 8 with ListProperty

use of com.xpn.xwiki.objects.ListProperty 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 9 with ListProperty

use of com.xpn.xwiki.objects.ListProperty 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)

Example 10 with ListProperty

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

the class ListClass method toFormString.

/**
 * Used in {@link #displayEdit(StringBuffer, String, String, BaseCollection, XWikiContext)}.
 *
 * @param property a property to be used in an form input
 * @return the text value to be used in an form input. If a {@link ListProperty} is passed, the list's separators
 *         defined by {@link #getSeparators()} are escaped for each list item and the items are joined by the first
 *         separator
 * @see #getStringFromList(List, String)
 */
public String toFormString(BaseProperty property) {
    String result;
    if (property instanceof ListProperty) {
        ListProperty listProperty = (ListProperty) property;
        result = ListClass.getStringFromList(listProperty.getList(), getSeparators());
    } else {
        result = property.toText();
    }
    return result;
}
Also used : StringListProperty(com.xpn.xwiki.objects.StringListProperty) ListProperty(com.xpn.xwiki.objects.ListProperty) DBStringListProperty(com.xpn.xwiki.objects.DBStringListProperty)

Aggregations

ListProperty (com.xpn.xwiki.objects.ListProperty)12 BaseProperty (com.xpn.xwiki.objects.BaseProperty)7 ArrayList (java.util.ArrayList)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 DBStringListProperty (com.xpn.xwiki.objects.DBStringListProperty)4 StringListProperty (com.xpn.xwiki.objects.StringListProperty)4 Test (org.junit.Test)3 StringProperty (com.xpn.xwiki.objects.StringProperty)2 XWikiException (com.xpn.xwiki.XWikiException)1 XMLAttributeValueFilter (com.xpn.xwiki.internal.xml.XMLAttributeValueFilter)1 BaseCollection (com.xpn.xwiki.objects.BaseCollection)1 BaseStringProperty (com.xpn.xwiki.objects.BaseStringProperty)1 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 org.apache.ecs.xhtml.select (org.apache.ecs.xhtml.select)1 Element (org.dom4j.Element)1 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)1 Session (org.hibernate.Session)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1