Search in sources :

Example 6 with AbstractLayout

use of com.vaadin.ui.AbstractLayout in project VaadinUtils by rlsutton1.

the class ContainerCSVExport method writeRow.

private void writeRow(CSVWriter writer, Table table, Object id, Set<Object> properties) {
    Item item = table.getItem(id);
    String[] values = new String[properties.size() + extraColumnHeadersAndPropertyIds.size()];
    int i = 0;
    for (Object propertyId : properties) {
        @SuppressWarnings("rawtypes") final Property itemProperty = item.getItemProperty(propertyId);
        if (itemProperty != null && itemProperty.getValue() != null) {
            ColumnGenerator generator = table.getColumnGenerator(propertyId);
            if (generator != null && itemProperty.getType() != Boolean.class) {
                Object value = generator.generateCell(table, id, propertyId);
                if (value instanceof Label) {
                    value = new HtmlToPlainText().getPlainText(Jsoup.parse(((Label) value).getValue()));
                }
                if (value instanceof AbstractLayout) {
                    value = new HtmlToPlainText().getPlainText(Jsoup.parse(itemProperty.getValue().toString()));
                }
                if (value instanceof Link) {
                    value = new HtmlToPlainText().getPlainText(Jsoup.parse(itemProperty.getValue().toString()));
                }
                if (value != null) {
                    values[i++] = value.toString();
                }
            } else {
                values[i++] = itemProperty.getValue().toString();
            }
        } else {
            ColumnGenerator generator = table.getColumnGenerator(propertyId);
            if (generator != null) {
                Object value = generator.generateCell(table, id, propertyId);
                if (value != null) {
                    if (value instanceof ClickableLabel) {
                        value = new HtmlToPlainText().getPlainText(Jsoup.parse(((ClickableLabel) value).getValue()));
                    }
                    if (value instanceof Label) {
                        value = new HtmlToPlainText().getPlainText(Jsoup.parse(((Label) value).getValue()));
                    // value = ((Label) value).getValue();
                    }
                    if (value instanceof AbstractLayout) {
                        // set a string using setData() on the layout.
                        if (((AbstractLayout) value).getData() instanceof ContainerCSVExportData) {
                            value = ((AbstractLayout) value).getData().toString();
                        } else {
                            value = "";
                        }
                    }
                    if (value instanceof Link) {
                        value = new HtmlToPlainText().getPlainText(Jsoup.parse(((Link) value).getCaption()));
                    }
                }
                if (value == null) {
                    value = "";
                }
                values[i++] = value.toString();
            } else {
                values[i++] = "";
            }
        }
    }
    for (Object columnId : extraColumnHeadersAndPropertyIds.values()) {
        String value = getValueForExtraColumn(item, columnId);
        if (value == null) {
            value = "";
        }
        values[i++] = value;
    }
    writer.writeNext(values);
}
Also used : HtmlToPlainText(org.jsoup.examples.HtmlToPlainText) ClickableLabel(au.com.vaadinutils.fields.ClickableLabel) Label(com.vaadin.ui.Label) Item(com.vaadin.data.Item) ColumnGenerator(com.vaadin.ui.Table.ColumnGenerator) ClickableLabel(au.com.vaadinutils.fields.ClickableLabel) AbstractLayout(com.vaadin.ui.AbstractLayout) Property(com.vaadin.data.Property) Link(com.vaadin.ui.Link)

Example 7 with AbstractLayout

use of com.vaadin.ui.AbstractLayout in project VaadinUtils by rlsutton1.

the class SearchableSelectableEntityTable method buildSearchBar.

protected AbstractLayout buildSearchBar() {
    VerticalLayout layout = new VerticalLayout();
    layout.setWidth(100, Unit.PERCENTAGE);
    searchField.setWidth(100, Unit.PERCENTAGE);
    searchBar = layout;
    HorizontalLayout basicSearchLayout = new HorizontalLayout();
    basicSearchLayout.setWidth(100, Unit.PERCENTAGE);
    layout.addComponent(basicSearchLayout);
    AbstractLayout advancedSearch = buildAdvancedSearch();
    if (advancedSearch != null) {
        basicSearchLayout.addComponent(advancedSearchCheckbox);
    }
    searchField.setInputPrompt("Search");
    searchField.setId("searchField");
    searchField.setTextChangeEventMode(TextChangeEventMode.LAZY);
    searchField.setImmediate(true);
    searchField.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void textChange(final TextChangeEvent event) {
            filterString = event.getText().trim();
            triggerFilter(filterString);
        }
    });
    // clear button
    Button clear = createClearButton();
    basicSearchLayout.addComponent(clear);
    basicSearchLayout.setComponentAlignment(clear, Alignment.MIDDLE_CENTER);
    basicSearchLayout.addComponent(searchField);
    basicSearchLayout.setExpandRatio(searchField, 1.0f);
    searchField.focus();
    return layout;
}
Also used : TextChangeEvent(com.vaadin.event.FieldEvents.TextChangeEvent) Button(com.vaadin.ui.Button) MouseButton(com.vaadin.shared.MouseEventDetails.MouseButton) VerticalLayout(com.vaadin.ui.VerticalLayout) AbstractLayout(com.vaadin.ui.AbstractLayout) TextChangeListener(com.vaadin.event.FieldEvents.TextChangeListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Aggregations

AbstractLayout (com.vaadin.ui.AbstractLayout)7 Button (com.vaadin.ui.Button)4 VerticalLayout (com.vaadin.ui.VerticalLayout)4 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 TextChangeEvent (com.vaadin.event.FieldEvents.TextChangeEvent)2 TextChangeListener (com.vaadin.event.FieldEvents.TextChangeListener)2 ClickEvent (com.vaadin.ui.Button.ClickEvent)2 ClickListener (com.vaadin.ui.Button.ClickListener)2 AdvancedSearchListener (au.com.vaadinutils.crud.AdvancedSearchListener)1 GridHeadingPropertySetIfc (au.com.vaadinutils.crud.GridHeadingPropertySetIfc)1 InputFormDialog (au.com.vaadinutils.editors.InputFormDialog)1 InputFormDialogRecipient (au.com.vaadinutils.editors.InputFormDialogRecipient)1 ClickableLabel (au.com.vaadinutils.fields.ClickableLabel)1 Filter (com.vaadin.data.Container.Filter)1 Item (com.vaadin.data.Item)1 Property (com.vaadin.data.Property)1 Sort (com.vaadin.data.sort.Sort)1 And (com.vaadin.data.util.filter.And)1 SimpleStringFilter (com.vaadin.data.util.filter.SimpleStringFilter)1 ItemClickEvent (com.vaadin.event.ItemClickEvent)1