com.vaadin.flow.data.value.ValueChangeMode Java Examples

The following examples show how to use com.vaadin.flow.data.value.ValueChangeMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserGroupsView.java    From radman with MIT License 6 votes vote down vote up
UserGroupFormDialog() {

            TextField username = new TextField("Name");
            username.setValueChangeMode(ValueChangeMode.EAGER);
            TextField description = new TextField("Description");
            description.setValueChangeMode(ValueChangeMode.EAGER);

            binder = new BeanValidationBinder<>(RadiusGroupDto.class);
            binder.bind(username, "name");
            binder.bind(description, "description");

            HorizontalLayout controlsLayout = new HorizontalLayout();
            controlsLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
            controlsLayout.add(new Button("Cancel", event -> setOpened(false)));
            controlsLayout.add(getConfirmBtn());
            controlsLayout.setWidthFull();

            add(new H3(getDialogTitle()));
            add(new FormLayout(username, description));
            add(new Hr());
            add(controlsLayout);
        }
 
Example #2
Source File: UsersView.java    From radman with MIT License 6 votes vote down vote up
UserFormDialog() {
    TextField username = new TextField("Username");
    username.setValueChangeMode(ValueChangeMode.EAGER);
    TextField description = new TextField("Description");
    description.setValueChangeMode(ValueChangeMode.EAGER);

    binder = new BeanValidationBinder<>(RadiusUserDto.class);
    binder.bind(username, "username");
    binder.bind(description, "description");

    HorizontalLayout controlsLayout = new HorizontalLayout();
    controlsLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
    controlsLayout.add(new Button("Cancel", event -> setOpened(false)));
    controlsLayout.add(getConfirmBtn());
    controlsLayout.setWidthFull();

    add(new H3(getDialogTitle()));
    add(new FormLayout(username, description));
    add(new Hr());
    add(controlsLayout);
}
 
Example #3
Source File: NasGroupsView.java    From radman with MIT License 6 votes vote down vote up
NasGroupFormDialog(NasService nasService) {
    this.nasService = nasService;

    TextField groupname = new TextField("Group name");
    groupname.setValueChangeMode(ValueChangeMode.EAGER);
    TextField nasIpAddress = new TextField("IP address");
    nasIpAddress.setValueChangeMode(ValueChangeMode.EAGER);
    TextField nasPortId = new TextField("Port ID");
    nasPortId.setValueChangeMode(ValueChangeMode.EAGER);

    binder = new BeanValidationBinder<>(NasGroupDto.class);
    binder.bind(groupname, "groupName");
    binder.bind(nasIpAddress, "nasIpAddress");
    binder.bind(nasPortId, "nasPortId");

    HorizontalLayout controlsLayout = new HorizontalLayout();
    controlsLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
    controlsLayout.add(new Button("Cancel", event -> setOpened(false)));
    controlsLayout.add(getConfirmBtn());
    controlsLayout.setWidthFull();

    add(new H3(getDialogTitle()));
    add(new FormLayout(groupname, nasIpAddress, nasPortId));
    add(new Hr());
    add(controlsLayout);
}
 
Example #4
Source File: SearchView.java    From vaadin-app-layout with Apache License 2.0 6 votes vote down vote up
public SearchView() {
    getElement().getStyle().set("width", "100%");
    setVerticalAlign(VerticalOrientation.TOP);
    setWithBackdrop(false);
    searchFieldWrapper.getStyle()
            .set("background", "var(--app-layout-bar-background-base-color)")
            .set("height", "var(--app-bar-height)")
            .set("box-shadow", "var(--app-layout-bar-shadow)")
            .set("padding", "var(--app-layout-bar-padding)")
            .set("z-index", "1");
    searchFieldWrapper.setWidthFull();
    searchFieldWrapper.setAlignItems(FlexComponent.Alignment.CENTER);
    searchFieldWrapper.setSpacing(false);
    searchField.getStyle().set("--lumo-contrast-10pct", "transparent");
    searchField.setValueChangeMode(ValueChangeMode.EAGER);
    searchField.setWidthFull();
    closeButton.setWidth("var(--app-bar-height)");
    closeButton.setHeight("var(--app-bar-height)");
    closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
    closeButton.addClickListener(event -> {
        searchField.clear();
        close();
    });
    add(searchFieldWrapper);
}
 
Example #5
Source File: MainView.java    From tutorials with MIT License 5 votes vote down vote up
public MainView(EmployeeRepository repo, EmployeeEditor editor) {
    this.employeeRepository = repo;
    this.editor = editor;
    this.grid = new Grid<>(Employee.class);
    this.filter = new TextField();
    this.addNewBtn = new Button("New employee", VaadinIcon.PLUS.create());

    HorizontalLayout actions = new HorizontalLayout(filter, addNewBtn);
    add(actions, grid, editor);

    grid.setHeight("200px");
    grid.setColumns("id", "firstName", "lastName");
    grid.getColumnByKey("id").setWidth("50px").setFlexGrow(0);

    filter.setPlaceholder("Filter by last name");

    filter.setValueChangeMode(ValueChangeMode.EAGER);
    filter.addValueChangeListener(e -> listEmployees(e.getValue()));

    grid.asSingleSelect().addValueChangeListener(e -> {
        editor.editEmployee(e.getValue());
    });

    addNewBtn.addClickListener(e -> editor.editEmployee(new Employee("", "")));

    editor.setChangeHandler(() -> {
        editor.setVisible(false);
        listEmployees(filter.getValue());
    });

    listEmployees(null);
}
 
Example #6
Source File: Input.java    From flow with Apache License 2.0 5 votes vote down vote up
@Override
public void setValueChangeMode(ValueChangeMode valueChangeMode) {
    currentMode = valueChangeMode;
    setSynchronizedEvent(
            ValueChangeMode.eventForMode(valueChangeMode, "input"));
    applyChangeTimeout();
}
 
Example #7
Source File: ValueChangeModeIT.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void onBlur() {
    toggleMode(ValueChangeMode.ON_BLUR);
    input.sendKeys("a");
    assertMessages();

    input.sendKeys("\n");
    assertMessages();

    blur();
    assertMessages("a");
}
 
Example #8
Source File: ValueChangeModeIT.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void onChange() {
    toggleMode(ValueChangeMode.ON_CHANGE);
    input.sendKeys("a");
    assertMessages();

    input.sendKeys("\n");
    assertMessages("a");
}
 
Example #9
Source File: ValueChangeModeView.java    From flow with Apache License 2.0 5 votes vote down vote up
private void addButtons(HasValueChangeMode component) {
    Arrays.stream(ValueChangeMode.values()).forEach(mode -> {
        NativeButton button = createButton(mode.name(), mode.name(),
                event -> component.setValueChangeMode(mode));
        add(button);
    });
}
 
Example #10
Source File: AuthView.java    From radman with MIT License 5 votes vote down vote up
private AbstractSinglePropertyField<? extends AbstractField<?, ?>, String> buildTextValueField() {
    binder.removeBinding("value");
    TextField valueField = new TextField("Value");
    valueField.setValueChangeMode(ValueChangeMode.EAGER);
    valueField.setClearButtonVisible(false);
    binder.bind(valueField, "value");
    return valueField;
}
 
Example #11
Source File: AuthView.java    From radman with MIT License 5 votes vote down vote up
private AbstractSinglePropertyField<? extends AbstractField<?, ?>, String> buildPasswordValueField() {
    binder.removeBinding("value");
    PasswordField valueField = new PasswordField("Value");
    valueField.setValueChangeMode(ValueChangeMode.EAGER);
    valueField.setClearButtonVisible(false);
    binder.bind(valueField, "value");
    return valueField;
}
 
Example #12
Source File: AccountingView.java    From radman with MIT License 4 votes vote down vote up
private void buildView() {
    setHeightFull();
    setSpacing(false);

    Grid<AccountingDto> grid = new Grid<>(AccountingDto.class, false);
    grid.addColumns("username", "callingStationId", "nasIpAddress", "serviceType");
    grid.addColumn(new LocalDateTimeRenderer<>((ValueProvider<AccountingDto, LocalDateTime>)
            accountingDto -> {
                if (Objects.isNull(accountingDto.getAcctStartTime())) {
                    return null;
                }
                return LocalDateTime.ofInstant(accountingDto.getAcctStartTime().toInstant(),
                        TimeZone.getDefault().toZoneId());
            })).setSortProperty("acctStartTime").setHeader("Acct Start Time");
    grid.addColumn(new LocalDateTimeRenderer<>((ValueProvider<AccountingDto, LocalDateTime>)
            accountingDto -> {
                if (Objects.isNull(accountingDto.getAcctStopTime())) {
                    return null;
                }
                return LocalDateTime.ofInstant(accountingDto.getAcctStopTime().toInstant(),
                        TimeZone.getDefault().toZoneId());
            })).setSortProperty("acctStopTime").setHeader("Acct Stop Time");
    grid.addColumns("acctTerminateCause", "framedIpAddress", "framedProtocol");
    grid.addColumns("acctAuthentic", "acctInputOctets", "acctInterval", "acctOutputOctets",
            "acctSessionId");
    grid.addColumn(accountingDto -> {
        if (Objects.isNull(accountingDto.getAcctSessionTime())) {
            return null;
        }
        return DurationFormatUtils.formatDurationHMS(accountingDto.getAcctSessionTime());
    }).setSortProperty("acctSessionTime").setHeader("Acct Session Time");
    grid.addColumns("acctUniqueId", "acctUpdateTime", "calledStationId",
            "connectInfoStart", "connectInfoStop", "nasPortId", "nasPortType", "radAcctId", "realm");

    DataProvider<AccountingDto, Object> dataProvider = new SpringDataProviderBuilder<>(
            (pageable, o) -> accountingService.pageAccountingRecords(filter, pageable),
            value -> accountingService.countAccountingRecords(filter))
            .withDefaultSort("acctStartTime", SortDirection.DESCENDING)
            .build();
    grid.setDataProvider(dataProvider);
    grid.getColumns().forEach(column -> column.setResizable(true));
    grid.setColumnReorderingAllowed(true);
    grid.setMinHeight("500px");
    grid.setHeight("100%");

    TextField search = new TextField(event -> {
        filter.setSearchText(event.getValue());
        grid.getDataProvider().refreshAll();
    });
    search.setValueChangeMode(ValueChangeMode.EAGER);
    search.setPlaceholder("Search...");

    SetAcctStopTimeDialog setAcctStopTimeDialog = new SetAcctStopTimeDialog((source, bean)
            -> grid.getDataProvider().refreshItem(bean));
    Button setAcctStopTimeButton = new Button("Set Acct Stop Time", event -> {
        Optional<AccountingDto> optional = grid.getSelectionModel().getFirstSelectedItem();
        optional.ifPresent(setAcctStopTimeDialog::set);
    });
    setAcctStopTimeButton.setEnabled(false);

    grid.asSingleSelect().addValueChangeListener(event
            -> setAcctStopTimeButton.setEnabled(Objects.nonNull(event.getValue())));

    Checkbox onlyActiveSessions = new Checkbox("Filter only active sessions");
    onlyActiveSessions.setValue(filter.isSearchOnlyActiveSessions());
    onlyActiveSessions.addValueChangeListener(event -> {
        filter.setSearchOnlyActiveSessions(event.getValue());
        grid.getDataProvider().refreshAll();
    });

    add(new H4("Data from Radius DB - \"radacct\" table"));
    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setDefaultVerticalComponentAlignment(FlexComponent.Alignment.BASELINE);
    horizontalLayout.add(new H3("Accounting"));
    horizontalLayout.add(setAcctStopTimeButton);
    horizontalLayout.add(search);
    horizontalLayout.add(onlyActiveSessions);
    add(horizontalLayout);
    add(grid);
}
 
Example #13
Source File: AttributesView.java    From radman with MIT License 4 votes vote down vote up
AttributeEditDialog(AttributeService attributeService, UpdateListener<T> updateListener) {
    this.attributeService = attributeService;

    FormLayout formLayout = new FormLayout();
    formLayout.add(new H3(getDialogTitle()));
    TextArea description = new TextArea("Description");
    description.setValueChangeMode(ValueChangeMode.EAGER);
    description.setWidthFull();

    binder = new Binder<>(getClazz());
    binder.forField(description).bind(AttributeDto::getDescription, AttributeDto::setDescription);

    Button cancelBtn = new Button("Cancel", event -> setOpened(false));
    Button saveBtn = new Button("Save", event -> {
        BinderValidationStatus<T> validationStatus = binder.validate();
        if (validationStatus.isOk()) {
            try {
                T attributeDto = binder.getBean();
                attributeDto = save(attributeDto);
                updateListener.onUpdated(this, attributeDto);
                setOpened(false);
            } catch (Exception e) {
                log.warn("Failed to update attribute. Reason = '{}'", e.getMessage());
                ErrorNotification.show("Error",
                        "Ooops, something went wrong, try again please");
            }
        }
    });

    HorizontalLayout controlsLayout = new HorizontalLayout();
    controlsLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
    controlsLayout.setWidthFull();
    controlsLayout.add(cancelBtn);
    controlsLayout.add(saveBtn);

    formLayout.add(description);
    formLayout.add(new Hr());
    formLayout.add(controlsLayout);
    formLayout.setMaxWidth("500px");
    add(formLayout);
}
 
Example #14
Source File: Input.java    From flow with Apache License 2.0 4 votes vote down vote up
private void applyChangeTimeout() {
    ValueChangeMode.applyChangeTimeout(currentMode, valueChangeTimeout,
            getSynchronizationRegistration());
}
 
Example #15
Source File: UserToGroupView.java    From radman with MIT License 4 votes vote down vote up
private void buildView() {
    setHeightFull();
    setSpacing(false);

    RoleDto role = securityService.getLoggedUserRole();
    Grid<RadiusUserToGroupDto> grid = new Grid<>(RadiusUserToGroupDto.class, false);
    grid.addColumns("username", "groupName", "userInRadman", "groupInRadman");
    DataProvider<RadiusUserToGroupDto, Object> dataProvider = new SpringDataProviderBuilder<>(
            (pageable, o) -> userService.pageRadiusUserToGroupRecords(filter, pageable),
            value -> userService.countRadiusUserToGroupRecords(filter))
            .withDefaultSort("username", SortDirection.ASCENDING)
            .build();
    grid.setDataProvider(dataProvider);
    grid.setSortableColumns("username", "groupName");
    grid.setColumnReorderingAllowed(true);
    grid.setMinHeight("500px");
    grid.setHeight("100%");

    Button addUserToGroup = new Button("Add user to group", event -> {
        AddUserToGroupDialog addDialog = new AddUserToGroupDialog(
                (source, bean) -> grid.getDataProvider().refreshAll());
        addDialog.startAdding();
    });
    addUserToGroup.setEnabled(role == RoleDto.ADMIN);

    ConfirmationDialog deleteDialog = new ConfirmationDialog();
    deleteDialog.setTitle("Delete User to Group mapping");
    deleteDialog.setDescription("Are you sure?");
    deleteDialog.setConfirmButtonCaption("Delete");
    deleteDialog.setConfirmListener(() -> {
        Optional<RadiusUserToGroupDto> optional = grid.getSelectionModel().getFirstSelectedItem();
        try {
            optional.ifPresent(userService::removeRadiusUserFromGroup);
            grid.getDataProvider().refreshAll();
        } catch (Exception e) {
            log.warn("Failed to delete user to group mapping. Reason = '{}'", e.getMessage());
            ErrorNotification.show("Error",
                    "Ooops, something went wrong, try again please");
        }
        deleteDialog.setOpened(false);
    });
    Button removeUserFromGroup = new Button("Remove user from group", event -> deleteDialog.setOpened(true));
    removeUserFromGroup.setEnabled(false);

    grid.asSingleSelect().addValueChangeListener(event ->
            removeUserFromGroup.setEnabled(Objects.nonNull(event.getValue()) && role == RoleDto.ADMIN));

    TextField search = new TextField(event -> {
        filter.setSearchText(event.getValue());
        grid.getDataProvider().refreshAll();
    });
    search.setValueChangeMode(ValueChangeMode.EAGER);
    search.setPlaceholder("Search...");

    add(new H4("Data from Radius DB - \"radusergroup\" table"));
    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setDefaultVerticalComponentAlignment(FlexComponent.Alignment.BASELINE);
    horizontalLayout.add(new H3("Users to Groups"));
    horizontalLayout.add(addUserToGroup);
    horizontalLayout.add(removeUserFromGroup);
    horizontalLayout.add(search);
    add(horizontalLayout);
    add(grid);
}
 
Example #16
Source File: Input.java    From flow with Apache License 2.0 4 votes vote down vote up
@Override
public ValueChangeMode getValueChangeMode() {
    return currentMode;
}
 
Example #17
Source File: ValueChangeModeIT.java    From flow with Apache License 2.0 4 votes vote down vote up
private void toggleMode(ValueChangeMode mode) {
    WebElement modeButton = findElement(By.id(mode.name()));
    modeButton.click();
}
 
Example #18
Source File: NasView.java    From radman with MIT License 4 votes vote down vote up
NasFormDialog(NasService nasService) {
    this.nasService = nasService;

    TextField name = new TextField("Name");
    name.setValueChangeMode(ValueChangeMode.EAGER);
    TextField shortName = new TextField("Short name");
    shortName.setValueChangeMode(ValueChangeMode.EAGER);
    TextField type = new TextField("Type");
    type.setValueChangeMode(ValueChangeMode.EAGER);
    NumberField port = new NumberField("Port");
    port.setValueChangeMode(ValueChangeMode.EAGER);
    PasswordField secret = new PasswordField("Secret");
    secret.setValueChangeMode(ValueChangeMode.EAGER);
    TextField server = new TextField("Server");
    server.setValueChangeMode(ValueChangeMode.EAGER);
    TextField community = new TextField("Community");
    community.setValueChangeMode(ValueChangeMode.EAGER);
    TextArea description = new TextArea("Description");
    description.setValueChangeMode(ValueChangeMode.EAGER);

    FormLayout formLayout = new FormLayout();
    formLayout.setWidthFull();
    formLayout.setMaxWidth("700px");
    formLayout.add(name, shortName, server, port, secret, type, community, description);
    formLayout.setResponsiveSteps(
            new FormLayout.ResponsiveStep("0px", 1),
            new FormLayout.ResponsiveStep("450px", 2));

    HorizontalLayout controlsLayout = new HorizontalLayout();
    controlsLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
    controlsLayout.add(new Button("Cancel", event -> setOpened(false)));
    controlsLayout.add(getConfirmBtn());
    controlsLayout.setWidthFull();

    add(new H3(getDialogTitle()));
    add(formLayout);
    add(new Hr());
    add(controlsLayout);

    binder = new BeanValidationBinder<>(NasDto.class);
    binder.bind(name, "nasName");
    binder.bind(shortName, "shortName");
    binder.bind(type, "type");
    binder.forField(port)
            .withConverter(new DoubleToIntegerConverter("Port must be number " +
                    "between 1 and " + 65535 + "."))
            .bind("ports");
    binder.bind(secret, "secret");
    binder.bind(server, "server");
    binder.bind(community, "community");
    binder.bind(description, "description");
}
 
Example #19
Source File: ValueChangeModeIT.java    From flow with Apache License 2.0 4 votes vote down vote up
@Test
@Ignore
public void timeout() throws InterruptedException {
    toggleMode(ValueChangeMode.TIMEOUT);
    assertThrottle(input);
}
 
Example #20
Source File: ValueChangeModeIT.java    From flow with Apache License 2.0 4 votes vote down vote up
@Test
public void lazy() throws InterruptedException {
    toggleMode(ValueChangeMode.LAZY);
    assertDebounce(input);
}
 
Example #21
Source File: ValueChangeModeIT.java    From flow with Apache License 2.0 4 votes vote down vote up
@Test
public void eager() {
    toggleMode(ValueChangeMode.EAGER);
    assertEager(input);
}
 
Example #22
Source File: AccountingView.java    From radman with MIT License 4 votes vote down vote up
SetAcctStopTimeDialog(UpdateListener<AccountingDto> updateListener) {
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setPadding(false);
    verticalLayout.setMargin(false);

    timestampField = new TextField("Timestamp");
    timestampField.setErrorMessage("Timestamp number is required");
    timestampField.setValueChangeMode(ValueChangeMode.EAGER);
    timestampField.addValueChangeListener(event -> isValid(event.getValue()));

    checkboxNow = new Checkbox("Now");
    Button setBtn = new Button("Set");
    Button cancelBtn = new Button("Cancel", event -> setOpened(false));

    checkboxNow.addValueChangeListener(event -> {
        if (event.getValue()) {
            timestampField.setValue(String.valueOf(Instant.now().getEpochSecond()));
        }
        timestampField.setEnabled(!event.getValue());
    });
    timestampField.addValueChangeListener(event -> setBtn.setEnabled(Objects.nonNull(event.getValue())));

    setBtn.setEnabled(false);
    setBtn.addClickListener(event -> {
        if (isValid(timestampField.getValue())) {
            try {
                long timestamp = Long.valueOf(timestampField.getValue());
                AccountingDto updatedAccountingDto = accountingService.setAcctStopTime(accountingDto,
                        new Date(timestamp * 1000));
                updateListener.onUpdated(this, updatedAccountingDto);
                setOpened(false);
            } catch (NotFoundException e) {
                e.printStackTrace();
            }
        }
    });

    HorizontalLayout controls = new HorizontalLayout();
    controls.add(cancelBtn, setBtn);
    verticalLayout.add(new H3("Set Acct Stop Time"), timestampField, checkboxNow, new Hr(), controls);
    verticalLayout.setHorizontalComponentAlignment(Alignment.END, controls);
    add(verticalLayout);

}
 
Example #23
Source File: DomEventFilterView.java    From flow with Apache License 2.0 4 votes vote down vote up
public DomEventFilterView() {
    Element space = new Element("input");
    space.setAttribute("id", "space");

    space.addEventListener("keypress",
            e -> addMessage("Space listener triggered"))
            .setFilter("event.key == ' ' || event.key == 'Spacebar'");
    // The key is called 'Spacebar' on IE11

    Element debounce = new Element("input");
    debounce.setAttribute("id", "debounce");

    debounce.addEventListener("input",
            e -> addMessage("Trailing: "
                    + e.getEventData().getString("element.value")))
            .debounce(1000).addEventData("element.value");
    debounce.addEventListener("input",
            e -> addMessage("Leading: "
                    + e.getEventData().getString("element.value")))
            .debounce(1000, DebouncePhase.LEADING);
    debounce.addEventListener("input",
            e -> addMessage("Throttle: "
                    + e.getEventData().getString("element.value")))
            .throttle(1000);

    DebounceComponent component = new DebounceComponent();
    component.setId("debounce-component");
    component.addInputListener(
            e -> addMessage("Component: " + e.getValue()), 1000);

    messages.setAttribute("id", "messages");
    getElement().appendChild(space, debounce, component.getElement(),
            messages);

    // tests for#5090
    final AtomicReference<DomListenerRegistration> atomicReference = new AtomicReference<>();
    final Paragraph resultParagraph = new Paragraph();
    resultParagraph.setId("result-paragraph");

    NativeButton removalButton = new NativeButton("Remove DOM listener", event -> {
        resultParagraph.setText("REMOVED");
        atomicReference.get().remove();
    });
    removalButton.setId("listener-removal-button");

    Input listenerInput = new Input(ValueChangeMode.ON_CHANGE);
    listenerInput.setId("listener-input");

    /*
    The event.preventDefault() is here to make sure that the listener
     has been cleaned on the client-side as well. The server-side
     cleaning is not really in question.
     */
    ComponentUtil.addListener(listenerInput, KeyDownEvent.class,
            event -> resultParagraph.setText("A"), registration -> {
                atomicReference.set(registration);
                registration.setFilter("event.key === 'a' && " +
                        "(event.preventDefault() || true)");
            });
    ComponentUtil.addListener(listenerInput, KeyDownEvent.class,
            event -> resultParagraph.setText("B"),
            registration -> registration.setFilter("event.key === 'b' && " +
                    "(event.preventDefault() || true)"));

    add(listenerInput, removalButton, resultParagraph);
}
 
Example #24
Source File: SearchOverlayView.java    From vaadin-app-layout with Apache License 2.0 4 votes vote down vote up
public SearchOverlayView() {
    getElement().getStyle().set("width", "100%");
    setVerticalAlign(VerticalOrientation.TOP);
    searchFieldWrapper.getStyle()
            .set("background", "var(--app-layout-bar-background-base-color)")
            .set("height", "var(--app-bar-height)")
            .set("box-shadow", "var(--app-layout-bar-shadow)")
            .set("padding", "var(--app-layout-bar-padding)")
            .set("flex-shrink", "0")
            .set("z-index", "1");
    searchFieldWrapper.setWidthFull();
    searchFieldWrapper.setAlignItems(FlexComponent.Alignment.CENTER);
    searchField.getStyle().set("--lumo-contrast-10pct", "transparent");
    searchField.addValueChangeListener(event -> {
        results.removeAll();
        List<T> result = dataProvider.fetch(queryProvider.apply(event.getValue())).collect(Collectors.toList());
        result.stream()
                .map(t -> new QueryPair<>(t, dataViewProvider.apply(t)))
                .forEach(clickNotifier -> {
                    results.add((Component) clickNotifier.getNotifier());
                    clickNotifier.getNotifier().addClickListener(clickEvent -> {
                        if (closeOnQueryResult) {
                            this.close();
                        }
                        if (queryResultListener != null) {
                            queryResultListener.accept(clickNotifier.getQuery());
                        }
                    });
                });
    });
    searchField.setValueChangeMode(ValueChangeMode.EAGER);
    searchField.setWidthFull();
    results.setSizeFull();
    results.setMargin(false);
    results.getStyle().set("overflow", "auto");
    closeButton.addClickListener(event -> {
        searchField.clear();
        close();
    });
    wrapper.setSizeFull();
    wrapper.setAlignItems(FlexComponent.Alignment.CENTER);
    wrapper.setMargin(false);
    wrapper.setPadding(false);
    wrapper.setSpacing(false);
    wrapper.getStyle()
            .set("max-width", "100vw")
            .set("height", "100vh");
    results.getStyle()
            .set("overflow-y", "auto")
            .set("max-width", "100%")
            .set("min-width", "40%")
            .set("--lumo-size-m", "var(--lumo-size-xl)")
            .set("--lumo-contrast-10pct", "transparent");
    results.setHeightFull();
    results.setWidth("unset");
    add(wrapper);
}
 
Example #25
Source File: Input.java    From flow with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new input without any specific type,
 * with {@link ValueChangeMode#ON_CHANGE ON_CHANGE} value change mode.
 */
public Input() {
    this(ValueChangeMode.ON_CHANGE);
}
 
Example #26
Source File: Input.java    From flow with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new input without any specific type.
 *
 * @param valueChangeMode
 *            initial value change mode, or <code>null</code>
 *            to disable the value synchronization
 */
public Input(ValueChangeMode valueChangeMode) {
    super("value", "", false);
    setValueChangeMode(valueChangeMode);
}