use of com.vaadin.v7.data.Property in project magnolia-vanity-url by aperto.
the class UniqueVanityUrlValidatorTest method customizeItem.
private void customizeItem(final JcrNodeAdapter item) throws RepositoryException {
Property property = mock(Property.class);
when(property.getValue()).thenReturn("site");
when(item.getItemProperty(PN_SITE)).thenReturn(property);
}
use of com.vaadin.v7.data.Property in project cuba by cuba-platform.
the class AbbreviatedColumnGenerator method generateCell.
@Override
public Object generateCell(com.vaadin.v7.ui.Table source, Object itemId, Object columnId) {
Property property = source.getItem(itemId).getItemProperty(columnId);
Object value = property.getValue();
if (value == null) {
return null;
}
String stringValue = value.toString();
if (columnId instanceof MetaPropertyPath) {
MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
stringValue = dynamicAttributesTools.getDynamicAttributeValueAsString(metaProperty, value);
}
}
String cellValue = stringValue;
boolean isMultiLineCell = StringUtils.contains(stringValue, "\n");
if (isMultiLineCell) {
cellValue = StringUtils.replaceChars(cellValue, '\n', ' ');
}
int maxTextLength = column.getMaxTextLength();
if (stringValue.length() > maxTextLength + MAX_TEXT_LENGTH_GAP || isMultiLineCell) {
return StringUtils.abbreviate(cellValue, maxTextLength);
} else {
return cellValue;
}
}
use of com.vaadin.v7.data.Property in project cuba by cuba-platform.
the class WebAbstractTable method formatCellValue.
protected String formatCellValue(Object rowId, Object colId, @Nullable Property<?> property) {
TableItems<E> tableItems = getItems();
if (tableItems == null || tableItems.getState() == BindingState.INACTIVE) {
return null;
}
Column<E> column = columns.get(colId);
if (column != null && column.getValueProvider() != null) {
E item = tableItems.getItem(rowId);
Object generatedValue = column.getValueProvider().apply(item);
Function<Object, String> formatter = column.getFormatter();
if (formatter != null) {
return column.getFormatter().apply(generatedValue);
}
return metadataTools.format(generatedValue);
}
Object cellValue;
if (ignoreUnfetchedAttributes && colId instanceof MetaPropertyPath) {
E item = tableItems.getItem(rowId);
cellValue = getValueExIgnoreUnfetched(item, ((MetaPropertyPath) colId).getPath());
} else if (property != null) {
cellValue = property.getValue();
} else {
cellValue = null;
}
if (colId instanceof MetaPropertyPath) {
MetaPropertyPath propertyPath = (MetaPropertyPath) colId;
if (column != null) {
if (column.getFormatter() != null) {
return column.getFormatter().apply(cellValue);
} else if (column.getXmlDescriptor() != null) {
// vaadin8 move to Column
String captionProperty = column.getXmlDescriptor().attributeValue("captionProperty");
if (StringUtils.isNotEmpty(captionProperty)) {
E item = getItems().getItemNN(rowId);
Object captionValue = item.getValueEx(captionProperty);
return captionValue != null ? String.valueOf(captionValue) : null;
}
}
}
return metadataTools.format(cellValue, propertyPath.getMetaProperty());
}
if (cellValue == null) {
return "";
}
if (!(cellValue instanceof Component)) {
return metadataTools.format(cellValue);
}
// fallback to Vaadin formatting
UI ui = component.getUI();
VaadinSession session = ui != null ? ui.getSession() : null;
Converter converter = ConverterUtil.getConverter(String.class, property.getType(), session);
if (converter != null) {
return (String) converter.convertToPresentation(cellValue, String.class, locale);
}
return cellValue.toString();
}
use of com.vaadin.v7.data.Property in project charts by vaadin.
the class ContainerDataSeriesBeanSerializer method createDataArray.
private ArrayNode createDataArray(Container container, Map<String, Object> pidMap) {
ArrayNode data = JsonNodeFactory.instance.arrayNode();
Mode mode = null;
for (Object o : pidMap.keySet()) {
if (!(o.equals(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1) || o.equals(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2))) {
mode = Mode.OBJECT;
break;
}
}
Object xProperty = pidMap.get(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1);
if (xProperty == null) {
xProperty = ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1;
}
Object yProperty = pidMap.get(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2);
if (yProperty == null) {
yProperty = ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2;
}
checkRequiredProperties(container, pidMap, yProperty);
if (mode != Mode.OBJECT) {
if (container.getContainerPropertyIds().contains(xProperty)) {
mode = Mode.XY;
} else {
mode = Mode.ONLY_Y;
}
}
for (Object iid : container.getItemIds()) {
Item item = container.getItem(iid);
switch(mode) {
case ONLY_Y:
addValue(data, item.getItemProperty(yProperty));
break;
case XY:
Property itemPropertyX = item.getItemProperty(xProperty);
Property itemPropertyY = item.getItemProperty(yProperty);
if (itemPropertyX.getValue() != null && itemPropertyY.getValue() != null) {
ArrayNode entryArray = JsonNodeFactory.instance.arrayNode();
data.add(entryArray);
addValue(entryArray, itemPropertyX);
addValue(entryArray, itemPropertyY);
} else {
data.addNull();
}
break;
default:
// render as json object
ObjectNode entryObject = JsonNodeFactory.instance.objectNode();
Property<?> x = item.getItemProperty(xProperty);
if (x != null) {
addNamedValue(entryObject, ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1, x);
}
Property<?> y = item.getItemProperty(yProperty);
if (y != null) {
addNamedValue(entryObject, ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2, y);
}
Iterator<String> iter = pidMap.keySet().iterator();
while (iter.hasNext()) {
String name = iter.next();
Object id = pidMap.get(name);
if (!id.equals(xProperty) && !id.equals(yProperty)) {
addNamedValue(entryObject, name, item.getItemProperty(id));
}
}
data.add(entryObject);
break;
}
}
return data;
}
Aggregations