Search in sources :

Example 1 with IntegerRangeValidator

use of com.vaadin.data.validator.IntegerRangeValidator in project GridFastNavigation by TatuLund.

the class DemoUI method initGrid.

private void initGrid(final Grid grid) {
    grid.setEditorEnabled(true);
    // Add some columns
    DeleteButtonRenderer deleteButton = new DeleteButtonRenderer(new DeleteRendererClickListener() {

        @Override
        public void click(DeleteRendererClickEvent event) {
            grid.getContainerDataSource().removeItem(event.getItem());
        }
    }, FontAwesome.TRASH.getHtml() + " Delete", FontAwesome.CHECK.getHtml() + " Confirm");
    deleteButton.setHtmlContentAllowed(true);
    grid.addColumn("action", Boolean.class);
    grid.getColumn("action").setEditable(false);
    grid.getColumn("action").setRenderer(deleteButton);
    grid.addColumn("col1", String.class);
    grid.addColumn("col2", String.class);
    for (int i = 0; i < 5; ++i) {
        grid.addColumn("col" + (i + 3), Integer.class);
    }
    TextField field = new TextField();
    field.addValidator(new IntegerRangeValidator("The value needs to be between 0 and 10", 0, 40));
    grid.getColumn("col3").setEditorField(field);
    grid.addColumn("col8", Date.class);
    grid.addColumn("col10", Boolean.class);
    grid.addColumn("col11", String.class);
    ComboBox comboBox = new ComboBox();
    comboBox.addItems("Soft", "Medium", "Hard");
    grid.getColumn("col11").setEditorField(comboBox);
    // Make column 2 read only to test statically read only columns
    grid.getColumn("col2").setEditable(false);
    Random rand = new Random();
    for (int i = 0; i < 100; ++i) {
        grid.addRow(true, "string 1 " + i, "string 2 " + i, rand.nextInt(i + 10), rand.nextInt(i + 10), rand.nextInt(i + 10), rand.nextInt(i + 10), rand.nextInt(i + 10), new Date(), false, "Medium");
    }
    grid.setSelectionMode(SelectionMode.SINGLE);
    grid.setSizeFull();
}
Also used : IntegerRangeValidator(com.vaadin.data.validator.IntegerRangeValidator) DeleteRendererClickListener(org.vaadin.grid.cellrenderers.action.DeleteButtonRenderer.DeleteRendererClickListener) Random(java.util.Random) ComboBox(com.vaadin.ui.ComboBox) TextField(com.vaadin.ui.TextField) DeleteButtonRenderer(org.vaadin.grid.cellrenderers.action.DeleteButtonRenderer) DeleteRendererClickEvent(org.vaadin.grid.cellrenderers.action.DeleteButtonRenderer.DeleteRendererClickEvent) Date(java.util.Date)

Example 2 with IntegerRangeValidator

use of com.vaadin.data.validator.IntegerRangeValidator in project unity by unity-idm.

the class OTPWithLDAPAuthenticatorEditor method buildServersConnectionConfigurationSection.

private CollapsibleLayout buildServersConnectionConfigurationSection() {
    FormLayoutWithFixedCaptionWidth serverConnectionLayout = new FormLayoutWithFixedCaptionWidth();
    serverConnectionLayout.setMargin(false);
    GridWithEditor<ServerSpecification> serverConfig = new GridWithEditor<>(msg, ServerSpecification.class);
    serverConnectionLayout.addComponent(serverConfig);
    serverConfig.addTextColumn(s -> s.getServer(), (t, v) -> t.setServer(v), msg.getMessage("LdapAuthenticatorEditor.server"), 40, true);
    serverConfig.addIntColumn(s -> s.getPort(), (t, v) -> t.setPort(v), msg.getMessage("LdapAuthenticatorEditor.port"), 10, Optional.of(new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 1, 65535)));
    serverConfig.setWidth(FieldSizeConstans.WIDE_FIELD_WIDTH, FieldSizeConstans.WIDE_FIELD_WIDTH_UNIT);
    configBinder.forField(serverConfig).withValidator((v, c) -> {
        if (v == null || v.isEmpty()) {
            return ValidationResult.error(msg.getMessage("fieldRequired"));
        } else {
            return ValidationResult.ok();
        }
    }).bind("servers");
    ComboBox<ConnectionMode> connectionMode = new ComboBox<>(msg.getMessage("LdapAuthenticatorEditor.connectionMode"));
    connectionMode.setItems(ConnectionMode.values());
    connectionMode.setEmptySelectionAllowed(false);
    configBinder.forField(connectionMode).bind("connectionMode");
    serverConnectionLayout.addComponent(connectionMode);
    TextField followReferrals = new TextField(msg.getMessage("LdapAuthenticatorEditor.followReferrals"));
    configBinder.forField(followReferrals).asRequired(msg.getMessage("notAPositiveNumber")).withConverter(new StringToIntegerConverter(msg.getMessage("notAPositiveNumber"))).withValidator(new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 0, null)).bind("followReferrals");
    serverConnectionLayout.addComponent(followReferrals);
    TextField searchTimeLimit = new TextField(msg.getMessage("LdapAuthenticatorEditor.searchTimeLimit"));
    configBinder.forField(searchTimeLimit).asRequired(msg.getMessage("notAPositiveNumber")).withConverter(new StringToIntegerConverter(msg.getMessage("notAPositiveNumber"))).withValidator(new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 0, null)).bind("searchTimeLimit");
    serverConnectionLayout.addComponent(searchTimeLimit);
    TextField socketTimeout = new TextField(msg.getMessage("LdapAuthenticatorEditor.socketTimeout"));
    configBinder.forField(socketTimeout).asRequired(msg.getMessage("notAPositiveNumber")).withConverter(new StringToIntegerConverter(msg.getMessage("notAPositiveNumber"))).withValidator(new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 0, null)).bind("socketTimeout");
    serverConnectionLayout.addComponent(socketTimeout);
    CheckBox trustAllCerts = new CheckBox(msg.getMessage("LdapAuthenticatorEditor.trustAllCerts"));
    configBinder.forField(trustAllCerts).bind("trustAllCerts");
    serverConnectionLayout.addComponent(trustAllCerts);
    ComboBox<String> clientTrustStore = new ComboBox<>(msg.getMessage("LdapAuthenticatorEditor.clientTrustStore"));
    clientTrustStore.setItems(validators);
    configBinder.forField(clientTrustStore).bind("clientTrustStore");
    serverConnectionLayout.addComponent(clientTrustStore);
    trustAllCerts.addValueChangeListener(e -> {
        clientTrustStore.setEnabled(!e.getValue());
    });
    TextField resultEntriesLimit = new TextField(msg.getMessage("LdapAuthenticatorEditor.resultEntriesLimit"));
    configBinder.forField(resultEntriesLimit).asRequired(msg.getMessage("notAPositiveNumber")).withConverter(new StringToIntegerConverter(msg.getMessage("notAPositiveNumber"))).withValidator(new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 0, null)).bind("resultEntriesLimit");
    serverConnectionLayout.addComponent(resultEntriesLimit);
    return new CollapsibleLayout(msg.getMessage("OTPWithLDAPAuthenticatorEditor.serverConnectionConfiguration"), serverConnectionLayout);
}
Also used : IntegerRangeValidator(com.vaadin.data.validator.IntegerRangeValidator) FieldSizeConstans(pl.edu.icm.unity.webui.common.FieldSizeConstans) TextField(com.vaadin.ui.TextField) PrototypeComponent(pl.edu.icm.unity.engine.api.utils.PrototypeComponent) VerticalLayout(com.vaadin.ui.VerticalLayout) ComboBox(com.vaadin.ui.ComboBox) Autowired(org.springframework.beans.factory.annotation.Autowired) ServerSpecification(pl.edu.icm.unity.ldap.client.config.ServerSpecification) ValidationResult(com.vaadin.data.ValidationResult) PKIManagement(pl.edu.icm.unity.engine.api.PKIManagement) Validator(com.vaadin.data.Validator) CheckBox(com.vaadin.ui.CheckBox) UserDNResolving(pl.edu.icm.unity.ldap.client.config.common.LDAPCommonConfiguration.UserDNResolving) AuthenticatorDefinition(pl.edu.icm.unity.types.authn.AuthenticatorDefinition) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchSpecification(pl.edu.icm.unity.ldap.client.config.SearchSpecification) MessageSource(pl.edu.icm.unity.MessageSource) IntegerRangeValidator(com.vaadin.data.validator.IntegerRangeValidator) CollapsibleLayout(pl.edu.icm.unity.webui.common.CollapsibleLayout) TooltipExtension.tooltip(io.imunity.tooltip.TooltipExtension.tooltip) GridWithEditor(pl.edu.icm.unity.webui.common.GridWithEditor) Set(java.util.Set) EnumComboBox(pl.edu.icm.unity.webui.common.EnumComboBox) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) SearchScope(pl.edu.icm.unity.ldap.client.config.common.LDAPConnectionProperties.SearchScope) Binder(com.vaadin.data.Binder) HashFunction(io.imunity.otp.HashFunction) EngineException(pl.edu.icm.unity.exceptions.EngineException) ObjectFactory(org.springframework.beans.factory.ObjectFactory) SubViewSwitcher(pl.edu.icm.unity.webui.common.webElements.SubViewSwitcher) AuthenticatorEditor(pl.edu.icm.unity.webui.authn.authenticators.AuthenticatorEditor) AuthenticatorEditorFactory(pl.edu.icm.unity.webui.authn.authenticators.AuthenticatorEditorFactory) I18nTextField(pl.edu.icm.unity.webui.common.i18n.I18nTextField) ConnectionMode(pl.edu.icm.unity.ldap.client.config.common.LDAPConnectionProperties.ConnectionMode) BaseAuthenticatorEditor(pl.edu.icm.unity.webui.authn.authenticators.BaseAuthenticatorEditor) RadioButtonGroup(com.vaadin.ui.RadioButtonGroup) FormValidationException(pl.edu.icm.unity.webui.common.FormValidationException) Optional(java.util.Optional) StringToIntegerConverter(com.vaadin.data.converter.StringToIntegerConverter) Filter(com.unboundid.ldap.sdk.Filter) Unit(com.vaadin.server.Sizeable.Unit) IntStepper(org.vaadin.risto.stepper.IntStepper) Component(com.vaadin.ui.Component) CollapsibleLayout(pl.edu.icm.unity.webui.common.CollapsibleLayout) ComboBox(com.vaadin.ui.ComboBox) EnumComboBox(pl.edu.icm.unity.webui.common.EnumComboBox) ServerSpecification(pl.edu.icm.unity.ldap.client.config.ServerSpecification) GridWithEditor(pl.edu.icm.unity.webui.common.GridWithEditor) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) CheckBox(com.vaadin.ui.CheckBox) ConnectionMode(pl.edu.icm.unity.ldap.client.config.common.LDAPConnectionProperties.ConnectionMode) TextField(com.vaadin.ui.TextField) I18nTextField(pl.edu.icm.unity.webui.common.i18n.I18nTextField) StringToIntegerConverter(com.vaadin.data.converter.StringToIntegerConverter)

Example 3 with IntegerRangeValidator

use of com.vaadin.data.validator.IntegerRangeValidator in project unity by unity-idm.

the class EmailConfirmationConfigurationEditor method initUI.

private void initUI() {
    binder = new Binder<>(EmailConfirmationConfiguration.class);
    msgTemplate = new CompatibleTemplatesComboBox(EmailConfirmationTemplateDef.NAME, msgTemplateMan);
    msgTemplate.setCaption(msg.getMessage("EmailConfirmationConfiguration.confirmationMsgTemplate"));
    msgTemplate.setDescription(msg.getMessage("EmailConfirmationConfiguration.confirmationMsgTemplateDesc"));
    msgTemplate.setEmptySelectionAllowed(true);
    validityTime = new TextField(msg.getMessage("EmailConfirmationConfiguration.validityTime"));
    addFieldToLayout(this);
    binder.forField(msgTemplate).bind("messageTemplate");
    binder.forField(validityTime).asRequired(msg.getMessage("fieldRequired")).withConverter(new StringToIntegerConverter(msg.getMessage("notAnIntNumber"))).withValidator(new IntegerRangeValidator(msg.getMessage("outOfBoundsNumber", 1, 60 * 24 * 365), 1, 60 * 24 * 365)).bind("validityTime");
    if (initial != null) {
        binder.setBean(initial);
    } else {
        EmailConfirmationConfiguration init = new EmailConfirmationConfiguration();
        init.setMessageTemplate(msgTemplate.getValue());
        init.setValidityTime(EmailConfirmationConfiguration.DEFAULT_VALIDITY);
        binder.setBean(init);
    }
}
Also used : IntegerRangeValidator(com.vaadin.data.validator.IntegerRangeValidator) TextField(com.vaadin.ui.TextField) StringToIntegerConverter(com.vaadin.data.converter.StringToIntegerConverter) EmailConfirmationConfiguration(pl.edu.icm.unity.types.confirmation.EmailConfirmationConfiguration) CompatibleTemplatesComboBox(pl.edu.icm.unity.webui.common.CompatibleTemplatesComboBox)

Example 4 with IntegerRangeValidator

use of com.vaadin.data.validator.IntegerRangeValidator in project unity by unity-idm.

the class EditTrustedFederationSubView method buildHeaderSection.

private FormLayout buildHeaderSection() {
    FormLayoutWithFixedCaptionWidth header = new FormLayoutWithFixedCaptionWidth();
    header.setMargin(true);
    TextField name = new TextField(msg.getMessage("EditTrustedFederationSubView.name"));
    binder.forField(name).asRequired(msg.getMessage("fieldRequired")).withValidator(new NoSpaceValidator(msg)).withValidator((s, c) -> {
        if (usedNames.contains(s)) {
            return ValidationResult.error(msg.getMessage("EditTrustedFederationSubView.nameExists"));
        } else {
            return ValidationResult.ok();
        }
    }).bind("name");
    header.addComponent(name);
    name.focus();
    url = new TextField(msg.getMessage("EditTrustedFederationSubView.url"));
    url.setWidth(FieldSizeConstans.LINK_FIELD_WIDTH, FieldSizeConstans.LINK_FIELD_WIDTH_UNIT);
    binder.forField(url).asRequired(msg.getMessage("fieldRequired")).bind("url");
    header.addComponent(url);
    httpsTruststore = new ComboBox<>(msg.getMessage("EditTrustedFederationSubView.httpsTruststore"));
    httpsTruststore.setItems(validators);
    binder.forField(httpsTruststore).bind("httpsTruststore");
    header.addComponent(httpsTruststore);
    CheckBox ignoreSignatureVerification = new CheckBox(msg.getMessage("EditTrustedFederationSubView.ignoreSignatureVerification"));
    binder.forField(ignoreSignatureVerification).bind("ignoreSignatureVerification");
    header.addComponent(ignoreSignatureVerification);
    ComboBox<String> signatureVerificationCertificate = new ComboBox<>(msg.getMessage("EditTrustedFederationSubView.signatureVerificationCertificate"));
    signatureVerificationCertificate.setItems(certificates);
    binder.forField(signatureVerificationCertificate).asRequired((v, c) -> ((v == null || v.isEmpty()) && !ignoreSignatureVerification.getValue()) ? ValidationResult.error(msg.getMessage("fieldRequired")) : ValidationResult.ok()).bind("signatureVerificationCertificate");
    header.addComponent(signatureVerificationCertificate);
    TextField refreshInterval = new TextField();
    refreshInterval.setCaption(msg.getMessage("EditTrustedFederationSubView.refreshInterval"));
    binder.forField(refreshInterval).asRequired(msg.getMessage("fieldRequired")).withConverter(new StringToIntegerConverter(msg.getMessage("notAPositiveNumber"))).withValidator(new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 0, null)).bind("refreshInterval");
    header.addComponent(refreshInterval);
    return header;
}
Also used : FieldSizeConstans(pl.edu.icm.unity.webui.common.FieldSizeConstans) Arrays(java.util.Arrays) CustomComponent(com.vaadin.ui.CustomComponent) URIHelper(pl.edu.icm.unity.engine.api.files.URIHelper) TextField(com.vaadin.ui.TextField) VerticalLayout(com.vaadin.ui.VerticalLayout) Alignment(com.vaadin.ui.Alignment) ComboBox(com.vaadin.ui.ComboBox) UI(com.vaadin.ui.UI) CompletableFuture(java.util.concurrent.CompletableFuture) FileStreamResource(pl.edu.icm.unity.webui.common.FileStreamResource) ValidationResult(com.vaadin.data.ValidationResult) NoSpaceValidator(pl.edu.icm.unity.webui.common.validators.NoSpaceValidator) MetadataDownloader(pl.edu.icm.unity.saml.metadata.srv.MetadataDownloader) UnitySubView(pl.edu.icm.unity.webui.common.webElements.UnitySubView) Resource(com.vaadin.server.Resource) CheckBox(com.vaadin.ui.CheckBox) Image(com.vaadin.ui.Image) Orientation(com.vaadin.shared.ui.Orientation) FilterableGridHelper(pl.edu.icm.unity.webui.common.grid.FilterableGridHelper) GridWithActionColumn(pl.edu.icm.unity.webui.common.GridWithActionColumn) ProgressBar(com.vaadin.ui.ProgressBar) SearchField(pl.edu.icm.unity.webui.common.SearchField) MessageSource(pl.edu.icm.unity.MessageSource) NotificationPopup(pl.edu.icm.unity.webui.common.NotificationPopup) IntegerRangeValidator(com.vaadin.data.validator.IntegerRangeValidator) CollapsibleLayout(pl.edu.icm.unity.webui.common.CollapsibleLayout) SAMLEntityWithLogo(pl.edu.icm.unity.saml.idp.console.SimpleIDPMetaConverter.SAMLEntityWithLogo) Set(java.util.Set) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) StandardButtonsHelper(pl.edu.icm.unity.webui.common.StandardButtonsHelper) Binder(com.vaadin.data.Binder) Images(pl.edu.icm.unity.webui.common.Images) Consumer(java.util.function.Consumer) List(java.util.List) Button(com.vaadin.ui.Button) SubViewSwitcher(pl.edu.icm.unity.webui.common.webElements.SubViewSwitcher) HorizontalLayout(com.vaadin.ui.HorizontalLayout) URIAccessService(pl.edu.icm.unity.engine.api.files.URIAccessService) FormLayout(com.vaadin.ui.FormLayout) FormValidationException(pl.edu.icm.unity.webui.common.FormValidationException) EntitiesDescriptorDocument(xmlbeans.org.oasis.saml2.metadata.EntitiesDescriptorDocument) StringToIntegerConverter(com.vaadin.data.converter.StringToIntegerConverter) FileStorageService(pl.edu.icm.unity.engine.api.files.FileStorageService) ComponentWithToolbar(pl.edu.icm.unity.webui.common.ComponentWithToolbar) Toolbar(pl.edu.icm.unity.webui.common.Toolbar) Collections(java.util.Collections) IntegerRangeValidator(com.vaadin.data.validator.IntegerRangeValidator) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) CheckBox(com.vaadin.ui.CheckBox) ComboBox(com.vaadin.ui.ComboBox) TextField(com.vaadin.ui.TextField) StringToIntegerConverter(com.vaadin.data.converter.StringToIntegerConverter) NoSpaceValidator(pl.edu.icm.unity.webui.common.validators.NoSpaceValidator)

Example 5 with IntegerRangeValidator

use of com.vaadin.data.validator.IntegerRangeValidator in project unity by unity-idm.

the class JWTAuthenticatorEditor method getEditor.

@Override
public Component getEditor(AuthenticatorDefinition toEdit, SubViewSwitcher switcher, boolean forceNameEditable) {
    boolean editMode = init(msg.getMessage("JWTAuthenticatorEditor.defaultName"), toEdit, forceNameEditable);
    ComboBox<String> credential = new ComboBox<>();
    credential.setCaption(msg.getMessage("JWTAuthenticatorEditor.signingCredential"));
    credential.setEmptySelectionAllowed(false);
    credential.setItems(credentials);
    TextField ttl = new TextField();
    ttl.setCaption(msg.getMessage("JWTAuthenticatorEditor.tokenTTL"));
    configBinder = new Binder<>(JWTConfiguration.class);
    configBinder.forField(credential).asRequired(msg.getMessage("fieldRequired")).bind("credential");
    configBinder.forField(ttl).asRequired(msg.getMessage("fieldRequired")).withConverter(new StringToIntegerConverter(msg.getMessage("notAPositiveNumber"))).withValidator(new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 0, null)).bind("ttl");
    FormLayoutWithFixedCaptionWidth main = new FormLayoutWithFixedCaptionWidth();
    main.setMargin(true);
    main.addComponents(name);
    main.addComponent(credential);
    main.addComponent(ttl);
    JWTConfiguration config = new JWTConfiguration();
    if (!credentials.isEmpty()) {
        config.setCredential(credentials.iterator().next());
    }
    if (editMode) {
        config.fromProperties(toEdit.configuration, msg);
    }
    configBinder.setBean(config);
    return main;
}
Also used : IntegerRangeValidator(com.vaadin.data.validator.IntegerRangeValidator) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) ComboBox(com.vaadin.ui.ComboBox) TextField(com.vaadin.ui.TextField) StringToIntegerConverter(com.vaadin.data.converter.StringToIntegerConverter)

Aggregations

IntegerRangeValidator (com.vaadin.data.validator.IntegerRangeValidator)16 TextField (com.vaadin.ui.TextField)12 StringToIntegerConverter (com.vaadin.data.converter.StringToIntegerConverter)11 CheckBox (com.vaadin.ui.CheckBox)8 ComboBox (com.vaadin.ui.ComboBox)8 FormLayoutWithFixedCaptionWidth (pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth)8 VerticalLayout (com.vaadin.ui.VerticalLayout)7 CollapsibleLayout (pl.edu.icm.unity.webui.common.CollapsibleLayout)7 MessageSource (pl.edu.icm.unity.MessageSource)6 Binder (com.vaadin.data.Binder)5 ValidationResult (com.vaadin.data.ValidationResult)5 Set (java.util.Set)5 FieldSizeConstans (pl.edu.icm.unity.webui.common.FieldSizeConstans)5 FormValidationException (pl.edu.icm.unity.webui.common.FormValidationException)5 SubViewSwitcher (pl.edu.icm.unity.webui.common.webElements.SubViewSwitcher)5 List (java.util.List)4 Component (com.vaadin.ui.Component)3 CustomComponent (com.vaadin.ui.CustomComponent)3 FormLayout (com.vaadin.ui.FormLayout)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3