Example usage for com.vaadin.ui CheckBox getValue

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

Introduction

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

Prototype

@Override
    public Boolean getValue() 

Source Link

Usage

From source file:org.vaadin.addons.javaee.form.EntityFieldGroup.java

License:Apache License

/**
 * @param onlyChanged//w w w  .  j  av a  2 s . co  m
 *            If true only fields with changed values are considered.
 */
public Filter getValuesAsFilter(boolean onlyChanged) {
    List<Filter> filters = new ArrayList<>();
    for (Field<?> field : getFields()) {
        if (field == null || field.getValue() == null || (onlyChanged && !field.isModified())) {
            continue;
        }
        if (field instanceof NumberField) {
            NumberField numberField = (NumberField) field;
            filters.add(new Compare.Equal(getPropertyId(field), numberField.getValue()));
        } else if (field instanceof CheckBox) {
            CheckBox checkBox = (CheckBox) field;
            filters.add(new Compare.Equal(getPropertyId(field), checkBox.getValue()));
        } else if (field instanceof AbstractSelect) {
            AbstractSelect abstractSelect = (AbstractSelect) field;
            filters.add(new Compare.Equal(getPropertyId(field), abstractSelect.getValue()));
        } else if (!StringUtils.isBlank(getStringValue(field))) {
            filters.add(new SimpleStringFilter(getPropertyId(field), getStringValue(field), false, false));
        }
    }
    Filter filter = new And(filters.toArray(new Filter[] {}));
    return filter;
}

From source file:org.vaadin.johannes.VaadingraphApplication.java

License:LGPL

private Component getStyleOptimizedBox() {
    final CheckBox cb = new CheckBox("Node specific styles enabled");
    cb.setImmediate(true);/*from  w  w w. j  a va2  s.  c  om*/
    cb.setValue(true);
    cb.addListener(new CheckBox.ClickListener() {
        private static final long serialVersionUID = 4837240993197391750L;

        public void buttonClick(final ClickEvent event) {
            graph.setOptimizedStyles(!(Boolean) cb.getValue());
        }
    });
    return cb;
}

From source file:org.vaadin.johannes.VaadingraphApplication.java

License:LGPL

private Component getTextHideBox() {
    final CheckBox cb = new CheckBox("Hide texts");
    cb.setImmediate(true);//from ww  w  . java  2 s  .  c o m
    cb.setValue(true);
    cb.addListener(new CheckBox.ClickListener() {
        private static final long serialVersionUID = 1981652250991931328L;

        public void buttonClick(final ClickEvent event) {
            graph.setTextsVisible(!(Boolean) cb.getValue());
        }
    });
    return cb;
}

From source file:org.vaadin.spring.samples.navigation.AccessControlView.java

License:Apache License

private CheckBox createViewCheckbox(String caption, final String viewName) {
    final CheckBox checkBox = new CheckBox(caption, true);
    checkBox.addValueChangeListener(new Property.ValueChangeListener() {
        @Override/*from www. j  ava  2 s .  c  o m*/
        public void valueChange(Property.ValueChangeEvent event) {
            if (checkBox.getValue()) {
                allowedViews.add(viewName);
            } else {
                allowedViews.remove(viewName);
            }
        }
    });
    return checkBox;
}

From source file:pl.exsio.frameset.vaadin.ui.support.component.data.form.SecurityPermissionsForm.java

License:Open Source License

private void handleRoleSelectionChange(ComboBox roleSelect, final FormLayout permissionsLayout,
        final JPAContainer<? extends Role> roles, final Map<String, Permission> permissionsMap) {
    roleSelect.addValueChangeListener(new Property.ValueChangeListener() {

        private Map<CheckBox, Permission> permissionCbsMap;

        @Override//from w ww  . j  ava2 s  . c  om
        public void valueChange(Property.ValueChangeEvent event) {
            if (event.getProperty().getValue() != null) {
                this.createRolePermissionsForm(event);
            }
        }

        private void createRolePermissionsForm(Property.ValueChangeEvent event) throws NumberFormatException {
            this.permissionCbsMap = new HashMap<>();
            permissionsLayout.removeAllComponents();

            Long itemId = Long.parseLong(event.getProperty().getValue().toString());
            Role selectedRole = roles.getItem(itemId).getEntity();
            final GrantedAuthoritySid sid = new GrantedAuthoritySid(selectedRole.getName());

            for (String permissionName : permissionsMap.keySet()) {
                CheckBox permissionCb = this.createPermissionCheckbox(permissionName, sid);
                permissionsLayout.addComponent(permissionCb);
            }

            Button savePermissions = this.createSaveButton(sid);
            permissionsLayout.addComponent(savePermissions);
        }

        private CheckBox createPermissionCheckbox(String permissionName, final GrantedAuthoritySid sid) {
            CheckBox permissionCb = new CheckBox(permissionName,
                    acl.isGranted(subject, permissionsMap.get(permissionName), sid));
            this.permissionCbsMap.put(permissionCb, permissionsMap.get(permissionName));
            return permissionCb;
        }

        private Button createSaveButton(final GrantedAuthoritySid sid) {
            Button savePermissions = new Button(t("core.save"), FontAwesome.FLOPPY_O);
            savePermissions.addClickListener(new Button.ClickListener() {

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    for (CheckBox permissionCb : permissionCbsMap.keySet()) {
                        if (permissionCb.getValue()) {
                            acl.grant(subject, permissionCbsMap.get(permissionCb), sid);
                        } else {
                            acl.revoke(subject, permissionCbsMap.get(permissionCb), sid);
                        }
                    }
                    Notification.show(t("core.security.management.permision.update.success"));
                }
            });
            return savePermissions;
        }
    });
}

From source file:ru.codeinside.adm.ui.AdminApp.java

License:Mozilla Public License

private RefreshableTab createSettings() {

    final Form systemForm;
    {/*from www .  ja v a 2 s .co m*/
        final ComboBox serviceLocation;
        {
            String[][] defs = { { "? ", "http://195.245.214.33:7777/esv" },
                    { "? ",
                            "http://oraas.rt.ru:7777/gateway/services/SID0003318" } };
            serviceLocation = new ComboBox("?? ?? ");
            serviceLocation.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_EXPLICIT);
            for (String[] def : defs) {
                addOption(serviceLocation, def[1], def[0], false);
            }
            serviceLocation.setImmediate(true);
            serviceLocation.setInputPrompt("http://");
            serviceLocation.setNewItemsAllowed(true);
            serviceLocation.setNewItemHandler(new AbstractSelect.NewItemHandler() {
                @Override
                public void addNewItem(String newItemCaption) {
                    addOption(serviceLocation, newItemCaption, newItemCaption, true);
                }
            });
            String href = AdminServiceProvider.get()
                    .getSystemProperty(CertificateVerifier.VERIFY_SERVICE_LOCATION);
            addOption(serviceLocation, href, href, true);
        }

        final CheckBox allowValidate;
        {
            allowValidate = new CheckBox(" ? ");
            allowValidate.setRequired(true);
            allowValidate.setImmediate(true);
            allowValidate.addListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(Property.ValueChangeEvent event) {
                    serviceLocation.setRequired(Boolean.TRUE.equals(event.getProperty().getValue()));
                }
            });
            allowValidate.setValue(AdminServiceProvider
                    .getBoolProperty(CertificateVerifier.ALLOW_VERIFY_CERTIFICATE_PROPERTY));
        }

        systemForm = new Form();
        systemForm.addField("location", serviceLocation);
        systemForm.addField("allowVerify", allowValidate);
        systemForm.setImmediate(true);
        systemForm.setWriteThrough(false);
        systemForm.setInvalidCommitted(false);

        Button commit = new Button("", new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                try {
                    systemForm.commit();
                    set(CertificateVerifier.VERIFY_SERVICE_LOCATION, serviceLocation.getValue());
                    set(CertificateVerifier.ALLOW_VERIFY_CERTIFICATE_PROPERTY, allowValidate.getValue());
                    event.getButton().getWindow().showNotification("?? ?",
                            Window.Notification.TYPE_HUMANIZED_MESSAGE);
                } catch (Validator.InvalidValueException ignore) {
                }
            }
        });

        HorizontalLayout buttons = new HorizontalLayout();
        buttons.setSpacing(true);
        buttons.addComponent(commit);
        systemForm.getFooter().addComponent(buttons);
    }

    Panel b1 = new Panel();
    b1.setSizeFull();
    Label b1label = new Label(" ?");
    b1label.addStyleName(Reindeer.LABEL_H2);
    b1.addComponent(b1label);
    b1.addComponent(systemForm);

    VerticalLayout certificates = new VerticalLayout();
    certificates.setSizeFull();
    certificates.setSpacing(true);

    HorizontalLayout topHl = new HorizontalLayout();
    topHl.setSizeFull();
    topHl.setSpacing(true);

    Panel certificatesPanel = new Panel("", certificates);
    certificatesPanel.setSizeFull();
    certificatesPanel.addStyleName(Reindeer.PANEL_LIGHT);

    boolean linkCertificate = AdminServiceProvider.getBoolProperty(CertificateVerifier.LINK_CERTIFICATE);
    final CheckBox switchLink = new CheckBox("? ");
    switchLink.setValue(linkCertificate);
    switchLink.setImmediate(true);
    switchLink.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            set(CertificateVerifier.LINK_CERTIFICATE, switchLink.getValue());
            event.getButton().getWindow().showNotification("?? ?",
                    Window.Notification.TYPE_HUMANIZED_MESSAGE);
        }
    });

    Panel b2 = new Panel();
    b2.setSizeFull();
    Label b2label = new Label("? ?");
    b2label.addStyleName(Reindeer.LABEL_H2);
    b2.addComponent(b2label);
    b2.addComponent(switchLink);

    certificates.addComponent(b1);
    certificates.addComponent(b2);
    certificates.setExpandRatio(b1, 0.7f);
    certificates.setExpandRatio(b2, 0.3f);

    CheckBox productionMode = new CheckBox("?  ",
            AdminServiceProvider.getBoolProperty(API.PRODUCTION_MODE));
    productionMode.setImmediate(true);
    productionMode.setDescription(
            " ?   ?   ??   ?? testMsg");
    productionMode.addListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            boolean value = Boolean.TRUE.equals(event.getProperty().getValue());
            set(API.PRODUCTION_MODE, value);
        }
    });
    Panel smevPanel = new Panel(" ");
    smevPanel.setSizeFull();
    smevPanel.addComponent(productionMode);

    HorizontalLayout bottomHl = new HorizontalLayout();
    bottomHl.setSizeFull();
    bottomHl.setSpacing(true);

    LogSettings logSettings = new LogSettings();
    Panel emailDatesPanel = createEmailDatesPanel();

    Panel mailTaskConfigPanel = createMilTaskConfigPanel();

    topHl.addComponent(certificatesPanel);
    topHl.addComponent(emailDatesPanel);
    topHl.addComponent(mailTaskConfigPanel);
    topHl.setExpandRatio(certificatesPanel, 0.4f);
    topHl.setExpandRatio(emailDatesPanel, 0.6f);
    topHl.setExpandRatio(mailTaskConfigPanel, 0.5f);

    Panel esiaPanel = buildEsiaPanel();
    Panel printTemplatesPanel = buildPrintTemplatesPanel();

    bottomHl.addComponent(smevPanel);
    bottomHl.addComponent(esiaPanel);
    bottomHl.addComponent(printTemplatesPanel);
    bottomHl.setExpandRatio(smevPanel, 0.2f);
    bottomHl.setExpandRatio(esiaPanel, 0.4f);
    bottomHl.setExpandRatio(printTemplatesPanel, 0.4f);

    final VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setSizeFull();
    layout.addComponent(topHl);
    layout.addComponent(logSettings);
    layout.addComponent(bottomHl);
    layout.setExpandRatio(topHl, 0.40f);
    layout.setExpandRatio(logSettings, 0.40f);
    layout.setExpandRatio(bottomHl, 0.20f);
    layout.setMargin(true);
    layout.setSpacing(true);

    return new RefreshableTab(layout, logSettings);
}

From source file:ru.codeinside.adm.ui.AdminApp.java

License:Mozilla Public License

private Panel buildEsiaPanel() {
    boolean isEsiaAuth = "true".equals(get(API.ALLOW_ESIA_LOGIN));

    final TextField esiaServiceLocation = new TextField("?? ?? ");
    esiaServiceLocation.setValue(get(API.ESIA_SERVICE_ADDRESS));
    esiaServiceLocation.setEnabled(isEsiaAuth);
    esiaServiceLocation.setRequired(isEsiaAuth);
    esiaServiceLocation.setWidth(370, Sizeable.UNITS_PIXELS);

    final CheckBox allowEsiaLogin = new CheckBox("   ?");
    allowEsiaLogin.setValue(isEsiaAuth);
    allowEsiaLogin.setImmediate(true);//  w  ww .  j  ava2s .co m
    allowEsiaLogin.addListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            Boolean newValue = (Boolean) valueChangeEvent.getProperty().getValue();
            esiaServiceLocation.setEnabled(newValue);
            esiaServiceLocation.setRequired(newValue);
        }
    });

    final Form form = new Form();
    form.addField(API.ALLOW_ESIA_LOGIN, allowEsiaLogin);
    form.addField(API.ESIA_SERVICE_ADDRESS, esiaServiceLocation);
    form.setImmediate(true);
    form.setWriteThrough(false);
    form.setInvalidCommitted(false);

    Button commit = new Button("", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                form.commit();
                set(API.ALLOW_ESIA_LOGIN, allowEsiaLogin.getValue());
                set(API.ESIA_SERVICE_ADDRESS, esiaServiceLocation.getValue());
                event.getButton().getWindow().showNotification("?? ?",
                        Window.Notification.TYPE_HUMANIZED_MESSAGE);
            } catch (Validator.InvalidValueException ignore) {
            }
        }
    });

    Panel panel = new Panel("?? ?");
    panel.setSizeFull();
    panel.addComponent(form);
    panel.addComponent(commit);
    return panel;
}

From source file:ru.codeinside.adm.ui.AdminApp.java

License:Mozilla Public License

private Panel buildPrintTemplatesPanel() {
    boolean isUseService = "true".equals(get(API.PRINT_TEMPLATES_USE_OUTER_SERVICE));

    final TextField serviceLocation = new TextField("?? ??");
    serviceLocation.setValue(get(API.PRINT_TEMPLATES_SERVICELOCATION));
    serviceLocation.setEnabled(isUseService);
    serviceLocation.setRequired(isUseService);
    serviceLocation.setWidth(370, Sizeable.UNITS_PIXELS);

    final CheckBox useOuterService = new CheckBox("?  ??");
    useOuterService.setValue(isUseService);
    useOuterService.setImmediate(true);/* w  w  w  .j  av a  2 s . c om*/
    useOuterService.addListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            Boolean newValue = (Boolean) valueChangeEvent.getProperty().getValue();
            serviceLocation.setEnabled(newValue);
            serviceLocation.setRequired(newValue);
        }
    });

    final Form form = new Form();
    form.addField(API.PRINT_TEMPLATES_USE_OUTER_SERVICE, useOuterService);
    form.addField(API.PRINT_TEMPLATES_SERVICELOCATION, serviceLocation);
    form.setImmediate(true);
    form.setWriteThrough(false);
    form.setInvalidCommitted(false);

    Button commit = new Button("", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                form.commit();
                set(API.PRINT_TEMPLATES_USE_OUTER_SERVICE, useOuterService.getValue());
                set(API.PRINT_TEMPLATES_SERVICELOCATION, serviceLocation.getValue());
                event.getButton().getWindow().showNotification("?? ?",
                        Window.Notification.TYPE_HUMANIZED_MESSAGE);
            } catch (Validator.InvalidValueException ignore) {
            }
        }
    });

    Panel panel = new Panel(" ");
    panel.setSizeFull();
    panel.addComponent(form);
    panel.addComponent(commit);
    return panel;
}

From source file:ru.codeinside.adm.ui.AdminApp.java

License:Mozilla Public License

private Panel createEmailDatesPanel() {
    VerticalLayout emailDates = new VerticalLayout();
    emailDates.setSpacing(true);/*  w  w w.  j  a v  a 2s . co  m*/
    emailDates.setMargin(true);
    emailDates.setSizeFull();
    Panel panel2 = new Panel(" ? ??", emailDates);
    panel2.setSizeFull();

    final TextField emailToField = new TextField("e-mail ?:");
    emailToField.setValue(get(API.EMAIL_TO));
    emailToField.setRequired(true);
    emailToField.setReadOnly(true);
    emailToField.addValidator(new EmailValidator("  e-mail ?"));

    final TextField receiverNameField = new TextField("? ?:");
    receiverNameField.setValue(get(API.RECEIVER_NAME));
    receiverNameField.setRequired(true);
    receiverNameField.setReadOnly(true);

    final TextField emailFromField = new TextField("e-mail ?:");
    emailFromField.setValue(get(API.EMAIL_FROM));
    emailFromField.setRequired(true);
    emailFromField.setReadOnly(true);
    emailFromField.addValidator(new EmailValidator("  e-mail ?"));

    final TextField senderLoginField = new TextField(" ?:");
    senderLoginField.setValue(get(API.SENDER_LOGIN));
    senderLoginField.setRequired(true);
    senderLoginField.setReadOnly(true);

    final TextField senderNameField = new TextField("? ?:");
    senderNameField.setValue(get(API.SENDER_NAME));
    senderNameField.setRequired(true);
    senderNameField.setReadOnly(true);

    final PasswordField passwordField = new PasswordField(":");
    passwordField.setValue(API.PASSWORD);
    passwordField.setRequired(true);
    passwordField.setReadOnly(true);

    final TextField hostField = new TextField("SMTP ?:");
    String host = get(API.HOST);
    hostField.setValue(host == null ? "" : host);
    hostField.setRequired(true);
    hostField.setReadOnly(true);

    final TextField portField = new TextField(":");
    String port = get(API.PORT);
    portField.setValue(port == null ? "" : port);
    portField.setRequired(true);
    portField.setReadOnly(true);
    portField.addValidator(new IntegerValidator(" "));

    final CheckBox tls = new CheckBox("? TLS",
            AdminServiceProvider.getBoolProperty(API.TLS));
    tls.setReadOnly(true);

    final Button save = new Button("");
    save.setVisible(false);
    final Button cancel = new Button("");
    cancel.setVisible(false);
    final Button change = new Button("");
    final Button check = new Button("");
    check.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            String emailTo = get(API.EMAIL_TO);
            String receiverName = get(API.RECEIVER_NAME);
            String hostName = get(API.HOST);
            String port = get(API.PORT);
            String senderLogin = get(API.SENDER_LOGIN);
            String password = get(API.PASSWORD);
            String emailFrom = get(API.EMAIL_FROM);
            String senderName = get(API.SENDER_NAME);
            if (emailTo.isEmpty() || receiverName.isEmpty() || hostName.isEmpty() || port.isEmpty()
                    || senderLogin.isEmpty() || password.isEmpty() || emailFrom.isEmpty()
                    || senderName.isEmpty()) {
                check.getWindow().showNotification("? ? ");
                return;
            }
            Email email = new SimpleEmail();
            try {
                email.setSubject("? ?");
                email.setMsg("? ?");
                email.addTo(emailTo, receiverName);
                email.setHostName(hostName);
                email.setSmtpPort(Integer.parseInt(port));
                email.setTLS(AdminServiceProvider.getBoolProperty(API.TLS));
                email.setAuthentication(senderLogin, password);
                email.setFrom(emailFrom, senderName);
                email.setCharset("utf-8");
                email.send();
            } catch (EmailException e) {
                check.getWindow().showNotification(e.getMessage());
                e.printStackTrace();
                return;
            }
            check.getWindow().showNotification("? ? ");
        }
    });
    change.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            emailToField.setReadOnly(false);
            receiverNameField.setReadOnly(false);
            emailFromField.setReadOnly(false);
            senderLoginField.setReadOnly(false);
            senderNameField.setReadOnly(false);
            passwordField.setReadOnly(false);
            hostField.setReadOnly(false);
            portField.setReadOnly(false);
            tls.setReadOnly(false);

            change.setVisible(false);
            check.setVisible(false);
            save.setVisible(true);
            cancel.setVisible(true);
        }
    });
    save.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (StringUtils.isEmpty((String) emailToField.getValue())
                    || StringUtils.isEmpty((String) receiverNameField.getValue())
                    || StringUtils.isEmpty((String) emailFromField.getValue())
                    || StringUtils.isEmpty((String) senderNameField.getValue())
                    || StringUtils.isEmpty((String) senderLoginField.getValue())
                    || StringUtils.isEmpty((String) passwordField.getValue())
                    || StringUtils.isEmpty((String) hostField.getValue()) || portField.getValue() == null) {
                emailToField.getWindow().showNotification(" ?",
                        Window.Notification.TYPE_HUMANIZED_MESSAGE);
                return;
            }
            boolean errors = false;
            try {
                emailToField.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            try {
                emailFromField.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            try {
                portField.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            if (errors) {
                return;
            }
            set(API.EMAIL_TO, emailToField.getValue());
            set(API.RECEIVER_NAME, receiverNameField.getValue());
            set(API.EMAIL_FROM, emailFromField.getValue());
            set(API.SENDER_LOGIN, senderLoginField.getValue());
            set(API.SENDER_NAME, senderNameField.getValue());
            set(API.PASSWORD, passwordField.getValue());
            set(API.HOST, hostField.getValue());
            set(API.PORT, portField.getValue());
            set(API.TLS, tls.getValue());

            emailToField.setReadOnly(true);
            receiverNameField.setReadOnly(true);
            emailFromField.setReadOnly(true);
            senderLoginField.setReadOnly(true);
            senderNameField.setReadOnly(true);
            passwordField.setReadOnly(true);
            hostField.setReadOnly(true);
            portField.setReadOnly(true);
            tls.setReadOnly(true);

            save.setVisible(false);
            cancel.setVisible(false);
            change.setVisible(true);
            check.setVisible(true);
            emailToField.getWindow().showNotification("?? ?",
                    Window.Notification.TYPE_HUMANIZED_MESSAGE);
        }
    });
    cancel.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            emailToField.setValue(get(API.EMAIL_TO));
            receiverNameField.setValue(get(API.RECEIVER_NAME));
            emailFromField.setValue(get(API.EMAIL_FROM));
            senderLoginField.setValue(get(API.SENDER_LOGIN));
            senderNameField.setValue(get(API.SENDER_NAME));
            passwordField.setValue(get(API.PASSWORD));
            hostField.setValue(get(API.HOST));
            portField.setValue(get(API.PORT));
            tls.setValue(AdminServiceProvider.getBoolProperty(API.TLS));

            emailToField.setReadOnly(true);
            receiverNameField.setReadOnly(true);
            emailFromField.setReadOnly(true);
            senderLoginField.setReadOnly(true);
            senderNameField.setReadOnly(true);
            passwordField.setReadOnly(true);
            hostField.setReadOnly(true);
            portField.setReadOnly(true);
            tls.setReadOnly(true);

            save.setVisible(false);
            cancel.setVisible(false);
            change.setVisible(true);
            check.setVisible(true);
        }
    });

    FormLayout fields1 = new FormLayout();
    fields1.setSizeFull();
    fields1.addComponent(senderLoginField);
    fields1.addComponent(passwordField);
    fields1.addComponent(hostField);
    fields1.addComponent(portField);
    fields1.addComponent(tls);

    FormLayout fields2 = new FormLayout();
    fields2.setSizeFull();
    fields2.addComponent(emailToField);
    fields2.addComponent(receiverNameField);
    fields2.addComponent(emailFromField);
    fields2.addComponent(senderNameField);

    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);
    fields.setSizeFull();
    fields.addComponent(fields1);
    fields.addComponent(fields2);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.addComponent(change);
    buttons.addComponent(save);
    buttons.addComponent(cancel);
    buttons.addComponent(check);

    Label label = new Label("?? ");
    label.addStyleName(Reindeer.LABEL_H2);
    emailDates.addComponent(label);
    emailDates.addComponent(fields);
    emailDates.addComponent(buttons);
    emailDates.setExpandRatio(fields, 1f);
    return panel2;
}

From source file:ru.codeinside.adm.ui.AdminApp.java

License:Mozilla Public License

private Panel createMilTaskConfigPanel() {
    VerticalLayout mailConfig = new VerticalLayout();
    mailConfig.setSpacing(true);/* w ww.  j a va2 s .  com*/
    mailConfig.setMargin(true);
    mailConfig.setSizeFull();
    Panel emailTaskPanel = new Panel("?? SMTP ? Email Task", mailConfig);
    emailTaskPanel.setSizeFull();

    final TextField mtDefaultFrom = new TextField("email  :");
    mtDefaultFrom.setValue(get(API.MT_DEFAULT_FROM));
    mtDefaultFrom.setRequired(true);
    mtDefaultFrom.setReadOnly(true);
    mtDefaultFrom.addValidator(new EmailValidator("  e-mail ?"));

    final TextField mtSenderLoginField = new TextField(" ?:");
    mtSenderLoginField.setValue(get(API.MT_SENDER_LOGIN));
    mtSenderLoginField.setRequired(true);
    mtSenderLoginField.setReadOnly(true);

    final PasswordField mtPasswordField = new PasswordField(":");
    mtPasswordField.setValue(API.MT_PASSWORD);
    mtPasswordField.setRequired(true);
    mtPasswordField.setReadOnly(true);

    final TextField mtHostField = new TextField("SMTP ?:");
    String host = get(API.MT_HOST);
    mtHostField.setValue(host == null ? "" : host);
    mtHostField.setRequired(true);
    mtHostField.setReadOnly(true);

    final TextField mtPortField = new TextField(":");
    String port = get(API.MT_PORT);
    mtPortField.setValue(port == null ? "" : port);
    mtPortField.setRequired(true);
    mtPortField.setReadOnly(true);
    mtPortField.addValidator(new IntegerValidator(" "));

    final CheckBox mtTls = new CheckBox("? TLS",
            AdminServiceProvider.getBoolProperty(API.MT_TLS));
    mtTls.setReadOnly(true);

    final Button save = new Button("");
    save.setVisible(false);
    final Button cancel = new Button("");
    cancel.setVisible(false);
    final Button change = new Button("");

    change.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            mtSenderLoginField.setReadOnly(false);
            mtDefaultFrom.setReadOnly(false);
            mtPasswordField.setReadOnly(false);
            mtHostField.setReadOnly(false);
            mtPortField.setReadOnly(false);
            mtTls.setReadOnly(false);

            change.setVisible(false);
            save.setVisible(true);
            cancel.setVisible(true);
        }
    });
    save.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (StringUtils.isEmpty((String) mtSenderLoginField.getValue())
                    || StringUtils.isEmpty((String) mtDefaultFrom.getValue())
                    || StringUtils.isEmpty((String) mtPasswordField.getValue())
                    || StringUtils.isEmpty((String) mtHostField.getValue()) || mtPortField.getValue() == null) {
                mtSenderLoginField.getWindow().showNotification(" ?",
                        Window.Notification.TYPE_HUMANIZED_MESSAGE);
                return;
            }
            boolean errors = false;
            try {
                mtDefaultFrom.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            try {
                mtPortField.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            if (errors) {
                return;
            }
            set(API.MT_SENDER_LOGIN, mtSenderLoginField.getValue());
            set(API.MT_DEFAULT_FROM, mtDefaultFrom.getValue());
            set(API.MT_PASSWORD, mtPasswordField.getValue());
            set(API.MT_HOST, mtHostField.getValue());
            set(API.MT_PORT, mtPortField.getValue());
            set(API.MT_TLS, mtTls.getValue());

            mtSenderLoginField.setReadOnly(true);
            mtDefaultFrom.setReadOnly(true);
            mtPasswordField.setReadOnly(true);
            mtHostField.setReadOnly(true);
            mtPortField.setReadOnly(true);
            mtTls.setReadOnly(true);

            save.setVisible(false);
            cancel.setVisible(false);
            change.setVisible(true);
            mtSenderLoginField.getWindow().showNotification("?? ?",
                    Window.Notification.TYPE_HUMANIZED_MESSAGE);
        }
    });
    cancel.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            mtSenderLoginField.setValue(get(API.MT_SENDER_LOGIN));
            mtDefaultFrom.setValue(get(API.MT_DEFAULT_FROM));
            mtPasswordField.setValue(get(API.MT_PASSWORD));
            mtHostField.setValue(get(API.MT_HOST));
            mtPortField.setValue(get(API.MT_PORT));
            mtTls.setValue(AdminServiceProvider.getBoolProperty(API.MT_TLS));

            mtSenderLoginField.setReadOnly(true);
            mtDefaultFrom.setReadOnly(true);
            mtPasswordField.setReadOnly(true);
            mtHostField.setReadOnly(true);
            mtPortField.setReadOnly(true);
            mtTls.setReadOnly(true);

            save.setVisible(false);
            cancel.setVisible(false);
            change.setVisible(true);
        }
    });

    FormLayout leftFields = new FormLayout();
    leftFields.setSizeFull();
    leftFields.addComponent(mtSenderLoginField);
    leftFields.addComponent(mtDefaultFrom);
    leftFields.addComponent(mtPasswordField);
    leftFields.addComponent(mtHostField);
    leftFields.addComponent(mtPortField);

    FormLayout rightFields = new FormLayout();
    rightFields.setSizeFull();
    rightFields.addComponent(mtTls);

    HorizontalLayout fieldsLayout = new HorizontalLayout();
    fieldsLayout.setSpacing(true);
    fieldsLayout.setSizeFull();
    fieldsLayout.addComponent(leftFields);
    fieldsLayout.addComponent(rightFields);
    fieldsLayout.setExpandRatio(leftFields, 0.6f);
    fieldsLayout.setExpandRatio(rightFields, 0.4f);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.addComponent(change);
    buttons.addComponent(save);
    buttons.addComponent(cancel);

    Label label = new Label("?? Email Task");
    label.addStyleName(Reindeer.LABEL_H2);
    mailConfig.addComponent(label);
    mailConfig.addComponent(fieldsLayout);
    mailConfig.addComponent(buttons);
    mailConfig.setExpandRatio(fieldsLayout, 1f);
    return emailTaskPanel;
}