Example usage for com.vaadin.ui Alignment MIDDLE_LEFT

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

Introduction

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

Prototype

Alignment MIDDLE_LEFT

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

Click Source Link

Usage

From source file:annis.gui.SearchUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    super.init(request);

    this.instanceConfig = getInstanceConfig(request);

    getPage().setTitle(instanceConfig.getInstanceDisplayName() + " (ANNIS Corpus Search)");

    queryController = new QueryController(this);

    refresh = new Refresher();
    // deactivate refresher by default
    refresh.setRefreshInterval(-1);//from  w ww  .j a v  a2 s .c  o  m
    refresh.addListener(queryController);
    addExtension(refresh);

    // always get the resize events directly
    setImmediate(true);

    VerticalLayout mainLayout = new VerticalLayout();
    setContent(mainLayout);

    mainLayout.setSizeFull();
    mainLayout.setMargin(false);

    final ScreenshotMaker screenshot = new ScreenshotMaker(this);
    addExtension(screenshot);

    css = new CSSInject(this);

    HorizontalLayout layoutToolbar = new HorizontalLayout();
    layoutToolbar.setWidth("100%");
    layoutToolbar.setHeight("-1px");

    mainLayout.addComponent(layoutToolbar);
    layoutToolbar.addStyleName("toolbar");
    layoutToolbar.addStyleName("border-layout");

    Button btAboutAnnis = new Button("About ANNIS");
    btAboutAnnis.addStyleName(ChameleonTheme.BUTTON_SMALL);
    btAboutAnnis.setIcon(new ThemeResource("info.gif"));

    btAboutAnnis.addClickListener(new AboutClickListener());

    btBugReport = new Button("Report Bug");
    btBugReport.addStyleName(ChameleonTheme.BUTTON_SMALL);
    btBugReport.setDisableOnClick(true);
    btBugReport.setIcon(new ThemeResource("../runo/icons/16/email.png"));
    btBugReport.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            screenshot.makeScreenshot();
            btBugReport.setCaption("bug report is initialized...");
        }
    });

    String bugmail = (String) VaadinSession.getCurrent().getAttribute("bug-e-mail");
    if (bugmail != null && !bugmail.isEmpty() && !bugmail.startsWith("${")
            && new EmailValidator("").isValid(bugmail)) {
        this.bugEMailAddress = bugmail;
    }
    btBugReport.setVisible(this.bugEMailAddress != null);

    lblUserName = new Label("not logged in");
    lblUserName.setWidth("-1px");
    lblUserName.setHeight("-1px");
    lblUserName.addStyleName("right-aligned-text");

    btLoginLogout = new Button("Login", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (isLoggedIn()) {
                // logout
                Helper.setUser(null);
                Notification.show("Logged out", Notification.Type.TRAY_NOTIFICATION);
                updateUserInformation();
            } else {
                showLoginWindow();
            }
        }
    });
    btLoginLogout.setSizeUndefined();
    btLoginLogout.setStyleName(ChameleonTheme.BUTTON_SMALL);
    btLoginLogout.setIcon(new ThemeResource("../runo/icons/16/user.png"));

    Button btOpenSource = new Button("Help us to make ANNIS better!");
    btOpenSource.setStyleName(BaseTheme.BUTTON_LINK);
    btOpenSource.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Window w = new HelpUsWindow();
            w.setCaption("Help us to make ANNIS better!");
            w.setModal(true);
            w.setResizable(true);
            w.setWidth("600px");
            w.setHeight("500px");
            addWindow(w);
            w.center();
        }
    });

    layoutToolbar.addComponent(btAboutAnnis);
    layoutToolbar.addComponent(btBugReport);
    layoutToolbar.addComponent(btOpenSource);
    layoutToolbar.addComponent(lblUserName);
    layoutToolbar.addComponent(btLoginLogout);

    layoutToolbar.setSpacing(true);
    layoutToolbar.setComponentAlignment(btAboutAnnis, Alignment.MIDDLE_LEFT);
    layoutToolbar.setComponentAlignment(btBugReport, Alignment.MIDDLE_LEFT);
    layoutToolbar.setComponentAlignment(btOpenSource, Alignment.MIDDLE_CENTER);
    layoutToolbar.setComponentAlignment(lblUserName, Alignment.MIDDLE_RIGHT);
    layoutToolbar.setComponentAlignment(btLoginLogout, Alignment.MIDDLE_RIGHT);
    layoutToolbar.setExpandRatio(btOpenSource, 1.0f);

    //HorizontalLayout hLayout = new HorizontalLayout();
    final HorizontalSplitPanel hSplit = new HorizontalSplitPanel();
    hSplit.setSizeFull();

    mainLayout.addComponent(hSplit);
    mainLayout.setExpandRatio(hSplit, 1.0f);

    AutoGeneratedQueries autoGenQueries = new AutoGeneratedQueries("example queries", this);

    controlPanel = new ControlPanel(queryController, instanceConfig, autoGenQueries);
    controlPanel.setWidth(100f, Layout.Unit.PERCENTAGE);
    controlPanel.setHeight(100f, Layout.Unit.PERCENTAGE);
    hSplit.setFirstComponent(controlPanel);

    tutorial = new TutorialPanel();
    tutorial.setHeight("99%");

    mainTab = new TabSheet();
    mainTab.setSizeFull();
    mainTab.addTab(autoGenQueries, "example queries");
    mainTab.addTab(tutorial, "Tutorial");

    queryBuilder = new QueryBuilderChooser(queryController, this, instanceConfig);
    mainTab.addTab(queryBuilder, "Query Builder");

    hSplit.setSecondComponent(mainTab);
    hSplit.setSplitPosition(CONTROL_PANEL_WIDTH, Unit.PIXELS);
    hSplit.addSplitterClickListener(new AbstractSplitPanel.SplitterClickListener() {
        @Override
        public void splitterClick(AbstractSplitPanel.SplitterClickEvent event) {
            if (event.isDoubleClick()) {
                if (hSplit.getSplitPosition() == CONTROL_PANEL_WIDTH) {
                    // make small
                    hSplit.setSplitPosition(0.0f, Unit.PIXELS);
                } else {
                    // reset to default width
                    hSplit.setSplitPosition(CONTROL_PANEL_WIDTH, Unit.PIXELS);
                }
            }
        }
    });
    // hLayout.setExpandRatio(mainTab, 1.0f);

    addAction(new ShortcutListener("^Query builder") {
        @Override
        public void handleAction(Object sender, Object target) {
            mainTab.setSelectedTab(queryBuilder);
        }
    });

    addAction(new ShortcutListener("Tutor^eial") {
        @Override
        public void handleAction(Object sender, Object target) {
            mainTab.setSelectedTab(tutorial);
        }
    });

    getPage().addUriFragmentChangedListener(this);

    getSession().addRequestHandler(new RequestHandler() {
        @Override
        public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
                throws IOException {
            checkCitation(request);

            if (request.getPathInfo() != null && request.getPathInfo().startsWith("/vis-iframe-res/")) {
                String uuidString = StringUtils.removeStart(request.getPathInfo(), "/vis-iframe-res/");
                UUID uuid = UUID.fromString(uuidString);
                IFrameResourceMap map = VaadinSession.getCurrent().getAttribute(IFrameResourceMap.class);
                if (map == null) {
                    response.setStatus(404);
                } else {
                    IFrameResource res = map.get(uuid);
                    if (res != null) {
                        response.setStatus(200);
                        response.setContentType(res.getMimeType());
                        response.getOutputStream().write(res.getData());
                    }
                }
                return true;
            }

            return false;
        }
    });

    getSession().setAttribute(MediaController.class, new MediaControllerImpl());

    getSession().setAttribute(PDFController.class, new PDFControllerImpl());

    loadInstanceFonts();

    checkCitation(request);
    lastQueriedFragment = "";
    evaluateFragment(getPage().getUriFragment());

    updateUserInformation();
}

From source file:at.peppol.webgui.app.components.InvoiceUploadWindow.java

License:Mozilla Public License

public InvoiceUploadWindow() {
    this.setSpacing(true);
    subwindow = new Window("Upload Invoice");
    subwindow.addComponent(status);/*from w  ww . j  av a 2 s  . c  o  m*/
    subwindow.addComponent(progressLayout);
    subwindow.addComponent(upload);
    subwindow.addStyleName("upload-popup");
    subwindow.setModal(true);

    upload.setImmediate(true);
    upload.setButtonCaption("Select local invoice");

    progressLayout.setSpacing(true);
    progressLayout.setVisible(false);
    progressLayout.addComponent(pi);
    progressLayout.setComponentAlignment(pi, Alignment.MIDDLE_LEFT);

    final Button cancelProcessing = new Button("Cancel");
    cancelProcessing.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(final com.vaadin.ui.Button.ClickEvent event) {
            upload.interruptUpload();
        }
    });
    cancelProcessing.setStyleName("small");
    progressLayout.addComponent(cancelProcessing);
    upload.addListener(new Upload.StartedListener() {

        @Override
        public void uploadStarted(final StartedEvent event) {
            // This method gets called immediately after upload is started
            upload.setVisible(false);
            progressLayout.setVisible(true);
            pi.setValue(Float.valueOf(0f));
            pi.setPollingInterval(500);
            status.setValue("Uploading file \"" + event.getFilename() + "\"");
        }
    });

    upload.addListener(new Upload.ProgressListener() {

        public void updateProgress(final long readBytes, final long contentLength) {
            // This method gets called several times during the update
            pi.setValue(new Float(readBytes / (float) contentLength));
        }
    });

    upload.addListener(new Upload.SucceededListener() {

        @Override
        public void uploadSucceeded(final SucceededEvent event) {
            // This method gets called when the upload finished successfully
            status.setValue("Uploading file \"" + event.getFilename() + "\" succeeded");
            if (ur != null) {
                ur.setSuccess(true);
            } else {
                logger.warn("Invoice upload succeeded, but no Upload request present!");
            }
        }
    });

    upload.addListener(new Upload.FailedListener() {

        @Override
        public void uploadFailed(final FailedEvent event) {
            status.setValue("Uploading interrupted");
            if (ur != null) {
                ur.setSuccess(false);
            } else {
                logger.warn("Invoice upload failed, but no Upload request present!");
            }
        }
    });

    upload.addListener(new Upload.FinishedListener() {

        @Override
        public void uploadFinished(final FinishedEvent event) {
            // This method gets called always when the upload finished, either
            // succeeding or failing
            progressLayout.setVisible(false);
            upload.setVisible(true);
            upload.setCaption("Select another file more filesss");
        }
    });

}

From source file:at.peppol.webgui.app.components.OrderUploadWindow.java

License:Mozilla Public License

public OrderUploadWindow() {
    this.setSpacing(true);
    subwindow = new Window("Upload Order");
    subwindow.addComponent(status);/*  ww w .  ja v a2  s .c  om*/
    subwindow.addComponent(progressLayout);
    subwindow.addComponent(upload);
    subwindow.addStyleName("upload-popup");
    subwindow.setModal(true);

    upload.setImmediate(true);
    upload.setButtonCaption("Select local order");

    progressLayout.setSpacing(true);
    progressLayout.setVisible(false);
    progressLayout.addComponent(pi);
    progressLayout.setComponentAlignment(pi, Alignment.MIDDLE_LEFT);

    final Button cancelProcessing = new Button("Cancel");
    cancelProcessing.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final com.vaadin.ui.Button.ClickEvent event) {
            upload.interruptUpload();
        }
    });
    cancelProcessing.setStyleName("small");
    progressLayout.addComponent(cancelProcessing);
    upload.addListener(new Upload.StartedListener() {

        @Override
        public void uploadStarted(final StartedEvent event) {
            // This method gets called immediately after upload is started
            upload.setVisible(false);
            progressLayout.setVisible(true);
            pi.setValue(Float.valueOf(0f));
            pi.setPollingInterval(500);
            status.setValue("Uploading file \"" + event.getFilename() + "\"");
        }
    });

    upload.addListener(new Upload.ProgressListener() {
        public void updateProgress(final long readBytes, final long contentLength) {
            // This method gets called several times during the update
            pi.setValue(new Float(readBytes / (float) contentLength));
        }
    });

    upload.addListener(new Upload.SucceededListener() {
        @Override
        public void uploadSucceeded(final SucceededEvent event) {
            // This method gets called when the upload finished successfully
            status.setValue("Uploading file \"" + event.getFilename() + "\" succeeded");
            if (ur != null)
                ur.setSuccess(true);
            else
                logger.warn("Order upload succeeded, but no Upload request present!");
        }
    });

    upload.addListener(new Upload.FailedListener() {
        @Override
        public void uploadFailed(final FailedEvent event) {
            status.setValue("Uploading interrupted");
            if (ur != null)
                ur.setSuccess(false);
            else
                logger.warn("Order upload failed, but no Upload request present!");
        }
    });

    upload.addListener(new Upload.FinishedListener() {
        @Override
        public void uploadFinished(final FinishedEvent event) {
            // This method gets called always when the upload finished, either
            // succeeding or failing
            progressLayout.setVisible(false);
            upload.setVisible(true);
            upload.setCaption("Select another file");
        }
    });

}

From source file:br.com.anteros.mobileserver.app.form.LogForm.java

License:Apache License

private void createForm() {
    btnRefresh = new Button("Atualizar");
    btnRefresh.addListener(this);
    header = new VerticalLayout();
    header.addComponent(btnRefresh);/* w  ww .ja  va2s  . co m*/
    header.setWidth("100%");
    header.setComponentAlignment(btnRefresh, Alignment.MIDDLE_LEFT);
    addComponent(header);

    textPanel = new Panel();
    textPanel.setImmediate(true);
    textPanel.setHeight("100%");
    textPanel.setWidth("100%");

    textLog = new Label();
    textLog.setContentMode(Label.CONTENT_XHTML);
    textLog.setWidth("100%");
    textLog.setHeight("100%");
    addComponent(textPanel);
    textPanel.addComponent(textLog);
}

From source file:br.com.anteros.mobileserver.app.form.ProcedureForm.java

License:Apache License

private void createButtons() {
    buttons = new HorizontalLayout();
    buttons.setSpacing(true);//from   w w  w.j a va  2 s  . c  o m
    buttons.setWidth("100%");

    btnAddParameter = new Button("Adicionar", this);
    btnAddParameter.setIcon(new ThemeResource("icons/16/parameterAdd.png"));
    buttons.addComponent(btnAddParameter);
    buttons.setComponentAlignment(btnAddParameter, Alignment.MIDDLE_LEFT);

    btnRemoveParameter = new Button("Remover", this);
    btnRemoveParameter.setIcon(new ThemeResource("icons/16/parameterRemove.png"));
    buttons.addComponent(btnRemoveParameter);
    buttons.setComponentAlignment(btnRemoveParameter, Alignment.MIDDLE_LEFT);

    btnEditParameter = new Button("Editar", this);
    btnEditParameter.setIcon(new ThemeResource("icons/16/parameterEdit.png"));
    buttons.addComponent(btnEditParameter);
    buttons.setComponentAlignment(btnEditParameter, Alignment.MIDDLE_LEFT);

    btnImport = new Button("Importar parmetros", this);
    btnImport.setIcon(new ThemeResource("icons/16/import.png"));
    buttons.addComponent(btnImport);
    buttons.setComponentAlignment(btnImport, Alignment.MIDDLE_LEFT);

    btnMoveUp = new Button("Mover p/cima", this);
    btnMoveUp.setIcon(new ThemeResource("icons/16/moveUp.png"));
    buttons.addComponent(btnMoveUp);
    buttons.setComponentAlignment(btnMoveUp, Alignment.MIDDLE_LEFT);

    btnMoveDown = new Button("Mover p/baixo", this);
    btnMoveDown.setIcon(new ThemeResource("icons/16/moveDown.png"));
    buttons.addComponent(btnMoveDown);
    buttons.setComponentAlignment(btnMoveDown, Alignment.MIDDLE_LEFT);

    btnOk = new Button("Ok", this);
    btnOk.addStyleName("default");
    btnOk.setIcon(new ThemeResource("icons/16/ok.png"));
    buttons.addComponent(btnOk);
    buttons.setComponentAlignment(btnOk, Alignment.MIDDLE_RIGHT);
    buttons.setExpandRatio(btnOk, 1);

    btnCancel = new Button("Cancela", this);
    btnCancel.setIcon(new ThemeResource("icons/16/cancel.png"));
    buttons.addComponent(btnCancel);
    buttons.setComponentAlignment(btnCancel, Alignment.MIDDLE_RIGHT);
    buttons.setMargin(true, false, true, false);
}

From source file:ch.bfh.ti.soed.hs16.srs.purple.view.ViewStructure.java

License:Open Source License

/**
 * Function inits the components of the graphical userinterface (GUI).
 *
 * @param vaadinRequest/*from   w  ww. j a  v  a  2  s. c  om*/
 *            - The vaadin request
 */
@Override
protected void init(VaadinRequest vaadinRequest) {

    this.contentPanel.setStyleName(Reindeer.PANEL_LIGHT);
    this.contentPanel.setSizeFull();
    this.contentPanel.addStyleName("contenPanel");
    this.contentPanel.setImmediate(true);
    this.logo.addStyleName("logo");

    this.reservationView.initView();
    this.registrationView.initView();
    this.userProfileView.initView();

    initMenu();

    if (this.loginController.isUserLoggedInOnSession()) {
        this.menu.setVisible(true);
        setContent(this.reservationView);
    } else {
        this.menu.setVisible(false);
        setContent(this.registrationView);
    }

    this.fullSite.setImmediate(true);
    this.loginView.initView();
    this.loginView.display(this.loginLogoutPart);

    this.fullSite.addComponent(this.logo, 0, 0);
    this.fullSite.setComponentAlignment(this.logo, Alignment.MIDDLE_LEFT);
    this.fullSite.addComponent(this.loginLogoutPart, 1, 0);
    this.fullSite.setComponentAlignment(this.loginLogoutPart, Alignment.MIDDLE_RIGHT);
    this.fullSite.setRowExpandRatio(0, 0);

    this.fullSite.addComponent(this.menu, 0, 1, 1, 1);
    this.fullSite.setComponentAlignment(this.menu, Alignment.TOP_LEFT);

    this.fullSite.addComponent(this.contentPanel, 0, 2, 1, 2);
    this.fullSite.setComponentAlignment(this.contentPanel, Alignment.TOP_LEFT);
    this.fullSite.setRowExpandRatio(2, 10);

    this.fullSite.setSizeFull();
    this.setContent(this.fullSite);

}

From source file:ch.wscr.management.ui.view.MemberView.java

/**
 * Kopfzeile fr das Grid erstellen//from w  w  w .  j a v  a  2 s. c o m
 *
 * @param grid das Grid dem die Kopfzeile hinzugefgt werden soll
 */
private void setHeaderRow(final Grid grid) {
    // TODO Erstellung neuer Mitglieder muss noch optimiert werden

    final Button addMember = new Button("Neu", clickEvent -> {
        BeanItem<Member> beanItem = memberBeanItemContainer.addItem(new Member());
        grid.setEditorEnabled(true);
        //grid.editItem(beanItem);

    });

    addMember.setStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
    addMember.setIcon(FontAwesome.PLUS_CIRCLE);

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSizeFull();
    buttonLayout.setSpacing(true);
    buttonLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    buttonLayout.addComponent(addMember);

    HeaderRow headerRow = grid.prependHeaderRow();
    headerRow.join("memberId", "lastName", "firstName", "adrStreet", "adrPostalCode", "adrCity", "adrCountry",
            "birthDate", "driverLicense");
    headerRow.getCell("lastName").setComponent(buttonLayout);
}

From source file:com.arcusys.liferay.vaadinplugin.ControlPanelUI.java

License:Apache License

private void createUI() {
    //create main layout
    mainLayout = new VerticalLayout();
    mainLayout.setWidth("720px");
    mainLayout.setSpacing(true);//  ww  w .j  a va2 s. c  om

    setContent(mainLayout);

    //create Setting layout
    settingsPanel = new Panel("Settings");
    settingsLayout = new FormLayout();
    settingsPanel.setContent(settingsLayout);

    versionUpgradeProgressIndicator = createProgressIndicator();

    changeVersionButton = createChangeVersionButton();
    updateVaadinVersionButton = createUpdateVaadinVersionButton();

    Version vaadinNewestVersion = newestDownloadInfo.getVersion();
    //add details
    detailsButton = createDetailsButton();

    vaadinVersionLayout = createVaadinVersionLayout(vaadinNewestVersion.toString(), changeVersionButton,
            updateVaadinVersionButton, versionUpgradeProgressIndicator, detailsButton);
    settingsLayout.addComponent(vaadinVersionLayout);

    activeWidgetsetLabel = createActiveWidgetsetLabel();
    settingsLayout.addComponent(activeWidgetsetLabel);

    // Add-on selection
    HorizontalLayout addonDirectoryLayout = createAddonDirectoryLayout();
    settingsLayout.addComponent(addonDirectoryLayout);

    //Add-on included
    includeAddonsOptionGroup = createIncludeAddonsList();
    addonsListHolder = createIncludeAddonsListLayout(includeAddonsOptionGroup);
    settingsLayout.addComponent(addonsListHolder);

    //addition dependencies
    additionalDependenciesLabel = createAdditionalDependenciesLabel();
    settingsLayout.addComponent(additionalDependenciesLabel);

    mainLayout.addComponent(settingsPanel);

    additionalDependenciesButton = createAdditionalDependenciesButton();
    mainLayout.addComponent(additionalDependenciesButton);

    //Compilation layout
    HorizontalLayout compilationlayout = new HorizontalLayout();
    compileWidgetsetButton = createCompileWidgetsetButton();
    compilationlayout.addComponent(compileWidgetsetButton);
    terminateCompilationButton = createTerminateCompilationButton();
    compilationlayout.addComponent(terminateCompilationButton);
    compilationProgressIndicator = createProgressIndicator();
    compilationlayout.addComponent(compilationProgressIndicator);
    compilationlayout.setComponentAlignment(compilationProgressIndicator, Alignment.MIDDLE_LEFT);
    settingsLayout.addComponent(compilationlayout);

    //Output console
    outputConsole = createOutputConsole();
    mainLayout.addComponent(outputConsole);

    addonsNotFoundLabel = createAddonsNotFoundLabel();
}

From source file:com.arcusys.liferay.vaadinplugin.ControlPanelUI.java

License:Apache License

private HorizontalLayout createAddonDirectoryLayout() {
    HorizontalLayout layout = new HorizontalLayout();
    layout.setSpacing(true);//from   www  .j  a v a 2 s. co  m
    layout.setCaption("Add-on Directory");
    addonLibDirLabel = createAddonLibDirLabel();
    layout.addComponent(addonLibDirLabel);
    refreshButton = createRefreshButton();
    layout.addComponent(refreshButton);
    layout.setComponentAlignment(refreshButton, Alignment.MIDDLE_LEFT);

    return layout;
}

From source file:com.cavisson.gui.dashboard.components.controls.Forms.java

License:Apache License

public Forms() {
    setSpacing(true);//from   w w w.  java  2s  .  c  o  m
    setMargin(true);

    Label title = new Label("Forms");
    title.addStyleName("h1");
    addComponent(title);

    final FormLayout form = new FormLayout();
    form.setMargin(false);
    form.setWidth("800px");
    form.addStyleName("light");
    addComponent(form);

    Label section = new Label("Personal Info");
    section.addStyleName("h2");
    section.addStyleName("colored");
    form.addComponent(section);
    StringGenerator sg = new StringGenerator();

    TextField name = new TextField("Name");
    name.setValue(sg.nextString(true) + " " + sg.nextString(true));
    name.setWidth("50%");
    form.addComponent(name);

    DateField birthday = new DateField("Birthday");
    birthday.setValue(new Date(80, 0, 31));
    form.addComponent(birthday);

    TextField username = new TextField("Username");
    username.setValue(sg.nextString(false) + sg.nextString(false));
    username.setRequired(true);
    form.addComponent(username);

    OptionGroup sex = new OptionGroup("Sex");
    sex.addItem("Female");
    sex.addItem("Male");
    sex.select("Male");
    sex.addStyleName("horizontal");
    form.addComponent(sex);

    section = new Label("Contact Info");
    section.addStyleName("h3");
    section.addStyleName("colored");
    form.addComponent(section);

    TextField email = new TextField("Email");
    email.setValue(sg.nextString(false) + "@" + sg.nextString(false) + ".com");
    email.setWidth("50%");
    email.setRequired(true);
    form.addComponent(email);

    TextField location = new TextField("Location");
    location.setValue(sg.nextString(true) + ", " + sg.nextString(true));
    location.setWidth("50%");
    location.setComponentError(new UserError("This address doesn't exist"));
    form.addComponent(location);

    TextField phone = new TextField("Phone");
    phone.setWidth("50%");
    form.addComponent(phone);

    HorizontalLayout wrap = new HorizontalLayout();
    wrap.setSpacing(true);
    wrap.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    wrap.setCaption("Newsletter");
    CheckBox newsletter = new CheckBox("Subscribe to newsletter", true);
    wrap.addComponent(newsletter);

    ComboBox period = new ComboBox();
    period.setTextInputAllowed(false);
    period.addItem("Daily");
    period.addItem("Weekly");
    period.addItem("Montly");
    period.setNullSelectionAllowed(false);
    period.select("Weekly");
    period.addStyleName("small");
    period.setWidth("10em");
    wrap.addComponent(period);
    form.addComponent(wrap);

    section = new Label("Additional Info");
    section.addStyleName("h4");
    section.addStyleName("colored");
    form.addComponent(section);

    TextField website = new TextField("Website");
    website.setInputPrompt("http://");
    website.setWidth("100%");
    form.addComponent(website);

    TextArea shortbio = new TextArea("Short Bio");
    shortbio.setValue(
            "Quis aute iure reprehenderit in voluptate velit esse. Cras mattis iudicium purus sit amet fermentum.");
    shortbio.setWidth("100%");
    shortbio.setRows(2);
    form.addComponent(shortbio);

    final RichTextArea bio = new RichTextArea("Bio");
    bio.setWidth("100%");
    bio.setValue(
            "<div><p><span>Integer legentibus erat a ante historiarum dapibus.</span> <span>Vivamus sagittis lacus vel augue laoreet rutrum faucibus.</span> <span>A communi observantia non est recedendum.</span> <span>Morbi fringilla convallis sapien, id pulvinar odio volutpat.</span> <span>Ab illo tempore, ab est sed immemorabili.</span> <span>Quam temere in vitiis, legem sancimus haerentia.</span></p><p><span>Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Cum sociis natoque penatibus et magnis dis parturient.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Tityre, tu patulae recubans sub tegmine fagi  dolor.</span></p><p><span>Curabitur blandit tempus ardua ridiculus sed magna.</span> <span>Phasellus laoreet lorem vel dolor tempus vehicula.</span> <span>Etiam habebis sem dicantur magna mollis euismod.</span> <span>Hi omnes lingua, institutis, legibus inter se differunt.</span></p></div>");
    form.addComponent(bio);

    form.setReadOnly(true);
    bio.setReadOnly(true);

    Button edit = new Button("Edit", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            boolean readOnly = form.isReadOnly();
            if (readOnly) {
                bio.setReadOnly(false);
                form.setReadOnly(false);
                form.removeStyleName("light");
                event.getButton().setCaption("Save");
                event.getButton().addStyleName("primary");
            } else {
                bio.setReadOnly(true);
                form.setReadOnly(true);
                form.addStyleName("light");
                event.getButton().setCaption("Edit");
                event.getButton().removeStyleName("primary");
            }
        }
    });

    HorizontalLayout footer = new HorizontalLayout();
    footer.setMargin(new MarginInfo(true, false, true, false));
    footer.setSpacing(true);
    footer.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    form.addComponent(footer);
    footer.addComponent(edit);

    Label lastModified = new Label("Last modified by you a minute ago");
    lastModified.addStyleName("light");
    footer.addComponent(lastModified);
}