Search in sources :

Example 66 with Checkbox

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

the class CheckboxDemoPage method addCheckboxHtmlLabel.

private void addCheckboxHtmlLabel() {
    Checkbox checkbox = new Checkbox();
    checkbox.setLabelAsHtml("Accept the <a href='https://vaadin.com/privacy-policy'>privacy policy</a>");
    checkbox.setId("html-label-checkbox");
    NativeButton button = new NativeButton("Change label", event -> {
        checkbox.setLabelAsHtml("Accept the <a href='https://vaadin.com/community-terms'>community terms</a>");
    });
    button.setId("change-html-label");
    addCard("Checkbox with the label that contains HTML markup", checkbox, button);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) Checkbox(com.vaadin.flow.component.checkbox.Checkbox)

Example 67 with Checkbox

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

the class AbstractItemCountComboBoxPage method initDataProvider.

private void initDataProvider() {
    menuBar.add("Defined / Undefined size");
    dataProvider = new LazyLoadingProvider();
    NativeButton button1 = new NativeButton("withUndefinedSize() -> undefined size", event -> switchToUndefinedSize());
    button1.setId(UNDEFINED_SIZE_BUTTON_ID);
    menuBar.add(button1);
    menuBar.add(new Hr());
    NativeButton button2 = new NativeButton("setDataProvider(FetchCallback) -> undefined size", event -> switchToUndefinedSizeCallback());
    menuBar.add(button2);
    button2.setId(SWITCH_TO_UNDEFINED_SIZE_BUTTON_ID);
    dataProviderSizeInput = new IntegerField("Fixed size backend size");
    menuBar.add(dataProviderSizeInput, new Hr());
    fetchCallbackSizeInput = new IntegerField("Undefined-size backend size", event -> fetchCallbackSize = event.getValue());
    fetchCallbackSizeInput.setId(UNDEFINED_SIZE_BACKEND_SIZE_INPUT_ID);
    fetchCallbackSizeInput.setWidthFull();
    menuBar.add(fetchCallbackSizeInput, new Hr());
    NativeButton button3 = new NativeButton("setDefinedSize(CountCallback) -> defined size", event -> switchToDefinedSize());
    menuBar.add(button3);
    button3.setId(DEFINED_SIZE_BUTTON_ID);
    NativeButton button4 = new NativeButton("setDataProvider(DataProvider) -> defined size", event -> switchToDataProvider());
    menuBar.add(button4);
    button4.setId(DATA_PROVIDER_BUTTON_ID);
    dataProviderSizeInput.setId(DATA_PROVIDER_SIZE_INPUT_ID);
    dataProviderSizeInput.setValue(dataProviderSize);
    dataProviderSizeInput.setWidthFull();
    dataProviderSizeInput.addValueChangeListener(event -> {
        dataProviderSize = event.getValue();
        dataProvider.refreshAll();
    });
    dataProviderSizeInput.setEnabled(false);
    menuBar.add(dataProviderSizeInput, new Hr());
    Checkbox checkbox = new Checkbox("Show fetch query logs", event -> logPanel.setVisible(event.getSource().getValue()));
    checkbox.setValue(true);
    menuBar.add(checkbox);
}
Also used : IntStream(java.util.stream.IntStream) Query(com.vaadin.flow.data.provider.Query) BeforeEnterEvent(com.vaadin.flow.router.BeforeEnterEvent) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) AbstractBackEndDataProvider(com.vaadin.flow.data.provider.AbstractBackEndDataProvider) Hr(com.vaadin.flow.component.html.Hr) Logger(java.util.logging.Logger) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Stream(java.util.stream.Stream) FlexLayout(com.vaadin.flow.component.orderedlayout.FlexLayout) IntegerField(com.vaadin.flow.component.textfield.IntegerField) RouterLink(com.vaadin.flow.router.RouterLink) BeforeEnterObserver(com.vaadin.flow.router.BeforeEnterObserver) Range(com.vaadin.flow.internal.Range) NativeButton(com.vaadin.flow.component.html.NativeButton) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Hr(com.vaadin.flow.component.html.Hr) IntegerField(com.vaadin.flow.component.textfield.IntegerField)

Example 68 with Checkbox

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

the class GridViewEditorPage method createBufferedDynamicEditor.

private void createBufferedDynamicEditor() {
    Div message = new Div();
    message.setId("buffered-dynamic-editor-msg");
    Grid<Person> grid = new Grid<>();
    List<Person> persons = new ArrayList<>();
    persons.addAll(createItems());
    grid.setItems(persons);
    Column<Person> nameColumn = grid.addColumn(Person::getFirstName).setHeader("Name");
    Column<Person> subscriberColumn = grid.addColumn(Person::isSubscriber).setHeader("Subscriber");
    Column<Person> emailColumn = grid.addColumn(Person::getEmail).setHeader("E-mail");
    Binder<Person> binder = new Binder<>(Person.class);
    Editor<Person> editor = grid.getEditor();
    editor.setBinder(binder);
    editor.setBuffered(true);
    TextField field = new TextField();
    binder.bind(field, "firstName");
    nameColumn.setEditorComponent(field);
    Div validationStatus = new Div();
    validationStatus.getStyle().set("color", "red");
    validationStatus.setId("email-validation");
    Checkbox checkbox = new Checkbox();
    binder.bind(checkbox, "subscriber");
    subscriberColumn.setEditorComponent(checkbox);
    TextField emailField = new TextField();
    // When not a subscriber, we want to show a read-only text-field that
    // ignores whatever is set to it
    TextField readOnlyEmail = new TextField();
    readOnlyEmail.setValue("Not a subscriber");
    readOnlyEmail.setReadOnly(true);
    Runnable bindEmail = () -> binder.forField(emailField).withValidator(new EmailValidator("Invalid email")).withStatusLabel(validationStatus).bind("email");
    Runnable setEmail = () -> emailColumn.setEditorComponent(item -> {
        if (item.isSubscriber()) {
            bindEmail.run();
            return emailField;
        } else {
            return readOnlyEmail;
        }
    });
    // Sets the binding based on the Person bean state
    setEmail.run();
    // Refresh subscriber editor component when checkbox value is changed
    checkbox.addValueChangeListener(event -> {
        // Only updates from the client-side should be taken into account
        if (event.isFromClient()) {
            // When using buffered mode, the partial updates shouldn't be
            // propagated to the bean before the Save button is clicked, so
            // here we need to override the binding function to take the
            // checkbox state into consideration instead
            emailColumn.setEditorComponent(item -> {
                if (checkbox.getValue()) {
                    bindEmail.run();
                    return emailField;
                } else {
                    return readOnlyEmail;
                }
            });
            grid.getEditor().refresh();
        }
    });
    Collection<Button> editButtons = Collections.newSetFromMap(new WeakHashMap<>());
    // Resets the binding function to use the bean state whenever the editor
    // is closed
    editor.addCloseListener(event -> {
        setEmail.run();
        editButtons.stream().forEach(button -> button.setEnabled(true));
    });
    Column<Person> editorColumn = grid.addComponentColumn(person -> {
        Button edit = new Button("Edit");
        edit.addClassName("edit");
        edit.addClickListener(e -> {
            editor.editItem(person);
            field.focus();
        });
        edit.setEnabled(!editor.isOpen());
        editButtons.add(edit);
        return edit;
    });
    editor.addOpenListener(e -> editButtons.stream().forEach(button -> button.setEnabled(!editor.isOpen())));
    editor.addCloseListener(e -> editButtons.stream().forEach(button -> button.setEnabled(!editor.isOpen())));
    Button save = new Button("Save", e -> editor.save());
    save.addClassName("save");
    Button cancel = new Button("Cancel", e -> editor.cancel());
    cancel.addClassName("cancel");
    // Add a keypress listener that listens for an escape key up event.
    // Note! some browsers return key as Escape and some as Esc
    grid.getElement().addEventListener("keyup", event -> editor.cancel()).setFilter("event.key === 'Escape' || event.key === 'Esc'");
    Div buttons = new Div(save, cancel);
    editorColumn.setEditorComponent(buttons);
    editor.addSaveListener(event -> message.setText(event.getItem().getFirstName() + ", " + event.getItem().isSubscriber() + ", " + event.getItem().getEmail()));
    grid.setId("buffered-dynamic-editor");
    addCard("Grid Editor", "Dynamic Editor in Buffered Mode", message, validationStatus, grid);
}
Also used : Grid(com.vaadin.flow.component.grid.Grid) EmailValidator(com.vaadin.flow.data.validator.EmailValidator) Collection(java.util.Collection) Editor(com.vaadin.flow.component.grid.editor.Editor) Binder(com.vaadin.flow.data.binder.Binder) Div(com.vaadin.flow.component.html.Div) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) List(java.util.List) Button(com.vaadin.flow.component.button.Button) Column(com.vaadin.flow.component.grid.Grid.Column) Person(com.vaadin.flow.data.bean.Person) Collections(java.util.Collections) TextField(com.vaadin.flow.component.textfield.TextField) WeakHashMap(java.util.WeakHashMap) EmailValidator(com.vaadin.flow.data.validator.EmailValidator) Grid(com.vaadin.flow.component.grid.Grid) ArrayList(java.util.ArrayList) Div(com.vaadin.flow.component.html.Div) Binder(com.vaadin.flow.data.binder.Binder) Button(com.vaadin.flow.component.button.Button) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) TextField(com.vaadin.flow.component.textfield.TextField) Person(com.vaadin.flow.data.bean.Person)

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