Search in sources :

Example 1 with ColumnGenerator

use of com.vaadin.ui.Table.ColumnGenerator in project ANNIS by korpling.

the class ExampleTable method attach.

@Override
public void attach() {
    super.attach();
    addGeneratedColumn("example", new ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            CorpusBrowserEntry corpusBrowserEntry = (CorpusBrowserEntry) itemId;
            Label l = new Label(corpusBrowserEntry.getExample());
            l.setContentMode(ContentMode.TEXT);
            l.addStyleName(Helper.CORPUS_FONT_FORCE);
            return l;
        }
    });
    setVisibleColumns("name", "example", "genlink");
    setColumnHeaders("Name", "Example (click to use query)", "URL");
    setColumnExpandRatio("name", 0.3f);
    setColumnExpandRatio("example", 0.7f);
    setImmediate(true);
}
Also used : CorpusBrowserEntry(annis.gui.beans.CorpusBrowserEntry) Table(com.vaadin.ui.Table) ColumnGenerator(com.vaadin.ui.Table.ColumnGenerator) Label(com.vaadin.ui.Label)

Example 2 with ColumnGenerator

use of com.vaadin.ui.Table.ColumnGenerator 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 3 with ColumnGenerator

use of com.vaadin.ui.Table.ColumnGenerator in project VaadinUtils by rlsutton1.

the class JasperReportScheduleLayout method getStatusColumnGenerator.

private ColumnGenerator getStatusColumnGenerator() {
    return new ColumnGenerator() {

        private static final long serialVersionUID = -1873561613938103218L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            @SuppressWarnings("unchecked") EntityItem<ReportEmailScheduleEntity> item = (EntityItem<ReportEmailScheduleEntity>) source.getItem(itemId);
            ReportEmailScheduleEntity schedule = item.getEntity();
            final Label label = new Label("<font color='green'>Scheduled</font>");
            label.setContentMode(ContentMode.HTML);
            if (schedule.getReportLog() != null && schedule.getReportLog().length() > 0 && !schedule.getReportLog().equals(Scheduler.REPORT_SUCCESSFULLY_RUN)) {
                label.setValue("<font color='red'><b>Error</b></font>");
            } else {
                if (!schedule.isEnabled()) {
                    label.setValue("<font color='orange'><b>Disabled</b></font>");
                }
            }
            return label;
        }
    };
}
Also used : EntityTable(au.com.vaadinutils.crud.EntityTable) Table(com.vaadin.ui.Table) ColumnGenerator(com.vaadin.ui.Table.ColumnGenerator) ReportEmailScheduleEntity(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity) Label(com.vaadin.ui.Label) EntityItem(com.vaadin.addon.jpacontainer.EntityItem)

Aggregations

Label (com.vaadin.ui.Label)3 ColumnGenerator (com.vaadin.ui.Table.ColumnGenerator)3 Table (com.vaadin.ui.Table)2 CorpusBrowserEntry (annis.gui.beans.CorpusBrowserEntry)1 EntityTable (au.com.vaadinutils.crud.EntityTable)1 ClickableLabel (au.com.vaadinutils.fields.ClickableLabel)1 ReportEmailScheduleEntity (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity)1 EntityItem (com.vaadin.addon.jpacontainer.EntityItem)1 Item (com.vaadin.data.Item)1 Property (com.vaadin.data.Property)1 AbstractLayout (com.vaadin.ui.AbstractLayout)1 Link (com.vaadin.ui.Link)1 HtmlToPlainText (org.jsoup.examples.HtmlToPlainText)1