Example usage for com.vaadin.ui HorizontalLayout setComponentAlignment

List of usage examples for com.vaadin.ui HorizontalLayout setComponentAlignment

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalLayout setComponentAlignment.

Prototype

@Override
    public void setComponentAlignment(Component childComponent, Alignment alignment) 

Source Link

Usage

From source file:com.esofthead.mycollab.module.user.accountsettings.profile.view.ProfileReadViewImpl.java

License:Open Source License

private void displayUserAvatar() {
    this.userAvatar.removeAllComponents();
    final Image cropField = UserAvatarControlFactory
            .createUserAvatarEmbeddedComponent(AppContext.getUserAvatarId(), 100);
    userAvatar.addComponent(cropField);//from w  w w .  ja  v a 2 s .  c om

    this.avatarAndPass.removeAllComponents();
    avatarAndPass.addComponent(userAvatar);

    User user = formItem.getUser();

    final VerticalLayout basicLayout = new VerticalLayout();
    basicLayout.setSpacing(true);

    final HorizontalLayout userWrapper = new HorizontalLayout();

    final Label userName = new Label(AppContext.getSession().getDisplayName());
    userName.setStyleName("h1");
    userWrapper.addComponent(userName);

    final Button btnChangeBasicInfo = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_EDIT),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(final ClickEvent event) {
                    UI.getCurrent().addWindow(new BasicInfoChangeWindow(formItem.getUser()));
                }
            });
    btnChangeBasicInfo.setStyleName("link");
    HorizontalLayout btnChangeBasicInfoWrapper = new HorizontalLayout();
    btnChangeBasicInfoWrapper.setWidth("40px");
    btnChangeBasicInfoWrapper.addComponent(btnChangeBasicInfo);
    btnChangeBasicInfoWrapper.setComponentAlignment(btnChangeBasicInfo, Alignment.MIDDLE_RIGHT);
    userWrapper.addComponent(btnChangeBasicInfoWrapper);
    basicLayout.addComponent(userWrapper);
    basicLayout.setComponentAlignment(userWrapper, Alignment.MIDDLE_LEFT);

    basicLayout.addComponent(new Label(AppContext.getMessage(UserI18nEnum.FORM_BIRTHDAY) + ": "
            + AppContext.formatDate(user.getDateofbirth())));
    basicLayout.addComponent(
            new MHorizontalLayout(new Label(AppContext.getMessage(UserI18nEnum.FORM_EMAIL) + ": "),
                    new LabelLink(user.getEmail(), "mailto:" + user.getEmail())));
    basicLayout.addComponent(new Label(AppContext.getMessage(UserI18nEnum.FORM_TIMEZONE) + ": "
            + TimezoneMapper.getTimezone(user.getTimezone()).getDisplayName()));
    basicLayout.addComponent(new Label(AppContext.getMessage(UserI18nEnum.FORM_LANGUAGE) + ": "
            + AppContext.getMessage(LangI18Enum.class, user.getLanguage())));

    HorizontalLayout passwordWrapper = new HorizontalLayout();
    passwordWrapper
            .addComponent(new Label(AppContext.getMessage(ShellI18nEnum.FORM_PASSWORD) + ": ***********"));

    final Button btnChangePassword = new Button("Change", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            UI.getCurrent().addWindow(new PasswordChangeWindow(formItem.user));
        }
    });
    btnChangePassword.setStyleName("link");
    HorizontalLayout btnChangePasswordWrapper = new HorizontalLayout();
    btnChangePasswordWrapper.setWidth("50px");
    btnChangePasswordWrapper.addComponent(btnChangePassword);
    btnChangePasswordWrapper.setComponentAlignment(btnChangePassword, Alignment.MIDDLE_RIGHT);
    passwordWrapper.addComponent(btnChangePasswordWrapper);
    basicLayout.addComponent(passwordWrapper);
    basicLayout.setComponentAlignment(passwordWrapper, Alignment.MIDDLE_LEFT);

    avatarAndPass.addComponent(basicLayout);
    avatarAndPass.setComponentAlignment(basicLayout, Alignment.TOP_LEFT);
    avatarAndPass.setExpandRatio(basicLayout, 1.0f);

    final UploadField avatarUploadField = new UploadField() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void updateDisplay() {
            byte[] imageData = (byte[]) this.getValue();
            String mimeType = this.getLastMimeType();
            if (mimeType.equals("image/jpeg")) {
                imageData = ImageUtil.convertJpgToPngFormat(imageData);
                if (imageData == null) {
                    throw new UserInvalidInputException("Do not support image format for avatar");
                } else {
                    mimeType = "image/png";
                }
            }

            if (mimeType.equals("image/png")) {
                EventBusFactory.getInstance()
                        .post(new ProfileEvent.GotoUploadPhoto(ProfileReadViewImpl.this, imageData));
            } else {
                throw new UserInvalidInputException(
                        "Upload file does not have valid image format. The supported formats are jpg/png");
            }
        }
    };
    avatarUploadField.addStyleName("upload-field");
    avatarUploadField.setButtonCaption(AppContext.getMessage(UserI18nEnum.BUTTON_CHANGE_AVATAR));
    avatarUploadField.setSizeUndefined();
    avatarUploadField.setFieldType(FieldType.BYTE_ARRAY);
    this.userAvatar.addComponent(avatarUploadField);
}

From source file:com.esofthead.mycollab.module.user.accountsettings.team.view.RoleListViewImpl.java

License:Open Source License

private ComponentContainer constructTableActionControls() {
    final CssLayout layoutWrapper = new CssLayout();
    layoutWrapper.setWidth("100%");
    final HorizontalLayout layout = new HorizontalLayout();
    layout.setSpacing(true);//from   ww w  . j ava  2  s  .  com
    layoutWrapper.addStyleName(UIConstants.TABLE_ACTION_CONTROLS);
    layoutWrapper.addComponent(layout);

    this.selectOptionButton = new SelectionOptionButton(this.tableItem);
    layout.addComponent(this.selectOptionButton);

    final Button deleteBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_DELETE));
    deleteBtn.setEnabled(AppContext.canAccess(RolePermissionCollections.ACCOUNT_ROLE));

    this.tableActionControls = new DefaultMassItemActionHandlersContainer();
    if (AppContext.canAccess(RolePermissionCollections.ACCOUNT_ROLE)) {
        tableActionControls.addActionItem(MassItemActionHandler.DELETE_ACTION, FontAwesome.TRASH_O, "delete",
                AppContext.getMessage(GenericI18Enum.BUTTON_DELETE));
    }
    tableActionControls.addDownloadActionItem(MassItemActionHandler.EXPORT_PDF_ACTION, FontAwesome.FILE_PDF_O,
            "export", "export.pdf", AppContext.getMessage(GenericI18Enum.BUTTON_EXPORT_PDF));

    tableActionControls.addDownloadActionItem(MassItemActionHandler.EXPORT_EXCEL_ACTION,
            FontAwesome.FILE_EXCEL_O, "export", "export.xlsx",
            AppContext.getMessage(GenericI18Enum.BUTTON_EXPORT_EXCEL));

    tableActionControls.addDownloadActionItem(MassItemActionHandler.EXPORT_CSV_ACTION, FontAwesome.FILE_TEXT_O,
            "export", "export.csv", AppContext.getMessage(GenericI18Enum.BUTTON_EXPORT_CSV));

    layout.addComponent(this.tableActionControls);
    layout.addComponent(this.selectedItemsNumberLabel);
    layout.setComponentAlignment(this.selectedItemsNumberLabel, Alignment.MIDDLE_CENTER);
    return layoutWrapper;
}

From source file:com.esofthead.mycollab.module.user.accountsettings.team.view.UserListViewImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w  ww  .  j  av a 2 s.  co  m*/
public void setSearchCriteria(UserSearchCriteria searchCriteria) {
    UserService userService = ApplicationContextUtil.getSpringBean(UserService.class);
    List<SimpleUser> userAccountList = userService
            .findPagableListByCriteria(new SearchRequest<>(searchCriteria, 0, Integer.MAX_VALUE));

    this.removeAllComponents();
    this.setSpacing(true);
    HorizontalLayout header = new HorizontalLayout();
    header.setStyleName(UIConstants.HEADER_VIEW);
    header.setWidth("100%");
    header.setMargin(new MarginInfo(true, false, true, false));
    Button createBtn = new Button("Invite user", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            EventBusFactory.getInstance().post(new UserEvent.GotoAdd(this, null));
        }
    });
    createBtn.setEnabled(AppContext.canWrite(RolePermissionCollections.ACCOUNT_USER));
    createBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    createBtn.setIcon(FontAwesome.PLUS);

    header.addComponent(createBtn);
    header.setComponentAlignment(createBtn, Alignment.MIDDLE_RIGHT);
    this.addComponent(header);

    CssLayout contentLayout = new CssLayout();
    contentLayout.setWidth("100%");
    for (SimpleUser userAccount : userAccountList) {
        contentLayout.addComponent(generateMemberBlock(userAccount));
    }
    this.addComponent(contentLayout);
}

From source file:com.esofthead.mycollab.vaadin.ui.AbstractBeanBlockList.java

License:Open Source License

protected CssLayout createPageControls() {
    this.controlBarWrapper = new CssLayout();
    this.controlBarWrapper.setWidth("100%");

    final HorizontalLayout controlBar = new HorizontalLayout();
    controlBar.setWidth("100%");
    this.controlBarWrapper.addComponent(controlBar);

    this.pageManagement = new HorizontalLayout();

    // defined layout here ---------------------------

    if (this.currentPage > 1) {
        final Button firstLink = new ButtonLink("1", new Button.ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override// w  w w  . j  av a2s  .c  om
            public void buttonClick(final ClickEvent event) {
                AbstractBeanBlockList.this.pageChange(1);
            }
        }, false);
        firstLink.addStyleName("buttonPaging");
        this.pageManagement.addComponent(firstLink);
    }
    if (this.currentPage >= 5) {
        final Label ss1 = new Label("...");
        ss1.addStyleName("buttonPaging");
        this.pageManagement.addComponent(ss1);
    }
    if (this.currentPage > 3) {
        final Button previous2 = new ButtonLink("" + (this.currentPage - 2), new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                AbstractBeanBlockList.this.pageChange(AbstractBeanBlockList.this.currentPage - 2);
            }
        }, false);
        previous2.addStyleName("buttonPaging");
        this.pageManagement.addComponent(previous2);
    }
    if (this.currentPage > 2) {
        final Button previous1 = new ButtonLink("" + (this.currentPage - 1), new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                AbstractBeanBlockList.this.pageChange(AbstractBeanBlockList.this.currentPage - 1);
            }
        }, false);
        previous1.addStyleName("buttonPaging");
        this.pageManagement.addComponent(previous1);
    }
    // Here add current ButtonLink
    final Button current = new ButtonLink("" + this.currentPage, new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            AbstractBeanBlockList.this.pageChange(AbstractBeanBlockList.this.currentPage);
        }
    }, false);
    current.addStyleName("buttonPaging");
    current.addStyleName("buttonPagingcurrent");

    this.pageManagement.addComponent(current);
    final int range = this.totalPage - this.currentPage;
    if (range >= 1) {
        final Button next1 = new ButtonLink("" + (this.currentPage + 1), new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                AbstractBeanBlockList.this.pageChange(AbstractBeanBlockList.this.currentPage + 1);
            }
        }, false);
        next1.addStyleName("buttonPaging");
        this.pageManagement.addComponent(next1);
    }
    if (range >= 2) {
        final Button next2 = new ButtonLink("" + (this.currentPage + 2), new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                AbstractBeanBlockList.this.pageChange(AbstractBeanBlockList.this.currentPage + 2);
            }
        }, false);
        next2.addStyleName("buttonPaging");
        this.pageManagement.addComponent(next2);
    }
    if (range >= 4) {
        final Label ss2 = new Label("...");
        ss2.addStyleName("buttonPaging");
        this.pageManagement.addComponent(ss2);
    }
    if (range >= 3) {
        final Button last = new ButtonLink("" + this.totalPage, new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                AbstractBeanBlockList.this.pageChange(AbstractBeanBlockList.this.totalPage);
            }
        }, false);
        last.addStyleName("buttonPaging");
        this.pageManagement.addComponent(last);
    }

    this.pageManagement.setWidth(null);
    this.pageManagement.setSpacing(true);
    controlBar.addComponent(this.pageManagement);
    controlBar.setComponentAlignment(this.pageManagement, Alignment.MIDDLE_RIGHT);

    return this.controlBarWrapper;
}

From source file:com.esofthead.mycollab.vaadin.ui.AbstractBeanPagedList.java

License:Open Source License

protected CssLayout createPageControls() {
    this.controlBarWrapper = new CssLayout();
    this.controlBarWrapper.setStyleName(listControlStyle);
    this.controlBarWrapper.setWidth("100%");

    final HorizontalLayout controlBar = new HorizontalLayout();
    controlBar.setWidth("100%");
    this.controlBarWrapper.addComponent(controlBar);

    this.pageManagement = new HorizontalLayout();

    // defined layout here ---------------------------

    if (this.currentPage > 1) {
        final Button firstLink = new ButtonLink("1", new Button.ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override//from  www . j  av  a2s.  c  om
            public void buttonClick(final ClickEvent event) {
                AbstractBeanPagedList.this.pageChange(1);
            }
        }, false);
        firstLink.addStyleName("buttonPaging");
        this.pageManagement.addComponent(firstLink);
    }
    if (this.currentPage >= 5) {
        final Label ss1 = new Label("...");
        ss1.addStyleName("buttonPaging");
        this.pageManagement.addComponent(ss1);
    }
    if (this.currentPage > 3) {
        final Button previous2 = new ButtonLink("" + (this.currentPage - 2), new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                AbstractBeanPagedList.this.pageChange(AbstractBeanPagedList.this.currentPage - 2);
            }
        }, false);
        previous2.addStyleName("buttonPaging");
        this.pageManagement.addComponent(previous2);
    }
    if (this.currentPage > 2) {
        final Button previous1 = new ButtonLink("" + (this.currentPage - 1), new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                AbstractBeanPagedList.this.pageChange(AbstractBeanPagedList.this.currentPage - 1);
            }
        }, false);
        previous1.addStyleName("buttonPaging");
        this.pageManagement.addComponent(previous1);
    }
    // Here add current ButtonLink
    final Button current = new ButtonLink("" + this.currentPage, new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            AbstractBeanPagedList.this.pageChange(AbstractBeanPagedList.this.currentPage);
        }
    }, false);
    current.addStyleName("buttonPaging");
    current.addStyleName("buttonPagingcurrent");

    this.pageManagement.addComponent(current);
    final int range = this.totalPage - this.currentPage;
    if (range >= 1) {
        final Button next1 = new ButtonLink("" + (this.currentPage + 1), new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                AbstractBeanPagedList.this.pageChange(AbstractBeanPagedList.this.currentPage + 1);
            }
        }, false);
        next1.addStyleName("buttonPaging");
        this.pageManagement.addComponent(next1);
    }
    if (range >= 2) {
        final Button next2 = new ButtonLink("" + (this.currentPage + 2), new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                AbstractBeanPagedList.this.pageChange(AbstractBeanPagedList.this.currentPage + 2);
            }
        }, false);
        next2.addStyleName("buttonPaging");
        this.pageManagement.addComponent(next2);
    }
    if (range >= 4) {
        final Label ss2 = new Label("...");
        ss2.addStyleName("buttonPaging");
        this.pageManagement.addComponent(ss2);
    }
    if (range >= 3) {
        final Button last = new ButtonLink("" + this.totalPage, new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                AbstractBeanPagedList.this.pageChange(AbstractBeanPagedList.this.totalPage);
            }
        }, false);
        last.addStyleName("buttonPaging");
        this.pageManagement.addComponent(last);
    }

    this.pageManagement.setWidth(null);
    this.pageManagement.setSpacing(true);
    controlBar.addComponent(this.pageManagement);
    controlBar.setComponentAlignment(this.pageManagement, Alignment.MIDDLE_RIGHT);

    return this.controlBarWrapper;
}

From source file:com.esofthead.mycollab.vaadin.ui.DateComboboxSelectionField.java

License:Open Source License

@Override
protected Component initContent() {
    HorizontalLayout layout = new HorizontalLayout();
    layout.setSpacing(true);/*from w w w  . j  a va 2s.  c om*/

    layout.addComponent(cboMonth);
    layout.setComponentAlignment(cboMonth, Alignment.TOP_CENTER);

    layout.addComponent(cboDate);
    layout.setComponentAlignment(cboDate, Alignment.TOP_CENTER);

    layout.addComponent(cboYear);
    layout.setComponentAlignment(cboYear, Alignment.TOP_CENTER);
    return layout;
}

From source file:com.esofthead.mycollab.vaadin.ui.EditFormControlsGenerator.java

License:Open Source License

public HorizontalLayout createButtonControls(final boolean isSaveBtnVisible,
        final boolean isSaveAndNewBtnVisible, final boolean isCancelBtnVisible) {
    final HorizontalLayout layout = new HorizontalLayout();
    layout.setSpacing(true);//from w ww.ja va 2s .  co  m
    layout.setSizeUndefined();
    layout.setStyleName("addNewControl");

    if (isSaveBtnVisible) {
        final Button saveBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        if (EditFormControlsGenerator.this.editForm.validateForm()) {
                            EditFormControlsGenerator.this.editForm.fireSaveForm();
                        }
                    }
                });
        saveBtn.setIcon(FontAwesome.SAVE);
        saveBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
        layout.addComponent(saveBtn);
        layout.setComponentAlignment(saveBtn, Alignment.MIDDLE_CENTER);
    }

    if (isSaveAndNewBtnVisible) {
        final Button saveAndNewBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE_NEW),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        if (EditFormControlsGenerator.this.editForm.validateForm()) {
                            EditFormControlsGenerator.this.editForm.fireSaveAndNewForm();
                        }
                    }
                });
        saveAndNewBtn.setIcon(FontAwesome.SHARE_ALT);
        saveAndNewBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
        layout.addComponent(saveAndNewBtn);
        layout.setComponentAlignment(saveAndNewBtn, Alignment.MIDDLE_CENTER);
    }

    if (isCancelBtnVisible) {
        final Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        EditFormControlsGenerator.this.editForm.fireCancelForm();
                    }
                });
        cancelBtn.setIcon(FontAwesome.MINUS);
        cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK);
        layout.addComponent(cancelBtn);
        layout.setComponentAlignment(cancelBtn, Alignment.MIDDLE_CENTER);
    }

    return layout;
}

From source file:com.esofthead.mycollab.vaadin.ui.FeedbackWindow.java

License:Open Source License

private void initUI() {
    GridLayout mainLayout = new GridLayout(2, 5);
    mainLayout.setMargin(true);//from   ww w .  j a v a2 s .  co  m
    mainLayout.setSpacing(true);

    emailNameTextField = new TextField();
    emailNameTextField.setWidth("500px");
    Label emailName = new Label("Your name: ");

    mainLayout.addComponent(emailName, 0, 0);
    mainLayout.addComponent(emailNameTextField, 1, 0);

    emailTextField = new TextField();
    emailTextField.setWidth("500px");
    emailTextField.setRequired(true);
    Label emailLbl = new Label("Your email: ");

    mainLayout.addComponent(emailLbl, 0, 1);
    mainLayout.addComponent(emailTextField, 1, 1);

    subjectTextField = new TextField();
    subjectTextField.setWidth("500px");
    subjectTextField.setRequired(true);
    Label subjectLbl = new Label("Subject: ");

    mainLayout.addComponent(subjectLbl, 0, 2);
    mainLayout.addComponent(subjectTextField, 1, 2);

    final RichTextArea contentArea = new RichTextArea();
    contentArea.setImmediate(true);
    contentArea.setWidth(500, Sizeable.Unit.PIXELS);
    contentArea.setHeight(200, Sizeable.Unit.PIXELS);
    Label contentLbl = new Label("Your feedback: ");

    mainLayout.addComponent(contentLbl, 0, 3);
    mainLayout.addComponent(contentArea, 1, 3);

    initDefaultData();

    HorizontalLayout controlsLayout = new HorizontalLayout();
    controlsLayout.setWidth("100%");

    final AttachmentPanel attachments = new AttachmentPanel();
    attachments.setWidth("350px");

    MultiFileUploadExt uploadExt = new MultiFileUploadExt(attachments);
    uploadExt.addComponent(attachments);

    // Panel attachedFilepanel = new Panel();
    VerticalLayout contentLayout = new VerticalLayout();
    contentLayout.setHeight("80px");
    contentLayout.setStyleName("noneBorder-panel");
    contentLayout.setSizeUndefined();

    contentLayout.addComponent(uploadExt);

    // attachedFilepanel.setContent(contentLayout);

    controlsLayout.addComponent(contentLayout);
    controlsLayout.setComponentAlignment(contentLayout, Alignment.BOTTOM_LEFT);
    controlsLayout.setExpandRatio(contentLayout, 1.0f);

    controlsLayout.setSpacing(true);

    Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                    FeedbackWindow.this.close();
                }
            });

    cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK);
    controlsLayout.addComponent(cancelBtn);
    controlsLayout.setComponentAlignment(cancelBtn, Alignment.MIDDLE_RIGHT);

    Button sendBtn = new Button("Send", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            String email = emailTextField.getValue().toString().trim();
            String subject = subjectTextField.getValue().toString().trim();
            if (!StringUtils.isValidEmail(email)) {
                NotificationUtil.showWarningNotification("The email is not valid, please check it again!");
                return;
            }
            if (!email.equals("") && !subject.equals("")) {
                ExtMailService systemMailService = ApplicationContextUtil.getSpringBean(ExtMailService.class);
                List<File> listFile = attachments.getListFile();
                List<EmailAttachementSource> emailAttachmentSource = null;

                if (CollectionUtils.isNotEmpty(listFile)) {
                    emailAttachmentSource = new ArrayList<EmailAttachementSource>();
                    for (File file : listFile) {
                        emailAttachmentSource.add(new FileEmailAttachmentSource(file));
                    }
                }

                String nameEmailFrom = emailNameTextField.getValue().toString().trim();
                nameEmailFrom = nameEmailFrom.equals("") ? email : nameEmailFrom;
                String toEmail = SiteConfiguration.getSendErrorEmail();

                FeedbackWindow.this.close();

                systemMailService.sendHTMLMail(email, nameEmailFrom,
                        Arrays.asList(new MailRecipientField(toEmail, toEmail)), null, null, subject,
                        contentArea.getValue().toString(), emailAttachmentSource);

            } else {
                NotificationUtil.showWarningNotification(
                        "The email field and subject field must be not empty! Please fulfil them before pressing enter button.");
            }
        }
    });
    sendBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    controlsLayout.addComponent(sendBtn);
    controlsLayout.setComponentAlignment(sendBtn, Alignment.MIDDLE_RIGHT);
    mainLayout.addComponent(controlsLayout, 0, 4, 1, 4);

    this.setContent(mainLayout);
}

From source file:com.esofthead.mycollab.vaadin.ui.MailFormWindow.java

License:Open Source License

private Layout createTextFieldMail(String title, Component component) {
    HorizontalLayout layout = new HorizontalLayout();
    Label lbTitle = new Label(title);
    lbTitle.setWidth("60px");
    lbTitle.setStyleName("lbmail");
    layout.addComponent(lbTitle);//from   w w  w  . jav  a  2 s. c o m
    layout.setComponentAlignment(lbTitle, Alignment.MIDDLE_RIGHT);
    layout.addComponent(component);
    layout.setComponentAlignment(component, Alignment.MIDDLE_LEFT);
    layout.setWidth("100%");
    layout.setExpandRatio(component, 1.0f);
    return layout;
}

From source file:com.esofthead.mycollab.vaadin.ui.MailFormWindow.java

License:Open Source License

private void initUI() {
    GridLayout mainLayout = new GridLayout(1, 5);
    mainLayout.setWidth("100%");
    mainLayout.setMargin(true);//from   w ww .ja v a  2 s  . c om
    mainLayout.setSpacing(true);

    CssLayout inputPanel = new CssLayout();
    inputPanel.setWidth("100%");
    inputPanel.setStyleName("mail-panel");

    inputLayout = new GridLayout(3, 4);
    inputLayout.setSpacing(true);
    inputLayout.setWidth("100%");
    inputLayout.setColumnExpandRatio(0, 1.0f);

    inputPanel.addComponent(inputLayout);

    mainLayout.addComponent(inputPanel);

    tokenFieldMailTo = new EmailTokenField();
    tokenFieldMailTo.setRequired(true);

    inputLayout.addComponent(createTextFieldMail("To:", tokenFieldMailTo), 0, 0);

    if (lstMail != null) {
        for (String mail : lstMail) {
            if (StringUtils.isNotBlank(mail)) {
                if (mail.indexOf("<") > -1) {
                    String strMail = mail.substring(mail.indexOf("<") + 1, mail.lastIndexOf(">"));
                    if (strMail != null && !strMail.equalsIgnoreCase("null")) {
                        tokenFieldMailTo.addToken(mail);
                    }
                } else {
                    tokenFieldMailTo.addToken(mail);
                }
            }
        }
    }

    final TextField subject = new TextField();
    subject.setRequired(true);
    subject.setWidth("100%");
    subjectField = createTextFieldMail("Subject:", subject);
    inputLayout.addComponent(subjectField, 0, 1);

    initButtonLinkCcBcc();

    ccField = createTextFieldMail("Cc:", tokenFieldMailCc);
    bccField = createTextFieldMail("Bcc:", tokenFieldMailBcc);

    final RichTextArea noteArea = new RichTextArea();
    noteArea.setWidth("100%");
    noteArea.setHeight("200px");
    mainLayout.addComponent(noteArea, 0, 1);
    mainLayout.setComponentAlignment(noteArea, Alignment.MIDDLE_CENTER);

    HorizontalLayout controlsLayout = new HorizontalLayout();
    controlsLayout.setWidth("100%");

    final AttachmentPanel attachments = new AttachmentPanel();
    attachments.setWidth("500px");

    MultiFileUploadExt uploadExt = new MultiFileUploadExt(attachments);
    uploadExt.addComponent(attachments);

    controlsLayout.addComponent(uploadExt);
    controlsLayout.setExpandRatio(uploadExt, 1.0f);

    controlsLayout.setSpacing(true);

    Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                    MailFormWindow.this.close();
                }
            });

    cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK);
    controlsLayout.addComponent(cancelBtn);
    controlsLayout.setComponentAlignment(cancelBtn, Alignment.MIDDLE_RIGHT);

    Button sendBtn = new Button("Send", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {

            if (tokenFieldMailTo.getListRecipient().size() <= 0 || subject.getValue().equals("")) {
                NotificationUtil.showErrorNotification(
                        "To Email field and Subject field must be not empty! Please fulfil them before sending email.");
                return;
            }
            if (AppContext.getSession().getEmail() != null && AppContext.getSession().getEmail().length() > 0) {
                ExtMailService systemMailService = ApplicationContextUtil.getSpringBean(ExtMailService.class);

                List<File> listFile = attachments.getListFile();
                List<EmailAttachementSource> emailAttachmentSource = null;
                if (listFile != null && listFile.size() > 0) {
                    emailAttachmentSource = new ArrayList<EmailAttachementSource>();
                    for (File file : listFile) {
                        emailAttachmentSource.add(new FileEmailAttachmentSource(file));
                    }
                }

                systemMailService.sendHTMLMail(AppContext.getSession().getEmail(),
                        AppContext.getSession().getDisplayName(), tokenFieldMailTo.getListRecipient(),
                        tokenFieldMailCc.getListRecipient(), tokenFieldMailBcc.getListRecipient(),
                        subject.getValue().toString(), noteArea.getValue().toString(), emailAttachmentSource);
                MailFormWindow.this.close();
            } else {
                NotificationUtil.showErrorNotification(
                        "Your email is empty value, please fulfil it before sending email!");
            }
        }
    });
    sendBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    controlsLayout.addComponent(sendBtn);
    controlsLayout.setComponentAlignment(sendBtn, Alignment.MIDDLE_RIGHT);
    mainLayout.addComponent(controlsLayout, 0, 2);

    this.setContent(mainLayout);
}