Example usage for com.vaadin.ui Alignment TOP_CENTER

List of usage examples for com.vaadin.ui Alignment TOP_CENTER

Introduction

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

Prototype

Alignment TOP_CENTER

To view the source code for com.vaadin.ui Alignment TOP_CENTER.

Click Source Link

Usage

From source file:com.mycollab.community.shell.view.AdWindow.java

License:Open Source License

AdWindow() {
    super(UserUIContext.getMessage(LicenseI18nEnum.OPT_TRIAL_THE_PRO_EDITION));
    this.withModal(true).withResizable(false).withWidth("1000px");
    RestTemplate restTemplate = new RestTemplate();
    MVerticalLayout content = new MVerticalLayout();
    try {/* w  ww  .ja  v  a  2  s .  c  o  m*/
        String result = restTemplate.getForObject(SiteConfiguration.getApiUrl("storeweb"), String.class);
        ELabel webPage = ELabel.html(result);
        webPage.setHeight("600px");
        this.setContent(content.with(webPage).withAlign(webPage, Alignment.TOP_CENTER));
    } catch (Exception e) {
        Div informDiv = new Div()
                .appendText("Can not load the store page. You can check the online edition at ")
                .appendChild(new A("https://www.mycollab.com/pricing/download/", "_blank").appendText("here"));
        Label webPage = new Label(informDiv.write(), ContentMode.HTML);
        this.setContent(content.with(webPage).withAlign(webPage, Alignment.TOP_CENTER));
    }
}

From source file:com.mycollab.mobile.module.project.view.ProjectDashboardViewImpl.java

License:Open Source License

@Override
public void displayDashboard() {
    mainLayout.removeAllComponents();/*from  ww w . j  ava  2  s . com*/
    SimpleProject currentProject = CurrentProjectVariables.getProject();
    VerticalLayout projectInfo = new VerticalLayout();
    projectInfo.setStyleName("project-info-layout");
    projectInfo.setWidth("100%");
    projectInfo.setDefaultComponentAlignment(Alignment.TOP_CENTER);

    ELabel projectIcon = ELabel.fontIcon(FontAwesome.BUILDING_O).withStyleName("project-icon")
            .withWidthUndefined();
    projectInfo.addComponent(projectIcon);

    ELabel projectName = new ELabel(currentProject.getName()).withFullWidth().withStyleName("project-name");
    projectInfo.addComponent(projectName);

    MHorizontalLayout metaInfo = new MHorizontalLayout();

    Label projectMemberBtn = ELabel
            .html(FontAwesome.USERS.getHtml() + " " + currentProject.getNumActiveMembers())
            .withDescription(UserUIContext.getMessage(ProjectMemberI18nEnum.OPT_ACTIVE_MEMBERS))
            .withStyleName(UIConstants.META_INFO);

    metaInfo.addComponent(projectMemberBtn);
    Label createdTimeLbl = ELabel
            .html(FontAwesome.CLOCK_O.getHtml() + " "
                    + UserUIContext.formatPrettyTime(currentProject.getCreatedtime()))
            .withDescription(UserUIContext.getMessage(GenericI18Enum.FORM_CREATED_TIME))
            .withStyleName(UIConstants.META_INFO);
    metaInfo.addComponent(createdTimeLbl);

    Label billableHoursLbl = ELabel
            .html(FontAwesome.MONEY.getHtml() + " "
                    + NumberUtils.roundDouble(2, currentProject.getTotalBillableHours()))
            .withDescription(UserUIContext.getMessage(TimeTrackingI18nEnum.OPT_BILLABLE_HOURS))
            .withStyleName(UIConstants.META_INFO);
    metaInfo.addComponent(billableHoursLbl);

    Label nonBillableHoursLbl = ELabel
            .html(FontAwesome.GIFT.getHtml() + " "
                    + NumberUtils.roundDouble(2, currentProject.getTotalNonBillableHours()))
            .withDescription(UserUIContext.getMessage(TimeTrackingI18nEnum.OPT_NON_BILLABLE_HOURS))
            .withStyleName(UIConstants.META_INFO);
    metaInfo.addComponent(nonBillableHoursLbl);
    projectInfo.addComponent(metaInfo);

    int openAssignments = currentProject.getNumOpenBugs() + currentProject.getNumOpenTasks()
            + currentProject.getNumOpenRisks();
    int totalAssignments = currentProject.getNumBugs() + currentProject.getNumTasks()
            + currentProject.getNumRisks();
    ELabel progressInfoLbl;
    if (totalAssignments > 0) {
        progressInfoLbl = new ELabel(UserUIContext.getMessage(ProjectI18nEnum.OPT_PROJECT_TICKET,
                (totalAssignments - openAssignments), totalAssignments,
                (totalAssignments - openAssignments) * 100 / totalAssignments)).withWidthUndefined()
                        .withStyleName(UIConstants.META_INFO);
    } else {
        progressInfoLbl = new ELabel(UserUIContext.getMessage(ProjectI18nEnum.OPT_NO_TICKET))
                .withWidthUndefined().withStyleName(UIConstants.META_INFO);
    }
    projectInfo.addComponent(progressInfoLbl);

    mainLayout.addComponent(projectInfo);

    VerticalComponentGroup btnGroup = new VerticalComponentGroup();

    NavigationButton activityBtn = new NavigationButton(
            UserUIContext.getMessage(ProjectCommonI18nEnum.M_VIEW_PROJECT_ACTIVITIES));
    activityBtn.addClickListener(navigationButtonClickEvent -> EventBusFactory.getInstance()
            .post(new ProjectEvent.MyProjectActivities(this, CurrentProjectVariables.getProjectId())));
    btnGroup.addComponent(new NavigationButtonWrap(FontAwesome.INBOX, activityBtn));

    NavigationButton messageBtn = new NavigationButton(UserUIContext.getMessage(MessageI18nEnum.LIST));
    messageBtn.addClickListener(navigationButtonClickEvent -> EventBusFactory.getInstance()
            .post(new MessageEvent.GotoList(this, null)));
    btnGroup.addComponent(
            new NavigationButtonWrap(ProjectAssetsManager.getAsset(ProjectTypeConstants.MESSAGE), messageBtn));

    NavigationButton milestoneBtn = new NavigationButton(UserUIContext.getMessage(MilestoneI18nEnum.LIST));
    milestoneBtn.addClickListener(navigationButtonClickEvent -> EventBusFactory.getInstance()
            .post(new MilestoneEvent.GotoList(this, null)));
    btnGroup.addComponent(new NavigationButtonWrap(
            ProjectAssetsManager.getAsset(ProjectTypeConstants.MILESTONE), milestoneBtn));

    NavigationButton taskBtn = new NavigationButton(UserUIContext.getMessage(TicketI18nEnum.LIST));
    taskBtn.addClickListener(navigationButtonClickEvent -> EventBusFactory.getInstance()
            .post(new TicketEvent.GotoDashboard(this, null)));
    btnGroup.addComponent(
            new NavigationButtonWrap(ProjectAssetsManager.getAsset(ProjectTypeConstants.TICKET), taskBtn));

    NavigationButton userBtn = new NavigationButton(UserUIContext.getMessage(ProjectMemberI18nEnum.LIST));
    userBtn.addClickListener(navigationButtonClickEvent -> EventBusFactory.getInstance()
            .post(new ProjectMemberEvent.GotoList(this, null)));
    btnGroup.addComponent(new NavigationButtonWrap(FontAwesome.USERS, userBtn));

    mainLayout.addComponent(btnGroup);
}

From source file:com.mycollab.mobile.module.user.view.LoginViewImpl.java

License:Open Source License

private void initUI() {
    MVerticalLayout contentLayout = new MVerticalLayout().withStyleName("content-wrapper").withFullWidth();
    contentLayout.setDefaultComponentAlignment(Alignment.TOP_CENTER);

    Image mainLogo = new Image(null,
            AccountAssetsResolver.createLogoResource(MyCollabUI.getBillingAccount().getLogopath(), 150));
    contentLayout.addComponent(mainLogo);

    CssLayout welcomeTextWrapper = new CssLayout();
    ELabel welcomeText = new ELabel(
            LocalizationHelper.getMessage(MyCollabUI.getDefaultLocale(), ShellI18nEnum.BUTTON_LOG_IN))
                    .withStyleName("h1");
    welcomeTextWrapper.addComponent(welcomeText);
    contentLayout.addComponent(welcomeText);

    final EmailField emailField = new EmailField();
    new Dom(emailField).setAttribute("placeholder",
            LocalizationHelper.getMessage(MyCollabUI.getDefaultLocale(), GenericI18Enum.FORM_EMAIL));
    emailField.setWidth("100%");
    contentLayout.addComponent(emailField);

    final PasswordField pwdField = new PasswordField();
    pwdField.setWidth("100%");
    new Dom(pwdField).setAttribute("placeholder",
            LocalizationHelper.getMessage(MyCollabUI.getDefaultLocale(), ShellI18nEnum.FORM_PASSWORD));
    contentLayout.addComponent(pwdField);

    final CheckBox rememberPassword = new CheckBox(
            LocalizationHelper.getMessage(MyCollabUI.getDefaultLocale(), ShellI18nEnum.OPT_REMEMBER_PASSWORD),
            true);/*from   w  w w.j  av  a 2 s  . co  m*/
    rememberPassword.setWidth("100%");
    contentLayout.addComponent(rememberPassword);

    MButton signInBtn = new MButton(
            LocalizationHelper.getMessage(MyCollabUI.getDefaultLocale(), ShellI18nEnum.BUTTON_LOG_IN),
            clickEvent -> {
                try {
                    LoginViewImpl.this.fireEvent(new ViewEvent<>(LoginViewImpl.this, new UserEvent.PlainLogin(
                            emailField.getValue(), pwdField.getValue(), rememberPassword.getValue())));
                } catch (Exception e) {
                    throw new MyCollabException(e);
                }
            }).withStyleName(MobileUIConstants.BUTTON_ACTION);
    contentLayout.addComponent(signInBtn);

    this.addComponent(contentLayout);
}

From source file:com.mycollab.mobile.shell.view.MainView.java

License:Open Source License

public MainView() {
    super();/*from   w w  w . j  av  a 2s .  com*/
    this.setSizeFull();

    MVerticalLayout contentLayout = new MVerticalLayout().withStyleName("content-wrapper").withFullWidth();
    contentLayout.setDefaultComponentAlignment(Alignment.TOP_CENTER);

    Image mainLogo = new Image(null, new ThemeResource("icons/logo_m.png"));
    contentLayout.addComponent(mainLogo);

    Label introText = new Label(
            "MyCollab helps you do all your office jobs on the computers, phones and tablets you use");
    introText.setStyleName("intro-text");
    contentLayout.addComponent(introText);

    CssLayout welcomeTextWrapper = new CssLayout();
    welcomeTextWrapper.setStyleName("welcometext-wrapper");
    welcomeTextWrapper.setWidth("100%");
    welcomeTextWrapper.setHeight("15px");
    contentLayout.addComponent(welcomeTextWrapper);

    Button crmButton = new Button(UserUIContext.getMessage(GenericI18Enum.MODULE_CRM),
            clickEvent -> EventBusFactory.getInstance().post(new ShellEvent.GotoCrmModule(this, null)));
    crmButton.addStyleName(MobileUIConstants.BUTTON_ACTION);
    crmButton.setWidth("100%");

    contentLayout.addComponent(crmButton);

    Button pmButton = new Button(UserUIContext.getMessage(GenericI18Enum.MODULE_PROJECT),
            clickEvent -> EventBusFactory.getInstance().post(new ShellEvent.GotoProjectModule(this, null)));
    pmButton.setWidth("100%");
    pmButton.addStyleName(MobileUIConstants.BUTTON_ACTION);
    contentLayout.addComponent(pmButton);

    this.addComponent(contentLayout);
}

From source file:com.mycollab.module.crm.ui.components.CrmListNoItemView.java

License:Open Source License

public CrmListNoItemView() {
    ELabel image = ELabel.h2(titleIcon().getHtml()).withWidthUndefined();
    ELabel title = ELabel.h2(titleMessage()).withWidthUndefined();
    ELabel hintLabel = new ELabel(hintMessage()).withWidthUndefined();

    MButton createItemBtn = new MButton(actionMessage(), actionListener())
            .withStyleName(WebThemes.BUTTON_ACTION).withVisible(hasPermission());
    MHorizontalLayout links = new MHorizontalLayout(createItemBtn);
    MVerticalLayout layout = new MVerticalLayout(image, title, hintLabel, links).withWidth("800px")
            .alignAll(Alignment.TOP_CENTER);
    this.with(layout).withAlign(layout, Alignment.TOP_CENTER);
}

From source file:com.mycollab.module.project.ui.components.ProjectListNoItemView.java

License:Open Source License

public ProjectListNoItemView() {
    MVerticalLayout content = new MVerticalLayout().withWidth("700px");
    ELabel image = ELabel.h2(viewIcon().getHtml()).withWidthUndefined();

    ELabel title = ELabel.h2(viewTitle()).withWidthUndefined();
    ELabel body = ELabel.html(viewHint()).withStyleName(UIConstants.LABEL_WORD_WRAP).withWidthUndefined();
    MHorizontalLayout links = createControlButtons();
    content.with(image, title, body, links).alignAll(Alignment.TOP_CENTER);
    this.addComponent(content);
    this.setComponentAlignment(content, Alignment.MIDDLE_CENTER);
}

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

License:Open Source License

@Override
public void lazyLoadView() {
    UserDashboardView userDashboardView = UIUtils.getRoot(this, UserDashboardView.class);
    List<Integer> prjKeys = userDashboardView.getInvolvedProjectKeys();
    if (CollectionUtils.isNotEmpty(prjKeys)) {
        ResponsiveLayout contentWrapper = new ResponsiveLayout(ResponsiveLayout.ContainerType.FIXED);
        contentWrapper.setSizeFull();/* w w  w . jav a  2  s .  c om*/
        addComponent(contentWrapper);

        ResponsiveRow row = new ResponsiveRow();

        AllMilestoneTimelineWidget milestoneTimelineWidget = new AllMilestoneTimelineWidget();
        TicketOverdueWidget ticketOverdueWidget = new TicketOverdueWidget();
        ActivityStreamComponent activityStreamComponent = new ActivityStreamComponent();
        UserUnresolvedTicketWidget unresolvedAssignmentThisWeekWidget = new UserUnresolvedTicketWidget();
        UserUnresolvedTicketWidget unresolvedAssignmentNextWeekWidget = new UserUnresolvedTicketWidget();

        ResponsiveColumn column1 = new ResponsiveColumn();
        column1.addRule(ResponsiveLayout.DisplaySize.LG, 7);
        column1.addRule(ResponsiveLayout.DisplaySize.MD, 7);
        column1.addRule(ResponsiveLayout.DisplaySize.SM, 12);
        column1.addRule(ResponsiveLayout.DisplaySize.XS, 12);
        MVerticalLayout leftPanel = new MVerticalLayout(milestoneTimelineWidget,
                unresolvedAssignmentThisWeekWidget, unresolvedAssignmentNextWeekWidget, ticketOverdueWidget)
                        .withMargin(new MarginInfo(true, true, false, false)).withFullWidth();
        column1.setComponent(leftPanel);

        MVerticalLayout rightPanel = new MVerticalLayout().withMargin(false);
        MyProjectListComponent myProjectListComponent = new MyProjectListComponent();
        rightPanel.with(myProjectListComponent, activityStreamComponent);

        ResponsiveColumn column2 = new ResponsiveColumn();
        column2.addRule(ResponsiveLayout.DisplaySize.LG, 5);
        column2.addRule(ResponsiveLayout.DisplaySize.MD, 5);
        column1.addRule(ResponsiveLayout.DisplaySize.SM, 12);
        column1.addRule(ResponsiveLayout.DisplaySize.XS, 12);
        column2.setComponent(rightPanel);

        row.addColumn(column1);
        row.addColumn(column2);
        contentWrapper.addRow(row);

        activityStreamComponent.showFeeds(prjKeys);
        milestoneTimelineWidget.display();
        myProjectListComponent.displayDefaultProjectsList();
        ticketOverdueWidget.showTicketsByStatus(prjKeys);
        unresolvedAssignmentThisWeekWidget.displayUnresolvedAssignmentsThisWeek();
        unresolvedAssignmentNextWeekWidget.displayUnresolvedAssignmentsNextWeek();
    } else {
        this.with(ELabel.h1(VaadinIcons.TASKS.getHtml()).withWidthUndefined());
        this.with(ELabel.h2(UserUIContext.getMessage(GenericI18Enum.VIEW_NO_ITEM_TITLE)).withWidthUndefined());
        if (UserUIContext.canWrite(RolePermissionCollections.CREATE_NEW_PROJECT)) {
            MButton newProjectBtn = new MButton(UserUIContext.getMessage(ProjectI18nEnum.NEW),
                    clickEvent -> UI.getCurrent()
                            .addWindow(ViewManager.getCacheComponent(AbstractProjectAddWindow.class)))
                                    .withStyleName(WebThemes.BUTTON_ACTION).withIcon(FontAwesome.PLUS);
            with(newProjectBtn);
        }
        alignAll(Alignment.TOP_CENTER);
    }
}

From source file:com.mycollab.reporting.CustomizeReportOutputWindow.java

License:Open Source License

public CustomizeReportOutputWindow(final String viewId, final String reportTitle, final Class<B> beanCls,
        final ISearchableService<S> searchableService, final VariableInjector<S> variableInjector) {
    super(UserUIContext.getMessage(GenericI18Enum.ACTION_EXPORT));
    MVerticalLayout contentLayout = new MVerticalLayout();
    this.withModal(true).withResizable(false).withWidth("1000px").withCenter().withContent(contentLayout);
    this.viewId = viewId;
    this.variableInjector = variableInjector;

    final OptionGroup optionGroup = new OptionGroup();
    optionGroup.addStyleName("sortDirection");
    optionGroup.addItems(UserUIContext.getMessage(FileI18nEnum.CSV), UserUIContext.getMessage(FileI18nEnum.PDF),
            UserUIContext.getMessage(FileI18nEnum.EXCEL));
    optionGroup.setValue(UserUIContext.getMessage(FileI18nEnum.CSV));
    contentLayout.with(new MHorizontalLayout(ELabel.h3(UserUIContext.getMessage(GenericI18Enum.ACTION_EXPORT)),
            optionGroup).alignAll(Alignment.MIDDLE_LEFT));

    contentLayout.with(ELabel.h3(UserUIContext.getMessage(GenericI18Enum.ACTION_SELECT_COLUMNS)));
    listBuilder = new ListBuilder();
    listBuilder.setImmediate(true);/*from  ww w  .  j  a v  a  2 s.c  o m*/
    listBuilder.setColumns(0);
    listBuilder.setLeftColumnCaption(UserUIContext.getMessage(GenericI18Enum.OPT_AVAILABLE_COLUMNS));
    listBuilder.setRightColumnCaption(UserUIContext.getMessage(GenericI18Enum.OPT_VIEW_COLUMNS));
    listBuilder.setWidth(100, Sizeable.Unit.PERCENTAGE);
    listBuilder.setItemCaptionMode(AbstractSelect.ItemCaptionMode.EXPLICIT);
    final BeanItemContainer<TableViewField> container = new BeanItemContainer<>(TableViewField.class,
            this.getAvailableColumns());
    listBuilder.setContainerDataSource(container);
    for (TableViewField field : getAvailableColumns()) {
        listBuilder.setItemCaption(field, UserUIContext.getMessage(field.getDescKey()));
    }
    final Collection<TableViewField> viewColumnIds = this.getViewColumns();
    listBuilder.setValue(viewColumnIds);
    contentLayout.with(listBuilder).withAlign(listBuilder, Alignment.TOP_CENTER);

    contentLayout.with(ELabel.h3(UserUIContext.getMessage(GenericI18Enum.ACTION_PREVIEW)));
    sampleTableDisplay = new Table();
    for (TableViewField field : getAvailableColumns()) {
        sampleTableDisplay.addContainerProperty(field.getField(), String.class, "",
                UserUIContext.getMessage(field.getDescKey()), null, Table.Align.LEFT);
        sampleTableDisplay.setColumnWidth(field.getField(), field.getDefaultWidth());
    }
    sampleTableDisplay.setWidth("100%");
    sampleTableDisplay.addItem(buildSampleData(), 1);
    sampleTableDisplay.setPageLength(1);
    contentLayout.with(sampleTableDisplay);
    filterColumns();

    listBuilder.addValueChangeListener(valueChangeEvent -> filterColumns());

    MButton resetBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_RESET), clickEvent -> {
        listBuilder.setValue(getDefaultColumns());
        filterColumns();
    }).withStyleName(WebThemes.BUTTON_LINK);

    MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            clickEvent -> close()).withStyleName(WebThemes.BUTTON_OPTION);

    final MButton exportBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.ACTION_EXPORT))
            .withStyleName(WebThemes.BUTTON_ACTION).withIcon(FontAwesome.DOWNLOAD);
    OnDemandFileDownloader pdfFileDownloader = new OnDemandFileDownloader(new LazyStreamSource() {
        @Override
        protected StreamResource.StreamSource buildStreamSource() {
            return (StreamResource.StreamSource) () -> {
                Collection<TableViewField> columns = (Collection<TableViewField>) listBuilder.getValue();
                // Save custom table view def
                CustomViewStoreService customViewStoreService = AppContextUtil
                        .getSpringBean(CustomViewStoreService.class);
                CustomViewStore viewDef = new CustomViewStore();
                viewDef.setSaccountid(MyCollabUI.getAccountId());
                viewDef.setCreateduser(UserUIContext.getUsername());
                viewDef.setViewid(viewId);
                viewDef.setViewinfo(FieldDefAnalyzer.toJson(new ArrayList<>(columns)));
                customViewStoreService.saveOrUpdateViewLayoutDef(viewDef);

                SimpleReportTemplateExecutor reportTemplateExecutor = new SimpleReportTemplateExecutor.AllItems<>(
                        reportTitle, new RpFieldsBuilder(columns), exportType, beanCls, searchableService);
                ReportStreamSource streamSource = new ReportStreamSource(reportTemplateExecutor) {
                    @Override
                    protected void initReportParameters(Map<String, Object> parameters) {
                        parameters.put(SimpleReportTemplateExecutor.CRITERIA, variableInjector.eval());
                    }
                };
                return streamSource.getStream();
            };
        }

        @Override
        public String getFilename() {
            String exportTypeVal = (String) optionGroup.getValue();
            if (UserUIContext.getMessage(FileI18nEnum.CSV).equals(exportTypeVal)) {
                exportType = ReportExportType.CSV;
            } else if (UserUIContext.getMessage(FileI18nEnum.EXCEL).equals(exportTypeVal)) {
                exportType = ReportExportType.EXCEL;
            } else {
                exportType = ReportExportType.PDF;
            }
            return exportType.getDefaultFileName();
        }
    });
    pdfFileDownloader.extend(exportBtn);

    MHorizontalLayout buttonControls = new MHorizontalLayout(resetBtn, cancelBtn, exportBtn);
    contentLayout.with(buttonControls).withAlign(buttonControls, Alignment.TOP_RIGHT);
}

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);/*ww  w  .ja  va  2  s  .  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.mvp.view.NotPresentedView.java

License:Open Source License

public NotPresentedView() {
    MVerticalLayout bodyLayout = new MVerticalLayout().withMargin(false);
    setContent(bodyLayout);//from  w ww. j  av a  2  s.  c o  m
    bodyLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);

    final ELabel titleIcon = ELabel.fontIcon(FontAwesome.EXCLAMATION_CIRCLE).withStyleName("warning-icon",
            ValoTheme.LABEL_NO_MARGIN);
    titleIcon.setWidthUndefined();
    bodyLayout.with(titleIcon);

    Label label = ELabel
            .h2(UserUIContext.getMessage(GenericI18Enum.NOTIFICATION_FEATURE_NOT_AVAILABLE_IN_VERSION))
            .withWidthUndefined();
    bodyLayout.with(label).withAlign(label, Alignment.MIDDLE_CENTER);

    RestTemplate restTemplate = new RestTemplate();
    try {
        String result = restTemplate.getForObject(SiteConfiguration.getApiUrl("storeweb"), String.class);
        ELabel webPage = ELabel.html(result);
        webPage.setHeight("480px");
        bodyLayout
                .with(new MVerticalLayout(webPage).withMargin(false).withAlign(webPage, Alignment.TOP_CENTER));
    } catch (Exception e) {
        Div informDiv = new Div()
                .appendText("Can not load the store page. You can check the online edition at ")
                .appendChild(new A("https://www.mycollab.com/pricing/download/", "_blank").appendText("here"));
        ELabel webPage = ELabel.html(informDiv.write()).withWidthUndefined();
        bodyLayout.with(new MVerticalLayout(webPage).withAlign(webPage, Alignment.TOP_CENTER));
    }
}