Search in sources :

Example 1 with EmailValidator

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

ReportEmailRecipientVisibility (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipientVisibility)1 EmailValidator (au.com.vaadinutils.validator.EmailValidator)1 Item (com.vaadin.data.Item)1 IndexedContainer (com.vaadin.data.util.IndexedContainer)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 LinkedList (java.util.LinkedList)1