Search in sources :

Example 6 with IronList

use of com.vaadin.flow.component.ironlist.IronList in project flow-components by vaadin.

the class IronListView method createPeopleListWithDataProviderAndComponentRenderer.

private void createPeopleListWithDataProviderAndComponentRenderer() {
    /* IronList that uses the component above */
    IronList<Person> list = new IronList<>();
    list.setHeight("400px");
    list.getStyle().set("border", "1px solid lightgray");
    DataProvider<Person, ?> dataProvider = DataProvider.ofCollection(createListOfPeople());
    list.setDataProvider(dataProvider);
    list.setGridLayout(true);
    // Uses the constructor of the PersonCard for each item in the list
    list.setRenderer(new ComponentRenderer<>(PersonCard::new));
    // For a smooth scrolling experience use a placeholder item
    Person placeholder = new Person();
    placeholder.setFirstName("-----");
    list.setPlaceholderItem(placeholder);
    NativeButton switchEnabled = new NativeButton("Switch enabled state", event -> list.setEnabled(!list.isEnabled()));
    list.setId("list-of-people-with-dataprovider-and-component-renderer");
    switchEnabled.setId("switch-enabled-people-list");
    addCard("Using components", "List of people with DataProvider and ComponentRenderer", new Label("List of people with grid layout"), list, switchEnabled);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) Label(com.vaadin.flow.component.html.Label) IronList(com.vaadin.flow.component.ironlist.IronList)

Example 7 with IronList

use of com.vaadin.flow.component.ironlist.IronList in project flow-components by vaadin.

the class IronListView method createDisabledStringsList.

private void createDisabledStringsList() {
    IronList<String> list = new IronList<>();
    list.setHeight("400px");
    list.getStyle().set("border", "1px solid lightgray");
    Div removalResult = new Div();
    removalResult.setId("disabled-removal-result");
    DataProvider<String, ?> dataProvider = DataProvider.fromCallbacks(query -> queryStringsFromDatabase(query), query -> countStringsFromDatabase(query));
    list.setDataProvider(dataProvider);
    // Disable the list so that scrolling still works but events are not
    // handled
    list.setEnabled(false);
    /*
         * The name of the event handlers defined at 'on-click' are used inside
         * the 'withEventHandler' calls.
         */
    list.setRenderer(TemplateRenderer.<String>of("<div style='display:flex; justify-content:space-between; padding:10px;'>" + "<div style='flex-grow:1'>[[item.name]]</div>" + "<div><button on-click='remove' style='color:red'>X</button></div>" + "<div>").withProperty("name", ValueProvider.identity()).withEventHandler("remove", item -> {
        removalResult.setText(item);
    }));
    NativeButton switchEnabled = new NativeButton("Switch enabled state", event -> list.setEnabled(!list.isEnabled()));
    list.setId("disabled-list-with-templates");
    switchEnabled.setId("switch-enabled-state-string-list");
    addCard("Using templates", "Using disabled list with templates", new Label("Rank up/down your favorite Lord of the Rings characters"), list, removalResult, switchEnabled);
}
Also used : Div(com.vaadin.flow.component.html.Div) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Arrays(java.util.Arrays) Image(com.vaadin.flow.component.html.Image) Component(com.vaadin.flow.component.Component) ValueProvider(com.vaadin.flow.function.ValueProvider) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) SecureRandom(java.security.SecureRandom) HashSet(java.util.HashSet) Faker(com.github.javafaker.Faker) DataProvider(com.vaadin.flow.data.provider.DataProvider) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) Query(com.vaadin.flow.data.provider.Query) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Set(java.util.Set) H2(com.vaadin.flow.component.html.H2) Serializable(java.io.Serializable) List(java.util.List) Stream(java.util.stream.Stream) IronList(com.vaadin.flow.component.ironlist.IronList) Collections(java.util.Collections) NativeButton(com.vaadin.flow.component.html.NativeButton) Label(com.vaadin.flow.component.html.Label) IronList(com.vaadin.flow.component.ironlist.IronList)

Example 8 with IronList

use of com.vaadin.flow.component.ironlist.IronList in project flow-components by vaadin.

the class IronListView method createRankedListWithEventHandling.

private void createRankedListWithEventHandling() {
    IronList<String> list = new IronList<>();
    list.setHeight("400px");
    list.getStyle().set("border", "1px solid lightgray");
    List<String> items = getLordOfTheRingsCharacters();
    list.setItems(items);
    /*
         * The name of the event handlers defined at 'on-click' are used inside
         * the 'withEventHandler' calls.
         */
    list.setRenderer(TemplateRenderer.<String>of("<div style='display:flex; justify-content:space-between; padding:10px;'>" + "<div style='flex-grow:1'>#[[item.rank]]: [[item.name]]</div>" + "<div><button on-click='up' hidden='[[item.upHidden]]'>&uarr;</button>" + "<button on-click='down' hidden='[[item.downHidden]]'>&darr;</button>" + "<button on-click='remove' style='color:red'>X</button></div>" + "<div>").withProperty("name", ValueProvider.identity()).withProperty("rank", item -> items.indexOf(item) + 1).withProperty("upHidden", item -> items.indexOf(item) == 0).withProperty("downHidden", item -> items.indexOf(item) == items.size() - 1).withEventHandler("up", item -> {
        int previousRank = items.indexOf(item);
        if (previousRank == 0) {
            return;
        }
        String previousItem = items.set(previousRank - 1, item);
        items.set(previousRank, previousItem);
        list.getDataCommunicator().reset();
    }).withEventHandler("down", item -> {
        int previousRank = items.indexOf(item);
        if (previousRank == items.size() - 1) {
            return;
        }
        String previousItem = items.set(previousRank + 1, item);
        items.set(previousRank, previousItem);
        list.getDataCommunicator().reset();
    }).withEventHandler("remove", item -> {
        items.remove(item);
        list.getDataCommunicator().reset();
    }));
    list.setId("using-events-with-templates");
    addCard("Using templates", "Using events with templates", new Label("Rank up/down your favorite Lord of the Rings characters"), list, new NativeButton("Reset", evt -> {
        items.clear();
        items.addAll(getLordOfTheRingsCharacters());
        list.getDataCommunicator().reset();
    }));
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Arrays(java.util.Arrays) Image(com.vaadin.flow.component.html.Image) Component(com.vaadin.flow.component.Component) ValueProvider(com.vaadin.flow.function.ValueProvider) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) SecureRandom(java.security.SecureRandom) HashSet(java.util.HashSet) Faker(com.github.javafaker.Faker) DataProvider(com.vaadin.flow.data.provider.DataProvider) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) Query(com.vaadin.flow.data.provider.Query) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Set(java.util.Set) H2(com.vaadin.flow.component.html.H2) Serializable(java.io.Serializable) List(java.util.List) Stream(java.util.stream.Stream) IronList(com.vaadin.flow.component.ironlist.IronList) Collections(java.util.Collections) NativeButton(com.vaadin.flow.component.html.NativeButton) Label(com.vaadin.flow.component.html.Label) IronList(com.vaadin.flow.component.ironlist.IronList)

Example 9 with IronList

use of com.vaadin.flow.component.ironlist.IronList in project flow-components by vaadin.

the class IronListTestPage method createListWithComponentRendererWithBeansAndPlaceholder.

private void createListWithComponentRendererWithBeansAndPlaceholder() {
    IronList<Person> list = new IronList<>();
    list.setHeight("100px");
    List<Person> people = createPeople(100);
    list.setRenderer(new ComponentRenderer<Label, Person>(person -> {
        Label label = new Label(person.getName());
        label.addClassName("component-rendered");
        return label;
    }));
    list.setItems(people);
    list.setId("component-renderer-with-beans");
    Person placeholder = new Person();
    placeholder.setName("the-placeholder");
    list.setPlaceholderItem(placeholder);
    add(list);
}
Also used : IntStream(java.util.stream.IntStream) LocalDateRenderer(com.vaadin.flow.data.renderer.LocalDateRenderer) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) ValueProvider(com.vaadin.flow.function.ValueProvider) LocalDateTime(java.time.LocalDateTime) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer) LocalDateTimeRenderer(com.vaadin.flow.data.renderer.LocalDateTimeRenderer) List(java.util.List) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) Locale(java.util.Locale) DataProvider(com.vaadin.flow.data.provider.DataProvider) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) LocalDate(java.time.LocalDate) IronList(com.vaadin.flow.component.ironlist.IronList) HasComponents(com.vaadin.flow.component.HasComponents) Renderer(com.vaadin.flow.data.renderer.Renderer) Label(com.vaadin.flow.component.html.Label) IronList(com.vaadin.flow.component.ironlist.IronList)

Example 10 with IronList

use of com.vaadin.flow.component.ironlist.IronList in project flow-components by vaadin.

the class IronListTestPage method createTemplateWithEventHandlers.

private void createTemplateWithEventHandlers() {
    IronList<String> list = new IronList<>();
    list.setHeight("100px");
    Label message = new Label();
    List<String> items = new ArrayList<>(Arrays.asList("Clickable item 1", "Clickable item 2", "Clickable item 3"));
    list.setRenderer(TemplateRenderer.<String>of("<div on-click='remove' id='template-events-item-[[index]]'>[[item.label]]</div>").withProperty("label", ValueProvider.identity()).withEventHandler("remove", item -> {
        items.remove(item);
        list.getDataCommunicator().reset();
        message.setText(item + " removed");
    }));
    list.setItems(items);
    list.setId("template-events");
    message.setId("template-events-message");
    add(list, message);
}
Also used : IntStream(java.util.stream.IntStream) LocalDateRenderer(com.vaadin.flow.data.renderer.LocalDateRenderer) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) ValueProvider(com.vaadin.flow.function.ValueProvider) LocalDateTime(java.time.LocalDateTime) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer) LocalDateTimeRenderer(com.vaadin.flow.data.renderer.LocalDateTimeRenderer) List(java.util.List) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) Locale(java.util.Locale) DataProvider(com.vaadin.flow.data.provider.DataProvider) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) LocalDate(java.time.LocalDate) IronList(com.vaadin.flow.component.ironlist.IronList) HasComponents(com.vaadin.flow.component.HasComponents) Renderer(com.vaadin.flow.data.renderer.Renderer) Label(com.vaadin.flow.component.html.Label) ArrayList(java.util.ArrayList) IronList(com.vaadin.flow.component.ironlist.IronList)

Aggregations

IronList (com.vaadin.flow.component.ironlist.IronList)15 NativeButton (com.vaadin.flow.component.html.NativeButton)12 Label (com.vaadin.flow.component.html.Label)11 Div (com.vaadin.flow.component.html.Div)8 DataProvider (com.vaadin.flow.data.provider.DataProvider)7 Query (com.vaadin.flow.data.provider.Query)7 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)7 TemplateRenderer (com.vaadin.flow.data.renderer.TemplateRenderer)7 ValueProvider (com.vaadin.flow.function.ValueProvider)7 Route (com.vaadin.flow.router.Route)7 ArrayList (java.util.ArrayList)7 Arrays (java.util.Arrays)7 List (java.util.List)7 HasComponents (com.vaadin.flow.component.HasComponents)5 LocalDateRenderer (com.vaadin.flow.data.renderer.LocalDateRenderer)5 LocalDateTimeRenderer (com.vaadin.flow.data.renderer.LocalDateTimeRenderer)5 NativeButtonRenderer (com.vaadin.flow.data.renderer.NativeButtonRenderer)5 NumberRenderer (com.vaadin.flow.data.renderer.NumberRenderer)5 Renderer (com.vaadin.flow.data.renderer.Renderer)5 LocalDate (java.time.LocalDate)5