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