Example usage for com.vaadin.ui CheckBox CheckBox

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

Introduction

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

Prototype

public CheckBox(String caption) 

Source Link

Document

Creates a new checkbox with a set caption.

Usage

From source file:com.gmail.volodymyrdotsenko.cms.fe.vaadin.LoginUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    langRepo.findAll().forEach(e -> {
        langSet.add(e.getCode());//from www.j ava 2  s .c o m
    });

    lang = new ComboBox("Language", langSet);

    getPage().setTitle("CMS");

    FormLayout loginForm = new FormLayout();
    loginForm.setSizeUndefined();

    loginForm.addComponent(userName = new TextField("Username"));
    userName.setRequired(true);
    loginForm.addComponent(passwordField = new PasswordField("Password"));
    passwordField.setRequired(true);
    loginForm.addComponent(rememberMe = new CheckBox("Remember me"));
    loginForm.addComponent(lang);
    lang.setRequired(true);
    lang.setNullSelectionAllowed(false);
    loginForm.addComponent(login = new Button("Login"));
    login.addStyleName(ValoTheme.BUTTON_PRIMARY);
    login.setDisableOnClick(true);
    login.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    login.addClickListener(e -> {
        login();
    });

    VerticalLayout loginLayout = new VerticalLayout();
    loginLayout.setSpacing(true);
    loginLayout.setSizeUndefined();

    if (request.getParameter("logout") != null) {
        loggedOutLabel = new Label("You have been logged out!");
        loggedOutLabel.addStyleName(ValoTheme.LABEL_SUCCESS);
        loggedOutLabel.setSizeUndefined();
        loginLayout.addComponent(loggedOutLabel);
        loginLayout.setComponentAlignment(loggedOutLabel, Alignment.BOTTOM_CENTER);
    }

    loginLayout.addComponent(loginFailedLabel = new Label());
    loginLayout.setComponentAlignment(loginFailedLabel, Alignment.BOTTOM_CENTER);
    loginFailedLabel.setSizeUndefined();
    loginFailedLabel.addStyleName(ValoTheme.LABEL_FAILURE);
    loginFailedLabel.setVisible(false);

    loginLayout.addComponent(loginForm);
    loginLayout.setComponentAlignment(loginForm, Alignment.TOP_CENTER);

    VerticalLayout rootLayout = new VerticalLayout(loginLayout);
    rootLayout.setSizeFull();
    rootLayout.setComponentAlignment(loginLayout, Alignment.MIDDLE_CENTER);
    setContent(rootLayout);
    setSizeFull();

    String currentLang = getLocale().getLanguage();
    if (langSet.contains(currentLang))
        lang.select(currentLang);
    else
        lang.select("en");
}

From source file:com.ies.schoolos.ui.mobile.info.layout.PersonalLayout.java

private void addressGroup() {
    addressGroup = new VerticalComponentGroup();
    addressGroup.setSizeUndefined();// ww  w  .  j  av  a  2s .c  o m

    addTab(addressGroup, "", FontAwesome.BOOK);

    tel = new TextField("");
    tel.setInputPrompt("");
    tel.setImmediate(false);
    tel.setWidth("-1px");
    tel.setHeight("-1px");
    tel.setNullRepresentation("");
    addressGroup.addComponent(tel);

    mobile = new TextField("");
    mobile.setInputPrompt("");
    mobile.setImmediate(false);
    mobile.setWidth("-1px");
    mobile.setHeight("-1px");
    mobile.setRequired(true);
    mobile.setNullRepresentation("");
    addressGroup.addComponent(mobile);

    email = new EmailField("");
    email.setInputPrompt("");
    email.setImmediate(false);
    email.setWidth("-1px");
    email.setHeight("-1px");
    email.setRequired(true);
    email.setNullRepresentation("");
    email.addTextChangeListener(new TextChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void textChange(TextChangeEvent event) {
            if (!isEdit) {
                if (event.getText() != null) {
                    if (event.getText().length() >= 13) {

                        userSqlContainer.addContainerFilter(new Equal(UserSchema.EMAIL, event.getText()));
                        if (userSqlContainer.size() > 0) {
                            disableDuplicateEmailForm();
                            Notification.show(
                                    "?? ??",
                                    Type.WARNING_MESSAGE);
                        } else {
                            enableDuplicateEmailForm();
                        }
                        userSqlContainer.removeAllContainerFilters();
                    }
                }
            }
        }
    });
    addressGroup.addComponent(email);

    Label currentLabel = new Label("");
    addressGroup.addComponent(currentLabel);

    currentAddress = new TextArea("");
    currentAddress.setInputPrompt("  ");
    currentAddress.setImmediate(false);
    currentAddress.setWidth("-1px");
    currentAddress.setHeight("-1px");
    currentAddress.setNullRepresentation("");
    addressGroup.addComponent(currentAddress);

    currentProvince = new NativeSelect("", new Province());
    //currentProvince.setInputPrompt("??");
    currentProvince.setItemCaptionPropertyId("name");
    currentProvince.setImmediate(true);
    currentProvince.setNullSelectionAllowed(false);
    currentProvince.setWidth("-1px");
    currentProvince.setHeight("-1px");
    //currentProvince.setFilteringMode(FilteringMode.CONTAINS);
    currentProvince.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (event.getProperty().getValue() != null)
                currentDistrict.setContainerDataSource(
                        new District(Integer.parseInt(event.getProperty().getValue().toString())));
        }
    });
    addressGroup.addComponent(currentProvince);

    currentDistrict = new NativeSelect("");
    //currentDistrict.setInputPrompt("??");
    currentDistrict.setItemCaptionPropertyId("name");
    currentDistrict.setImmediate(true);
    currentDistrict.setNullSelectionAllowed(false);
    currentDistrict.setWidth("-1px");
    currentDistrict.setHeight("-1px");
    //currentDistrict.setFilteringMode(FilteringMode.CONTAINS);
    currentDistrict.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (event.getProperty().getValue() != null) {
                currentCity.setContainerDataSource(
                        new City(Integer.parseInt(event.getProperty().getValue().toString())));
                currentPostcode.setContainerDataSource(
                        new Postcode(Integer.parseInt(event.getProperty().getValue().toString())));
            }
        }
    });
    addressGroup.addComponent(currentDistrict);

    currentCity = new NativeSelect("");
    //currentCity.setInputPrompt("??");
    currentCity.setItemCaptionPropertyId("name");
    currentCity.setImmediate(true);
    currentCity.setNullSelectionAllowed(false);
    currentCity.setWidth("-1px");
    currentCity.setHeight("-1px");
    //currentCity.setFilteringMode(FilteringMode.CONTAINS);
    addressGroup.addComponent(currentCity);

    currentPostcode = new NativeSelect("");
    //currentPostcode.setInputPrompt("??");
    currentPostcode.setItemCaptionPropertyId("name");
    currentPostcode.setImmediate(true);
    currentPostcode.setNullSelectionAllowed(false);
    currentPostcode.setWidth("-1px");
    currentPostcode.setHeight("-1px");
    //currentPostcode.setFilteringMode(FilteringMode.CONTAINS);
    addressGroup.addComponent(currentPostcode);

    isSameCurrentAddress = new CheckBox(
            "?");
    isSameCurrentAddress.setImmediate(true);
    isSameCurrentAddress.setWidth("-1px");
    isSameCurrentAddress.setHeight("-1px");
    isSameCurrentAddress.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (event.getProperty().getValue() != null) {
                if ((boolean) event.getProperty().getValue()) {
                    censusAddress.setValue(currentAddress.getValue());
                    censusProvince.setValue(currentProvince.getValue());
                    censusDistrict.setValue(currentDistrict.getValue());
                    censusCity.setValue(currentCity.getValue());
                    censusPostcode.setValue(currentPostcode.getValue());
                } else {
                    censusAddress.setValue(null);
                    censusProvince.setValue(null);
                    censusDistrict.setValue(null);
                    censusCity.setValue(null);
                    censusPostcode.setValue(null);
                }
            }
        }
    });
    addressGroup.addComponent(isSameCurrentAddress);

    censusAddress = new TextArea("");
    censusAddress.setInputPrompt("  ");
    censusAddress.setImmediate(false);
    censusAddress.setWidth("-1px");
    censusAddress.setHeight("-1px");
    censusAddress.setNullRepresentation("");
    addressGroup.addComponent(censusAddress);

    censusProvince = new NativeSelect("",
            new Province());
    //censusProvince.setInputPrompt("??");
    censusProvince.setItemCaptionPropertyId("name");
    censusProvince.setImmediate(true);
    censusProvince.setNullSelectionAllowed(false);
    censusProvince.setWidth("-1px");
    censusProvince.setHeight("-1px");
    //censusProvince.setFilteringMode(FilteringMode.CONTAINS);
    censusProvince.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (event.getProperty().getValue() != null)
                censusDistrict.setContainerDataSource(
                        new District(Integer.parseInt(event.getProperty().getValue().toString())));
        }
    });
    addressGroup.addComponent(censusProvince);

    censusDistrict = new NativeSelect("");
    //censusDistrict.setInputPrompt("??");
    censusDistrict.setItemCaptionPropertyId("name");
    censusDistrict.setImmediate(true);
    censusDistrict.setNullSelectionAllowed(false);
    censusDistrict.setWidth("-1px");
    censusDistrict.setHeight("-1px");
    //censusDistrict.setFilteringMode(FilteringMode.CONTAINS);
    censusDistrict.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (event.getProperty().getValue() != null) {
                censusCity.setContainerDataSource(
                        new City(Integer.parseInt(event.getProperty().getValue().toString())));
                censusPostcode.setContainerDataSource(
                        new Postcode(Integer.parseInt(event.getProperty().getValue().toString())));
            }
        }
    });
    addressGroup.addComponent(censusDistrict);

    censusCity = new NativeSelect("");
    //censusCity.setInputPrompt("??");
    censusCity.setItemCaptionPropertyId("name");
    censusCity.setImmediate(true);
    censusCity.setNullSelectionAllowed(false);
    censusCity.setWidth("-1px");
    censusCity.setHeight("-1px");
    //censusCity.setFilteringMode(FilteringMode.CONTAINS);
    addressGroup.addComponent(censusCity);

    censusPostcode = new NativeSelect(
            "");
    //censusPostcode.setInputPrompt("??");
    censusPostcode.setItemCaptionPropertyId("name");
    censusPostcode.setImmediate(true);
    censusPostcode.setNullSelectionAllowed(false);
    censusPostcode.setWidth("-1px");
    censusPostcode.setHeight("-1px");
    //censusPostcode.setFilteringMode(FilteringMode.CONTAINS);
    addressGroup.addComponent(censusPostcode);

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    addressGroup.addComponent(buttonLayout);

    licensessBack = new Button(FontAwesome.ARROW_LEFT);
    licensessBack.setWidth("100%");
    licensessBack.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            setSelectedTab(licenseeGroup);
        }
    });
    buttonLayout.addComponents(licensessBack);

    fatherNext = new Button(FontAwesome.SAVE);
    fatherNext.setWidth("100%");
    fatherNext.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            ConfirmDialog.show(UI.getCurrent(), "",
                    "?    ?",
                    "", "", new ConfirmDialog.Listener() {
                        private static final long serialVersionUID = 1L;

                        public void onClose(ConfirmDialog dialog) {
                            /*   ?
                             *  ? ?
                             *  ?  ?? */
                            if (dialog.isConfirmed()) {
                                isInsertParents = true;
                                setSelectedTab(fatherGroup);
                            } else {
                                isInsertParents = false;

                                finish.click();
                            }
                        }
                    });
        }
    });

    buttonLayout.addComponents(fatherNext);
}

From source file:com.klwork.explorer.project.MyCalendarView.java

License:Apache License

private void initHideWeekEndButton() {
    hideWeekendsButton = new CheckBox("??");
    hideWeekendsButton.setImmediate(true);
    hideWeekendsButton.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override// w w  w .j a va 2s .  c  o  m
        public void valueChange(ValueChangeEvent event) {
            setWeekendsHidden(hideWeekendsButton.getValue());
        }
    });
}

From source file:com.klwork.explorer.project.MyCalendarView.java

License:Apache License

private void initReadOnlyButton() {
    readOnlyButton = new CheckBox("Read-only mode");
    readOnlyButton.setImmediate(true);//from  www  .  ja v  a  2 s .c o m
    readOnlyButton.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            calendarComponent.setReadOnly(readOnlyButton.getValue());
        }
    });
}

From source file:com.klwork.explorer.project.MyCalendarView.java

License:Apache License

private void initDisabledButton() {
    disabledButton = new CheckBox("Disabled");
    disabledButton.setImmediate(true);//from  w ww  .  j  av  a 2  s.c  o m
    disabledButton.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            calendarComponent.setEnabled(!disabledButton.getValue());
        }
    });
}

From source file:com.klwork.explorer.ui.form.BooleanFormPropertyRenderer.java

License:Apache License

@Override
public Field getPropertyField(FormProperty formProperty) {

    CheckBox checkBox = new CheckBox(getPropertyLabel(formProperty));
    checkBox.setRequired(formProperty.isRequired());
    checkBox.setEnabled(formProperty.isWritable());

    if (formProperty.getValue() != null) {
        Boolean value = new Boolean(Boolean.parseBoolean(formProperty.getValue()));
        checkBox.setValue(value);//from  w  w w.j av  a  2 s  .  c o m
    }

    return checkBox;
}

From source file:com.liferay.mail.vaadin.AccountEditor.java

License:Open Source License

private void createComponents() {

    addressField = new TextField(Lang.get("email-address"));
    addressField.focus();/*  w  w  w  .  j a  va2  s. c  o  m*/
    loginField = new TextField(Lang.get("login"));
    personalNameField = new TextField(Lang.get("personal-name"));
    passwordField = new TextField(Lang.get("password"));
    passwordField.setSecret(true);
    passwordSavedCheckBox = new CheckBox(Lang.get("save-password"));
    mailInHostNameField = new TextField(Lang.get("incoming-imap-server"));
    mailInPortCombo = new ComboBox(Lang.get("incoming-port"),
            controller.getConfigurationManager().getIncomingPorts());
    mailInSecureCheckBox = new CheckBox(Lang.get("use-secure-incoming-connection"));
    mailOutHostNameField = new TextField(Lang.get("outgoing-smtp-server"));
    mailOutPortCombo = new ComboBox(Lang.get("outgoing-port"),
            controller.getConfigurationManager().getOutgoingPorts());
    mailOutSecureCheckBox = new CheckBox(Lang.get("use-secure-outgoing-connection"));

    // initial validation - the account is then tested
    addressField.setRequired(true);
    mailInHostNameField.setRequired(true);
    mailOutHostNameField.setRequired(true);

    addComponent(addressField);
    if (!useLocalPartOfEmailAddressAsLogin) {
        addComponent(loginField);
    }
    addComponent(personalNameField);
    addComponent(passwordField);
    addComponent(passwordSavedCheckBox);
    if (!hideSettings) {
        addComponent(mailInHostNameField);
        addComponent(mailInPortCombo);
        addComponent(mailInSecureCheckBox);
        addComponent(mailOutHostNameField);
        addComponent(mailOutPortCombo);
        addComponent(mailOutSecureCheckBox);
    }

    HorizontalLayout footer = new HorizontalLayout();
    footer.setSpacing(true);
    okButton = new Button(Lang.get("save"));
    okButton.setStyleName("primary");
    okButton.addListener(this);
    footer.addComponent(okButton);
    cancelButton = new Button(Lang.get("cancel"));
    cancelButton.addListener(this);
    footer.addComponent(cancelButton);

    // TODO add footer to layout in a cleaner manner
    addComponent(footer);
}

From source file:com.lst.deploymentautomation.vaadin.page.SettingsView.java

License:Open Source License

private VerticalLayout createSubstitutionSection(LspsUI ui, Person user) {
    VerticalLayout substitution = new VerticalLayout();
    substitution.setSpacing(true);//from   w  w  w.ja  v  a2s  .  c  o m

    Label substitutionHeader = new Label("<h2>" + ui.getMessage("settings.substitutionSection") + "</h2>",
            ContentMode.HTML);
    substitution.addComponent(substitutionHeader);

    Label substitutionHelp = new Label(ui.getMessage("settings.substitutionHelp"));
    substitutionHelp.setStyleName("form-help");
    substitution.addComponent(substitutionHelp);

    this.substitutionActive = new CheckBox(ui.getMessage("settings.substitutionActive"));
    substitutionActive.addStyleName("ui-spacing");
    substitutionActive.setValue(user.isSubstitutionActive());
    substitution.addComponent(substitutionActive);

    //substitutes
    Set<Person> selectedPersons = user.getDirectSubstitutes();
    //all persons except the user himself
    Collection<Person> persons = new ArrayList<Person>(
            personService.findPersons(new PersonCriteria()).getData());

    this.substitutes = new OptionGroup(ui.getMessage("settings.substitutes"));
    substitutes.setMultiSelect(true);
    substitutes.addStyleName("ui-spacing");
    for (Person substitute : persons) {
        if (!substitute.equals(user)) {
            substitutes.addItem(substitute);
            substitutes.setItemCaption(substitute, substitute.getFullName());
        }
    }
    substitutes.setValue(selectedPersons);
    substitution.addComponent(substitutes);

    return substitution;
}

From source file:com.mcparland.john.vaadin_mvn_arch.samples.crud.CategoryField.java

License:Apache License

/**
 * Set the collection of categories among which the used can select a
 * subset./*from w  w w . j a v  a2s .  co m*/
 * 
 * @param categories
 *            all available categories
 */
public void setOptions(Collection<Category> categories) {
    options.removeAllComponents();
    checkboxes.clear();
    for (final Category category : categories) {
        final CheckBox box = new CheckBox(category.getName());
        checkboxes.put(category, box);
        box.addValueChangeListener(new ValueChangeListener() {

            /**
             * The serialVersionUID.
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
                if (!updatingField) {
                    Set<Category> oldCategories = getValue();
                    Set<Category> categories;
                    if (oldCategories != null) {
                        categories = new HashSet<Category>(oldCategories);
                    } else {
                        categories = new HashSet<Category>();
                    }
                    if (box.getValue()) {
                        categories.add(category);
                    } else {
                        categories.remove(category);
                    }
                    setInternalValue(categories);
                }
            }
        });
        options.addComponent(box);
    }
}

From source file:com.morevaadin.vaadin7.refresh.Vaadin7Root.java

License:Apache License

public Vaadin7Root() {

    addComponent(mainLayout);/*from w  w w  .j  a v  a 2  s  .  c o m*/

    final CheckBox checkBox = new CheckBox("Preserve root");

    checkBox.setImmediate(true);

    checkBox.addListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {

            getApplication().setRootPreserved(checkBox.getValue());
        }
    });

    mainLayout.addComponent(checkBox);

    gridLayout.setColumns(2);

    mainLayout.addComponent(gridLayout);
}