Example usage for com.vaadin.v7.data Property getValue

List of usage examples for com.vaadin.v7.data Property getValue

Introduction

In this page you can find the example usage for com.vaadin.v7.data Property getValue.

Prototype

public T getValue();

Source Link

Document

Gets the value stored in the Property.

Usage

From source file:com.haulmont.cuba.web.gui.components.table.AbbreviatedColumnGenerator.java

License:Apache License

@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;
    }/*from w ww.  j av a  2 s  .  c om*/

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

From source file:com.haulmont.cuba.web.widgets.renderers.componentrenderer.grid.editor.ComponentCustomField.java

License:Apache License

@Override
public void setPropertyDataSource(Property newDataSource) {
    super.setPropertyDataSource(newDataSource);

    if (newDataSource != null) {
        layout.removeAllComponents();/*ww w  . j av  a2  s.c o  m*/
        Component value = (Component) newDataSource.getValue();
        if (value != null) {
            layout.addComponent(value);
        }
    }
}

From source file:de.symeda.sormas.ui.utils.RoleFilter.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from w  ww.  j  a v a  2s  .  com
public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
    final Property<?> p = item.getItemProperty(getPropertyId());
    if (null == p) {
        return false;
    }
    Collection<UserRole> roles = (Collection<UserRole>) p.getValue();
    for (UserRole role : roles) {
        if (compareEquals(roleToFilter, role)) {
            return true;
        }
    }

    // all cases should have been processed above
    return false;
}

From source file:de.symeda.sormas.ui.utils.V7GridExportStreamResource.java

License:Open Source License

public V7GridExportStreamResource(Indexed container, List<Column> gridColumns, String tempFilePrefix,
        String filename, String... ignoredPropertyIds) {
    super(new StreamSource() {
        @Override/*www. j  a  v a 2 s.  c  om*/
        public InputStream getStream() {
            List<String> ignoredPropertyIdsList = Arrays.asList(ignoredPropertyIds);
            List<Column> columns = new ArrayList<>(gridColumns);
            columns.removeIf(c -> c.isHidden());
            columns.removeIf(c -> ignoredPropertyIdsList.contains(c.getPropertyId()));
            Collection<?> itemIds = container.getItemIds();

            try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream()) {
                try (CSVWriter writer = CSVUtils.createCSVWriter(
                        new OutputStreamWriter(byteStream, StandardCharsets.UTF_8.name()),
                        FacadeProvider.getConfigFacade().getCsvSeparator())) {

                    List<String> headerRow = new ArrayList<>();
                    columns.forEach(c -> {
                        headerRow.add(c.getHeaderCaption());
                    });
                    writer.writeNext(headerRow.toArray(new String[headerRow.size()]));

                    itemIds.forEach(i -> {
                        List<String> row = new ArrayList<>();
                        columns.forEach(c -> {
                            Property<?> property = container.getItem(i).getItemProperty(c.getPropertyId());
                            if (property.getValue() != null) {
                                if (property.getType() == Date.class) {
                                    row.add(DateHelper.formatLocalDateTime((Date) property.getValue()));
                                } else if (property.getType() == Boolean.class) {
                                    if ((Boolean) property.getValue() == true) {
                                        row.add(I18nProperties.getEnumCaption(YesNoUnknown.YES));
                                    } else
                                        row.add(I18nProperties.getEnumCaption(YesNoUnknown.NO));
                                } else {
                                    row.add(property.getValue().toString());
                                }
                            } else {
                                row.add("");
                            }
                        });

                        writer.writeNext(row.toArray(new String[row.size()]));
                    });

                    writer.flush();
                }
                return new BufferedInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
            } catch (IOException e) {
                // TODO This currently requires the user to click the "Export" button again or reload the page as the UI
                // is not automatically updated; this should be changed once Vaadin push is enabled (see #516)
                new Notification(I18nProperties.getString(Strings.headingExportFailed),
                        I18nProperties.getString(Strings.messageExportFailed), Type.ERROR_MESSAGE, false)
                                .show(Page.getCurrent());
                return null;
            }
        }
    }, filename);
    setMIMEType("text/csv");
    setCacheTime(0);
}