Search in sources :

Example 56 with TextField

use of com.vaadin.flow.component.textfield.TextField in project furms by unity-idm.

the class AlarmFormView method prepareValidator.

private void prepareValidator(TextField nameField, ComboBox<String> allocationComboBox, IntegerField thresholdField, Checkbox checkbox, MultiselectComboBox<String> multiselectComboBox) {
    binder.forField(nameField).withValidator(value -> Objects.nonNull(value) && !value.isBlank(), getTranslation("view.project-admin.alarms.form.error.name")).bind(model -> model.name, (model, name) -> model.name = name);
    binder.forField(allocationComboBox).withValidator(Objects::nonNull, getTranslation("view.project-admin.alarms.form.error.allocation")).bind(model -> model.allocationId, (model, id) -> model.allocationId = id);
    binder.forField(thresholdField).withValidator(threshold -> threshold >= 1.0 && threshold <= 100.0, getTranslation("view.project-admin.alarms.form.error.threshold")).bind(model -> model.threshold, (model, threshold) -> model.threshold = threshold);
    binder.forField(checkbox).bind(model -> model.allUsers, (model, value) -> model.allUsers = value);
    binder.forField(multiselectComboBox).withValidator(emails -> emails.stream().noneMatch(email -> emailValidator.apply(email, new ValueContext()).isError()), getTranslation("view.project-admin.alarms.form.error.emails")).bind(model -> model.users, (model, policyFile) -> model.users = multiselectComboBox.getSelectedItems());
}
Also used : DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) Label(com.vaadin.flow.component.html.Label) PageTitle(io.imunity.furms.ui.components.PageTitle) BeforeEvent(com.vaadin.flow.router.BeforeEvent) FurmsFormLayout(io.imunity.furms.ui.components.FurmsFormLayout) Route(com.vaadin.flow.router.Route) Map(java.util.Map) Key(com.vaadin.flow.component.Key) UI(com.vaadin.flow.component.UI) TextField(com.vaadin.flow.component.textfield.TextField) FormButtons(io.imunity.furms.ui.components.FormButtons) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) OptionalParameter(com.vaadin.flow.router.OptionalParameter) Objects(java.util.Objects) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) EmailNotPresentException(io.imunity.furms.api.validation.exceptions.EmailNotPresentException) AlarmAlreadyExceedThresholdException(io.imunity.furms.api.validation.exceptions.AlarmAlreadyExceedThresholdException) AlarmService(io.imunity.furms.api.alarms.AlarmService) Optional(java.util.Optional) VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) ResourceGetter.getCurrentResourceId(io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) EmailValidator(com.vaadin.flow.data.validator.EmailValidator) Binder(com.vaadin.flow.data.binder.Binder) Div(com.vaadin.flow.component.html.Div) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Function(java.util.function.Function) HashSet(java.util.HashSet) AlarmWithUserEmails(io.imunity.furms.domain.alarms.AlarmWithUserEmails) TextFieldVariant(com.vaadin.flow.component.textfield.TextFieldVariant) MultiselectComboBox(org.vaadin.gatanaso.MultiselectComboBox) ProjectAllocationService(io.imunity.furms.api.project_allocation.ProjectAllocationService) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) IntegerField(com.vaadin.flow.component.textfield.IntegerField) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) ValueContext(com.vaadin.flow.data.binder.ValueContext) ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) EAGER(com.vaadin.flow.data.value.ValueChangeMode.EAGER) ProjectAdminMenu(io.imunity.furms.ui.views.project.ProjectAdminMenu) FiredAlarmThresholdReduceException(io.imunity.furms.api.validation.exceptions.FiredAlarmThresholdReduceException) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) Optional.ofNullable(java.util.Optional.ofNullable) AlarmId(io.imunity.furms.domain.alarms.AlarmId) Button(com.vaadin.flow.component.button.Button) ProjectService(io.imunity.furms.api.projects.ProjectService) ValueContext(com.vaadin.flow.data.binder.ValueContext)

Example 57 with TextField

use of com.vaadin.flow.component.textfield.TextField in project furms by unity-idm.

the class SitesView method updateAction.

private void updateAction(Editor<SiteGridItem> siteEditor) {
    if (siteEditor.getBinder().isValid()) {
        Optional<Component> component = siteEditor.getGrid().getColumnByKey("name").getEditorComponent().getChildren().filter(c -> c instanceof TextField).findFirst();
        if (component.isPresent()) {
            TextField name = component.map(c -> (TextField) c).get();
            try {
                siteService.update(Site.builder().id(siteEditor.getItem().getId()).name(name.getValue()).build());
                siteEditor.cancel();
                refreshGrid(siteEditor);
                showSuccessNotification(getTranslation("view.sites.form.save.success"));
            } catch (DuplicatedNameValidationError e) {
                name.setErrorMessage(getTranslation("view.sites.form.error.validation.field.name.unique"));
                name.setInvalid(true);
            } catch (RuntimeException e) {
                LOG.warn("Could not update Site.", e);
                showErrorNotification(getTranslation("view.sites.form.error.unexpected", "update"));
            }
        }
    }
}
Also used : DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) Component(com.vaadin.flow.component.Component) LoggerFactory(org.slf4j.LoggerFactory) MenuButton(io.imunity.furms.ui.components.MenuButton) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) FlexLayout(com.vaadin.flow.component.orderedlayout.FlexLayout) DenseGrid(io.imunity.furms.ui.components.DenseGrid) Key(com.vaadin.flow.component.Key) UI(com.vaadin.flow.component.UI) TextField(com.vaadin.flow.component.textfield.TextField) USERS(com.vaadin.flow.component.icon.VaadinIcon.USERS) MethodHandles(java.lang.invoke.MethodHandles) Editor(com.vaadin.flow.component.grid.editor.Editor) RouterGridLink(io.imunity.furms.ui.components.RouterGridLink) END(com.vaadin.flow.component.grid.ColumnTextAlign.END) Objects(java.util.Objects) List(java.util.List) Optional(java.util.Optional) NotificationUtils.showSuccessNotification(io.imunity.furms.ui.utils.NotificationUtils.showSuccessNotification) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) EditorOpenEvent(com.vaadin.flow.component.grid.editor.EditorOpenEvent) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) SiteHasResourceCreditsRemoveValidationError(io.imunity.furms.api.validation.exceptions.SiteHasResourceCreditsRemoveValidationError) Binder(com.vaadin.flow.data.binder.Binder) Div(com.vaadin.flow.component.html.Div) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) PLUS_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.PLUS_CIRCLE) LUMO_TERTIARY(com.vaadin.flow.component.button.ButtonVariant.LUMO_TERTIARY) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) RouterLink(com.vaadin.flow.router.RouterLink) SiteService(io.imunity.furms.api.sites.SiteService) Icon(com.vaadin.flow.component.icon.Icon) EAGER(com.vaadin.flow.data.value.ValueChangeMode.EAGER) Logger(org.slf4j.Logger) Grid(com.vaadin.flow.component.grid.Grid) TRASH(com.vaadin.flow.component.icon.VaadinIcon.TRASH) FENIX_ADMIN_SITES(io.imunity.furms.domain.constant.RoutesConst.FENIX_ADMIN_SITES) EDIT(com.vaadin.flow.component.icon.VaadinIcon.EDIT) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) GridActionsButtonLayout(io.imunity.furms.ui.components.GridActionsButtonLayout) ClickEvent(com.vaadin.flow.component.ClickEvent) Site(io.imunity.furms.domain.sites.Site) FenixAdminMenu(io.imunity.furms.ui.views.fenix.menu.FenixAdminMenu) Collectors.toList(java.util.stream.Collectors.toList) Button(com.vaadin.flow.component.button.Button) SitesAdminsView(io.imunity.furms.ui.views.fenix.sites.admins.SitesAdminsView) Comparator(java.util.Comparator) SitesAddView(io.imunity.furms.ui.views.fenix.sites.add.SitesAddView) NAME_MAX_LENGTH(io.imunity.furms.ui.utils.FormSettings.NAME_MAX_LENGTH) DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) TextField(com.vaadin.flow.component.textfield.TextField) Component(com.vaadin.flow.component.Component) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent)

Example 58 with TextField

use of com.vaadin.flow.component.textfield.TextField in project furms by unity-idm.

the class ProjectsView method createSearchFilterLayout.

private HorizontalLayout createSearchFilterLayout() {
    TextField textField = new TextField();
    textField.setPlaceholder(getTranslation("view.user-settings.projects.field.search"));
    textField.setPrefixComponent(SEARCH.create());
    textField.setValueChangeMode(ValueChangeMode.EAGER);
    textField.setClearButtonVisible(true);
    textField.addValueChangeListener(event -> {
        searchText = textField.getValue().toLowerCase();
        textField.blur();
        loadGridContent();
        textField.focus();
    });
    HorizontalLayout search = new HorizontalLayout(textField);
    search.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
    return search;
}
Also used : TextField(com.vaadin.flow.component.textfield.TextField) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 59 with TextField

use of com.vaadin.flow.component.textfield.TextField in project psip-automation by bssw-psip.

the class Assessment method displaySaveDialog.

private void displaySaveDialog(String url) {
    Dialog dialog = new Dialog();
    dialog.setCloseOnOutsideClick(false);
    dialog.setWidth("500px");
    Label header = new Label("Copy this URL and paste into your browser to resume your assessment.");
    TextField field = new TextField();
    field.setValue(url);
    Button copyButton = new Button(VaadinIcon.COPY.create());
    ClipboardHelper helper = new ClipboardHelper(url, copyButton);
    HorizontalLayout fieldLayout = new HorizontalLayout(field, helper);
    fieldLayout.setMargin(false);
    fieldLayout.setWidthFull();
    fieldLayout.setFlexGrow(1, field);
    Anchor closeButton = new Anchor();
    closeButton.setText("Close");
    closeButton.getElement().addEventListener("click", event -> {
        dialog.close();
    });
    VerticalLayout dialogLayout = new VerticalLayout(header, fieldLayout, closeButton);
    dialogLayout.setHorizontalComponentAlignment(Alignment.START, header, field);
    dialogLayout.setHorizontalComponentAlignment(Alignment.CENTER, closeButton);
    dialog.add(dialogLayout);
    dialog.open();
}
Also used : Anchor(com.vaadin.flow.component.html.Anchor) Button(com.vaadin.flow.component.button.Button) Dialog(com.vaadin.flow.component.dialog.Dialog) Label(com.vaadin.flow.component.html.Label) TextField(com.vaadin.flow.component.textfield.TextField) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) ClipboardHelper(org.vaadin.olli.ClipboardHelper) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 60 with TextField

use of com.vaadin.flow.component.textfield.TextField in project testbench by vaadin.

the class ComponentQueryTest method id_matchingComponent_getsComponent.

@Test
void id_matchingComponent_getsComponent() {
    Element rootElement = getCurrentView().getElement();
    List<TextField> textFields = IntStream.rangeClosed(1, 5).mapToObj(idx -> {
        TextField field = new TextField();
        field.setId("field-" + idx);
        return field;
    }).peek(field -> rootElement.appendChild(field.getElement())).collect(Collectors.toList());
    ComponentQuery<TextField> query = $view(TextField.class);
    textFields.forEach(field -> Assertions.assertSame(field, query.id(field.getId().orElse("")).getComponent()));
}
Also used : IntStream(java.util.stream.IntStream) Text(com.vaadin.flow.component.Text) Component(com.vaadin.flow.component.Component) Div(com.vaadin.flow.component.html.Div) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) HasLabel(com.vaadin.flow.component.HasLabel) List(java.util.List) Tag(com.vaadin.flow.component.Tag) Button(com.vaadin.flow.component.button.Button) Span(com.vaadin.testbench.unit.ComponentWrapTest.Span) GeneratedVaadinTextField(com.vaadin.flow.component.textfield.GeneratedVaadinTextField) Arrays.asList(java.util.Arrays.asList) IntegerField(com.vaadin.flow.component.textfield.IntegerField) Element(com.vaadin.flow.dom.Element) Assertions(org.junit.jupiter.api.Assertions) UI(com.vaadin.flow.component.UI) NoSuchElementException(java.util.NoSuchElementException) Collections(java.util.Collections) TextField(com.vaadin.flow.component.textfield.TextField) TextComponent(com.vaadin.testbench.unit.ElementConditionsTest.TextComponent) Element(com.vaadin.flow.dom.Element) GeneratedVaadinTextField(com.vaadin.flow.component.textfield.GeneratedVaadinTextField) TextField(com.vaadin.flow.component.textfield.TextField) Test(org.junit.jupiter.api.Test)

Aggregations

TextField (com.vaadin.flow.component.textfield.TextField)227 Test (org.junit.jupiter.api.Test)61 Button (com.vaadin.flow.component.button.Button)54 Div (com.vaadin.flow.component.html.Div)38 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)32 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)29 Binder (com.vaadin.flow.data.binder.Binder)29 GeneratedVaadinTextField (com.vaadin.flow.component.textfield.GeneratedVaadinTextField)28 Element (com.vaadin.flow.dom.Element)26 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)23 Route (com.vaadin.flow.router.Route)21 Component (com.vaadin.flow.component.Component)16 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)15 BinderCrudEditor (com.vaadin.flow.component.crud.BinderCrudEditor)15 Grid (com.vaadin.flow.component.grid.Grid)15 Span (com.vaadin.flow.component.html.Span)15 List (java.util.List)15 EmailField (com.vaadin.flow.component.textfield.EmailField)14 TextArea (com.vaadin.flow.component.textfield.TextArea)14 Test (org.junit.Test)14