use of au.com.vaadinutils.validator.EmailValidator 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