From 7b768d8962a81f14ab45052972a65bfcbe8e6ee7 Mon Sep 17 00:00:00 2001 From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com> Date: Thu, 25 Nov 2021 16:27:43 -0300 Subject: [PATCH] feat: add support for reversed orientation Close #87 --- .../addons/twincolgrid/TwinColGrid.java | 62 +++++++++++++------ ...entationDemo.java => OrientationDemo.java} | 21 +++++-- .../addons/twincolgrid/TwincolDemoView.java | 2 +- 3 files changed, 60 insertions(+), 25 deletions(-) rename src/test/java/com/flowingcode/vaadin/addons/twincolgrid/{VerticalOrientationDemo.java => OrientationDemo.java} (75%) diff --git a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java index 9cdd88d..4419b30 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java +++ b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java @@ -104,7 +104,9 @@ Collection getItems() { /** enumeration of all available orientation for TwinGolGrid component */ public enum Orientation { HORIZONTAL, - VERTICAL; + VERTICAL, + HORIZONTAL_REVERSE, + VERTICAL_REVERSE; } private final TwinColModel available; @@ -235,14 +237,43 @@ private void updateContainerLayout() { } private Component createContainerLayout() { - return orientation == Orientation.VERTICAL - ? createVerticalContainer() - : createHorizontalContainer(); + switch (orientation) { + case HORIZONTAL: + addButton.setIcon(VaadinIcon.ANGLE_RIGHT.create()); + addAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_RIGHT.create()); + removeButton.setIcon(VaadinIcon.ANGLE_LEFT.create()); + removeAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_LEFT.create()); + return createHorizontalContainer(false); + case HORIZONTAL_REVERSE: + addButton.setIcon(VaadinIcon.ANGLE_LEFT.create()); + addAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_LEFT.create()); + removeButton.setIcon(VaadinIcon.ANGLE_RIGHT.create()); + removeAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_RIGHT.create()); + return createHorizontalContainer(true); + case VERTICAL: + addButton.setIcon(VaadinIcon.ANGLE_DOWN.create()); + addAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_DOWN.create()); + removeButton.setIcon(VaadinIcon.ANGLE_UP.create()); + removeAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_UP.create()); + return createVerticalContainer(false); + case VERTICAL_REVERSE: + addButton.setIcon(VaadinIcon.ANGLE_UP.create()); + addAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_UP.create()); + removeButton.setIcon(VaadinIcon.ANGLE_DOWN.create()); + removeAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_DOWN.create()); + return createVerticalContainer(true); + } + throw new IllegalStateException(); } - private HorizontalLayout createHorizontalContainer() { + private HorizontalLayout createHorizontalContainer(boolean reverse) { buttonContainer = getVerticalButtonContainer(); - HorizontalLayout hl = new HorizontalLayout(available.layout, buttonContainer, selection.layout); + HorizontalLayout hl; + if (reverse) { + hl = new HorizontalLayout(selection.layout, buttonContainer, available.layout); + } else { + hl = new HorizontalLayout(available.layout, buttonContainer, selection.layout); + } hl.getElement().getStyle().set("min-height", "0px"); hl.getElement().getStyle().set("flex", "1 1 0px"); hl.setMargin(false); @@ -250,9 +281,14 @@ private HorizontalLayout createHorizontalContainer() { return hl; } - private VerticalLayout createVerticalContainer() { + private VerticalLayout createVerticalContainer(boolean reverse) { buttonContainer = getHorizontalButtonContainer(); - VerticalLayout vl = new VerticalLayout(available.layout, buttonContainer, selection.layout); + VerticalLayout vl; + if (reverse) { + vl = new VerticalLayout(selection.layout, buttonContainer, available.layout); + } else { + vl = new VerticalLayout(available.layout, buttonContainer, selection.layout); + } vl.getElement().getStyle().set("min-width", "0px"); vl.getElement().getStyle().set("flex", "1 1 0px"); vl.setMargin(false); @@ -262,11 +298,6 @@ private VerticalLayout createVerticalContainer() { } private VerticalLayout getVerticalButtonContainer() { - addButton.setIcon(VaadinIcon.ANGLE_RIGHT.create()); - addAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_RIGHT.create()); - removeButton.setIcon(VaadinIcon.ANGLE_LEFT.create()); - removeAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_LEFT.create()); - fakeButtonContainerLabel.getElement().setProperty("innerHTML", " "); fakeButtonContainerLabel.setVisible(false); @@ -280,11 +311,6 @@ private VerticalLayout getVerticalButtonContainer() { } private HorizontalLayout getHorizontalButtonContainer() { - addButton.setIcon(VaadinIcon.ANGLE_DOWN.create()); - addAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_DOWN.create()); - removeButton.setIcon(VaadinIcon.ANGLE_UP.create()); - removeAllButton.setIcon(VaadinIcon.ANGLE_DOUBLE_UP.create()); - HorizontalLayout hButtonContainer = new HorizontalLayout( addAllButton, addButton, removeButton, removeAllButton); diff --git a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/VerticalOrientationDemo.java b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/OrientationDemo.java similarity index 75% rename from src/test/java/com/flowingcode/vaadin/addons/twincolgrid/VerticalOrientationDemo.java rename to src/test/java/com/flowingcode/vaadin/addons/twincolgrid/OrientationDemo.java index d9398ba..8db67d2 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/VerticalOrientationDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/OrientationDemo.java @@ -21,7 +21,9 @@ import com.flowingcode.vaadin.addons.demo.DemoSource; import com.flowingcode.vaadin.addons.twincolgrid.TwinColGrid.Orientation; +import com.vaadin.flow.component.formlayout.FormLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.component.select.Select; import com.vaadin.flow.router.PageTitle; import java.util.ArrayList; import java.util.Comparator; @@ -30,19 +32,19 @@ import java.util.Set; @SuppressWarnings("serial") -@PageTitle("Vertical Orientation") +@PageTitle("Orientation") @DemoSource( - "https://github.com/FlowingCode/TwinColGridAddon/blob/master/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/VerticalOrientationDemo.java") -public class VerticalOrientationDemo extends VerticalLayout { +"https://github.com/FlowingCode/TwinColGridAddon/blob/master/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/OrientationDemo.java") +public class OrientationDemo extends VerticalLayout { private final Set selectedBooks = new HashSet<>(); private final List availableBooks = new ArrayList<>(); - public VerticalOrientationDemo() { + public OrientationDemo() { initializeData(); final TwinColGrid twinColGrid = - new TwinColGrid<>(availableBooks, "TwinColGrid demo with drag and drop support") + new TwinColGrid<>(availableBooks, null) .addSortableColumn(Book::getIsbn, Comparator.comparing(Book::getIsbn), "ISBN") .addSortableColumn(Book::getTitle, Comparator.comparing(Book::getTitle), "Title") .withAvailableGridCaption("Available books") @@ -52,7 +54,14 @@ public VerticalOrientationDemo() { .withOrientation(Orientation.VERTICAL); twinColGrid.setValue(selectedBooks); - add(twinColGrid); + FormLayout formLayout = new FormLayout(); + Select orientationField = new Select<>(Orientation.values()); + orientationField.addValueChangeListener(ev -> twinColGrid.withOrientation(ev.getValue())); + orientationField.setValue(twinColGrid.getOrientation()); + orientationField.setWidth("225px"); + formLayout.addFormItem(orientationField, "Orientation"); + + add(formLayout, twinColGrid); setSizeFull(); } diff --git a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwincolDemoView.java b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwincolDemoView.java index 06d010d..042da5b 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwincolDemoView.java +++ b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwincolDemoView.java @@ -36,7 +36,7 @@ public TwincolDemoView() { addDemo(new DragAndDropDemo()); addDemo(new FilterableDemo()); addDemo(new BoundDemo()); - addDemo(new VerticalOrientationDemo()); + addDemo(new OrientationDemo()); setSizeFull(); } }