Search in sources :

Example 6 with IndexedContainer

use of com.vaadin.data.util.IndexedContainer in project VaadinUtils by rlsutton1.

the class PreviewCSV method getContentFromList.

public Component getContentFromList(List<List<String>> data, String caption, int rowLimit) {
    Table table = new Table();
    table.setSizeFull();
    if (data.size() > 1) {
        IndexedContainer indexedContainer = buildContainerFromList(data, rowLimit);
        /* Finally, let's update the table with the container */
        table.setCaption(caption);
        table.setContainerDataSource(indexedContainer);
        table.setVisible(true);
    } else {
        /* Finally, let's update the table with the container */
        table.setCaption("No file selected");
        table.setVisible(true);
    }
    /* Main layout */
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setSizeFull();
    layout.addComponent(table);
    layout.setExpandRatio(table, 1);
    return layout;
}
Also used : Table(com.vaadin.ui.Table) IndexedContainer(com.vaadin.data.util.IndexedContainer) VerticalLayout(com.vaadin.ui.VerticalLayout)

Example 7 with IndexedContainer

use of com.vaadin.data.util.IndexedContainer in project VaadinUtils by rlsutton1.

the class PreviewCSV method buildContainerFromList.

private IndexedContainer buildContainerFromList(List<List<String>> data, int rowLimit) {
    IndexedContainer container = new IndexedContainer();
    String[] columnHeaders = null;
    // Import no more than 100 records as this is only a sample
    int count = 0;
    for (List<String> row : data) {
        String[] rowArray = row.toArray(new String[0]);
        if (columnHeaders == null) {
            addItemProperties(container, rowArray);
            columnHeaders = rowArray;
        } else {
            addRow(container, rowArray, columnHeaders);
            count++;
        }
        if (count > 100)
            break;
    }
    return container;
}
Also used : IndexedContainer(com.vaadin.data.util.IndexedContainer)

Example 8 with IndexedContainer

use of com.vaadin.data.util.IndexedContainer in project VaadinUtils by rlsutton1.

the class PreviewCSV method getContentFile.

public Component getContentFile(File tempFile, String caption, int rowLimit) {
    Table table = new Table();
    table.setSizeFull();
    FileReader reader;
    try {
        if (tempFile.exists()) {
            reader = new FileReader(tempFile);
            IndexedContainer indexedContainer = buildContainerFromCSV(reader, rowLimit);
            reader.close();
            /* Finally, let's update the table with the container */
            table.setCaption(caption);
            table.setContainerDataSource(indexedContainer);
            table.setVisible(true);
        } else {
            /* Finally, let's update the table with the container */
            table.setCaption("No file selected");
            table.setVisible(true);
        }
    } catch (FileNotFoundException e) {
        logger.error(e, e);
        throw new RuntimeException(e);
    } catch (IOException e) {
        logger.error(e, e);
        Notification.show(e.getMessage());
    }
    /* Main layout */
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setSizeFull();
    layout.addComponent(table);
    layout.setExpandRatio(table, 1);
    return layout;
}
Also used : Table(com.vaadin.ui.Table) IndexedContainer(com.vaadin.data.util.IndexedContainer) FileNotFoundException(java.io.FileNotFoundException) VerticalLayout(com.vaadin.ui.VerticalLayout) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 9 with IndexedContainer

use of com.vaadin.data.util.IndexedContainer in project VaadinUtils by rlsutton1.

the class EmailTargetLayout method insertTargetLine.

private EmailTargetLine insertTargetLine(final int row, ReportEmailRecipient recip) {
    final HorizontalLayout recipientHolder = new HorizontalLayout();
    recipientHolder.setSizeFull();
    recipientHolder.setSpacing(true);
    recipientHolder.setHeight("30");
    final List<ReportEmailRecipientVisibility> targetTypes = new LinkedList<ReportEmailRecipientVisibility>();
    for (ReportEmailRecipientVisibility rerv : ReportEmailRecipientVisibility.values()) {
        targetTypes.add(rerv);
    }
    final EmailTargetLine line = new EmailTargetLine();
    line.row = row;
    line.targetTypeCombo = new ComboBox(null, targetTypes);
    line.targetTypeCombo.setWidth("80");
    line.targetTypeCombo.select(targetTypes.get(0));
    line.targetAddress = new ComboBox(null);
    line.targetAddress.setImmediate(true);
    line.targetAddress.setTextInputAllowed(true);
    line.targetAddress.setInputPrompt("Enter Contact Name or email address");
    line.targetAddress.setWidth("100%");
    line.targetAddress.addValidator(new EmailValidator("Please enter a valid email address."));
    getValidEmailContacts(line.targetAddress);
    line.targetAddress.setItemCaptionPropertyId("namedemail");
    line.targetAddress.setNewItemsAllowed(true);
    if (recip != null && recip.getEmail() != null) {
        line.targetAddress.setValue(recip.getEmail());
        line.targetTypeCombo.setValue(recip.getVisibility());
    }
    line.targetAddress.setNewItemHandler(new NewItemHandler() {

        private static final long serialVersionUID = 1L;

        @Override
        public void addNewItem(final String newItemCaption) {
            final IndexedContainer container = (IndexedContainer) line.targetAddress.getContainerDataSource();
            final Item item = addItem(container, "", newItemCaption);
            if (item != null) {
                line.targetAddress.addItem(item.getItemProperty("id").getValue());
                line.targetAddress.setValue(item.getItemProperty("id").getValue());
            }
            setHeight(calculateHeight());
        }
    });
    if (recip != null) {
    }
    if (row == 0) {
        line.actionButton = new Button("+");
        line.actionButton.setDescription("Click to add another email address line.");
        line.actionButton.setStyleName(Reindeer.BUTTON_SMALL);
        line.actionButton.addClickListener(new ClickListener() {

            private static final long serialVersionUID = 6505218353927273720L;

            @Override
            public void buttonClick(ClickEvent event) {
                lines.add(insertTargetLine(lines.size(), null));
                setHeight(calculateHeight());
            }
        });
    } else {
        line.actionButton = new Button("-");
        line.actionButton.setDescription("Click to remove this email address line.");
        line.actionButton.setStyleName(Reindeer.BUTTON_SMALL);
        line.actionButton.addClickListener(new ClickListener() {

            private static final long serialVersionUID = 3104323607502279386L;

            @Override
            public void buttonClick(ClickEvent event) {
                removeComponent(recipientHolder);
                lines.remove(line);
                setHeight(calculateHeight());
            }
        });
    }
    recipientHolder.addComponent(line.targetTypeCombo);
    recipientHolder.addComponent(line.targetAddress);
    recipientHolder.addComponent(line.actionButton);
    recipientHolder.setExpandRatio(line.targetAddress, 1);
    addComponent(recipientHolder);
    return line;
}
Also used : EmailValidator(au.com.vaadinutils.validator.EmailValidator) ComboBox(com.vaadin.ui.ComboBox) IndexedContainer(com.vaadin.data.util.IndexedContainer) ClickEvent(com.vaadin.ui.Button.ClickEvent) NewItemHandler(com.vaadin.ui.AbstractSelect.NewItemHandler) LinkedList(java.util.LinkedList) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Item(com.vaadin.data.Item) Button(com.vaadin.ui.Button) ClickListener(com.vaadin.ui.Button.ClickListener) ReportEmailRecipientVisibility(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipientVisibility)

Aggregations

IndexedContainer (com.vaadin.data.util.IndexedContainer)9 Table (com.vaadin.ui.Table)3 Item (com.vaadin.data.Item)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 Annotation (annis.model.Annotation)1 CSVReader (au.com.bytecode.opencsv.CSVReader)1 ReportEmailRecipientVisibility (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipientVisibility)1 EmailValidator (au.com.vaadinutils.validator.EmailValidator)1 NewItemHandler (com.vaadin.ui.AbstractSelect.NewItemHandler)1 Button (com.vaadin.ui.Button)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 ComboBox (com.vaadin.ui.ComboBox)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1