Java源码示例:com.vaadin.flow.component.notification.Notification

示例1
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));
}
 
示例2
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));
}
 
示例3
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));
}
 
示例4
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));
}
 
示例5
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));
}
 
示例6
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));
}
 
示例7
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));
}
 
示例8
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));
}
 
示例9
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);
}
 
示例10
public MainAppLayout() {
    notifications.addClickListener(notification -> {/* ... */});
    init(AppLayoutBuilder.get(LeftLayouts.LeftResponsiveHybrid.class)
            .withTitle("App Layout")
            .withAppBar(AppBarBuilder.get()
                    .add(new NotificationButton<>(VaadinIcon.BELL, notifications))
                    .build())
            .withAppMenu(LeftAppMenuBuilder.get()
                    .addToSection(HEADER,
                            new LeftHeaderItem("Menu-Header", "Version 4.0.0", "/frontend/images/logo.png")
                    )
                    .add(new LeftNavigationItem("Home", VaadinIcon.HOME.create(), View1.class),
                            new LeftNavigationItem("Menu", VaadinIcon.MENU.create(), View2.class))
                    .withStickyFooter()
                    .addToSection(FOOTER,
                            new LeftClickableItem("Footer Clickable!", VaadinIcon.COG.create(), clickEvent -> Notification.show("Clicked!")))
                    .build())
            .build());
}
 
示例11
public MainAppLayout() {
    // An Search overlay
    SearchOverlayButton<TestSearchResult, SerializablePredicate<TestSearchResult>> searchOverlayButton = initSearchOverlayButton();
    // An AppBar overlay with a search field
    SearchButton searchButton = new SearchButton().withValueChangeListener(event -> {
        /* React manually to user inputs */
    });

    init(AppLayoutBuilder.get(LeftLayouts.LeftResponsive.class)
            .withTitle("App Layout")
            .withAppBar(AppBarBuilder.get()
                    .add(searchButton)
                    .add(searchOverlayButton)
                    .build())
            .withAppMenu(LeftAppMenuBuilder.get()
                    .addToSection(HEADER,
                            new LeftHeaderItem("Menu-Header", "Version 4.0.0", "/frontend/images/logo.png"),
                            new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), event -> Notification.show("onClick ..."))
                    )
                    .add(new LeftNavigationItem("Home", VaadinIcon.HOME.create(), View1.class))
                    .addToSection(FOOTER,
                            new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), clickEvent -> Notification.show("onClick ..."))
                    )
                    .build())
            .build());
}
 
示例12
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());

    }
 
示例13
public MainAppLayout() {
    ProfileButton profileButton = AppBarProfileButtonBuilder.get()
            .withItem("ProfileButton Entry 1", event -> Notification.show("Profile clicked"))
            .withItem("ProfileButton Entry 2", event -> Notification.show("Profile clicked"))
            .withItem("ProfileButton Entry 3", event -> Notification.show("Profile clicked"))
            .build();

    init(AppLayoutBuilder.get(LeftLayouts.LeftResponsive.class)
            .withTitle("App Layout")
            .withAppBar(AppBarBuilder.get()
                    .add(profileButton)
                    .build())
            .withAppMenu(LeftAppMenuBuilder.get()
                    .addToSection(HEADER,
                            new LeftHeaderItem("Menu-Header", "Version 4.0.0", "/frontend/images/logo.png"),
                            new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), event -> Notification.show("onClick ..."))
                    )
                    .add(new LeftNavigationItem("Home", VaadinIcon.HOME.create(), View1.class))
                    .addToSection(FOOTER,
                            new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), clickEvent -> Notification.show("onClick ..."))
                    )
                    .build())
            .build());
}
 
示例14
public static void show(String title, LoadingResult result) {
    Notification notification = new Notification();
    notification.setDuration(5000);
    notification.add(new H3(title));
    VerticalLayout description = new VerticalLayout();
    description.setMargin(false);
    description.setSpacing(false);
    description.setDefaultHorizontalComponentAlignment(FlexComponent.Alignment.CENTER);
    description.add(row(label("Loaded", "100px"), label(result.getLoaded())));
    description.add(row(label("Duplicate", "100px"), label(result.getDuplicate())));
    description.add(row(label("Errored", "100px"), label(result.getErrored())));
    notification.add(description);
    notification.setPosition(Notification.Position.TOP_END);
    notification.open();
}
 
示例15
public static void show(String title, String description) {
    Notification notification = new Notification();
    notification.setDuration(3000);
    notification.add(new H3(title));
    notification.add(new Label(description));
    notification.setPosition(Notification.Position.TOP_END);
    notification.open();
}
 
示例16
VerticalLayout makeConfigForm() {
    VerticalLayout content = new VerticalLayout();
    appName = new TextField("App Name");
    appName.setWidth("300px");
    configName = new TextField("Key");
    configName.setWidth("300px");
    configValue = new TextArea("Value");
    configValue.setWidth("600px");
    HorizontalLayout buttons = new HorizontalLayout();
    saveButton = new Button("Save", buttonClickEvent -> {
        String key = appName.getValue() + ":" + configName.getValue();
        AppConfigEvent appConfigEvent = new AppConfigEvent(appName.getValue(), configName.getValue(), configValue.getValue());
        configurationService.put(key, configValue.getValue())
                .doOnSuccess(aVoid -> Notification.show("Saved Successfully"))
                .then(brokerManager.broadcast(appConfigEvent.toCloudEvent(URI.create("broker:" + brokerManager.localBroker().getIp()))))
                .subscribe();
    });
    content.add(new H3("Key/Value"));
    content.add(appName);
    content.add(configName);
    content.add(configValue);
    buttons.add(saveButton);
    buttons.add(new Button("New Configuration", buttonClickEvent -> {
        clearForm();
    }));
    content.add(buttons);
    return content;
}
 
示例17
@Override
protected void onAttach(AttachEvent attachEvent) {
    super.onAttach(attachEvent);
    closeSubscribeQuietly();
    this.notificationSubscribe = this.notificationProcessor.subscribe(text -> {
        attachEvent.getUI().access(() -> {
            Notification.show(text);
        });
    });
}
 
示例18
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));
}
 
示例19
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));
}
 
示例20
private void objectMultiselectComboBoxValueChangeHandler(
        MultiselectComboBox<User> multiselectComboBox) {
    Set<User> selectedItems = multiselectComboBox.getValue();
    String value = selectedItems.stream().map(User::toString)
            .collect(Collectors.joining(", "));
    Notification.show("Users value: " + value);
}
 
示例21
public AbstractLeftBehaviorBasicView() {
    badgeHolder = new DefaultBadgeHolder();
    LeftNavigationItem home = new LeftNavigationItem("View1", VaadinIcon.HOME.create(), getViewForI(1));
    LeftNavigationItem menu = new LeftNavigationItem("View9", VaadinIcon.MENU.create(), getViewForI(9));
    badgeHolder.bind(menu.getBadge());

    appBar = AppBarBuilder.get()
            .add(new IconButton(VaadinIcon.EDIT.create(), event -> Notification.show("IconButton clicked")))
            .build();

    AppLayoutBuilder builder = AppLayoutBuilder.get(getVariant())
            .withTitle("App Layout")
            .withIcon("frontend/images/logo.png")
            .withAppBar(appBar)
            .withAppMenu(
                    LeftAppMenuBuilder.get()
                            .addToSection(Section.HEADER,
                                    new LeftHeaderItem("App-Layout", "Version 4.0.0", "frontend/images/logo.png"),
                                    new LeftClickableItem("Set Behaviour HEADER", VaadinIcon.COG.create(), clickEvent -> {
                                    })
                            )
                            .add(home,
                                    LeftSubMenuBuilder.get("My Submenu", VaadinIcon.PLUS.create())
                                            .add(new LeftNavigationItem("View2", VaadinIcon.SPLINE_CHART.create(), getViewForI(2)),
                                                    new LeftNavigationItem("View3", VaadinIcon.CONNECT.create(), getViewForI(3)),
                                                    new LeftNavigationItem("View4", VaadinIcon.COG.create(), getViewForI(4)),
                                                    new LeftNavigationItem("View5", VaadinIcon.CONNECT.create(), getViewForI(5)),
                                                    new LeftNavigationItem("View6", VaadinIcon.COG.create(), getViewForI(6)))
                                            .build(),
                                    new LeftNavigationItem("View7", VaadinIcon.COG.create(), getViewForI(7)),
                                    new LeftNavigationItem("View8", VaadinIcon.COG.create(), getViewForI(8)),
                                    menu)
                            .build()
            );
    furtherConfiguration(builder);
    init(builder.build());
}
 
示例22
@Override
public void furtherConfiguration(AppLayoutBuilder builder) {
    ProfileButton button = AppBarProfileButtonBuilder.get()
            .withItem("Profile Entry 1", event -> Notification.show("Profile Entry 1 clicked"))
            .withItem("Profile Entry 2", event -> Notification.show("Profile Entry 2 clicked"))
            .withItem("Profile Entry 3", event -> Notification.show("Profile Entry 3 clicked"))
            .build();
    button.getWrappedComponent().setId("it-test-profile-button");
    builder.withAppBar(button);
}
 
示例23
@Override
public void furtherConfiguration(AppLayoutBuilder builder) {
    ListDataProvider<TestSearchResult> dataProvider = new ListDataProvider<>(Arrays.asList(
            new TestSearchResult("Header1", "Description1"),
            new TestSearchResult("Header2", "Description2"),
            new TestSearchResult("Header3", "Description3"),
            new TestSearchResult("Header4", "Description4"),
            new TestSearchResult("Header5", "Description5"),
            new TestSearchResult("Header6", "Description6"),
            new TestSearchResult("Header7", "Description7"),
            new TestSearchResult("Header8", "Description8"),
            new TestSearchResult("Header9", "Description9"),
            new TestSearchResult("Header10", "Description10")
    ));

    SearchOverlayButton<TestSearchResult, SerializablePredicate<TestSearchResult>> button = new SearchOverlayButtonBuilder<TestSearchResult, SerializablePredicate<TestSearchResult>>()
            .withDataProvider(dataProvider)
            .withQueryProvider(s -> new Query<TestSearchResult, SerializablePredicate<TestSearchResult>>(testEntity -> !s.equals("") && testEntity.getHeader().startsWith(s)))
            .withDataViewProvider(result -> {
                RippleClickableCard card = new RippleClickableCard(new Item(result.getHeader(), result.getDescription()));
                card.setWidthFull();
                card.setBackground("var(--lumo-base-color)");
                return card;
            })
            .withQueryResultListener(testSearchResult -> Notification.show(testSearchResult.header + " clicked"))
            .build();

    button.setId("it-test-search-button");
    button.getSearchView().getSearchField().setId("it-test-search-field");
    button.getSearchView().getCloseButton().setId("it-test-search-close");
    builder.withAppBar(button);
}
 
示例24
public MainAppLayout() {
    DefaultNotificationHolder notifications = new DefaultNotificationHolder();
    notifications.addClickListener(notification -> {/* ... */});
    init(AppLayoutBuilder.get(LeftLayouts.LeftResponsive.class)
            .withTitle("App Layout")
            .withAppBar(AppBarBuilder.get()
                    .add(new NotificationButton<>(VaadinIcon.BELL, notifications))
                    .build()
            )
            .withAppMenu(LeftAppMenuBuilder.get()
                    .addToSection(HEADER,
                            new LeftHeaderItem("Menu-Header", "Version 4.0.0", "/frontend/images/logo.png"),
                            new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), clickEvent -> Notification.show("onClick ..."))
                    )
                    .add(new LeftNavigationItem(View1.class),
                            LeftSubMenuBuilder.get("My Submenu", VaadinIcon.PLUS.create())
                                    .add(LeftSubMenuBuilder.get("My Submenu", VaadinIcon.PLUS.create())
                                                    .add(new LeftNavigationItem(View2.class),
                                                            new LeftNavigationItem(View3.class),
                                                            new LeftNavigationItem(View4.class))
                                                    .build(),
                                            new LeftNavigationItem(View3.class),
                                            new LeftNavigationItem(View4.class))
                                    .build(),
                            new LeftNavigationItem(View5.class)
                    )
                    .addToSection(FOOTER,
                            new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), clickEvent -> Notification.show("onClick ..."))
                    )
                    .build())
            .build());
}
 
示例25
public MainAppLayout() {
    LeftNavigationItem menuEntry = new LeftNavigationItem("Menu", VaadinIcon.MENU.create(), View6.class);
    DefaultBadgeHolder badge = new DefaultBadgeHolder(5);
    badge.bind(menuEntry.getBadge());

    init(AppLayoutBuilder.get(LeftLayouts.LeftResponsive.class)
            .withTitle("App Layout")
            .withAppMenu(LeftAppMenuBuilder.get()
                    .addToSection(HEADER,
                            new LeftHeaderItem("Menu-Header", "Version 4.0.0", "/frontend/images/logo.png"),
                            new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), event -> Notification.show("onClick ..."))
                    )
                    .add(new LeftNavigationItem("Home", VaadinIcon.HOME.create(), View1.class),
                            new LeftNavigationItem("Grid", VaadinIcon.TABLE.create(), GridTest.class),
                            LeftSubMenuBuilder.get("My Submenu", VaadinIcon.PLUS.create())
                                    .add(LeftSubMenuBuilder.get("My Submenu", VaadinIcon.PLUS.create())
                                                    .add(new LeftNavigationItem("Charts", VaadinIcon.SPLINE_CHART.create(), View2.class),
                                                            new LeftNavigationItem("Contact", VaadinIcon.CONNECT.create(), View3.class),
                                                            new LeftNavigationItem("More", VaadinIcon.COG.create(), View4.class))
                                                    .build(),
                                            new LeftNavigationItem("Contact1", VaadinIcon.CONNECT.create(), View3.class),
                                            new LeftNavigationItem("More1", VaadinIcon.COG.create(), View5.class))
                                    .build(),
                            menuEntry
                    )
                    .addToSection(FOOTER,
                            new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), clickEvent -> Notification.show("onClick ..."))
                    )
                    .build())
            .build());
}
 
示例26
private SearchOverlayButton<TestSearchResult, SerializablePredicate<TestSearchResult>> initSearchOverlayButton() {
    // The data provider that provides the entities for the search
    ListDataProvider<TestSearchResult> listDataProvider = new ListDataProvider<>(Arrays.asList(
            new TestSearchResult("Header1", "Description1"),
            new TestSearchResult("Header2", "Description2"),
            new TestSearchResult("Header3", "Description3"),
            new TestSearchResult("Header4", "Description4"),
            new TestSearchResult("Header5", "Description5"),
            new TestSearchResult("Header6", "Description6"),
            new TestSearchResult("Header7", "Description7"),
            new TestSearchResult("Header8", "Description8"),
            new TestSearchResult("Header9", "Description9"),
            new TestSearchResult("Header10", "Description10")
    ));

    return new SearchOverlayButtonBuilder<TestSearchResult, SerializablePredicate<TestSearchResult>>()
            // add the data provider
            .withDataProvider(listDataProvider)
            // Set the query that is executed to filter the Entities above
            .withQueryProvider(s -> new Query<>(testEntity -> !s.equals("") && testEntity.getHeader().startsWith(s)))
            // Set the producer that produces Components to be shown as search result
            .withDataViewProvider(queryResult -> {
                RippleClickableCard card = new RippleClickableCard(new Item(queryResult.getHeader(), queryResult.getDescription()));
                card.setWidthFull();
                card.setBackground("var(--lumo-base-color)");
                return card;
            })
            // A Listener to react if a search result was clicked
            .withQueryResultListener(testSearchResult -> Notification.show(testSearchResult.getHeader()))
            .build();
}
 
示例27
public MainAppLayout() {
    DefaultNotificationHolder notifications = new DefaultNotificationHolder();
    notifications.addClickListener(notification -> {/* Use the listener to react on the click on the notification */});
    notifications.add(
            new DefaultNotification("Header1", "Very long description 1"),
            new DefaultNotification("Header2", "Very long description 2"),
            new DefaultNotification("Header3", "Very long description 3"),
            new DefaultNotification("Header4", "Very long description 4")
    );

    init(AppLayoutBuilder.get(LeftLayouts.LeftResponsive.class)
            .withTitle("App Layout")
            .withAppBar(AppBarBuilder.get()
                    .add(new NotificationButton<>(VaadinIcon.BELL, notifications))
                    .build())
            .withAppMenu(LeftAppMenuBuilder.get()
                    .addToSection(HEADER,
                            new LeftHeaderItem("Menu-Header", "Version 4.0.0", "/frontend/images/logo.png"),
                            new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), event -> Notification.show("onClick ..."))
                    )
                    .add(new LeftNavigationItem("Home", VaadinIcon.HOME.create(), View1.class))
                    .addToSection(FOOTER,
                            new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), clickEvent -> Notification.show("onClick ..."))
                    )
                    .build())
            .build());
}
 
示例28
public MainAppLayout() {
    notifications.addClickListener(notification -> {/* ... */});

    LeftNavigationItem menuEntry = new LeftNavigationItem("Menu", VaadinIcon.MENU.create(), View6.class);
    badge.bind(menuEntry.getBadge());

    init(AppLayoutBuilder.get(LeftLayouts.LeftResponsive.class)
            .withTitle("App Layout")
            .withAppBar(AppBarBuilder.get()
                    .add(new NotificationButton<>(VaadinIcon.BELL, notifications))
                    .build())
            .withAppMenu(LeftAppMenuBuilder.get()
                    .addToSection(HEADER,
                            new LeftHeaderItem("Menu-Header", "Version 4.0.0", "/frontend/images/logo.png"),
                            new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), clickEvent -> Notification.show("onClick ..."))
                    )
                    .add(new LeftNavigationItem("Home", VaadinIcon.HOME.create(), View1.class),
                            new LeftNavigationItem("Grid", VaadinIcon.TABLE.create(), GridTest.class),
                            LeftSubMenuBuilder.get("My Submenu", VaadinIcon.PLUS.create())
                                    .add(LeftSubMenuBuilder
                                                    .get("My Submenu", VaadinIcon.PLUS.create())
                                                    .add(new LeftNavigationItem("Charts", VaadinIcon.SPLINE_CHART.create(), View2.class),
                                                            new LeftNavigationItem("Contact", VaadinIcon.CONNECT.create(), View3.class),
                                                            new LeftNavigationItem("More", VaadinIcon.COG.create(), View4.class))
                                                    .build(),
                                            new LeftNavigationItem("Contact1", VaadinIcon.CONNECT.create(), View3.class),
                                            new LeftNavigationItem("More1", VaadinIcon.COG.create(), View5.class))
                                    .build(),
                            menuEntry)
                    .addToSection(FOOTER, new LeftClickableItem("Clickable Entry", VaadinIcon.COG.create(), clickEvent -> Notification.show("onClick ...")))
                    .build())
            .build());
}
 
示例29
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;
}
 
示例30
@Override
public void showError(CrudOperation operation, Exception e) {
    if (errorListener != null) {
        errorListener.accept(e);
    } else {
        if (CrudOperationException.class.isAssignableFrom(e.getClass())) {
            // FIXME no Notification.Type
            Notification.show(e.getMessage());
        } else {
            Notification.show(e.getMessage());
            throw new RuntimeException("Error executing " + operation.name() + " operation", e);
        }
    }
}