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);
}
}
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));
}
}
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;
}
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;
}
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;
}
Aggregations