Example usage for com.vaadin.ui TextField setValue

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

Introduction

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

Prototype

@Override
public void setValue(String value) 

Source Link

Document

Sets the value of this text field.

Usage

From source file:pl.edu.agh.samm.testapp.SAMMTestApplication.java

License:Apache License

private TextField createSlavesCountTextField() {
    TextField slavesCount = new TextField();
    slavesCount.setValue("1");
    slavesCount.setEnabled(false);/*  ww w . jav a2 s.c  o  m*/
    slavesCount.setColumns(3);
    return slavesCount;
}

From source file:pl.edu.agh.samm.testapp.SAMMTestApplication.java

License:Apache License

private TextField createExpressionsPerMinuteTextField() {
    TextField textField = new TextField();
    textField.setValue("60");
    return textField;
}

From source file:qbic.vaadincomponents.ParameterComponent.java

License:Open Source License

public void buildForm(final Workflow workFlow) {

    parameterForm.removeAllComponents();
    parameterFieldGroup = new FieldGroup();
    inputListFieldGroup = new FieldGroup();

    /*/*from ww  w . ja va 2  s .  co  m*/
     * for (Map.Entry<String, Parameter> entry : workFlow.getData().getData().entrySet()) {
     * FileParameter param = (FileParameter) entry.getValue(); FileNameValidator fileNameValidator =
     * new FileNameValidator("Please provide a valid file path"); TextField newField =
     * createInputField(param, fileNameValidator);
     * 
     * parameterForm.addComponent(newField); inputListFieldGroup.bind(newField, entry.getKey()); //
     * Have to set it here because field gets cleared upon binding
     * newField.setValue(param.getValue().toString()); }
     */

    for (Map.Entry<String, Parameter> entry : workFlow.getParameters().getParams().entrySet()) {
        if (entry.getValue() instanceof FloatParameter) {
            FloatParameter param = (FloatParameter) entry.getValue();
            FloatRangeValidator floatValidator = new FloatRangeValidator(
                    String.format("Parameter has to be in the range of %s to %s", param.getMinimum(),
                            param.getMaximum()),
                    param.getMinimum(), param.getMaximum());
            TextField newField = createParameterField(param, floatValidator, new StringToFloatConverter());

            parameterForm.addComponent(newField);
            parameterFieldGroup.bind(newField, entry.getKey());
            // Have to set it here because field gets cleared upon binding
            newField.setValue(param.getValue().toString());
            newField.setRequired(param.isRequired());
        }

        else if (entry.getValue() instanceof IntParameter) {
            IntParameter param = (IntParameter) entry.getValue();
            IntegerRangeValidator intValidator = new IntegerRangeValidator(
                    String.format("Parameter has to be in the range of %s to %s", param.getMinimum(),
                            param.getMaximum()),
                    param.getMinimum(), param.getMaximum());
            TextField newField = createParameterField(param, intValidator, new StringToIntegerConverter());

            parameterForm.addComponent(newField);
            parameterFieldGroup.bind(newField, entry.getKey());
            // Have to set it here because field gets cleared upon binding
            newField.setValue(param.getValue().toString());
            newField.setRequired(param.isRequired());
        }

        else if (entry.getValue() instanceof StringParameter) {
            StringParameter param = (StringParameter) entry.getValue();

            if (param.getRange().size() == 0) {
                TextField newField = createInputField(param, null);

                parameterForm.addComponent(newField);
                parameterFieldGroup.bind(newField, entry.getKey());
                // Have to set it here because field gets cleared upon binding
                newField.setValue(param.getValue().toString());
                newField.setRequired(param.isRequired());
            } else {
                ComboBox newField = createStringSelectionParameterField(param);
                parameterForm.addComponent(newField);
                parameterFieldGroup.bind(newField, entry.getKey());
                // Have to set it here because field gets cleared upon binding
                newField.setValue(param.getValue().toString());
                newField.setRequired(param.isRequired());
            }
        }

        else if (entry.getValue() instanceof BooleanParameter) {
            BooleanParameter param = (BooleanParameter) entry.getValue();

            CheckBox newField = createParameterCheckBox(param);
            newField.setValue((boolean) param.getValue());
            parameterForm.addComponent(newField);
            parameterFieldGroup.bind(newField, entry.getKey());
            // Have to set it here because field gets cleared upon binding
            newField.setValue((Boolean) param.getValue());
            newField.setRequired(param.isRequired());
        }
    }
}

From source file:qbic.vaadincomponents.ParameterComponent.java

License:Open Source License

public void resetInputList() {
    Collection<Field<?>> registeredFields = inputListFieldGroup.getFields();
    InputList inpList = workFlow.getData();

    for (Field<?> field : registeredFields) {
        TextField fieldToReset = (TextField) field;
        fieldToReset.setValue(inpList.getParam(field.getCaption()).getValue().toString());
    }//from  w  w  w .  j  a  v  a 2s .  c  om
}

From source file:roart.client.MyVaadinUI.java

private TextField getConfigValue(final ControlService.Config config) {
    TextField tf = new TextField("Set " + ControlService.configStrMap.get(config));
    tf.setValue("" + ControlService.configMap.get(config));

    // Handle changes in the value
    tf.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            // Assuming that the value type is a String
            String value = (String) event.getProperty().getValue();
            // Do something with the value
            try {
                Integer i = new Integer(value);
                if (i.intValue() < 0) {
                    throw new NumberFormatException();
                }/*from  w  w w . j a v  a  2  s.c  om*/
                ControlService.configMap.put(config, i);
                Notification.show("Value changed");
            } catch (NumberFormatException e) {
                Notification.show("Illegal value, unchanged");
                log.error(Constants.EXCEPTION, e);
            } catch (Exception e) {
                log.error(Constants.EXCEPTION, e);
            }
        }
    });
    // Fire value changes immediately when the field loses focus
    tf.setImmediate(true);
    return tf;
}

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);//from  w w w.j av  a2s. com
    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);//from   w w w. ja va 2  s . co  m
    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);/*from  w  w w.  j  ava 2s.  c  o 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);//from w  w  w .j  av  a 2  s .c  o m
    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;
}

From source file:ru.codeinside.adm.ui.employee.TableEmployee.java

License:Mozilla Public License

protected void edit(final CustomTable table) {
    final Item item = table.getItem(table.getValue());
    final String login = (String) item.getItemProperty("login").getValue();
    final UserItem userItem = AdminServiceProvider.get().getUserItem(login);
    final Pattern snilsPattern = Pattern.compile("\\d{11}");
    final Pattern splitSnilsPattern = Pattern.compile("(\\d{3})(\\d{3})(\\d{3})(\\d{2})");

    final Panel layout = new Panel();
    ((Layout.SpacingHandler) layout.getContent()).setSpacing(true);
    layout.setSizeFull();/*from w  w w  . ja  v  a 2s  . c om*/
    layout.addComponent(new Label("? ? " + login));

    String widthColumn = "100px";

    final PasswordField fieldPass = addPasswordField(layout, widthColumn, "");
    final PasswordField fieldPassRepeat = addPasswordField(layout, widthColumn,
            " ?");
    fieldPassRepeat.addValidator(new RepeatPasswordValidator(fieldPass));
    final MaskedTextField fieldSnils = addMaskedTextField(layout, widthColumn, "?");
    fieldSnils.setMask("###-###-### ##");
    final TextField fieldFIO = addTextField(layout, widthColumn, "");
    final String snils = userItem.getSnils() == null ? "" : userItem.getSnils();
    final Matcher maskMatcher = snilsPattern.matcher(snils);
    final Matcher splitMatcher = splitSnilsPattern.matcher(snils);
    if (maskMatcher.matches()) {
        String maskedSnils = splitMatcher.replaceAll("$1-$2-$3 $4");
        fieldSnils.setValue(maskedSnils);
    }
    fieldFIO.setValue(userItem.getFio());

    HorizontalLayout l1 = new HorizontalLayout();
    Label labelRole = new Label("");
    labelRole.setWidth(widthColumn);
    l1.addComponent(labelRole);
    l1.setComponentAlignment(labelRole, Alignment.MIDDLE_LEFT);
    final OptionGroup roleOptionGroup = TableEmployee.createRoleOptionGroup(null);
    roleOptionGroup.setValue(userItem.getRoles());
    l1.addComponent(roleOptionGroup);
    layout.addComponent(l1);

    final CertificateBlock certificateBlock = new CertificateBlock(userItem);
    layout.addComponent(certificateBlock);

    final ExecutorGroupsBlock executorGroupsBlock = new ExecutorGroupsBlock(userItem);
    layout.addComponent(executorGroupsBlock);

    final HorizontalLayout supervisorGroupsEmp = new HorizontalLayout();
    supervisorGroupsEmp.setMargin(true, true, true, false);
    supervisorGroupsEmp.setSpacing(true);
    supervisorGroupsEmp
            .setCaption("?  ? ? ?");
    final FilterTable allSupervisorGroupsEmp = new FilterTable();
    allSupervisorGroupsEmp.setCaption("?");
    table(supervisorGroupsEmp, allSupervisorGroupsEmp);
    final FilterTable currentSupervisorGroupsEmp = new FilterTable();
    currentSupervisorGroupsEmp.setCaption("");
    table(supervisorGroupsEmp, currentSupervisorGroupsEmp);
    for (String groupName : AdminServiceProvider.get().getEmpGroupNames()) {
        for (Group group : AdminServiceProvider.get().findGroupByName(groupName)) {
            if (userItem.getEmployeeGroups().contains(groupName)) {
                currentSupervisorGroupsEmp.addItem(new Object[] { groupName, group.getTitle() }, groupName);
            } else {
                allSupervisorGroupsEmp.addItem(new Object[] { groupName, group.getTitle() }, groupName);
            }
        }
    }
    addListener(allSupervisorGroupsEmp, currentSupervisorGroupsEmp);
    addListener(currentSupervisorGroupsEmp, allSupervisorGroupsEmp);
    layout.addComponent(supervisorGroupsEmp);

    final HorizontalLayout supervisorGroupsOrg = new HorizontalLayout();
    supervisorGroupsOrg.setMargin(true, true, true, false);
    supervisorGroupsOrg.setSpacing(true);
    supervisorGroupsOrg
            .setCaption("?   ? ?");
    final FilterTable allSupervisorGroupsOrg = new FilterTable();
    allSupervisorGroupsOrg.setCaption("?");
    table(supervisorGroupsOrg, allSupervisorGroupsOrg);
    final FilterTable currentSupervisorGroupsOrg = new FilterTable();
    currentSupervisorGroupsOrg.setCaption("");
    table(supervisorGroupsOrg, currentSupervisorGroupsOrg);
    for (String groupName : AdminServiceProvider.get().getOrgGroupNames()) {
        for (Group group : AdminServiceProvider.get().findGroupByName(groupName)) {
            if (userItem.getOrganizationGroups().contains(groupName)) {
                currentSupervisorGroupsOrg.addItem(new Object[] { groupName, group.getTitle() }, groupName);
            } else {
                allSupervisorGroupsOrg.addItem(new Object[] { groupName, group.getTitle() }, groupName);
            }
        }
    }
    addListener(allSupervisorGroupsOrg, currentSupervisorGroupsOrg);
    addListener(currentSupervisorGroupsOrg, allSupervisorGroupsOrg);
    layout.addComponent(supervisorGroupsOrg);

    setRolesEnabled(roleOptionGroup, certificateBlock, executorGroupsBlock, supervisorGroupsEmp,
            supervisorGroupsOrg);
    roleOptionGroup.addListener(new Listener() {
        private static final long serialVersionUID = 1L;

        public void componentEvent(Event event) {
            setRolesEnabled(roleOptionGroup, certificateBlock, executorGroupsBlock, supervisorGroupsEmp,
                    supervisorGroupsOrg);
        }
    });

    Button cancel = new Button("", new Button.ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            removeComponent(layout);
            addComponent(table);
            table.setValue(null);
            if (hr != null) {
                hr.setVisible(true);
            }
            setExpandRatio(table, 1f);
        }
    });

    Button apply = new Button("", new Button.ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            String password = (String) fieldPass.getValue();
            String passwordRepeat = (String) fieldPassRepeat.getValue();
            if (!fieldPassRepeat.isValid() || !(password.equals(passwordRepeat))) {
                getWindow().showNotification(
                        "?   ? ?  ?",
                        Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            }

            String snilsFieldValue = fieldSnils.getValue() == null ? "" : (String) fieldSnils.getValue();
            String snilsValue = snilsFieldValue.replaceAll("\\D+", "");
            Matcher snilsMatcher = snilsPattern.matcher(snilsValue);

            if (!snilsFieldValue.isEmpty() && !snilsMatcher.matches()) {
                getWindow().showNotification("?  ",
                        Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            }

            if (!AdminServiceProvider.get().isUniqueSnils(login, snilsValue)) {
                getWindow().showNotification(" ?  ",
                        Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            }

            String fio = (String) fieldFIO.getValue();
            Set<Role> roles = (Set) roleOptionGroup.getValue();

            TreeSet<String> groupExecutor = executorGroupsBlock.getGroups();
            TreeSet<String> groupSupervisorEmp = new TreeSet<String>(
                    (Collection<String>) currentSupervisorGroupsEmp.getItemIds());
            TreeSet<String> groupSupervisorOrg = new TreeSet<String>(
                    (Collection<String>) currentSupervisorGroupsOrg.getItemIds());

            boolean modified = false;

            if (certificateBlock.isCertificateWasRemoved()) {
                userItem.setX509(null);
                modified = true;
            }

            if (!password.equals("") && password.equals(passwordRepeat)) {
                userItem.setPassword1(password);
                userItem.setPassword2(passwordRepeat);
                modified = true;
            }
            if (!fio.trim().equals("") && !fio.equals(userItem.getFio())) {
                userItem.setFio(fio);
                userItem.setX509(null);
                modified = true;
            }
            if (!snilsValue.equals(userItem.getSnils())) {
                userItem.setSnils(snilsValue);
                modified = true;
            }
            if (!roles.equals(userItem.getRoles())) {
                userItem.setRoles(roles);
                modified = true;
            }
            if (!groupExecutor.equals(userItem.getGroups())) {
                userItem.setGroups(groupExecutor);
                modified = true;
            }
            if (!groupSupervisorEmp.equals(userItem.getEmployeeGroups())) {
                userItem.setEmployeeGroups(groupSupervisorEmp);
                modified = true;
            }
            if (!groupSupervisorOrg.equals(userItem.getOrganizationGroups())) {
                userItem.setOrganizationGroups(groupSupervisorOrg);
                modified = true;
            }

            if (modified) {
                // TODO :  userInfoPanel
                // if (getApplication().getUser().equals(login)) {
                // ((AdminApp) getApplication()).getUserInfoPanel().setRole(
                // userItem.getRoles().toString());
                // }
                AdminServiceProvider.get().setUserItem(login, userItem);
                final Container container = table.getContainerDataSource();
                if (container instanceof LazyLoadingContainer2) {
                    ((LazyLoadingContainer2) container).fireItemSetChange();
                }
                getWindow().showNotification(" " + login + " ");
            } else {
                getWindow().showNotification(" ");
            }

            removeComponent(layout);
            addComponent(table);
            table.setValue(null);
            if (hr != null) {
                hr.setVisible(true);
            }
            setExpandRatio(table, 1f);
            refresh(table);
        }
    });

    cancel.setClickShortcut(KeyCode.ESCAPE, 0);
    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.addComponent(apply);
    buttons.addComponent(cancel);
    layout.addComponent(buttons);
    removeComponent(table);
    addComponent(layout);
    setExpandRatio(layout, 1f);
}