|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * TwinColGrid add-on |
| 4 | + * %% |
| 5 | + * Copyright (C) 2017 - 2022 Flowing Code |
| 6 | + * %% |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * #L% |
| 19 | + */ |
| 20 | +package com.flowingcode.vaadin.addons.twincolgrid; |
| 21 | + |
| 22 | +import com.flowingcode.vaadin.addons.demo.DemoSource; |
| 23 | +import com.vaadin.flow.component.html.Span; |
| 24 | +import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
| 25 | +import com.vaadin.flow.router.PageTitle; |
| 26 | +import com.vaadin.flow.router.Route; |
| 27 | +import java.util.ArrayList; |
| 28 | +import java.util.Comparator; |
| 29 | +import java.util.HashSet; |
| 30 | +import java.util.List; |
| 31 | +import java.util.Set; |
| 32 | + |
| 33 | +@SuppressWarnings("serial") |
| 34 | +@PageTitle("Double click") |
| 35 | +@DemoSource |
| 36 | +@Route(value = "twincolgrid/doubleclick", layout = TwincolDemoView.class) |
| 37 | +public class DoubleClickDemo extends VerticalLayout { |
| 38 | + |
| 39 | + private final Set<Book> selectedBooks = new HashSet<>(); |
| 40 | + private final List<Book> availableBooks = new ArrayList<>(); |
| 41 | + |
| 42 | + public DoubleClickDemo() { |
| 43 | + initializeData(); |
| 44 | + |
| 45 | + final TwinColGrid<Book> twinColGrid = |
| 46 | + new TwinColGrid<>(availableBooks, null) |
| 47 | + .addSortableColumn(Book::getIsbn, Comparator.comparing(Book::getIsbn), "ISBN") |
| 48 | + .addSortableColumn(Book::getTitle, Comparator.comparing(Book::getTitle), "Title") |
| 49 | + .withAvailableGridCaption("Available books") |
| 50 | + .withSelectionGridCaption("Added books") |
| 51 | + .withSizeFull() |
| 52 | + .selectRowOnClick(); |
| 53 | + twinColGrid.setValue(selectedBooks); |
| 54 | + twinColGrid.setMoveItemsByDoubleClick(true); |
| 55 | + |
| 56 | + add(new Span("Move items by double click"), twinColGrid); |
| 57 | + setSizeFull(); |
| 58 | + } |
| 59 | + |
| 60 | + private void initializeData() { |
| 61 | + selectedBooks.add(new Book("1478375108", "Vaadin Recipes")); |
| 62 | + selectedBooks.add(new Book("9789526800677", "Book of Vaadin: Volume 2 ")); |
| 63 | + availableBooks.add(new Book("1478375108", "Vaadin Recipes")); |
| 64 | + availableBooks.add(new Book("9781849515221", "Learning Vaadin")); |
| 65 | + availableBooks.add( |
| 66 | + new Book("9781782162261", "Vaadin 7 UI Design By Example: Beginner\u2019s Guide")); |
| 67 | + availableBooks.add(new Book("9781849518802", "Vaadin 7 Cookbook")); |
| 68 | + availableBooks.add(new Book("9526800605", "Book of Vaadin: 7th Edition, 1st Revision")); |
| 69 | + availableBooks.add(new Book("9789526800677", "Book of Vaadin: Volume 2 ")); |
| 70 | + availableBooks.add(new Book("9529267533", "Book of Vaadin")); |
| 71 | + availableBooks.add(new Book("1782169776", "Learning Vaadin 7, Second Edition")); |
| 72 | + } |
| 73 | +} |
0 commit comments