com.vaadin.flow.component.button.Button Java Examples

The following examples show how to use com.vaadin.flow.component.button.Button. 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: View1.java    From vaadin-app-layout with Apache License 2.0 6 votes vote down vote up
public View1(@Autowired MessageBean bean, @Autowired MainAppLayout appLayout) {

    	Button button = new Button("Click me",
                e -> Notification.show(bean.getMessage()));
        add(button);

        // can access the AppLayout instance via dependency injection
        int notificationCount = appLayout.getNotifications().getNotificationSize();
        add(new Paragraph("You have "+notificationCount+" notification(s)"));

        add(getLabel());
        add(getLabel());
        add(getLabel());
        add(getLabel());
        add(getLabel());
        add(getLabel());

    }
 
Example #2
Source File: UserGroupsView.java    From radman with MIT License 6 votes vote down vote up
@Override
Button getConfirmBtn() {
    return new Button("Create", event -> {
        RadiusGroupDto dto = new RadiusGroupDto();
        if (binder.writeBeanIfValid(dto)) {
            try {
                dto = service.createRadiusUsersGroup(dto);
                creationListener.onCreated(this, dto);
                setOpened(false);
            } catch (Exception e) {
                log.warn("Failed to create radius group. Reason = '{}'", e.getMessage());
                ErrorNotification.show("Error",
                        "Ooops, something went wrong, try again please");
            }
        }
    });
}
 
Example #3
Source File: UserGroupsView.java    From radman with MIT License 6 votes vote down vote up
@Override
Button getConfirmBtn() {
    return new Button("Save", event -> {
        BinderValidationStatus<RadiusGroupDto> validationStatus = binder.validate();
        if (validationStatus.isOk()) {
            try {
                RadiusGroupDto dto = binder.getBean();
                dto = service.updateRadiusUsersGroup(dto);
                updateListener.onUpdated(this, dto);
                setOpened(false);
            } catch (Exception e) {
                log.warn("Failed to update Radius group. Reason = '{}'", e.getMessage());
                ErrorNotification.show("Error",
                        "Ooops, something went wrong, try again please");
            }
        }
    });
}
 
Example #4
Source File: GridCrud.java    From crudui with Apache License 2.0 6 votes vote down vote up
protected void showForm(CrudOperation operation, T domainObject, boolean readOnly, String successMessage, ComponentEventListener<ClickEvent<Button>> buttonClickListener) {
    Component form = crudFormFactory.buildNewForm(operation, domainObject, readOnly, cancelClickEvent -> {
        if (clickRowToUpdate) {
            grid.asSingleSelect().clear();
        } else {
            T selected = grid.asSingleSelect().getValue();
            crudLayout.hideForm();
            grid.asSingleSelect().clear();
            grid.asSingleSelect().setValue(selected);
        }
    }, operationPerformedClickEvent -> {
        buttonClickListener.onComponentEvent(operationPerformedClickEvent);
        if (!clickRowToUpdate) {
            crudLayout.hideForm();
        }
        showNotification(successMessage);
    });
    String caption = crudFormFactory.buildCaption(operation, domainObject);
    crudLayout.showForm(operation, form, caption);
}
 
Example #5
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 #6
Source File: GridCrud.java    From crudui with Apache License 2.0 6 votes vote down vote up
protected void initLayout() {
    findAllButton = new Button(VaadinIcon.REFRESH.create(), e -> findAllButtonClicked());
    findAllButton.getElement().setAttribute("title", "Refresh list");

    crudLayout.addToolbarComponent(findAllButton);

    addButton = new Button(VaadinIcon.PLUS.create(), e -> addButtonClicked());
    addButton.getElement().setAttribute("title", "Add");
    crudLayout.addToolbarComponent(addButton);

    updateButton = new Button(VaadinIcon.PENCIL.create(), e -> updateButtonClicked());
    updateButton.getElement().setAttribute("title", "Update");
    crudLayout.addToolbarComponent(updateButton);

    deleteButton = new Button(VaadinIcon.TRASH.create(), e -> deleteButtonClicked());
    deleteButton.getElement().setAttribute("title", "Delete");
    crudLayout.addToolbarComponent(deleteButton);

    grid = new Grid<>(domainType);
    grid.addSelectionListener(e -> gridSelectionChanged());
    crudLayout.setMainComponent(grid);

    updateButtons();
}
 
Example #7
Source File: NasView.java    From radman with MIT License 6 votes vote down vote up
@Override
Button getConfirmBtn() {
    return new Button("Create", event -> {
        NasDto nasDto = new NasDto();
        if (binder.writeBeanIfValid(nasDto)) {
            try {
                nasDto = nasService.createNas(nasDto);
                creationListener.onCreated(this, nasDto);
                setOpened(false);
            } catch (Exception e) {
                log.warn("Failed to create NAS. Reason = '{}'", e.getMessage());
                ErrorNotification.show("Error",
                        "Ooops, something went wrong, try again please");
            }
        }
    });
}
 
Example #8
Source File: AbstractAutoGeneratedCrudFormFactory.java    From crudui with Apache License 2.0 6 votes vote down vote up
protected Component buildFooter(CrudOperation operation, T domainObject, ComponentEventListener<ClickEvent<Button>> cancelButtonClickListener, ComponentEventListener<ClickEvent<Button>> operationButtonClickListener) {
    Button operationButton = buildOperationButton(operation, domainObject, operationButtonClickListener);
    Button cancelButton = buildCancelButton(cancelButtonClickListener);

    HorizontalLayout footerLayout = new HorizontalLayout();
    footerLayout.setSizeUndefined();
    footerLayout.setSpacing(true);
    footerLayout.setPadding(false);

    if (cancelButton != null) {
        footerLayout.add(cancelButton);
    }

    if (operationButton != null) {
        footerLayout.add(operationButton);
    }

    return footerLayout;
}
 
Example #9
Source File: UsersView.java    From radman with MIT License 6 votes vote down vote up
@Override
Button getConfirmBtn() {
    return new Button("Save", event -> {
        BinderValidationStatus<RadiusUserDto> validationStatus = binder.validate();
        if (validationStatus.isOk()) {
            try {
                RadiusUserDto dto = binder.getBean();
                dto = userService.updateRadiusUser(dto);
                updateListener.onUpdated(this, dto);
                setOpened(false);
            } catch (Exception e) {
                log.warn("Failed to update Radius user. Reason = '{}'", e.getMessage());
                ErrorNotification.show("Error",
                        "Ooops, something went wrong, try again please");
            }
        }
    });
}
 
Example #10
Source File: UsersView.java    From radman with MIT License 6 votes vote down vote up
@Override
Button getConfirmBtn() {
    return new Button("Create", event -> {
        RadiusUserDto dto = new RadiusUserDto();
        if (binder.writeBeanIfValid(dto)) {
            try {
                dto = userService.createRadiusUser(dto);
                creationListener.onCreated(this, dto);
                setOpened(false);
            } catch (Exception e) {
                log.warn("Failed to create radius user. Reason = '{}'", e.getMessage());
                ErrorNotification.show("Error",
                        "Ooops, something went wrong, try again please");
            }
        }
    });
}
 
Example #11
Source File: DefaultCrudFormFactory.java    From crudui with Apache License 2.0 6 votes vote down vote up
@Override
public Component buildNewForm(CrudOperation operation, T domainObject, boolean readOnly, ComponentEventListener<ClickEvent<Button>> cancelButtonClickListener, ComponentEventListener<ClickEvent<Button>> operationButtonClickListener) {
    FormLayout formLayout = new FormLayout();
    formLayout.setSizeFull();
    formLayout.setResponsiveSteps(responsiveSteps);

    List<HasValueAndElement> fields = buildFields(operation, domainObject, readOnly);
    fields.stream()
            .forEach(field ->
                    formLayout.getElement().appendChild(field.getElement()));

    Component footerLayout = buildFooter(operation, domainObject, cancelButtonClickListener, operationButtonClickListener);

    com.vaadin.flow.component.orderedlayout.VerticalLayout mainLayout = new VerticalLayout(formLayout, footerLayout);
    mainLayout.setFlexGrow(1, formLayout);
    mainLayout.setHorizontalComponentAlignment(Alignment.END, footerLayout);
    mainLayout.setMargin(false);
    mainLayout.setPadding(false);
    mainLayout.setSpacing(true);

    return mainLayout;
}
 
Example #12
Source File: MainLayout.java    From electron-java-app with Apache License 2.0 6 votes vote down vote up
private void onMenuAbout() {
    var helpWindow = new Dialog();
    helpWindow.setSizeUndefined();

    var content = new VerticalLayout();
    content.setSizeUndefined();
    content.setPadding(false);

    content.add(new H2("About"));

    var aboutLabel = new Html("<span>Electron+Vaadin Demo<br>Authors: Yuriy Artamonov, Erik Lumme</span>");
    content.add(aboutLabel);

    var okBtn = new Button("Ok", VaadinIcon.CHECK.create());
    okBtn.focus();
    okBtn.addClickListener(event -> helpWindow.close());

    content.add(okBtn);
    content.setAlignSelf(Alignment.CENTER, okBtn);

    helpWindow.add(content);
    helpWindow.open();
}
 
Example #13
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 #14
Source File: NasGroupsView.java    From radman with MIT License 6 votes vote down vote up
@Override
Button getConfirmBtn() {
    return new Button("Create", event -> {
        NasGroupDto dto = new NasGroupDto();
        if (binder.writeBeanIfValid(dto)) {
            try {
                dto = nasService.createNasGroup(dto);
                creationListener.onCreated(this, dto);
                setOpened(false);
            } catch (Exception e) {
                log.warn("Failed to create NAS group. Reason = '{}'", e.getMessage());
                ErrorNotification.show("Error",
                        "Ooops, something went wrong, try again please");
            }
        }
    });
}
 
Example #15
Source File: UpdateExample.java    From apexcharts-flow with Apache License 2.0 6 votes vote down vote up
public UpdateExample() {
    ApexCharts chart = ApexChartsBuilder.get().withChart(ChartBuilder.get()
            .withType(Type.bar)
            .build())
            .withPlotOptions(PlotOptionsBuilder.get()
                    .withBar(BarBuilder.get()
                            .withHorizontal(true)
                            .build())
                    .build())
            .withDataLabels(DataLabelsBuilder.get()
                    .withEnabled(false)
                    .build())
            .withSeries(new Series<>(400.0, 430.0, 448.0, 470.0, 540.0, 580.0, 690.0, 1100.0, 1200.0, 1380.0))
            .withXaxis(XAxisBuilder.get()
                    .withCategories()
                    .build())
            .build();
    chart.setHeight("400px");
    Button update = new Button("Update", buttonClickEvent -> {
        chart.updateSeries(new Series<>(400.0, 430.0, 448.0, 470.0, 540.0, 580.0, 690.0, 1100.0, 1200.0, 500.0));
        Notification.show("The chart was updated!");
    });
    add(chart, update);
}
 
Example #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
Source File: AbstractAutoGeneratedCrudFormFactory.java    From crudui with Apache License 2.0 5 votes vote down vote up
protected Button buildCancelButton(ComponentEventListener<ClickEvent<Button>> clickListener) {
    if (clickListener == null) {
        return null;
    }

    return new Button(cancelButtonCaption, clickListener);
}
 
Example #29
Source File: HelloVaadinLatest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public HelloVaadinLatest() {
    final VerticalLayout layout = new VerticalLayout();
    layout
        .add(new Button("click me",
                        event -> layout.add(new Label("clicked again"))
        ));
    //set the main Component
    getContent().add(layout);

}
 
Example #30
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);
}