Example usage for com.vaadin.ui TextField TextField

List of usage examples for com.vaadin.ui TextField TextField

Introduction

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

Prototype

public TextField() 

Source Link

Document

Constructs an empty TextField with no caption.

Usage

From source file:com.mycollab.module.project.view.ProjectAddBaseTemplateWindow.java

License:Open Source License

public ProjectAddBaseTemplateWindow() {
    super(UserUIContext.getMessage(OPT_CREATE_PROJECT_FROM_TEMPLATE));
    this.withModal(true).withClosable(true).withResizable(false).withWidth("550px");
    MVerticalLayout content = new MVerticalLayout();
    GridFormLayoutHelper gridFormLayoutHelper = GridFormLayoutHelper.defaultFormLayoutHelper(1, 3);
    final TemplateProjectComboBox templateProjectComboBox = new TemplateProjectComboBox();
    gridFormLayoutHelper.addComponent(templateProjectComboBox, UserUIContext.getMessage(FORM_TEMPLATE),
            UserUIContext.getMessage(OPT_MARK_TEMPLATE_HELP), 0, 0);
    final TextField prjNameField = new TextField();
    gridFormLayoutHelper.addComponent(prjNameField, UserUIContext.getMessage(FORM_NAME), 0, 1);
    final TextField prjKeyField = new TextField();
    gridFormLayoutHelper.addComponent(prjKeyField, UserUIContext.getMessage(FORM_SHORT_NAME), 0, 2);

    MButton okBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_OK), clickEvent -> {
        SimpleProject templatePrj = (SimpleProject) templateProjectComboBox.getValue();
        if (templatePrj == null) {
            NotificationUtil//from w w w.j  a  va2  s.  c  om
                    .showErrorNotification(UserUIContext.getMessage(ERROR_MUST_CHOOSE_TEMPLATE_PROJECT));
            return;
        }
        String newPrjName = prjNameField.getValue();
        if (newPrjName.length() == 0) {
            NotificationUtil.showErrorNotification(UserUIContext.getMessage(ErrorI18nEnum.FIELD_MUST_NOT_NULL,
                    UserUIContext.getMessage(GenericI18Enum.FORM_NAME)));
            return;
        }
        String newPrjKey = prjKeyField.getValue();
        if (newPrjKey.length() > 3 || newPrjKey.length() == 0) {
            NotificationUtil
                    .showErrorNotification(UserUIContext.getMessage(ProjectI18nEnum.ERROR_PROJECT_KEY_INVALID));
            return;
        }
        ProjectTemplateService projectTemplateService = AppContextUtil
                .getSpringBean(ProjectTemplateService.class);
        if (projectTemplateService != null) {
            Integer newProjectId = projectTemplateService.cloneProject(templatePrj.getId(), newPrjName,
                    newPrjKey, MyCollabUI.getAccountId(), UserUIContext.getUsername());
            EventBusFactory.getInstance().post(new ProjectEvent.GotoMyProject(this,
                    new PageActionChain(new ProjectScreenData.Goto(newProjectId))));
            close();
        }
    }).withIcon(FontAwesome.SAVE).withStyleName(WebThemes.BUTTON_ACTION);
    MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            clickEvent -> close()).withStyleName(WebThemes.BUTTON_OPTION);
    MHorizontalLayout buttonControls = new MHorizontalLayout(cancelBtn, okBtn);
    content.with(gridFormLayoutHelper.getLayout(), buttonControls).withAlign(buttonControls,
            Alignment.MIDDLE_RIGHT);
    this.setContent(content);
}

From source file:com.mycollab.module.project.view.settings.component.ComponentEditFormFieldFactory.java

License:Open Source License

@Override
protected Field<?> onCreateField(final Object propertyId) {
    if (Component.Field.name.equalTo(propertyId)) {
        final TextField tf = new TextField();
        if (isValidateForm) {
            tf.setNullRepresentation("");
            tf.setRequired(true);/* w  w  w.j ava2 s.  c om*/
            tf.setRequiredError(UserUIContext.getMessage(ErrorI18nEnum.FIELD_MUST_NOT_NULL,
                    UserUIContext.getMessage(GenericI18Enum.FORM_NAME)));
        }
        return tf;
    } else if (Component.Field.description.equalTo(propertyId)) {
        return new RichTextArea();
    } else if (Component.Field.userlead.equalTo(propertyId)) {
        return new ProjectMemberSelectionField();
    }

    return null;
}

From source file:com.mycollab.module.project.view.settings.component.VersionEditFormFieldFactory.java

License:Open Source License

@Override
protected Field<?> onCreateField(final Object propertyId) {
    if (Version.Field.name.equalTo(propertyId)) {
        final TextField tf = new TextField();
        if (isValidateForm) {
            tf.setNullRepresentation("");
            tf.setRequired(true);/*  www.j  av a 2s.  com*/
            tf.setRequiredError(UserUIContext.getMessage(ErrorI18nEnum.FIELD_MUST_NOT_NULL,
                    UserUIContext.getMessage(GenericI18Enum.FORM_NAME)));
        }
        return tf;
    } else if (Version.Field.description.equalTo(propertyId)) {
        return new RichTextArea();
    } else if (Version.Field.duedate.equalTo(propertyId)) {
        final PopupDateFieldExt dateField = new PopupDateFieldExt();
        dateField.setResolution(Resolution.DAY);
        return dateField;
    }

    return null;
}

From source file:com.mycollab.module.project.view.settings.ProjectRoleAddViewImpl.java

License:Open Source License

@Override
protected AbstractBeanFieldGroupEditFieldFactory<ProjectRole> initBeanFormFieldFactory() {
    return new AbstractBeanFieldGroupEditFieldFactory<ProjectRole>(editForm) {
        private static final long serialVersionUID = 1L;

        @Override/*from   www . j  ava 2s  . co m*/
        protected Field<?> onCreateField(Object propertyId) {
            if (propertyId.equals("description")) {
                final TextArea textArea = new TextArea();
                textArea.setNullRepresentation("");
                return textArea;
            } else if (propertyId.equals("rolename")) {
                final TextField tf = new TextField();
                if (isValidateForm) {
                    tf.setNullRepresentation("");
                    tf.setRequired(true);
                    tf.setRequiredError("Please enter a projectRole name");
                }
                return tf;
            }
            return null;
        }
    };
}

From source file:com.mycollab.module.project.view.task.components.ToggleTaskSummaryField.java

License:Open Source License

public ToggleTaskSummaryField(final SimpleTask task, int maxLength) {
    this.setWidth("100%");
    this.maxLength = maxLength;
    this.task = task;
    titleLinkLbl = ELabel.html(buildTaskLink()).withWidthUndefined().withStyleName(UIConstants.LABEL_WORD_WRAP);

    this.addComponent(titleLinkLbl);
    buttonControls = new MHorizontalLayout().withStyleName("toggle").withSpacing(false);
    if (CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS)) {
        this.addStyleName("editable-field");

        MButton instantEditBtn = new MButton("", clickEvent -> {
            if (isRead) {
                ToggleTaskSummaryField.this.removeComponent(titleLinkLbl);
                ToggleTaskSummaryField.this.removeComponent(buttonControls);
                final TextField editField = new TextField();
                editField.setValue(task.getTaskname());
                editField.setWidth("100%");
                editField.focus();/* w w w  .java  2 s  .  c  o  m*/
                ToggleTaskSummaryField.this.addComponent(editField);
                ToggleTaskSummaryField.this.removeStyleName("editable-field");
                editField.addValueChangeListener(valueChangeEvent -> updateFieldValue(editField));
                editField.addBlurListener(blurEvent -> updateFieldValue(editField));
                isRead = !isRead;
            }
        }).withIcon(FontAwesome.EDIT).withStyleName(ValoTheme.BUTTON_ICON_ONLY,
                ValoTheme.BUTTON_ICON_ALIGN_TOP);
        instantEditBtn.setDescription("Edit task name");
        buttonControls.with(instantEditBtn);
        this.addComponent(buttonControls);
    }
}

From source file:com.mycollab.module.project.view.task.TaskEditFormFieldFactory.java

License:Open Source License

@Override
protected Field<?> onCreateField(final Object propertyId) {
    if (Task.Field.assignuser.equalTo(propertyId)) {
        ProjectMemberSelectionField field = new ProjectMemberSelectionField();
        field.addValueChangeListener(valueChangeEvent -> {
            Property property = valueChangeEvent.getProperty();
            SimpleProjectMember member = (SimpleProjectMember) property.getValue();
            if (member != null) {
                subscribersComp.addFollower(member.getUsername());
            }/*from  w  w w .j a  va 2  s .c  om*/
        });
        return field;
    } else if (Task.Field.milestoneid.equalTo(propertyId)) {
        return new MilestoneComboBox();
    } else if (Task.Field.description.equalTo(propertyId)) {
        final RichTextArea richTextArea = new RichTextArea();
        richTextArea.setNullRepresentation("");
        return richTextArea;
    } else if (Task.Field.name.equalTo(propertyId)) {
        return new MTextField().withNullRepresentation("").withRequired(true)
                .withRequiredError(UserUIContext.getMessage(ErrorI18nEnum.FIELD_MUST_NOT_NULL,
                        UserUIContext.getMessage(GenericI18Enum.FORM_NAME)));
    } else if (Task.Field.status.equalTo(propertyId)) {
        return new TaskStatusComboBox();
    } else if (Task.Field.percentagecomplete.equalTo(propertyId)) {
        return new TaskSliderField();
    } else if (Task.Field.priority.equalTo(propertyId)) {
        return new PriorityComboBox();
    } else if (Task.Field.duration.equalTo(propertyId)) {
        final TextField field = new TextField();
        field.setConverter(new HumanTimeConverter());
        final SimpleTask beanItem = attachForm.getBean();
        if (beanItem.getNumSubTasks() != null && beanItem.getNumSubTasks() > 0) {
            field.setEnabled(false);
            field.setDescription(UserUIContext.getMessage(TaskI18nEnum.ERROR_CAN_NOT_EDIT_PARENT_TASK_FIELD));
        }

        //calculate the end date if the start date is set
        field.addBlurListener(blurEvent -> {
            HumanTime humanTime = HumanTime.eval(field.getValue());
            long duration = Long.valueOf(humanTime.getDelta() + "");
            DateTimeOptionField startDateField = (DateTimeOptionField) fieldGroup
                    .getField(Task.Field.startdate.name());
            Date startDateVal = startDateField.getValue();
            if (duration > 0 && startDateVal != null) {
                int daysDuration = (int) (duration / DateTimeUtils.MILLISECONDS_IN_A_DAY);
                if (daysDuration > 0) {
                    DateTime startDateJoda = new DateTime(startDateVal);
                    LocalDate calculatedDate = BusinessDayTimeUtils.plusDays(startDateJoda.toLocalDate(),
                            daysDuration);
                    DateTime endDateJoda = new DateTime(calculatedDate.toDate());
                    DateTimeOptionField endDateField = (DateTimeOptionField) fieldGroup
                            .getField(Task.Field.enddate.name());
                    beanItem.setEnddate(endDateJoda.toDate());
                    endDateField.setPropertyDataSource(
                            new TransactionalPropertyWrapper<>(new MethodProperty(beanItem, "enddate")));
                }
            }
        });
        return field;
    } else if (Task.Field.originalestimate.equalTo(propertyId)
            || Task.Field.remainestimate.equalTo(propertyId)) {
        return new DoubleField();
    } else if (Task.Field.startdate.equalTo(propertyId)) {
        final DateTimeOptionField startDateField = new DateTimeOptionField(true);
        startDateField.addValueChangeListener(valueChangeEvent -> calculateDurationBaseOnStartAndEndDates());
        return startDateField;
    } else if (Task.Field.enddate.equalTo(propertyId)) {
        DateTimeOptionField endDateField = new DateTimeOptionField(true);
        endDateField.addValueChangeListener(valueChangeEvent -> calculateDurationBaseOnStartAndEndDates());
        return endDateField;
    } else if (Task.Field.id.equalTo(propertyId)) {
        Task beanItem = attachForm.getBean();
        if (beanItem.getId() != null) {
            String attachmentPath = AttachmentUtils.getProjectEntityAttachmentPath(MyCollabUI.getAccountId(),
                    beanItem.getProjectid(), ProjectTypeConstants.TASK, "" + beanItem.getId());
            attachmentUploadField = new AttachmentUploadField(attachmentPath);
        } else {
            attachmentUploadField = new AttachmentUploadField();
        }
        return attachmentUploadField;
    } else if (Task.Field.duedate.equalTo(propertyId)) {
        return new DateTimeOptionField(true);
    } else if (propertyId.equals("selected")) {
        return subscribersComp;
    }
    return null;
}

From source file:com.mycollab.module.project.view.task.ToggleTaskSummaryField.java

License:Open Source License

public ToggleTaskSummaryField(final SimpleTask task, int maxLength, boolean toggleStatusSupport,
        boolean canRemove) {
    this.setWidth("100%");
    this.maxLength = maxLength;
    this.task = task;
    titleLinkLbl = ELabel.html(buildTaskLink()).withWidthUndefined().withStyleName(UIConstants.LABEL_WORD_WRAP);

    if (toggleStatusSupport && CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS)) {
        toggleStatusSelect = new CssCheckBox();
        toggleStatusSelect.setSimpleMode(true);
        toggleStatusSelect.setValue(task.isCompleted());
        displayTooltip();/*from   w ww .  j  a  v  a  2  s.c om*/
        toggleStatusSelect.addValueChangeListener(valueChangeEvent -> {
            if (task.isCompleted()) {
                task.setStatus(StatusI18nEnum.Open.name());
                task.setPercentagecomplete(0d);
                titleLinkLbl.removeStyleName(WebThemes.LINK_COMPLETED);
            } else {
                task.setStatus(StatusI18nEnum.Closed.name());
                task.setPercentagecomplete(100d);
                titleLinkLbl.addStyleName(WebThemes.LINK_COMPLETED);
            }
            displayTooltip();
            ProjectTaskService projectTaskService = AppContextUtil.getSpringBean(ProjectTaskService.class);
            projectTaskService.updateWithSession(task, UserUIContext.getUsername());

            if (StatusI18nEnum.Closed.name().equals(task.getStatus())) {
                Integer countOfOpenSubTasks = projectTaskService.getCountOfOpenSubTasks(task.getId());
                if (countOfOpenSubTasks > 0) {
                    ConfirmDialogExt.show(UI.getCurrent(),
                            UserUIContext.getMessage(GenericI18Enum.OPT_QUESTION, MyCollabUI.getSiteName()),
                            UserUIContext.getMessage(ProjectCommonI18nEnum.OPT_CLOSE_SUB_ASSIGNMENTS),
                            UserUIContext.getMessage(GenericI18Enum.BUTTON_YES),
                            UserUIContext.getMessage(GenericI18Enum.BUTTON_NO), confirmDialog -> {
                                if (confirmDialog.isConfirmed()) {
                                    projectTaskService.massUpdateTaskStatuses(task.getId(),
                                            StatusI18nEnum.Closed.name(), MyCollabUI.getAccountId());
                                }
                            });
                }
            }
        });
        this.addComponent(toggleStatusSelect);
        this.addComponent(ELabel.EMPTY_SPACE());
    }

    this.addComponent(titleLinkLbl);
    buttonControls = new MHorizontalLayout().withMargin(new MarginInfo(false, false, false, true))
            .withStyleName("toggle");
    if (CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS)) {
        this.addStyleName("editable-field");

        MButton instantEditBtn = new MButton("", clickEvent -> {
            if (isRead) {
                ToggleTaskSummaryField.this.removeComponent(titleLinkLbl);
                ToggleTaskSummaryField.this.removeComponent(buttonControls);
                final TextField editField = new TextField();
                editField.setValue(task.getName());
                editField.setWidth("100%");
                editField.focus();
                ToggleTaskSummaryField.this.addComponent(editField);
                ToggleTaskSummaryField.this.removeStyleName("editable-field");
                editField.addValueChangeListener(valueChangeEvent -> updateFieldValue(editField));
                editField.addBlurListener(blurEvent -> updateFieldValue(editField));
                isRead = !isRead;
            }
        }).withIcon(FontAwesome.EDIT).withStyleName(ValoTheme.BUTTON_ICON_ALIGN_TOP);
        instantEditBtn.setDescription(UserUIContext.getMessage(TaskI18nEnum.OPT_EDIT_TASK_NAME));
        buttonControls.with(instantEditBtn);
    }

    if (canRemove && CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.TASKS)) {
        MButton removeBtn = new MButton("", clickEvent -> {
            ConfirmDialogExt.show(UI.getCurrent(),
                    UserUIContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, MyCollabUI.getSiteName()),
                    UserUIContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE),
                    UserUIContext.getMessage(GenericI18Enum.BUTTON_YES),
                    UserUIContext.getMessage(GenericI18Enum.BUTTON_NO), confirmDialog -> {
                        if (confirmDialog.isConfirmed()) {
                            AppContextUtil.getSpringBean(ProjectTaskService.class).removeWithSession(task,
                                    UserUIContext.getUsername(), MyCollabUI.getAccountId());
                            BlockRowRender rowRenderer = UIUtils.getRoot(ToggleTaskSummaryField.this,
                                    BlockRowRender.class);
                            if (rowRenderer != null) {
                                rowRenderer.selfRemoved();
                            }
                            EventBusFactory.getInstance().post(new TaskEvent.TaskDeleted(this, task.getId()));
                        }
                    });
        }).withIcon(FontAwesome.TRASH).withStyleName(ValoTheme.BUTTON_ICON_ALIGN_TOP);
        buttonControls.with(removeBtn);
    }
    if (buttonControls.getComponentCount() > 0) {
        this.addComponent(buttonControls);
    }
}

From source file:com.mycollab.module.project.view.ticket.ToggleTicketSummaryField.java

License:Open Source License

public ToggleTicketSummaryField(final ProjectTicket ticket) {
    this.ticket = ticket;
    this.setWidth("100%");
    titleLinkLbl = ELabel.html(buildTicketLink())
            .withStyleName(ValoTheme.LABEL_NO_MARGIN, UIConstants.LABEL_WORD_WRAP).withWidthUndefined();
    if (ticket.isClosed()) {
        titleLinkLbl.addStyleName(WebThemes.LINK_COMPLETED);
    } else if (ticket.isOverdue()) {
        titleLinkLbl.addStyleName(WebThemes.LINK_OVERDUE);
    }//from w  w  w . j  a va 2 s .co  m
    this.addComponent(titleLinkLbl);
    if (CurrentProjectVariables.canWriteTicket(ticket)) {
        this.addStyleName("editable-field");
        buttonControls = new MHorizontalLayout().withMargin(new MarginInfo(false, false, false, true))
                .withStyleName("toggle");
        buttonControls.setDefaultComponentAlignment(Alignment.TOP_LEFT);
        MButton instantEditBtn = new MButton("", clickEvent -> {
            if (isRead) {
                removeComponent(titleLinkLbl);
                removeComponent(buttonControls);
                final TextField editField = new TextField();
                editField.setValue(ticket.getName());
                editField.setWidth("100%");
                editField.focus();
                addComponent(editField);
                removeStyleName("editable-field");
                editField.addValueChangeListener(valueChangeEvent -> updateFieldValue(editField));
                editField.addBlurListener(blurEvent -> updateFieldValue(editField));
                isRead = !isRead;
            }
        }).withIcon(FontAwesome.EDIT).withStyleName(ValoTheme.BUTTON_ICON_ALIGN_TOP);
        instantEditBtn.setDescription(UserUIContext.getMessage(GenericI18Enum.ACTION_CLICK_TO_EDIT));
        buttonControls.with(instantEditBtn);

        if ((ticket.isRisk() && CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.RISKS))
                || (ticket.isBug() && CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.BUGS))
                || (ticket.isTask()
                        && CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.TASKS))) {
            MButton removeBtn = new MButton("", clickEvent -> {
                ConfirmDialogExt.show(UI.getCurrent(),
                        UserUIContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, MyCollabUI.getSiteName()),
                        UserUIContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE),
                        UserUIContext.getMessage(GenericI18Enum.BUTTON_YES),
                        UserUIContext.getMessage(GenericI18Enum.BUTTON_NO), confirmDialog -> {
                            if (confirmDialog.isConfirmed()) {
                                AppContextUtil.getSpringBean(ProjectTicketService.class).removeTicket(ticket,
                                        UserUIContext.getUsername());
                                BlockRowRender rowRenderer = UIUtils.getRoot(ToggleTicketSummaryField.this,
                                        BlockRowRender.class);
                                if (rowRenderer != null) {
                                    rowRenderer.selfRemoved();
                                }
                                EventBusFactory.getInstance()
                                        .post(new TicketEvent.HasTicketPropertyChanged(this, "all"));
                            }
                        });
            }).withIcon(FontAwesome.TRASH).withStyleName(ValoTheme.BUTTON_ICON_ALIGN_TOP);
            buttonControls.with(removeBtn);
        }

        this.addComponent(buttonControls);
    }
}

From source file:com.mycollab.shell.view.SetupNewInstanceView.java

License:Open Source License

SetupNewInstanceView() {
    this.setDefaultComponentAlignment(Alignment.TOP_CENTER);
    MHorizontalLayout content = new MHorizontalLayout().withFullHeight();
    this.with(content);
    content.with(new MHorizontalLayout(
            ELabel.html(UserUIContext.getMessage(ShellI18nEnum.OPT_SUPPORTED_LANGUAGES_INTRO))
                    .withStyleName(WebThemes.META_COLOR)).withMargin(true).withWidth("400px")
                            .withStyleName("separator"));
    MVerticalLayout formLayout = new MVerticalLayout().withWidth("600px");
    content.with(formLayout).withAlign(formLayout, Alignment.TOP_LEFT);
    formLayout.with(ELabel.h2("Last step, you are almost there!").withWidthUndefined());
    formLayout.with(ELabel.h3("All fields are required *").withStyleName("overdue").withWidthUndefined());

    GridFormLayoutHelper formLayoutHelper = GridFormLayoutHelper.defaultFormLayoutHelper(2, 8, "200px");
    formLayoutHelper.getLayout().setWidth("600px");
    final TextField adminField = formLayoutHelper.addComponent(new TextField(), "Admin email", 0, 0);
    final PasswordField passwordField = formLayoutHelper.addComponent(new PasswordField(), "Admin password", 0,
            1);/*from   www.j  a v a  2s . c  o  m*/
    final PasswordField retypePasswordField = formLayoutHelper.addComponent(new PasswordField(),
            "Retype Admin password", 0, 2);
    final DateFormatField dateFormatField = formLayoutHelper.addComponent(
            new DateFormatField(SimpleBillingAccount.DEFAULT_DATE_FORMAT),
            UserUIContext.getMessage(AdminI18nEnum.FORM_DEFAULT_YYMMDD_FORMAT),
            UserUIContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 3);

    final DateFormatField shortDateFormatField = formLayoutHelper.addComponent(
            new DateFormatField(SimpleBillingAccount.DEFAULT_SHORT_DATE_FORMAT),
            UserUIContext.getMessage(AdminI18nEnum.FORM_DEFAULT_MMDD_FORMAT),
            UserUIContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 4);

    final DateFormatField longDateFormatField = formLayoutHelper.addComponent(
            new DateFormatField(SimpleBillingAccount.DEFAULT_LONG_DATE_FORMAT),
            UserUIContext.getMessage(AdminI18nEnum.FORM_DEFAULT_HUMAN_DATE_FORMAT),
            UserUIContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 5);

    final TimeZoneSelectionField timeZoneSelectionField = formLayoutHelper.addComponent(
            new TimeZoneSelectionField(false), UserUIContext.getMessage(AdminI18nEnum.FORM_DEFAULT_TIMEZONE), 0,
            6);
    timeZoneSelectionField.setValue(TimeZone.getDefault().getID());
    final LanguageSelectionField languageBox = formLayoutHelper.addComponent(new LanguageSelectionField(),
            UserUIContext.getMessage(AdminI18nEnum.FORM_DEFAULT_LANGUAGE), 0, 7);
    languageBox.setValue(Locale.US.toLanguageTag());
    formLayout.with(formLayoutHelper.getLayout());

    CheckBox createSampleDataSelection = new CheckBox("Create sample data", true);

    MButton installBtn = new MButton("Setup", clickEvent -> {
        String adminName = adminField.getValue();
        String password = passwordField.getValue();
        String retypePassword = retypePasswordField.getValue();
        if (!StringUtils.isValidEmail(adminName)) {
            NotificationUtil.showErrorNotification("Invalid email value");
            return;
        }

        if (!password.equals(retypePassword)) {
            NotificationUtil.showErrorNotification("Password is not match");
            return;
        }

        String dateFormat = dateFormatField.getValue();
        String shortDateFormat = shortDateFormatField.getValue();
        String longDateFormat = longDateFormatField.getValue();
        if (!isValidDayPattern(dateFormat) || !isValidDayPattern(shortDateFormat)
                || !isValidDayPattern(longDateFormat)) {
            NotificationUtil.showErrorNotification("Invalid date format");
            return;
        }
        String language = languageBox.getValue();
        String timezoneDbId = timeZoneSelectionField.getValue();
        BillingAccountMapper billingAccountMapper = AppContextUtil.getSpringBean(BillingAccountMapper.class);
        BillingAccountExample ex = new BillingAccountExample();
        ex.createCriteria().andIdEqualTo(MyCollabUI.getAccountId());
        List<BillingAccount> billingAccounts = billingAccountMapper.selectByExample(ex);
        BillingAccount billingAccount = billingAccounts.get(0);
        billingAccount.setDefaultlanguagetag(language);
        billingAccount.setDefaultyymmddformat(dateFormat);
        billingAccount.setDefaultmmddformat(shortDateFormat);
        billingAccount.setDefaulthumandateformat(longDateFormat);
        billingAccount.setDefaulttimezone(timezoneDbId);
        billingAccountMapper.updateByPrimaryKey(billingAccount);

        BillingAccountService billingAccountService = AppContextUtil.getSpringBean(BillingAccountService.class);
        billingAccountService.createDefaultAccountData(adminName, password, timezoneDbId, language, true,
                createSampleDataSelection.getValue(), MyCollabUI.getAccountId());

        ((DesktopApplication) UI.getCurrent()).doLogin(adminName, password, false);
    }).withStyleName(WebThemes.BUTTON_ACTION);

    MHorizontalLayout buttonControls = new MHorizontalLayout(createSampleDataSelection, installBtn)
            .alignAll(Alignment.MIDDLE_RIGHT);
    formLayout.with(buttonControls).withAlign(buttonControls, Alignment.MIDDLE_RIGHT);
}

From source file:com.mycollab.vaadin.web.ui.BuildCriterionComponent.java

License:Open Source License

private void buildSaveFilterBox() {
    filterBox.removeAllComponents();/*from   w w w  .  j ava 2 s  .co  m*/

    final TextField queryTextField = new TextField();
    filterBox.addComponent(queryTextField);

    MButton saveBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_SAVE), clickEvent -> {
        String queryText = queryTextField.getValue();
        saveSearchCriteria(queryText);
    }).withIcon(FontAwesome.SAVE).withStyleName(WebThemes.BUTTON_ACTION);
    filterBox.addComponent(saveBtn);

    MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            clickEvent -> buildFilterBox(null)).withStyleName(WebThemes.BUTTON_OPTION);
    filterBox.addComponent(cancelBtn);
}