Package sk.vrto.web.views

Source Code of sk.vrto.web.views.NewEmailView

package sk.vrto.web.views;

import com.vaadin.ui.*;
import com.vaadin.ui.Component;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.*;
import sk.vrto.web.presenters.NewEmailPresenter;
import sk.vrto.web.ui.ImageDropBox;

@org.springframework.stereotype.Component
@Scope("prototype")
public class NewEmailView extends VerticalLayout {

    transient private NewEmailPresenter presenter;

    // ui
    private ComboBox contactsBox;
    private ContactViewPopup triggeredFrom;
    protected TextField title;
    protected RichTextArea mailArea;

    @Autowired
    public NewEmailView(NewEmailPresenter presenter) {
        this.presenter = presenter;
        presenter.setView(this);

        setSpacing(true);
        setWidth("99%");
        setHeight("95%");

        addComponent(suggestableContactsBar());
        addComponent(titleArea());
        addComponent(attachmentsBar());

        mailArea = mailArea();
        addComponent(mailArea);

        Component sendButton = sendButton();
        addComponent(sendButton);
        setComponentAlignment(sendButton, Alignment.MIDDLE_RIGHT);
        setExpandRatio(mailArea, 1.0f);
    }

    public void mailSent(String address) {
        getWindow().showNotification("Your mail has been send to " + address);
    }

    public void insertContact(String email) {
        contactsBox.addItem(email);
    }

    public void deleteContact(String email) {
        contactsBox.removeItem(email);
    }

    private Component titleArea() {
        title = new TextField();
        title.setWidth("99%");
        title.setInputPrompt("Title");
        title.setStyleName("left-marged");
        return title;
    }

    private Component sendButton() {
        Button send = new Button("Send message");
        send.addListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                presenter.sendMail(
                        contactsBox.getValue().toString(),
                        title.getValue().toString(),
                        mailArea.getValue().toString());

                // clear stuff
                String address = contactsBox.getValue().toString();
                contactsBox.setValue(null);
                title.setValue("");
                mailArea.setValue("");

                mailSent(address);
            }
        });
        return send;
    }

    private RichTextArea mailArea() {
        mailArea = new RichTextArea();
        mailArea.setWidth("99%");
        mailArea.setHeight("100%");
        mailArea.setStyleName("left-marged");
        return mailArea;
    }

    private Component attachmentsBar() {
        ProgressIndicator progress = new ProgressIndicator();
        progress.setIndeterminate(true);
        progress.setVisible(false);
        addComponent(progress);

        HorizontalLayout dropPane = new HorizontalLayout();
        dropPane.setHeight("40px");
        dropPane.setWidth("600px");

        ImageDropBox dropBox = new ImageDropBox(dropPane, progress);
        dropBox.setSizeUndefined();

        Panel panel = new Panel(dropBox);
        panel.setDescription("Drag content here");
        panel.setCaption("Attachments (drag 'n' drop content)");
        panel.setStyleName("left-marged");
        panel.setWidth("99%");

        return panel;
    }

    private Component suggestableContactsBar() {
        contactsBox = new ComboBox("", presenter.getAddresses());
        contactsBox.addStyleName("left-marged");
        contactsBox.setWidth("99.4%");
        contactsBox.setImmediate(true);
        contactsBox.setInputPrompt("Start typing recepient ...");
        contactsBox.setNewItemsAllowed(true);
        contactsBox.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);

        return contactsBox;
    }

    public ComboBox getContactsBox() {
        return contactsBox;
    }

    public void setTriggeredFrom(ContactViewPopup triggeredFrom) {
        this.triggeredFrom = triggeredFrom;
    }

    public ContactViewPopup getTriggeredFrom() {
        return triggeredFrom;
    }

    public TextField getTitle() {
        return title;
    }

    public RichTextArea getMailArea() {
        return mailArea;
    }
}
TOP

Related Classes of sk.vrto.web.views.NewEmailView

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.