vaadin / framework

Vaadin 6, 7, 8 is a Java framework for modern Java web applications.
http://vaadin.com/
Other
1.77k stars 729 forks source link

feat: Add better API to configure maximum allowed rows #12466

Closed TatuLund closed 2 years ago

TatuLund commented 2 years ago

Some components are harder to extend than Grid for overriding max rows limit. However getDataCommunicator is a public method and thus this API would make overriding the limit easier, see example

@Theme("mytheme")
public class MyUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();

        TwinColSelect<String> twin = new TwinColSelect<>();
        twin.getDataCommunicator().setMaximumAllowedRows(1000);

        ComboBox<String> combo = new ComboBox<>();
        combo.getDataCommunicator().setMaximumAllowedRows(1000);

        List<String> items = new ArrayList<>();
        for (int i=0;i<800;i++) {
            items.add("Item "+i);
        }

        twin.setItems(items);
        twin.setItemCaptionGenerator(item -> item.toUpperCase());
        combo.setItems(items);
        combo.setScrollToSelectedItem(true);

        layout.addComponents(twin, combo);

        setContent(layout);
    }

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }
}
TatuLund commented 2 years ago

Just noting, that Tree does not have convenience API for getting data communicator of the internal TreeGrid, but it is possible to extend Tree as follows:

    public class ExtTree<T> extends Tree<T> {

        public HierarchicalDataCommunicator<T> getDataCommunicator() {
            return ((TreeGrid) super.getCompositionRoot()).getDataCommunicator();
        }
    }