diff --git a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/DragAndDropDemo.java b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/DragAndDropDemo.java index d4befff..ab13c7a 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/DragAndDropDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/DragAndDropDemo.java @@ -21,8 +21,12 @@ package com.flowingcode.vaadin.addons.twincolgrid; import com.flowingcode.vaadin.addons.demo.DemoSource; +import com.vaadin.flow.component.checkbox.Checkbox; +import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.html.Label; +import com.vaadin.flow.component.html.Span; import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.function.SerializableRunnable; import com.vaadin.flow.router.PageTitle; import java.util.ArrayList; import java.util.Comparator; @@ -39,11 +43,12 @@ public class DragAndDropDemo extends VerticalLayout { private final Set selectedBooks = new HashSet<>(); private final List availableBooks = new ArrayList<>(); + private TwinColGrid twinColGrid; + public DragAndDropDemo() { initializeData(); - final TwinColGrid twinColGrid = - new TwinColGrid<>(availableBooks, "TwinColGrid demo with drag and drop support") + twinColGrid = new TwinColGrid<>(availableBooks, "TwinColGrid demo with drag and drop support") .addSortableColumn(Book::getIsbn, Comparator.comparing(Book::getIsbn), "ISBN") .addSortableColumn(Book::getTitle, Comparator.comparing(Book::getTitle), "Title") .withAvailableGridCaption("Available books") @@ -53,6 +58,7 @@ public DragAndDropDemo() { .withDragAndDropSupport() .withSelectionGridReordering() .selectRowOnClick(); + twinColGrid.setValue(selectedBooks); final Label countLabel = new Label("Selected items in left grid: 0"); @@ -61,6 +67,8 @@ public DragAndDropDemo() { twinColGrid.addValueChangeListener(e -> countLabel.setText("Selected items in left grid: 0")); add(twinColGrid, countLabel); + + addReorderingToggle(); setSizeFull(); } @@ -79,4 +87,24 @@ private void initializeData() { availableBooks.add(new Book("9529267533", "Book of Vaadin")); availableBooks.add(new Book("1782169776", "Learning Vaadin 7, Second Edition")); } + + private void addReorderingToggle() { + Checkbox checkbox = new Checkbox("Selection Grid reordering allowed", true); + Span description = new Span("(Reordering is disabled while the grid is sorted)"); + description.setVisible(false); + + SerializableRunnable refresh = () -> { + boolean sorted = !twinColGrid.getSelectionGrid().getSortOrder().isEmpty(); + boolean allowed = twinColGrid.isSelectionGridReorderingAllowed(); + description.setVisible(sorted && allowed); + }; + + checkbox.addValueChangeListener(ev -> { + twinColGrid.setSelectionGridReorderingAllowed(ev.getValue()); + refresh.run(); + }); + + twinColGrid.getSelectionGrid().addSortListener(ev -> refresh.run()); + add(new Div(checkbox, description)); + } }