Search in sources :

Example 16 with Checkbox

use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.

the class TestView method createOptions.

private void createOptions() {
    Div options = new Div();
    options.add(new NativeButton(SELECT_FIRST_ITEM, event -> select.setValue(items.get(0))));
    options.add(new NativeButton(SELECT_THIRD_ITEM, event -> select.setValue(items.get(2))));
    options.add(new NativeButton(SELECT_LAST_ITEM, event -> select.setValue(items.get(items.size() - 1))));
    options.add(new Div());
    options.add(new NativeButton("Reset 0 items", event -> setItems(0)));
    options.add(new NativeButton("Reset 1 items", event -> setItems(1)));
    options.add(new NativeButton("Reset 2 items", event -> setItems(2)));
    options.add(new NativeButton("Reset 5 items", event -> setItems(5)));
    options.add(new NativeButton("Reset 10 items", event -> setItems(10)));
    options.add(new NativeButton("Reset 20 items", event -> setItems(20)));
    options.add(new NativeButton("Reset 50 items", event -> setItems(50)));
    options.add(new Div());
    options.add(new NativeButton("Refresh item 0", event -> refreshItem(0)));
    options.add(new NativeButton("Refresh item 2", event -> refreshItem(2)));
    options.add(new NativeButton("Refresh item 10", event -> refreshItem(10)));
    options.add(new NativeButton("Refresh All", event -> refreshAll()));
    options.add(new Div());
    options.add(new Checkbox("ItemLabelGenerator", event -> setItemLabelGenerator(event.getValue())));
    options.add(new Checkbox("ItemEnabledProvider", event -> setItemEnabledProvider(event.getValue())));
    options.add(new Div());
    Checkbox emptySelectionEnabled = new Checkbox("emptySelectionEnabled", event -> setEmptySelectionAllowed(event.getValue()));
    emptySelectionEnabled.setValue(select.isEmptySelectionAllowed());
    emptySelectionEnabled.setId("emptySelectionEnabled");
    options.add(emptySelectionEnabled);
    Input emptySelectionCaption = new Input();
    emptySelectionCaption.setId("emptySelectionCaption");
    emptySelectionCaption.setValue(select.getEmptySelectionCaption());
    emptySelectionCaption.addValueChangeListener(event -> setEmptySelectionCaption(event.getValue()));
    options.add(new Span("EmptySelectionCaption:"), emptySelectionCaption);
    options.add(new Div());
    options.add(new NativeButton("focus()", event -> select.focus()));
    Checkbox requiredIndicatorVisible = new Checkbox("RequiredIndicator", event -> select.setRequiredIndicatorVisible(event.getValue()));
    requiredIndicatorVisible.setValue(select.isRequiredIndicatorVisible());
    requiredIndicatorVisible.setId("requiredIndicatorVisible");
    options.add(requiredIndicatorVisible);
    Input errorMessage = new Input();
    errorMessage.setId("errorMessage");
    errorMessage.addValueChangeListener(event -> select.setErrorMessage(event.getValue()));
    options.add(new Span("errorMessage"), errorMessage);
    Input placeholder = new Input();
    placeholder.setId("placeholder");
    placeholder.addValueChangeListener(event -> select.setPlaceholder(event.getValue()));
    options.add(new Span("placeholder"), placeholder);
    options.add(new Div());
    options.add(new NativeButton("Set renderer", event -> {
        if (select.getItemRenderer() == null) {
            select.setRenderer(componentRenderer);
        } else {
            select.setRenderer(null);
        }
    }), new NativeButton("Add HR 0", event -> addHrInBeginning()), new NativeButton("Remove HR 0", event -> removeHrInBeginning()), new NativeButton("Add HR 2", event -> addHrAfterIndexTwo()), new NativeButton("Remove HR 2", event -> removeHrAfterIndexTwo()), new NativeButton("Add HR LAST", event -> addHrLast()), new NativeButton("Remove HR LAST", event -> removeHrLast()));
    options.add(new Div());
    enabled = new Checkbox("Enabled");
    enabled.setValue(select.isEnabled());
    enabled.addValueChangeListener(event -> select.setEnabled(event.getValue()));
    readOnly = new Checkbox("ReadOnly");
    readOnly.setValue(select.isReadOnly());
    readOnly.addValueChangeListener(event -> select.setReadOnly(event.getValue()));
    visible = new Checkbox("Visible");
    visible.setValue(select.isVisible());
    visible.addValueChangeListener(event -> select.setVisible(event.getValue()));
    helperText = new Checkbox("HelperText");
    helperText.setValue(false);
    helperText.addValueChangeListener(event -> {
        if (event.getValue())
            select.setHelperText("Helper text");
        else
            select.setHelperText(null);
    });
    options.add(enabled, readOnly, visible, helperText);
    add(options);
}
Also used : Div(com.vaadin.flow.component.html.Div) HasValue(com.vaadin.flow.component.HasValue) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) HasUrlParameter(com.vaadin.flow.router.HasUrlParameter) Select(com.vaadin.flow.component.select.Select) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Hr(com.vaadin.flow.component.html.Hr) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) Objects(java.util.Objects) OptionalParameter(com.vaadin.flow.router.OptionalParameter) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) List(java.util.List) Input(com.vaadin.flow.component.html.Input) Span(com.vaadin.flow.component.html.Span) NativeButton(com.vaadin.flow.component.html.NativeButton) Input(com.vaadin.flow.component.html.Input) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Span(com.vaadin.flow.component.html.Span)

Example 17 with Checkbox

use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.

the class DisabledGridPage method createCheckBox.

private Checkbox createCheckBox(String item) {
    Checkbox checkbox = new Checkbox();
    checkbox.addValueChangeListener(event -> reportError());
    return checkbox;
}
Also used : Checkbox(com.vaadin.flow.component.checkbox.Checkbox)

Example 18 with Checkbox

use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.

the class AbstractLayout method createToggleThemeCheckbox.

public static Checkbox createToggleThemeCheckbox(String themeName, Consumer<Boolean> toggleAction, boolean defaultValue) {
    Checkbox toggleButton = new Checkbox(themeName);
    toggleButton.setValue(defaultValue);
    toggleButton.addValueChangeListener(event -> toggleAction.accept(event.getValue()));
    toggleButton.setId(String.format("toggle-%s", themeName));
    return toggleButton;
}
Also used : Checkbox(com.vaadin.flow.component.checkbox.Checkbox)

Example 19 with Checkbox

use of com.vaadin.flow.component.checkbox.Checkbox 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 20 with Checkbox

use of com.vaadin.flow.component.checkbox.Checkbox in project furms by unity-idm.

the class PendingRequestsView method createPendingMessagesGrid.

private Grid<PendingMessageGridModel> createPendingMessagesGrid(Map<CorrelationId, Checkbox> checkboxes, Component mainContextMenu) {
    Grid<PendingMessageGridModel> grid;
    grid = new DenseGrid<>(PendingMessageGridModel.class);
    grid.addComponentColumn(pendingMessageGridModel -> {
        Checkbox checkbox = new Checkbox();
        checkboxes.put(pendingMessageGridModel.id, checkbox);
        HorizontalLayout horizontalLayout = new HorizontalLayout(checkbox, grid.isDetailsVisible(pendingMessageGridModel) ? ANGLE_DOWN.create() : ANGLE_RIGHT.create(), new Paragraph(getTranslationOrDefault("view.site-admin.pending-requests.page.grid.operation-type." + pendingMessageGridModel.operationType, pendingMessageGridModel.operationType)));
        horizontalLayout.setAlignItems(CENTER);
        return horizontalLayout;
    }).setHeader(new HorizontalLayout(mainContextMenu, new Label(getTranslation("view.site-admin.pending-requests.page.grid.1")))).setFlexGrow(2);
    grid.addColumn(model -> model.status).setHeader(getTranslation("view.site-admin.pending-requests.page.grid.2")).setSortable(true);
    grid.addColumn(model -> model.sentAt.format(dateTimeFormatter)).setHeader(getTranslation("view.site-admin.pending-requests.page.grid.3")).setSortable(true);
    grid.addColumn(model -> Optional.ofNullable(model.ackAt).map(ackTime -> ackTime.format(dateTimeFormatter)).orElse("")).setHeader(getTranslation("view.site-admin.pending-requests.page.grid.4")).setSortable(true);
    grid.addColumn(model -> model.retryAmount).setHeader(getTranslation("view.site-admin.pending-requests.page.grid.5")).setSortable(true);
    grid.addComponentColumn(this::createContextMenu).setHeader(getTranslation("view.site-admin.pending-requests.page.grid.6")).setTextAlign(ColumnTextAlign.END);
    grid.setItemDetailsRenderer(new ComponentRenderer<>(data -> {
        Paragraph json = new Paragraph(data.json);
        json.getStyle().set("font-family", "monospace");
        json.getStyle().set("word-wrap", "break-word");
        json.getElement().getStyle().set("white-space", "pre-wrap");
        return json;
    }));
    return grid;
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) UTCTimeUtils.convertToZoneTime(io.imunity.furms.utils.UTCTimeUtils.convertToZoneTime) Component(com.vaadin.flow.component.Component) PLAY(com.vaadin.flow.component.icon.VaadinIcon.PLAY) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) LoggerFactory(org.slf4j.LoggerFactory) Label(com.vaadin.flow.component.html.Label) MenuButton(io.imunity.furms.ui.components.MenuButton) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) DenseGrid(io.imunity.furms.ui.components.DenseGrid) SiteAgentConnectionService(io.imunity.furms.api.site_agent_pending_message.SiteAgentConnectionService) Map(java.util.Map) UI(com.vaadin.flow.component.UI) ANGLE_RIGHT(com.vaadin.flow.component.icon.VaadinIcon.ANGLE_RIGHT) Paragraph(com.vaadin.flow.component.html.Paragraph) SiteAdminMenu(io.imunity.furms.ui.views.site.SiteAdminMenu) CorrelationId(io.imunity.furms.domain.site_agent.CorrelationId) MethodHandles(java.lang.invoke.MethodHandles) MissingResourceException(java.util.MissingResourceException) Set(java.util.Set) SearchLayout(io.imunity.furms.ui.components.administrators.SearchLayout) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ANGLE_DOWN(com.vaadin.flow.component.icon.VaadinIcon.ANGLE_DOWN) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) Optional(java.util.Optional) Dialog(com.vaadin.flow.component.dialog.Dialog) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) ResourceGetter.getCurrentResourceId(io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId) IconButton(io.imunity.furms.ui.components.IconButton) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) HashMap(java.util.HashMap) REFRESH(com.vaadin.flow.component.icon.VaadinIcon.REFRESH) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) Grid(com.vaadin.flow.component.grid.Grid) UIContext(io.imunity.furms.ui.user_context.UIContext) Logger(org.slf4j.Logger) CENTER(com.vaadin.flow.component.orderedlayout.FlexComponent.Alignment.CENTER) ProgressBar(com.vaadin.flow.component.progressbar.ProgressBar) SiteId(io.imunity.furms.domain.sites.SiteId) TRASH(com.vaadin.flow.component.icon.VaadinIcon.TRASH) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) GridActionsButtonLayout(io.imunity.furms.ui.components.GridActionsButtonLayout) Consumer(java.util.function.Consumer) Button(com.vaadin.flow.component.button.Button) DateTimeFormatter(java.time.format.DateTimeFormatter) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Label(com.vaadin.flow.component.html.Label) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Paragraph(com.vaadin.flow.component.html.Paragraph)

Aggregations

Checkbox (com.vaadin.flow.component.checkbox.Checkbox)68 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)16 Div (com.vaadin.flow.component.html.Div)14 TextField (com.vaadin.flow.component.textfield.TextField)14 Route (com.vaadin.flow.router.Route)14 Button (com.vaadin.flow.component.button.Button)12 Grid (com.vaadin.flow.component.grid.Grid)12 Label (com.vaadin.flow.component.html.Label)12 Collectors (java.util.stream.Collectors)10 Component (com.vaadin.flow.component.Component)8 NativeButton (com.vaadin.flow.component.html.NativeButton)8 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)8 Optional (java.util.Optional)8 Binder (com.vaadin.flow.data.binder.Binder)7 EmailValidator (com.vaadin.flow.data.validator.EmailValidator)7 Set (java.util.Set)7 FurmsViewComponent (io.imunity.furms.ui.components.FurmsViewComponent)6 PageTitle (io.imunity.furms.ui.components.PageTitle)6 NotificationUtils.showErrorNotification (io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification)6 DateTimeFormatter (java.time.format.DateTimeFormatter)6