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