Java Code Examples for com.vaadin.flow.component.button.Button#addClickListener()

The following examples show how to use com.vaadin.flow.component.button.Button#addClickListener() . 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: DemoView.java    From multiselect-combo-box-flow with Apache License 2.0 6 votes vote down vote up
private void addSimpleStringDemo() {
    MultiselectComboBox<String> multiselectComboBox = new MultiselectComboBox();
    multiselectComboBox.setLabel("Multiselect combo box with string items");
    multiselectComboBox.setPlaceholder("Add");
    multiselectComboBox.setWidth("100%");
    multiselectComboBox.setItems("Item 1", "Item 2", "Item 3", "Item 4");
    multiselectComboBox.addSelectionListener(
            event -> Notification.show(event.toString()));

    Button getValueBtn = new Button("Get value");
    getValueBtn.addClickListener(
            event -> multiselectComboBoxValueChangeHandler(
                    multiselectComboBox));

    add(buildDemoContainer(multiselectComboBox, getValueBtn));
}
 
Example 2
Source File: DemoView.java    From multiselect-combo-box-flow with Apache License 2.0 6 votes vote down vote up
private void addObjectDemo() {
    MultiselectComboBox<User> multiselectComboBox = new MultiselectComboBox();
    multiselectComboBox.setLabel("Multiselect combo box with object items");
    multiselectComboBox.setPlaceholder("Add");
    multiselectComboBox.setWidth("100%");
    List<User> data = Arrays.asList(
            new User("Leanne Graham", "leanne", "[email protected]"),
            new User("Ervin Howell", "ervin", "[email protected]"),
            new User("Samantha Doe", "samantha", "[email protected]"));
    multiselectComboBox.setItems(data);
    multiselectComboBox.addSelectionListener(
            event -> Notification.show(event.toString()));

    Button getValueBtn = new Button("Get value");
    getValueBtn.addClickListener(
            event -> objectMultiselectComboBoxValueChangeHandler(
                    multiselectComboBox));

    add(buildDemoContainer(multiselectComboBox, getValueBtn));
}
 
Example 3
Source File: DemoView.java    From multiselect-combo-box-flow with Apache License 2.0 6 votes vote down vote up
private void addObjectDemoWithLabelGenerator() {
    MultiselectComboBox<User> multiselectComboBox = new MultiselectComboBox();
    multiselectComboBox.setLabel(
            "Multiselect combo box with object items and custom item label generator");
    multiselectComboBox.setPlaceholder("Add");
    multiselectComboBox.setWidth("100%");
    List<User> data = Arrays.asList(
            new User("Leanne Graham", "leanne", "[email protected]"),
            new User("Ervin Howell", "ervin", "[email protected]"),
            new User("Samantha Doe", "samantha", "[email protected]"));
    multiselectComboBox.setItems(data);
    multiselectComboBox.setItemLabelGenerator(User::getEmail);
    multiselectComboBox.addSelectionListener(
            event -> Notification.show(event.toString()));

    Button getValueBtn = new Button("Get value");
    getValueBtn.addClickListener(
            event -> objectMultiselectComboBoxValueChangeHandler(
                    multiselectComboBox));

    add(buildDemoContainer(multiselectComboBox, getValueBtn));
}
 
Example 4
Source File: DemoView.java    From multiselect-combo-box-flow with Apache License 2.0 6 votes vote down vote up
private void addRequiredDemo() {
    MultiselectComboBox<String> multiselectComboBox = new MultiselectComboBox();
    multiselectComboBox.setLabel("Required multiselect combo box");
    multiselectComboBox.setPlaceholder("Add");
    multiselectComboBox.setWidth("100%");
    multiselectComboBox.setRequired(true);
    multiselectComboBox.setErrorMessage("The field is mandatory");
    multiselectComboBox.setItems("Item 1", "Item 2", "Item 3", "Item 4");
    multiselectComboBox.addSelectionListener(
            event -> Notification.show(event.toString()));

    Button getValueBtn = new Button("Get value");
    getValueBtn.addClickListener(
            event -> multiselectComboBoxValueChangeHandler(
                    multiselectComboBox));

    add(buildDemoContainer(multiselectComboBox, getValueBtn));
}
 
Example 5
Source File: DemoView.java    From multiselect-combo-box-flow with Apache License 2.0 6 votes vote down vote up
private void addCompactModeDemo() {
    MultiselectComboBox<String> multiselectComboBox = new MultiselectComboBox();
    multiselectComboBox.setLabel("Multiselect combo box in compact mode");
    multiselectComboBox.setPlaceholder("Add");
    multiselectComboBox.setWidth("100%");
    multiselectComboBox.setItems("Item 1", "Item 2", "Item 3", "Item 4");
    multiselectComboBox.addSelectionListener(
            event -> Notification.show(event.toString()));

    multiselectComboBox.setCompactMode(true);

    Button getValueBtn = new Button("Get value");
    getValueBtn.addClickListener(
            event -> multiselectComboBoxValueChangeHandler(
                    multiselectComboBox));

    add(buildDemoContainer(multiselectComboBox, getValueBtn));
}
 
Example 6
Source File: DemoView.java    From multiselect-combo-box-flow with Apache License 2.0 6 votes vote down vote up
private void addOrderedDemo() {
    MultiselectComboBox<String> multiselectComboBox = new MultiselectComboBox();
    multiselectComboBox.setLabel(
            "Multiselect combo box with ordered selected items list");
    multiselectComboBox.setPlaceholder("Add");
    multiselectComboBox.setWidth("100%");
    multiselectComboBox.setItems("Item 1", "Item 2", "Item 3", "Item 4");
    multiselectComboBox.addSelectionListener(
            event -> Notification.show(event.toString()));

    multiselectComboBox.setOrdered(true);

    Button getValueBtn = new Button("Get value");
    getValueBtn.addClickListener(
            event -> multiselectComboBoxValueChangeHandler(
                    multiselectComboBox));

    add(buildDemoContainer(multiselectComboBox, getValueBtn));
}
 
Example 7
Source File: DemoView.java    From multiselect-combo-box-flow with Apache License 2.0 6 votes vote down vote up
private void addLazyLoadingDemo() {
    MultiselectComboBox<String> multiselectComboBox = new MultiselectComboBox();
    multiselectComboBox.setLabel("Multiselect with lazy loading");
    multiselectComboBox.setPlaceholder("Add");
    multiselectComboBox.setWidth("100%");

    List<String> items =IntStream.range(1, 10000).mapToObj(num -> "Item " + num).collect(Collectors.toList());
    multiselectComboBox.setItems(items);

    multiselectComboBox.addSelectionListener(
            event -> Notification.show(event.toString()));

    Button getValueBtn = new Button("Get value");
    getValueBtn.addClickListener(
            event -> multiselectComboBoxValueChangeHandler(
                    multiselectComboBox));

    add(buildDemoContainer(multiselectComboBox, getValueBtn));
}
 
Example 8
Source File: DemoView.java    From multiselect-combo-box-flow with Apache License 2.0 6 votes vote down vote up
private void addClearButtonVisibleDemo() {
    MultiselectComboBox<String> multiselectComboBox = new MultiselectComboBox();
    multiselectComboBox.setLabel("Multiselect combo box with `clear-button-visible`");
    multiselectComboBox.setPlaceholder("Add");
    multiselectComboBox.setWidth("100%");
    multiselectComboBox.setItems("Item 1", "Item 2", "Item 3", "Item 4");
    multiselectComboBox.addSelectionListener(
            event -> Notification.show(event.toString()));

    multiselectComboBox.setClearButtonVisible(true);

    Button getValueBtn = new Button("Get value");
    getValueBtn.addClickListener(
            event -> multiselectComboBoxValueChangeHandler(
                    multiselectComboBox));

    add(buildDemoContainer(multiselectComboBox, getValueBtn));
}
 
Example 9
Source File: DemoView.java    From multiselect-combo-box-flow with Apache License 2.0 6 votes vote down vote up
private void addAllowCustomValuesDemo() {
    MultiselectComboBox<String> multiselectComboBox = new MultiselectComboBox();
    multiselectComboBox.setLabel("Allow custom values");
    multiselectComboBox.setPlaceholder("Select existing or input custom value");
    multiselectComboBox.setWidth("100%");
    List<String> items = Arrays.asList("Java", "Go", "Python", "C#");
    multiselectComboBox.setItems(items);

    multiselectComboBox.addCustomValuesSetListener(e -> {
        Set<String> existingSelected = multiselectComboBox.getValue().stream().collect(Collectors.toSet());
        existingSelected.add(e.getDetail());
        List<String> updatedItems = multiselectComboBox.getDataProvider().fetch(new Query<>()).collect(Collectors.toList());
        updatedItems.add(e.getDetail());
        multiselectComboBox.setItems(updatedItems);
        multiselectComboBox.setValue(existingSelected);
    });

    Button getValueBtn = new Button("Get value");
    getValueBtn.addClickListener(
        event -> multiselectComboBoxValueChangeHandler(
            multiselectComboBox));

    add(buildDemoContainer(multiselectComboBox, getValueBtn));
}
 
Example 10
Source File: DemoView.java    From multiselect-combo-box-flow with Apache License 2.0 5 votes vote down vote up
public void addTemplateRendererDemo() {
    MultiselectComboBox<User> multiselectComboBox = new MultiselectComboBox();
    multiselectComboBox.setLabel(
        "Multiselect combo box with TemplateRenderer");
    multiselectComboBox.setPlaceholder("Add");
    multiselectComboBox.setWidth("100%");
    List<User> data = Arrays.asList(
        new User("Leanne Graham", "leanne", "[email protected]"),
        new User("Ervin Howell", "ervin", "[email protected]"),
        new User("Samantha Doe", "samantha", "[email protected]"));
    multiselectComboBox.setItems(data);
    multiselectComboBox.setItemLabelGenerator(User::getEmail);
    multiselectComboBox.addSelectionListener(
        event -> Notification.show(event.toString()));

    Button getValueBtn = new Button("Get value");
    getValueBtn.addClickListener(
        event -> objectMultiselectComboBoxValueChangeHandler(
            multiselectComboBox));

    multiselectComboBox.setRenderer(
        TemplateRenderer.<User>of("<div>[[item.username]]<br/><small>[[item.email]]</small><br/><small>[[item.name]]<small></div>")
            .withProperty("name", User::getName)
            .withProperty("email", User::getEmail)
            .withProperty("username", User::getUsername));

    add(buildDemoContainer(multiselectComboBox, getValueBtn));
}
 
Example 11
Source File: DemoView.java    From multiselect-combo-box-flow with Apache License 2.0 5 votes vote down vote up
public void addComponentRendererDemo() {
    MultiselectComboBox<User> multiselectComboBox = new MultiselectComboBox();
    multiselectComboBox.setLabel(
        "Multiselect combo box with ComponentRenderer");
    multiselectComboBox.setPlaceholder("Add");
    multiselectComboBox.setWidth("100%");
    List<User> data = Arrays.asList(
        new User("Leanne Graham", "leanne", "[email protected]"),
        new User("Ervin Howell", "ervin", "[email protected]"),
        new User("Samantha Doe", "samantha", "[email protected]"));
    multiselectComboBox.setItems(data);
    multiselectComboBox.setItemLabelGenerator(User::getEmail);
    multiselectComboBox.addSelectionListener(
        event -> Notification.show(event.toString()));

    Button getValueBtn = new Button("Get value");
    getValueBtn.addClickListener(
        event -> objectMultiselectComboBoxValueChangeHandler(
            multiselectComboBox));

    multiselectComboBox.setRenderer(new ComponentRenderer<VerticalLayout, User>(VerticalLayout::new, (container, user) -> {
        HorizontalLayout name = new HorizontalLayout(new Icon(VaadinIcon.USER), new Label(user.getName()));
        HorizontalLayout email = new HorizontalLayout(new Icon(VaadinIcon.SUITCASE), new Label(user.getEmail()));
        container.add(name, email);
    }));

    add(buildDemoContainer(multiselectComboBox, getValueBtn));
}
 
Example 12
Source File: AbstractAutoGeneratedCrudFormFactory.java    From crudui with Apache License 2.0 5 votes vote down vote up
protected Button buildOperationButton(CrudOperation operation, T domainObject, ComponentEventListener<ClickEvent<Button>> clickListener) {
    if (clickListener == null) {
        return null;
    }

    String caption = buttonCaptions.get(operation);
    Icon icon = buttonIcons.get(operation);
    Button button = icon != null ? new Button(caption, icon) : new Button(caption);
    if (buttonStyleNames.containsKey(operation)) {
        buttonStyleNames.get(operation).stream().filter(styleName -> styleName != null).forEach(styleName -> button.addClassName(styleName));
    }
    if (buttonThemes.containsKey(operation)) {
        button.getElement().setAttribute("theme", buttonThemes.get(operation));
    }

    button.addClickListener(event -> {
        if (binder.writeBeanIfValid(domainObject)) {
            try {
                clickListener.onComponentEvent(event);
            } catch (Exception e) {
                showError(operation, e);
            }
        } else {
            Notification.show(validationErrorMessage);
        }
    });
    return button;
}
 
Example 13
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);

}