Search in sources :

Example 1 with Property

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);
}
Also used : Property(com.vaadin.v7.data.Property)

Example 2 with 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;
    }
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Property(com.vaadin.v7.data.Property) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 3 with Property

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();
}
Also used : AppUI(com.haulmont.cuba.web.AppUI) CubaUI(com.haulmont.cuba.web.widgets.CubaUI) VaadinSession(com.vaadin.server.VaadinSession) Converter(com.vaadin.v7.data.util.converter.Converter) Component(com.vaadin.ui.Component)

Example 4 with Property

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;
}
Also used : Item(com.vaadin.v7.data.Item) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Property(com.vaadin.v7.data.Property)

Aggregations

Property (com.vaadin.v7.data.Property)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 AppUI (com.haulmont.cuba.web.AppUI)1 CubaUI (com.haulmont.cuba.web.widgets.CubaUI)1 VaadinSession (com.vaadin.server.VaadinSession)1 Component (com.vaadin.ui.Component)1 Item (com.vaadin.v7.data.Item)1 Converter (com.vaadin.v7.data.util.converter.Converter)1