├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.yml │ ├── config.yml │ └── feature-request.yml └── workflows │ ├── commits.yml │ ├── maven-v0.yml │ └── maven.yml ├── .gitignore ├── LICENSE ├── README.md ├── drivers.xml ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── flowingcode │ │ └── vaadin │ │ └── addons │ │ └── gridhelpers │ │ ├── CheckboxColumn.java │ │ ├── CheckboxColumnGridHelper.java │ │ ├── ColumnToggleEvent.java │ │ ├── ColumnToggleHelper.java │ │ ├── EmptyLabelGridHelper.java │ │ ├── EnhancedSelectionGridHelper.java │ │ ├── FooterToolbarGridHelper.java │ │ ├── GridHelper.java │ │ ├── GridHelperClassNameGenerator.java │ │ ├── GridRadioSelectionColumn.java │ │ ├── GridRadioSelectionColumnHelper.java │ │ ├── GridResponsiveStep.java │ │ ├── GridResponsiveStepEvent.java │ │ ├── GridStylesHelper.java │ │ ├── HeaderFooterStylesHelper.java │ │ ├── HeaderFooterVisibilityHelper.java │ │ ├── HeightByRowsHelper.java │ │ ├── HeightMode.java │ │ ├── LazySelectAllGridHelper.java │ │ ├── ResponsiveGridHelper.java │ │ ├── SelectionColumnHelper.java │ │ └── SelectionFilterHelper.java └── resources │ └── META-INF │ ├── VAADIN │ └── package.properties │ ├── frontend │ └── fcGridHelper │ │ ├── connector.js │ │ ├── grid-flow-radio-selection-column.js │ │ ├── grid-radio-selection-column-base-mixin.js │ │ ├── grid-radio-selection-column-mixin.js │ │ ├── grid-radio-selection-column.js │ │ ├── vaadin-checkbox.css │ │ ├── vaadin-context-menu-item.css │ │ ├── vaadin-context-menu-list-box.css │ │ ├── vaadin-grid.css │ │ ├── vaadin-menu-bar-item.css │ │ ├── vaadin-menu-bar-list-box.css │ │ └── vaadin-menu-bar.css │ └── resources │ └── static_addon_resources └── test ├── java └── com │ └── flowingcode │ └── vaadin │ └── addons │ ├── DemoLayout.java │ └── gridhelpers │ ├── AddToolbarFooterDemo.java │ ├── AllFeaturesDemo.java │ ├── CheckboxColumnDemo.java │ ├── ColumnToggleMenuDemo.java │ ├── DemoView.java │ ├── DenseThemeDemo.java │ ├── EmptyGridLabelDemo.java │ ├── EnableArrowSelectionDemo.java │ ├── EnableEnhancedSelectionDemo.java │ ├── EnableSelectionOnClickDemo.java │ ├── FreezeSelectionColumnDemo.java │ ├── GetHeaderFooterDemo.java │ ├── GridHelpersDemoView.java │ ├── GridRadioSelectionColumnDemo.java │ ├── HeightByRowsDemo.java │ ├── HideSelectionColumnDemo.java │ ├── LazyMultiSelectionDemo.java │ ├── LazyTestData.java │ ├── LombokDemo.java │ ├── Person.java │ ├── SelectionFilterDemo.java │ ├── TestData.java │ ├── it │ ├── AbstractViewTest.java │ ├── ColumnToggleIT.java │ ├── EmptyLabelIT.java │ ├── FooterToolbarIT.java │ ├── GridHelperElement.java │ ├── GridRadioSelectionColumnIT.java │ ├── HeaderFooterVisibilityIT.java │ ├── HeightByRowsIT.java │ ├── HeightByRowsITView.java │ ├── HeightByRowsITViewCallables.java │ ├── IntegrationView.java │ ├── IntegrationViewCallables.java │ ├── MyGridElement.java │ ├── ResponsiveGridIT.java │ ├── ResponsiveGridITView.java │ ├── ResponsiveGridITViewCallables.java │ ├── SelectOnClickIT.java │ ├── SelectionColumnIT.java │ └── SelectionFilterIT.java │ └── test │ ├── FooterToolbarTest.java │ ├── GridHelperTest.java │ └── SerializationTest.java └── resources └── META-INF ├── frontend └── styles │ └── shared-styles.css └── resources ├── gridhelpers ├── gridhelpers-demo.js └── styles.css └── static_addon_test_resources /.github/ISSUE_TEMPLATE/bug-report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: Please report issues related to Grid Helpers add-on here. 3 | body: 4 | - type: textarea 5 | id: problem-description 6 | attributes: 7 | label: Describe the bug 8 | description: A clear description of the issue you're experiencing. 9 | validations: 10 | required: true 11 | - type: textarea 12 | id: expected-behavior 13 | attributes: 14 | label: Expected behavior 15 | description: A clear and concise description of the expected behavior. 16 | validations: 17 | required: false 18 | - type: textarea 19 | id: minimal-reproduction 20 | attributes: 21 | label: Minimal reproducible example 22 | description: If possible, add a concise code snippet that reproduces the issue and describe the steps needed to follow to reproduce it. 23 | validations: 24 | required: false 25 | - type: input 26 | id: addon-version 27 | attributes: 28 | label: Add-on Version 29 | description: The version of the add-on on which you're experiencing the issue. 30 | validations: 31 | required: true 32 | - type: input 33 | id: vaadin-version 34 | attributes: 35 | label: Vaadin Version 36 | description: The complete Vaadin version (X.Y.Z) on which the issue is reproducible. 37 | validations: 38 | required: true 39 | - type: textarea 40 | id: additional-information 41 | attributes: 42 | label: Additional information 43 | description: "Any other context/information about the issue can be added here (browser, OS, etc.)." 44 | validations: 45 | required: false 46 | 47 | 48 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 2 | description: Please add feature suggestions related to Grid Helpers add-on here. 3 | body: 4 | - type: textarea 5 | id: feature-proposal 6 | attributes: 7 | label: Feature proposal 8 | description: A concise but detailed description of the feature that you would like to see in the add-on. 9 | validations: 10 | required: true 11 | - type: textarea 12 | id: feature-implementation 13 | attributes: 14 | label: Describe solution expectations 15 | description: Do you have an idea/expectations of how it could be implemented? Did you try a possible solution that you want to share? 16 | validations: 17 | required: false 18 | - type: textarea 19 | id: additional-information 20 | attributes: 21 | label: Additional information 22 | description: Add any extra information you think it might be relevant to the request. 23 | validations: 24 | required: false 25 | -------------------------------------------------------------------------------- /.github/workflows/commits.yml: -------------------------------------------------------------------------------- 1 | name: Check Commits 2 | 3 | on: 4 | pull_request: 5 | 6 | jobs: 7 | check-commits: 8 | uses: FlowingCode/GithubActions/.github/workflows/check-commits.yml@main 9 | -------------------------------------------------------------------------------- /.github/workflows/maven-v0.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Java CI with Maven 10 | 11 | on: 12 | push: 13 | branches: [ "0.x" ] 14 | pull_request: 15 | branches: [ "0.x" ] 16 | 17 | jobs: 18 | build-vaadin22: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | - name: Set up JDK 23 | uses: actions/setup-java@v3 24 | with: 25 | java-version: '8' 26 | distribution: 'temurin' 27 | cache: maven 28 | - name: Build (Vaadin 22) 29 | run: mvn -B package --file pom.xml 30 | 31 | build-vaadin23: 32 | runs-on: ubuntu-latest 33 | steps: 34 | - uses: actions/checkout@v4 35 | - name: Set up JDK 36 | uses: actions/setup-java@v3 37 | with: 38 | java-version: '11' 39 | distribution: 'temurin' 40 | cache: maven 41 | - name: Build (Vaadin 23) 42 | run: mvn -B package --file pom.xml -Pv23 43 | 44 | build-vaadin24: 45 | runs-on: ubuntu-latest 46 | steps: 47 | - uses: actions/checkout@v4 48 | - name: Set up JDK 49 | uses: actions/setup-java@v3 50 | with: 51 | java-version: '17' 52 | distribution: 'temurin' 53 | cache: maven 54 | - name: Build (Vaadin 24) 55 | run: mvn -B package --file pom.xml -Pv24 56 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Java CI with Maven 10 | 11 | on: 12 | push: 13 | branches: [ "master" ] 14 | pull_request: 15 | branches: [ "master" ] 16 | 17 | jobs: 18 | build-vaadin23: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | - name: Set up JDK 23 | uses: actions/setup-java@v3 24 | with: 25 | java-version: '11' 26 | distribution: 'temurin' 27 | cache: maven 28 | - name: Build (Vaadin 23) 29 | run: mvn -B package --file pom.xml -Pv23 30 | 31 | build-vaadin24: 32 | runs-on: ubuntu-latest 33 | steps: 34 | - uses: actions/checkout@v4 35 | - name: Set up JDK 36 | uses: actions/setup-java@v3 37 | with: 38 | java-version: '17' 39 | distribution: 'temurin' 40 | cache: maven 41 | - name: Build (Vaadin 24) 42 | run: mvn -B package --file pom.xml -Pv24 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | target 3 | .vscode 4 | .settings 5 | .project 6 | .classpath 7 | webpack.generated.js 8 | package-lock.json 9 | package.json 10 | webpack.config.js 11 | /error-screenshots 12 | drivers 13 | tsconfig.json 14 | .idea 15 | types.d.ts 16 | /.npmrc 17 | /frontend/generated 18 | /frontend/index.html 19 | /pnpm-lock.yaml 20 | /pnpmfile.js 21 | /src/main/dev-bundle 22 | vite.generated.ts 23 | vite.config.ts 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/grid-helpers-add-on) 2 | [![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/grid-helpers-add-on.svg)](https://vaadin.com/directory/component/grid-helpers-add-on) 3 | [![Build Status](https://jenkins.flowingcode.com/job/GridHelpers-addon/badge/icon)](https://jenkins.flowingcode.com/job/GridHelpers-addon) 4 | [![Javadoc](https://img.shields.io/badge/javadoc-00b4f0)](https://javadoc.flowingcode.com/artifact/org.vaadin.addons.flowingcode/grid-helpers) 5 | 6 | # Grid Helpers Add-on 7 | 8 | Several grid recipes for Vaadin 23+ (and 22), ready to use. DOES NOT require extending `Grid`. 9 | 10 | ## Features 11 | 12 | - Remove multiselect selection column 13 | - Freeze a grid's selection (checkbox) column 14 | - Create Grid with conditional selection (with the following limitations: [#11](https://github.com/FlowingCode/GridHelpers/issues/11), [#12](https://github.com/FlowingCode/GridHelpers/issues/12)) 15 | - Select Grid rows automatically using up/down arrow keys 16 | - Show a Vaadin Grid with compact row styling 17 | - Show a meaningful message instead of an empty Grid 18 | - Show a menu to toggle the visibility of grid columns 19 | 20 | ## Online demo 21 | 22 | [Online demo here](http://addonsv23.flowingcode.com/grid-helpers) 23 | 24 | ## Download release 25 | 26 | [Available in Vaadin Directory](https://vaadin.com/directory/component/grid-helpers-add-on) 27 | 28 | ## Building and running demo 29 | 30 | - git clone repository 31 | - mvn clean install jetty:run 32 | 33 | To see the demo, navigate to http://localhost:8080/ 34 | 35 | ## Release notes 36 | 37 | See [here](https://github.com/FlowingCode/GridHelpers/releases) 38 | 39 | ## Issue tracking 40 | 41 | The issues for this add-on are tracked on its github.com page. All bug reports and feature requests are appreciated. 42 | 43 | ## Contributions 44 | 45 | Contributions are welcome, but there are no guarantees that they are accepted as such. Process for contributing is the following: 46 | 47 | - Fork this project 48 | - Create an issue to this project about the contribution (bug or feature) if there is no such issue about it already. Try to keep the scope minimal. 49 | - Develop and test the fix or functionality carefully. Only include minimum amount of code needed to fix the issue. 50 | - Refer to the fixed issue in commit 51 | - Send a pull request for the original project 52 | - Comment on the original issue that you have implemented a fix for it 53 | 54 | ## License & Author 55 | 56 | This add-on is distributed under Apache License 2.0. For license terms, see LICENSE.txt. 57 | 58 | Grid Helpers Add-on is written by Flowing Code S.A. 59 | 60 | # Developer Guide 61 | 62 | ## Getting started 63 | 64 | The class `GridHelper` provides several static methods that receive a `Grid` or `Column` as the first parameter: 65 | 66 | ``` 67 | grid.setSelectionMode(SelectionMode.MULTI); 68 | grid.addThemeName(GridHelper.DENSE_THEME); 69 | GridHelper.setSelectOnClick(grid, true); 70 | GridHelper.setArrowSelectionEnabled(grid, true); 71 | GridHelper.setSelectionColumnHidden(grid, true); 72 | 73 | Column firstNameColumn = grid.addColumn(Person::getFirstName).setHeader("First name"); 74 | GridHelper.setHidingToggleCaption(firstNameColumn, "First name"); 75 | ``` 76 | 77 | If you use [Project Lombok](https://projectlombok.org/), you can benefit from the [extension method](https://projectlombok.org/features/experimental/ExtensionMethod) feature: 78 | 79 | ``` 80 | @ExtensionMethod(GridHelper.class) 81 | public class LombokDemo extends Div { 82 | 83 | public LombokDemo() { 84 | Grid grid = new Grid<>(); 85 | 86 | grid.setSelectionMode(SelectionMode.MULTI); 87 | 88 | grid.setSelectionColumnHidden(true); 89 | grid.setSelectOnClick(true); 90 | grid.setSelectionFilter(Person::isActive); 91 | 92 | grid.addColumn(Person::getFirstName) 93 | .setHeader("First name") 94 | .setHidingToggleCaption("First name"); 95 | 96 | add(grid); 97 | } 98 | } 99 | ``` 100 | 101 | ## Special configuration when using Spring 102 | 103 | By default, Vaadin Flow only includes ```com/vaadin/flow/component``` to be always scanned for UI components and views. For this reason, the add-on might need to be whitelisted in order to display correctly. 104 | 105 | To do so, just add ```com.flowingcode``` to the ```vaadin.whitelisted-packages``` property in ```src/main/resources/application.properties```, like: 106 | 107 | ```vaadin.whitelisted-packages = com.vaadin,org.vaadin,dev.hilla,com.flowingcode``` 108 | 109 | More information on Spring whitelisted configuration [here](https://vaadin.com/docs/latest/integrations/spring/configuration/#configure-the-scanning-of-packages). 110 | -------------------------------------------------------------------------------- /drivers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | https://chromedriver.storage.googleapis.com/80.0.3987.106/chromedriver_win32.zip 8 | 9 | 40aeb7b0b3a3ea23a139a764b56e172f2fdb90a4 10 | sha1 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | https://chromedriver.storage.googleapis.com/80.0.3987.106/chromedriver_linux64.zip 20 | 21 | 0e8848ebca11706768fd748dd0282672acad35ac 22 | sha1 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | https://chromedriver.storage.googleapis.com/80.0.3987.106/chromedriver_mac64.zip 33 | 34 | 3b58b8039f363de3b13a8bea7d4646105fbbd177 35 | sha1 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/CheckboxColumnGridHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.gridhelpers.CheckboxColumn.CheckboxColumnConfiguration; 24 | import com.vaadin.flow.component.checkbox.Checkbox; 25 | import com.vaadin.flow.data.provider.BackEndDataProvider; 26 | import java.io.Serializable; 27 | import lombok.RequiredArgsConstructor; 28 | 29 | /** 30 | * Helper class to create a grid column where boolean value is rendered as a {@link Checkbox}. 31 | *

32 | * Note that using this helper with a {@link BackEndDataProvider} could lead to performance 33 | * penalties as the total amount of items must be fetched from backend. 34 | * 35 | * @param 36 | */ 37 | @SuppressWarnings("serial") 38 | @RequiredArgsConstructor 39 | final class CheckboxColumnGridHelper implements Serializable { 40 | 41 | private final GridHelper helper; 42 | 43 | /** 44 | * Creates a {@link CheckboxColumn} using a given configuration. 45 | * 46 | * @param config configuration to apply. 47 | * @return the created {@link CheckboxColumn} 48 | */ 49 | public CheckboxColumn addCheckboxColumn( 50 | CheckboxColumnConfiguration config) { 51 | return new CheckboxColumn<>(helper.getGrid(), config); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/ColumnToggleEvent.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers; 21 | 22 | import com.vaadin.flow.component.ComponentEvent; 23 | import com.vaadin.flow.component.grid.Grid; 24 | import com.vaadin.flow.component.grid.Grid.Column; 25 | 26 | /** 27 | * Event describing a change in column visibility through the toggle menu. 28 | * 29 | * @see GridHelper#addColumnToggleListener(Grid, com.vaadin.flow.component.ComponentEventListener) 30 | * 31 | * @param the grid bean type 32 | */ 33 | @SuppressWarnings("serial") 34 | public class ColumnToggleEvent extends ComponentEvent> { 35 | 36 | private Column column; 37 | 38 | public ColumnToggleEvent(Grid source, Column column, boolean fromClient) { 39 | super(source, fromClient); 40 | this.column = column; 41 | } 42 | 43 | /** Returns the column whose visibility was toggled. */ 44 | public Column getColumn() { 45 | return column; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/ColumnToggleHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | /* 22 | * This file incorporates work licensed under the Apache License, Version 2.0 23 | * from Vaadin Cookbook https://github.com/vaadin/cookbook 24 | * Copyright 2020-2022 Vaadin Ltd. 25 | */ 26 | 27 | package com.flowingcode.vaadin.addons.gridhelpers; 28 | 29 | import com.vaadin.flow.component.ComponentEventListener; 30 | import com.vaadin.flow.component.ComponentUtil; 31 | import com.vaadin.flow.component.checkbox.Checkbox; 32 | import com.vaadin.flow.component.contextmenu.MenuItem; 33 | import com.vaadin.flow.component.contextmenu.SubMenu; 34 | import com.vaadin.flow.component.grid.Grid; 35 | import com.vaadin.flow.component.grid.Grid.Column; 36 | import com.vaadin.flow.component.icon.VaadinIcon; 37 | import com.vaadin.flow.component.menubar.MenuBar; 38 | import com.vaadin.flow.component.menubar.MenuBarVariant; 39 | import com.vaadin.flow.shared.Registration; 40 | import java.io.Serializable; 41 | import java.util.Optional; 42 | import lombok.NonNull; 43 | import lombok.RequiredArgsConstructor; 44 | 45 | @SuppressWarnings("serial") 46 | @RequiredArgsConstructor 47 | class ColumnToggleHelper implements Serializable { 48 | 49 | private static final String GRID_HELPER_TOGGLE_THEME = "gridHelperToggle"; 50 | 51 | private static final String TOGGLE_CAPTION_DATA = GridHelper.class.getName() + "#TOGGLE_CAPTION"; 52 | 53 | private static final String HIDABLE_DATA = GridHelper.class.getName() + "#HIDABLE"; 54 | 55 | private final GridHelper helper; 56 | 57 | private Column menuToggleColumn; 58 | 59 | public void setColumnToggleVisible(boolean visible) { 60 | // https://cookbook.vaadin.com/grid-column-toggle 61 | if (visible) { 62 | showColumnToggle(); 63 | } else { 64 | hideColumnToggle(); 65 | } 66 | } 67 | 68 | public boolean isColumnToggleVisible() { 69 | return menuToggleColumn != null && menuToggleColumn.isVisible(); 70 | } 71 | 72 | private void showColumnToggle() { 73 | createMenuToggle() 74 | .ifPresent( 75 | toggle -> { 76 | Grid grid = helper.getGrid(); 77 | if (menuToggleColumn == null) { 78 | menuToggleColumn = grid.addColumn(t -> "").setWidth("auto").setFlexGrow(0); 79 | } else { 80 | menuToggleColumn.setVisible(true); 81 | } 82 | grid.getHeaderRows().get(0).getCell(menuToggleColumn).setComponent(toggle); 83 | }); 84 | } 85 | 86 | private void hideColumnToggle() { 87 | if (menuToggleColumn != null) { 88 | menuToggleColumn.setVisible(false); 89 | } 90 | } 91 | 92 | private Optional createMenuToggle() { 93 | Grid grid = helper.getGrid(); 94 | 95 | MenuBar menuBar = new MenuBar(); 96 | menuBar.getThemeNames().add(MenuBarVariant.LUMO_TERTIARY_INLINE.getVariantName()); 97 | MenuItem menuItem = menuBar.addItem(VaadinIcon.ELLIPSIS_DOTS_V.create()); 98 | SubMenu subMenu = menuItem.getSubMenu(); 99 | 100 | for (Column column : grid.getColumns()) { 101 | if (isHidable(column)) { 102 | String label = getHidingToggleCaption(column); 103 | Checkbox checkbox = new Checkbox(label); 104 | checkbox.setValue(column.isVisible()); 105 | checkbox.addValueChangeListener(e -> setColumnVisible(column, e.getValue())); 106 | MenuItem submenuItem = subMenu.addItem(checkbox); 107 | submenuItem.addAttachListener(ev -> stopClickPropagation(submenuItem)); 108 | stopClickPropagation(submenuItem); 109 | } 110 | } 111 | 112 | menuBar.getThemeNames().add(GRID_HELPER_TOGGLE_THEME); 113 | return Optional.of(menuBar).filter(_menuBar -> !_menuBar.getItems().isEmpty()); 114 | } 115 | 116 | private static void stopClickPropagation(MenuItem menuItem) { 117 | menuItem.getElement().executeJs("this.addEventListener('click',ev=>ev.stopPropagation())"); 118 | } 119 | 120 | 121 | private void setColumnVisible(Column column, boolean visible) { 122 | Grid grid = helper.getGrid(); 123 | column.setVisible(visible); 124 | ComponentUtil.fireEvent(helper.getGrid(), new ColumnToggleEvent<>(grid, column, true)); 125 | } 126 | 127 | public Registration addColumnToggleListener( 128 | @NonNull ComponentEventListener> listener) { 129 | @SuppressWarnings({"rawtypes", "unchecked"}) 130 | Class> eventType = (Class) ColumnToggleEvent.class; 131 | return ComponentUtil.addListener(helper.getGrid(), eventType, listener); 132 | } 133 | 134 | public String getHidingToggleCaption(@NonNull Column column) { 135 | Grid grid = helper.getGrid(); 136 | return Optional.ofNullable((String) ComponentUtil.getData(column, TOGGLE_CAPTION_DATA)) 137 | .orElseGet(() -> GridHelper.getHeader(grid, column)); 138 | } 139 | 140 | public boolean isHidable(Column column) { 141 | return column!=null && Boolean.TRUE.equals(ComponentUtil.getData(column, HIDABLE_DATA)); 142 | } 143 | 144 | public void setHidable(Column column, boolean hidable) { 145 | if (column != null) { 146 | Grid grid = helper.getGrid(); 147 | if (!grid.getColumns().contains(column)) { 148 | throw new IllegalArgumentException(); 149 | } 150 | ComponentUtil.setData(column, HIDABLE_DATA, hidable); 151 | if (isColumnToggleVisible()) { 152 | showColumnToggle(); 153 | } 154 | } 155 | } 156 | 157 | public void setHidingToggleCaption(Column column, String caption) { 158 | if (column != null) { 159 | Grid grid = helper.getGrid(); 160 | if (!grid.getColumns().contains(column)) { 161 | throw new IllegalArgumentException(); 162 | } 163 | ComponentUtil.setData(column, TOGGLE_CAPTION_DATA, caption); 164 | if (caption!=null && ComponentUtil.getData(column, HIDABLE_DATA)==null) { 165 | ComponentUtil.setData(column, HIDABLE_DATA, Boolean.TRUE); 166 | } 167 | if (isColumnToggleVisible()) { 168 | showColumnToggle(); 169 | } 170 | } 171 | } 172 | 173 | Column getMenuToggleColumn() { 174 | return menuToggleColumn; 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/EmptyLabelGridHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | /* 22 | * This file incorporates work licensed under the Apache License, Version 2.0 23 | * from Vaadin Cookbook https://github.com/vaadin/cookbook 24 | * Copyright 2020-2022 Vaadin Ltd. 25 | */ 26 | 27 | package com.flowingcode.vaadin.addons.gridhelpers; 28 | 29 | import com.vaadin.flow.component.Component; 30 | import com.vaadin.flow.component.grid.Grid; 31 | import com.vaadin.flow.data.provider.DataProviderListener; 32 | import com.vaadin.flow.data.provider.Query; 33 | import com.vaadin.flow.shared.Registration; 34 | import java.io.Serializable; 35 | import java.util.Optional; 36 | import lombok.RequiredArgsConstructor; 37 | 38 | @SuppressWarnings("serial") 39 | @RequiredArgsConstructor 40 | class EmptyLabelGridHelper implements Serializable { 41 | 42 | private final GridHelper helper; 43 | 44 | private Component emptyLabel; 45 | private Registration registration; 46 | 47 | // - Show a meaningful message instead of an empty Grid 48 | // https://cookbook.vaadin.com/grid-message-when-empty 49 | void setEmptyGridLabel(Component component) { 50 | Grid grid = helper.getGrid(); 51 | 52 | Optional.ofNullable(emptyLabel).ifPresent(l -> l.setVisible(false)); 53 | 54 | emptyLabel = component; 55 | 56 | if (registration != null) { 57 | registration.remove(); 58 | registration = null; 59 | } 60 | 61 | if (component != null) { 62 | DataProviderListener listener = 63 | ev -> component.setVisible(grid.getDataProvider().size(new Query<>()) == 0); 64 | registration = grid.getDataProvider().addDataProviderListener(listener); 65 | 66 | // Initial run of the listener, as there is no event fired for the initial state 67 | // of the data set that might be empty or not. 68 | listener.onDataChange(null); 69 | } 70 | } 71 | 72 | Component getEmptyGridLabel() { 73 | return emptyLabel; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/FooterToolbarGridHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers; 21 | 22 | import com.vaadin.flow.component.Component; 23 | import com.vaadin.flow.component.grid.FooterRow; 24 | import com.vaadin.flow.component.grid.FooterRow.FooterCell; 25 | import com.vaadin.flow.component.grid.Grid; 26 | import java.io.Serializable; 27 | import lombok.RequiredArgsConstructor; 28 | 29 | @SuppressWarnings("serial") 30 | @RequiredArgsConstructor 31 | class FooterToolbarGridHelper implements Serializable { 32 | 33 | private final GridHelper helper; 34 | 35 | private FooterCell footerCell; 36 | 37 | public void setFooterToolbar(Component toolBar) { 38 | Grid grid = helper.getGrid(); 39 | if (grid.getFooterRows().isEmpty()) { 40 | // create a fake footer and hide it (workaround: 41 | // https://github.com/vaadin/flow-components/issues/1558#issuecomment-987783794) 42 | grid.appendFooterRow(); 43 | grid.getElement().getThemeList().add("hide-first-footer"); 44 | } 45 | if (footerCell == null) { 46 | FooterRow fr = grid.appendFooterRow(); 47 | if(grid.getColumns().size() > 1) { 48 | footerCell = fr.join(grid.getColumns().toArray(new Grid.Column[0])); 49 | } else { 50 | footerCell = fr.getCell(grid.getColumns().get(0)); 51 | } 52 | } 53 | toolBar.getElement().setAttribute("fcGh-footer", true); 54 | footerCell.setComponent(toolBar); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelperClassNameGenerator.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.vaadin.flow.function.SerializableFunction; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | import java.util.Objects; 27 | import java.util.Optional; 28 | import java.util.stream.Collectors; 29 | import java.util.stream.Stream; 30 | import lombok.Getter; 31 | import lombok.Setter; 32 | import org.apache.commons.lang3.StringUtils; 33 | 34 | @SuppressWarnings("serial") 35 | final class GridHelperClassNameGenerator implements SerializableFunction { 36 | 37 | private Map, SerializableFunction> helperClassNameGenerators = 38 | new HashMap<>(); 39 | 40 | @Getter @Setter private SerializableFunction gridClassNameGenerator; 41 | 42 | private transient boolean invoked; 43 | 44 | void setHelperClassNameGenerator(Class clazz, SerializableFunction generator) { 45 | if (generator != null) { 46 | helperClassNameGenerators.put(clazz, generator); 47 | } else { 48 | helperClassNameGenerators.remove(clazz); 49 | } 50 | } 51 | 52 | private Stream> generators() { 53 | return Stream.concat( 54 | Optional.ofNullable(gridClassNameGenerator).map(Stream::of).orElseGet(Stream::empty), 55 | helperClassNameGenerators.values().stream()); 56 | } 57 | 58 | @Override 59 | public String apply(T t) { 60 | if (invoked) { 61 | return null; 62 | } 63 | 64 | invoked = true; 65 | try { 66 | return StringUtils.trimToNull( 67 | generators() 68 | .map(generator -> generator.apply(t)) 69 | .map(StringUtils::trimToNull) 70 | .filter(Objects::nonNull) 71 | .flatMap(s -> Stream.of(s.trim().split("\\s+"))) 72 | .distinct() 73 | .collect(Collectors.joining(" "))); 74 | } finally { 75 | invoked = false; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridRadioSelectionColumn.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.vaadin.flow.component.Component; 24 | import com.vaadin.flow.component.HasStyle; 25 | import com.vaadin.flow.component.Synchronize; 26 | import com.vaadin.flow.component.Tag; 27 | import com.vaadin.flow.component.dependency.JsModule; 28 | import com.vaadin.flow.component.dependency.NpmPackage; 29 | import com.vaadin.flow.component.dependency.Uses; 30 | import com.vaadin.flow.component.radiobutton.RadioButtonGroup; 31 | 32 | /** 33 | * Server side implementation for the flow specific grid radio selection column. 34 | */ 35 | @Tag("grid-flow-radio-selection-column") 36 | @NpmPackage(value = "@vaadin/polymer-legacy-adapter", version = "24.3.2") 37 | @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") 38 | @JsModule("./fcGridHelper/grid-flow-radio-selection-column.js") 39 | @Uses(RadioButtonGroup.class) 40 | public class GridRadioSelectionColumn extends Component implements HasStyle { 41 | 42 | /** 43 | * Sets this column's frozen state. 44 | * 45 | * @param frozen whether to freeze or unfreeze this column 46 | */ 47 | public void setFrozen(boolean frozen) { 48 | getElement().setProperty("frozen", frozen); 49 | } 50 | 51 | /** 52 | * Gets the this column's frozen state. 53 | * 54 | * @return whether this column is frozen 55 | */ 56 | @Synchronize("frozen-changed") 57 | public boolean isFrozen() { 58 | return getElement().getProperty("frozen", false); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridRadioSelectionColumnHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.vaadin.flow.component.grid.Grid; 24 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 25 | import java.io.Serializable; 26 | import lombok.RequiredArgsConstructor; 27 | 28 | @SuppressWarnings("serial") 29 | @RequiredArgsConstructor 30 | class GridRadioSelectionColumnHelper implements Serializable { 31 | 32 | private final GridHelper helper; 33 | 34 | private GridRadioSelectionColumn selectionColumn; 35 | 36 | public GridRadioSelectionColumn showRadioSelectionColumn() { 37 | remove(); 38 | 39 | Grid grid = helper.getGrid(); 40 | grid.setSelectionMode(SelectionMode.SINGLE); 41 | 42 | selectionColumn = new GridRadioSelectionColumn(); 43 | selectionColumn.setClassName("fc-grid-radio-selection-column"); 44 | 45 | if (grid.getElement().getNode().isAttached()) { 46 | grid.getElement().insertChild(0, selectionColumn.getElement()); 47 | } else { 48 | grid.getElement().getNode().runWhenAttached(ui -> { 49 | grid.getElement().insertChild(0, selectionColumn.getElement()); 50 | }); 51 | } 52 | 53 | return selectionColumn; 54 | } 55 | 56 | private void remove() { 57 | if (selectionColumn != null && selectionColumn.getElement().getNode().isAttached()) { 58 | helper.getGrid().getElement().removeChild(selectionColumn.getElement()); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridResponsiveStepEvent.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers; 21 | 22 | import com.vaadin.flow.component.grid.Grid; 23 | import java.util.EventObject; 24 | 25 | /** An event that is fired when the responsive step of a Grid component changes. */ 26 | @SuppressWarnings("serial") 27 | public class GridResponsiveStepEvent extends EventObject { 28 | 29 | private final int minWidth; 30 | 31 | /** 32 | * Constructs a {@code GridResponsiveStepEvent} object with the specified source grid and minimum 33 | * width for the step. 34 | * 35 | * @param source the {@code Grid} component that fired the event 36 | * @param minWidth the minimum width (in pixels) on which the step is applied 37 | */ 38 | GridResponsiveStepEvent(Grid source, int minWidth) { 39 | super(source); 40 | this.minWidth = minWidth; 41 | } 42 | 43 | /** 44 | * Returns the {@code Grid} component that fired the event. 45 | * 46 | * @return the source {@code Grid} component 47 | */ 48 | @Override 49 | public Grid getSource() { 50 | return (Grid) super.getSource(); 51 | } 52 | 53 | /** 54 | * Returns the minimum width (in pixels) on which the step is applied. 55 | * 56 | * @return the minimum width of the {@link GridResponsiveStep} 57 | */ 58 | public int getMinWidth() { 59 | return minWidth; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridStylesHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers; 21 | 22 | /** 23 | * Represents an HTML element that supports CSS classes. 24 | */ 25 | public interface GridStylesHelper { 26 | // methods from HasStyle (minus getElement and getStyle) 27 | 28 | /** 29 | * Adds a CSS class name to this element. 30 | * 31 | * @param className the CSS class name to add, not null 32 | */ 33 | void addClassName(String className); 34 | 35 | /** 36 | * Removes a CSS class name from this element. 37 | * 38 | * @param className the CSS class name to remove, not null 39 | * @return true if the class name was removed, false if the class list 40 | * didn't contain the class name 41 | */ 42 | boolean removeClassName(String className); 43 | 44 | /** 45 | * Sets the CSS class names of this element. This method overwrites any previous set class names. 46 | * 47 | * @param className a space-separated string of class names to set, or null to remove 48 | * all class names 49 | */ 50 | void setClassName(String className); 51 | 52 | /** 53 | * Gets the CSS class names for this element. 54 | * 55 | * @return a space-separated string of class names, or null if there are no class 56 | * names 57 | */ 58 | String getClassName(); 59 | 60 | /** 61 | * Sets or removes the given class name for this element. 62 | * 63 | * @param className the class name to set or remove, not null 64 | * @param set true to set the class name, false to remove it 65 | */ 66 | void setClassName(String className, boolean set); 67 | 68 | /** 69 | * Checks if the element has the given class name. 70 | * 71 | * @param className the class name to check for 72 | * @return true if the element has the given class name, false otherwise 73 | */ 74 | boolean hasClassName(String className); 75 | 76 | /** 77 | * Adds one or more CSS class names to this element. Multiple class names can be specified by 78 | * using spaces or by giving multiple parameters. 79 | * 80 | * @param classNames the CSS class name or class names to be added to the element 81 | */ 82 | void addClassNames(String... classNames); 83 | 84 | /** 85 | * Removes one or more CSS class names from element. Multiple class names can be specified by 86 | * using spaces or by giving multiple parameters. 87 | * 88 | * @param classNames the CSS class name or class names to be removed from the element 89 | */ 90 | void removeClassNames(String... classNames); 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/HeaderFooterVisibilityHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers; 21 | 22 | import java.io.Serializable; 23 | import lombok.RequiredArgsConstructor; 24 | 25 | @SuppressWarnings("serial") 26 | @RequiredArgsConstructor 27 | class HeaderFooterVisibilityHelper implements Serializable { 28 | 29 | private final GridHelper helper; 30 | 31 | private static final String HIDE_HEADERS = "fcGh-hide-headers"; 32 | 33 | private static final String HIDE_FOOTERS = "fcGh-hide-footers"; 34 | 35 | private void setThemeName(String themeName, boolean set) { 36 | helper.getGrid().setThemeName(themeName, set); 37 | } 38 | 39 | private boolean hasThemeName(String themeName) { 40 | return helper.getGrid().hasThemeName(themeName); 41 | } 42 | 43 | public void setHeaderVisible(boolean visible) { 44 | setThemeName(HIDE_HEADERS, !visible); 45 | } 46 | 47 | public boolean isHeaderVisible() { 48 | return !hasThemeName(HIDE_HEADERS); 49 | } 50 | 51 | public void setFooterVisible(boolean visible) { 52 | setThemeName(HIDE_FOOTERS, !visible); 53 | } 54 | 55 | public boolean isFooterVisible() { 56 | return !hasThemeName(HIDE_FOOTERS); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/HeightByRowsHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers; 21 | 22 | import com.vaadin.flow.component.grid.Grid; 23 | import java.io.Serializable; 24 | import java.util.Optional; 25 | import lombok.Getter; 26 | import lombok.RequiredArgsConstructor; 27 | 28 | @SuppressWarnings("serial") 29 | @RequiredArgsConstructor 30 | class HeightByRowsHelper implements Serializable { 31 | 32 | private static final String THEME = "height-by-rows"; 33 | 34 | private final GridHelper helper; 35 | 36 | @Getter 37 | private double heightByRows; 38 | 39 | private HeightMode heightMode; 40 | 41 | void setHeightByRows(double rows) { 42 | if (rows <= 0.0d) { 43 | throw new IllegalArgumentException("More than zero rows must be shown."); 44 | } else if (Double.isInfinite(rows)) { 45 | throw new IllegalArgumentException("Grid doesn't support infinite heights"); 46 | } else if (Double.isNaN(rows)) { 47 | throw new IllegalArgumentException("NaN is not a valid row count"); 48 | } 49 | 50 | heightByRows = rows; 51 | 52 | Grid grid = helper.getGrid(); 53 | if (heightMode == HeightMode.ROW && grid.isAttached()) { 54 | grid.getElement().executeJs("this.fcGridHelper.setHeightByRows($0)", rows); 55 | grid.setThemeName(THEME, heightMode == HeightMode.ROW); 56 | } 57 | } 58 | 59 | void setHeightMode(HeightMode heightMode) { 60 | if (this.heightMode == null) { 61 | helper.getGrid().addAttachListener(ev -> { 62 | if (heightMode == HeightMode.ROW) { 63 | setHeightByRows(heightByRows); 64 | } 65 | }); 66 | } 67 | 68 | this.heightMode = heightMode; 69 | if (heightMode == HeightMode.ROW && heightByRows != 0) { 70 | setHeightByRows(heightByRows); 71 | helper.getGrid().addThemeName(THEME); 72 | } else { 73 | helper.getGrid().removeThemeName(THEME); 74 | } 75 | } 76 | 77 | HeightMode getHeightMode() { 78 | return Optional.ofNullable(heightMode).orElse(HeightMode.CSS); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/HeightMode.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers; 21 | 22 | import com.vaadin.flow.component.grid.Grid; 23 | 24 | /** 25 | * The modes for height calculation that are supported {@link GridHelper}. 26 | * 27 | * @see GridHelper#setHeightMode(Grid, HeightMode) 28 | */ 29 | public enum HeightMode { 30 | /** 31 | * 32 | * The height of the Component is defined by a CSS-like value. 33 | */ 34 | CSS, 35 | 36 | /** 37 | * The height of the Component is defined by a number of rows. 38 | */ 39 | ROW; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/LazySelectAllGridHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers; 21 | 22 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 23 | import com.vaadin.flow.component.grid.GridMultiSelectionModel; 24 | import java.io.Serializable; 25 | import lombok.RequiredArgsConstructor; 26 | 27 | /** 28 | * By default Vaadin hides select all checkbox when grid's data is NOT in-memory (lazy). 29 | *

30 | * This grid helper allows showing or hiding select all checkbox no matter if data provider is or 31 | * not memory. 32 | *

33 | * Note that enabling select all checkbox when grid uses a lazy data provider could lead to memory 34 | * and performance issues, given that all the items must be eagerly loaded at the moment user clicks 35 | * the checkbox. 36 | * 37 | * @param the type of items in grid 38 | */ 39 | @RequiredArgsConstructor 40 | final class LazySelectAllGridHelper implements Serializable { 41 | 42 | private static final long serialVersionUID = 1L; 43 | 44 | private final GridHelper helper; 45 | 46 | /** 47 | * Toggles select all checkbox visibility. 48 | * 49 | * @param visible true to show the select all checkbox, false to hide it. 50 | */ 51 | void toggleSelectAllCheckbox(boolean visible) { 52 | if (SelectionMode.MULTI.equals(GridHelper.getSelectionMode(helper.getGrid()))) { 53 | GridMultiSelectionModel model = 54 | (GridMultiSelectionModel) helper.getGrid().getSelectionModel(); 55 | if (visible) { 56 | model.setSelectAllCheckboxVisibility( 57 | GridMultiSelectionModel.SelectAllCheckboxVisibility.VISIBLE); 58 | } else { 59 | model.setSelectAllCheckboxVisibility( 60 | GridMultiSelectionModel.SelectAllCheckboxVisibility.HIDDEN); 61 | } 62 | } 63 | } 64 | 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/ResponsiveGridHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers; 21 | 22 | import com.vaadin.flow.component.grid.Grid; 23 | import com.vaadin.flow.dom.DebouncePhase; 24 | import com.vaadin.flow.shared.Registration; 25 | import elemental.json.Json; 26 | import elemental.json.JsonArray; 27 | import java.io.Serializable; 28 | import java.util.Collection; 29 | import java.util.Collections; 30 | import java.util.NavigableMap; 31 | import java.util.TreeMap; 32 | import lombok.Getter; 33 | import lombok.RequiredArgsConstructor; 34 | 35 | @SuppressWarnings("serial") 36 | @RequiredArgsConstructor 37 | class ResponsiveGridHelper implements Serializable { 38 | 39 | private final GridHelper helper; 40 | 41 | private boolean initialized; 42 | 43 | private NavigableMap> steps = new TreeMap<>(); 44 | 45 | @Getter 46 | private int currentMinWidth = -1; 47 | 48 | private Registration refreshRegistration; 49 | 50 | Grid getGrid() { 51 | return helper.getGrid(); 52 | } 53 | 54 | GridResponsiveStep getOrCreate(int minWidth) { 55 | Grid grid = helper.getGrid(); 56 | 57 | if (minWidth < 0) { 58 | throw new IllegalArgumentException(); 59 | } 60 | 61 | steps.computeIfAbsent(minWidth, w -> new GridResponsiveStep<>(w, this)); 62 | 63 | if (initialized) { 64 | sendSteps(); 65 | } else { 66 | initialized = true; 67 | grid.addAttachListener(ev -> initialize()); 68 | if (grid.isAttached()) { 69 | initialize(); 70 | } 71 | } 72 | 73 | return steps.get(minWidth); 74 | } 75 | 76 | private void initialize() { 77 | Grid grid = helper.getGrid(); 78 | grid.getElement().addEventListener("fcgh-responsive-step", ev -> { 79 | apply((int) ev.getEventData().getNumber("event.detail.step"), false); 80 | }).addEventData("event.detail.step").debounce(200, DebouncePhase.TRAILING); 81 | sendSteps(); 82 | } 83 | 84 | private void sendSteps() { 85 | JsonArray widths = Json.createArray(); 86 | steps.keySet().forEach(w -> widths.set(widths.length(), w)); 87 | helper.getGrid().getElement().executeJs("this.fcGridHelper._setResponsiveSteps($0)", widths); 88 | } 89 | 90 | private void refresh() { 91 | apply(currentMinWidth, true); 92 | } 93 | 94 | void requireRefresh(GridResponsiveStep step) { 95 | if (step.getMinWidth() <= currentMinWidth) { 96 | Grid grid = helper.getGrid(); 97 | grid.getUI().ifPresent(ui -> { 98 | if (refreshRegistration != null) { 99 | refreshRegistration.remove(); 100 | } 101 | refreshRegistration = ui.beforeClientResponse(grid, context -> refresh()); 102 | }); 103 | } 104 | } 105 | 106 | private void apply(int width, boolean force) { 107 | if (steps.floorKey(width) != null) { 108 | Grid grid = helper.getGrid(); 109 | GridResponsiveStep step = new GridResponsiveStep().show(grid.getColumns()); 110 | steps.subMap(0, true, width, true).values().forEach(step::accumulate); 111 | if (step.getMinWidth() >= 0) { 112 | if (force || currentMinWidth != step.getMinWidth()) { 113 | currentMinWidth = step.getMinWidth(); 114 | step.apply(helper.getGrid()); 115 | } 116 | } 117 | } else { 118 | currentMinWidth = -1; 119 | } 120 | } 121 | 122 | void remove(GridResponsiveStep step) { 123 | if (steps.remove(step.getMinWidth(), step)) { 124 | sendSteps(); 125 | } else { 126 | throw new IllegalArgumentException("The responsive step is not connected to this grid"); 127 | } 128 | } 129 | 130 | Collection> getAll() { 131 | return Collections.unmodifiableCollection(steps.values()); 132 | } 133 | 134 | } 135 | 136 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/SelectionColumnHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | /* 22 | * This file incorporates work licensed under the Apache License, Version 2.0 23 | * from Vaadin Cookbook https://github.com/vaadin/cookbook 24 | * Copyright 2020-2022 Vaadin Ltd. 25 | */ 26 | 27 | package com.flowingcode.vaadin.addons.gridhelpers; 28 | 29 | import java.io.Serializable; 30 | import lombok.Getter; 31 | import lombok.RequiredArgsConstructor; 32 | 33 | @SuppressWarnings("serial") 34 | @RequiredArgsConstructor 35 | class SelectionColumnHelper implements Serializable { 36 | 37 | private final GridHelper helper; 38 | 39 | @Getter private boolean selectionColumnHidden; 40 | 41 | public void setSelectionColumnHidden(boolean value) { 42 | // https://cookbook.vaadin.com/grid-multiselect-no-selectcolumn 43 | selectionColumnHidden = value; 44 | helper 45 | .getGrid() 46 | .getElement() 47 | .executeJs( 48 | "this.getElementsByTagName('vaadin-grid-flow-selection-column')[0].hidden = $0;", 49 | value); 50 | } 51 | 52 | void onAttach() { 53 | if (isSelectionColumnHidden()) { 54 | setSelectionColumnHidden(true); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/flowingcode/vaadin/addons/gridhelpers/SelectionFilterHelper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | /* 22 | * This file incorporates work licensed under the Apache License, Version 2.0 23 | * from Vaadin Cookbook https://github.com/vaadin/cookbook 24 | * Copyright 2020-2022 Vaadin Ltd. 25 | */ 26 | 27 | package com.flowingcode.vaadin.addons.gridhelpers; 28 | 29 | import com.vaadin.flow.component.grid.Grid; 30 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 31 | import com.vaadin.flow.data.selection.SelectionEvent; 32 | import com.vaadin.flow.function.SerializablePredicate; 33 | import com.vaadin.flow.shared.Registration; 34 | import java.io.Serializable; 35 | import java.util.Optional; 36 | import java.util.stream.Collectors; 37 | import lombok.Getter; 38 | import lombok.RequiredArgsConstructor; 39 | 40 | @SuppressWarnings("serial") 41 | @RequiredArgsConstructor 42 | class SelectionFilterHelper implements Serializable { 43 | 44 | private final GridHelper helper; 45 | 46 | private Registration selectionListenerRegistration; 47 | 48 | @Getter private SerializablePredicate selectionFilter; 49 | 50 | // holds latest selected item or null 51 | private T currentSingleSelectedItem; 52 | 53 | public void setSelectionFilter(SerializablePredicate predicate) { 54 | Optional.ofNullable(selectionListenerRegistration).ifPresent(Registration::remove); 55 | selectionListenerRegistration = null; 56 | 57 | Grid grid = helper.getGrid(); 58 | this.selectionFilter = predicate; 59 | currentSingleSelectedItem = null; 60 | if (predicate != null) { 61 | deselectIf(predicate.negate()); 62 | helper.setHelperClassNameGenerator( 63 | this.getClass(), row -> predicate.test(row) ? null : "fcGh-noselect"); 64 | selectionListenerRegistration = grid.addSelectionListener(this::onSelection); 65 | } else { 66 | helper.setHelperClassNameGenerator(this.getClass(), null); 67 | } 68 | } 69 | 70 | boolean canSelect(T item) { 71 | return selectionFilter == null || selectionFilter.test(item); 72 | } 73 | 74 | private void deselectIf(SerializablePredicate predicate) { 75 | Grid grid = helper.getGrid(); 76 | switch (GridHelper.getSelectionMode(grid)) { 77 | case MULTI: 78 | grid.asMultiSelect() 79 | .deselect( 80 | grid.asMultiSelect().getSelectedItems().stream() 81 | .filter(predicate) 82 | .collect(Collectors.toList())); 83 | break; 84 | case SINGLE: 85 | grid.asSingleSelect() 86 | .getOptionalValue() 87 | .filter(predicate) 88 | .ifPresent(x -> grid.asSingleSelect().clear()); 89 | break; 90 | default: 91 | break; 92 | } 93 | } 94 | 95 | private void onSelection(SelectionEvent, T> event) { 96 | SelectionMode currentSelectionMode = GridHelper.getSelectionMode(event.getSource()); 97 | if (event.isFromClient()) { 98 | if (SelectionMode.SINGLE.equals(currentSelectionMode)) { 99 | event.getFirstSelectedItem().ifPresent(item -> { 100 | if (canSelect(item)) { 101 | currentSingleSelectedItem = item; 102 | } else { 103 | // restore previous selected item 104 | if (currentSingleSelectedItem != null && canSelect(currentSingleSelectedItem)) { 105 | event.getSource().select(currentSingleSelectedItem); 106 | } else { 107 | event.getSource().deselect(item); 108 | currentSingleSelectedItem = null; 109 | } 110 | } 111 | }); 112 | } else if (SelectionMode.MULTI.equals(currentSelectionMode)) { 113 | event.getAllSelectedItems().forEach(item -> { 114 | // Revert selection if item cannot be selected 115 | if (!canSelect(item)) { 116 | event.getSource().deselect(item); 117 | } 118 | }); 119 | } 120 | } 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/VAADIN/package.properties: -------------------------------------------------------------------------------- 1 | vaadin.allowed-packages=com.flowingcode 2 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/connector.js: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | /* 22 | * This file incorporates work licensed under the Apache License, Version 2.0 23 | * from Vaadin Cookbook https://github.com/vaadin/cookbook 24 | * Copyright 2020-2022 Vaadin Ltd. 25 | */ 26 | 27 | import { Grid } from '@vaadin/grid/src/vaadin-grid.js'; 28 | 29 | (function () { 30 | window.Vaadin.Flow.fcGridHelperConnector = { 31 | initLazy: grid => { 32 | 33 | //https://cookbook.vaadin.com/grid-arrow-selection 34 | grid.addEventListener('keyup', function(e) { 35 | if (e.keyCode == 32) return; 36 | if (!grid._fcghArrowSelection || grid._fcghEnhancedSelection) return; 37 | if (grid.selectedItems){ 38 | grid.activeItem=grid.getEventContext(e).item; 39 | grid.selectedItems=[grid.getEventContext(e).item]; 40 | grid.$server.select(grid.getEventContext(e).item.key); 41 | } 42 | }); 43 | 44 | const __updateHorizontalScrollPosition = grid.__updateHorizontalScrollPosition.bind(grid); 45 | grid.__updateHorizontalScrollPosition = function() { 46 | __updateHorizontalScrollPosition(); 47 | this.querySelectorAll("[fcgh-footer]").forEach(footer=>{ 48 | const slot = footer.closest('vaadin-grid-cell-content').assignedSlot; 49 | if (slot) { 50 | slot.parentElement.parentElement.style.transform = `translate(${this._scrollLeft}px, 0)`; 51 | } 52 | }); 53 | }.bind(grid); 54 | 55 | grid.fcGridHelper = { 56 | setHeightByRows : function(n) { 57 | if (grid.fcGridHelper._heightByRowsObserver) { 58 | grid.fcGridHelper._heightByRowsObserver.unobserve(grid); 59 | } 60 | 61 | grid.fcGridHelper._heightByRowsObserver = new ResizeObserver(() => { 62 | grid.fcGridHelper._updateHeightByRows(n); 63 | }); 64 | 65 | grid.fcGridHelper._heightByRowsObserver.observe(grid); 66 | 67 | grid.removeEventListener('loading-changed', grid.fcGridHelper._heightByRowsListener); 68 | 69 | grid.fcGridHelper._heightByRowsListener = ()=>{ 70 | if (!grid.loading) grid.fcGridHelper._updateHeightByRows(n); 71 | }; 72 | 73 | grid.addEventListener('loading-changed', grid.fcGridHelper._heightByRowsListener); 74 | }, 75 | 76 | _updateHeightByRows : function(n) { 77 | var height = grid.fcGridHelper.computeHeightByRows(n); 78 | grid.style.setProperty('--height-by-rows',height+'px'); 79 | }, 80 | 81 | computeHeightByRows : function(n) { 82 | var height = 0; 83 | var rows = grid.shadowRoot.querySelectorAll("tbody tr"); 84 | 85 | if (rows.length>0) { 86 | for(var i=0;i { 110 | const observer = grid.fcGridHelper._resizeObserver; 111 | for (const e of entries) { 112 | let width = e.contentBoxSize[0].inlineSize; 113 | width = observer.widths.findLast(step=>step a - b); 124 | observer.unobserve(grid); 125 | 126 | if (widths.length>0) { 127 | observer.observe(grid); 128 | } else { 129 | observer.width=undefined; 130 | grid.dispatchEvent(new CustomEvent("fcgh-responsive-step", { detail: {step: -1} })); 131 | } 132 | } 133 | 134 | }; 135 | } 136 | 137 | } 138 | })(); 139 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/grid-flow-radio-selection-column.js: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | import '@vaadin/grid/vaadin-grid-column.js'; 22 | import { GridColumn } from '@vaadin/grid/src/vaadin-grid-column.js'; 23 | import { GridRadioSelectionColumnBaseMixin } from './grid-radio-selection-column-base-mixin.js'; 24 | 25 | class GridFlowRadioSelectionColumn extends GridRadioSelectionColumnBaseMixin(GridColumn) { 26 | 27 | static get is() { 28 | return 'grid-flow-radio-selection-column'; 29 | } 30 | 31 | static get properties() { 32 | return { 33 | /** 34 | * Override property to enable auto-width 35 | */ 36 | autoWidth: { 37 | type: Boolean, 38 | value: true 39 | }, 40 | 41 | /** 42 | * Override property to set custom width 43 | */ 44 | width: { 45 | type: String, 46 | value: '56px' 47 | }, 48 | 49 | /** 50 | * The previous state of activeItem. When activeItem turns to `null`, 51 | * previousActiveItem will have an Object with just unselected activeItem 52 | * @private 53 | */ 54 | __previousActiveItem: Object, 55 | }; 56 | } 57 | 58 | 59 | constructor() { 60 | super(); 61 | this.__boundOnActiveItemChanged = this.__onActiveItemChanged.bind(this); 62 | } 63 | 64 | /** @protected */ 65 | disconnectedCallback() { 66 | this._grid.removeEventListener('active-item-changed', this.__boundOnActiveItemChanged); 67 | super.disconnectedCallback(); 68 | } 69 | 70 | /** @protected */ 71 | connectedCallback() { 72 | super.connectedCallback(); 73 | if (this._grid) { 74 | this._grid.addEventListener('active-item-changed', this.__boundOnActiveItemChanged); 75 | } 76 | } 77 | 78 | /** 79 | * Override a method from `GridRadioSelectionColumnBaseMixin` to handle the user 80 | * selecting an item. 81 | * 82 | * @param {Object} item the item to select 83 | * @protected 84 | * @override 85 | */ 86 | _selectItem(item) { 87 | this._grid.$connector.doSelection([item], true); 88 | } 89 | 90 | /** 91 | * Override a method from `GridRadioSelectionColumnBaseMixin` to handle the user 92 | * deselecting an item. 93 | * 94 | * @param {Object} item the item to deselect 95 | * @protected 96 | * @override 97 | */ 98 | _deselectItem(item) { 99 | this._grid.$connector.doDeselection([item], true); 100 | } 101 | 102 | 103 | /** @private */ 104 | __onActiveItemChanged(e) { 105 | const activeItem = e.detail.value; 106 | if (activeItem) { 107 | if(this.__previousActiveItem !== activeItem) { 108 | this._deselectItem(this.__previousActiveItem); 109 | } 110 | this._selectItem(activeItem); 111 | this.__previousActiveItem = activeItem; 112 | } else { 113 | this.__previousActiveItem = undefined; 114 | } 115 | } 116 | 117 | /** 118 | * Override a method from `GridRadioSelectionColumnBaseMixin` to handle the user clicked on an item. 119 | * 120 | * @param {Object} item the clicked item 121 | * @protected 122 | * @override 123 | */ 124 | _onItemClicked(item) { 125 | super._onItemClicked(item); 126 | this.__previousActiveItem = item; 127 | } 128 | 129 | } 130 | 131 | customElements.define(GridFlowRadioSelectionColumn.is, GridFlowRadioSelectionColumn); 132 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/grid-radio-selection-column-base-mixin.js: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | import { addListener } from '@vaadin/component-base/src/gestures.js'; 22 | 23 | /** 24 | * A mixin that provides basic functionality for the 25 | * ``. This includes properties, cell rendering, 26 | * and overridable methods for handling changes to the selection state. 27 | * 28 | * **NOTE**: This mixin is re-used by the Flow component, and as such must not 29 | * implement any selection state updates for the column element or the grid. 30 | * Web component-specific selection state updates must be implemented in the 31 | * `` itself, by overriding the protected methods 32 | * provided by this mixin. 33 | * 34 | * @polymerMixin 35 | */ 36 | export const GridRadioSelectionColumnBaseMixin = (superClass) => 37 | class GriRadioSelectionColumnBaseMixin extends superClass { 38 | static get properties() { 39 | return { 40 | /** 41 | * Width of the cells for this column. 42 | */ 43 | width: { 44 | type: String, 45 | value: '58px', 46 | }, 47 | 48 | /** 49 | * Flex grow ratio for the cell widths. When set to 0, cell width is fixed. 50 | * @attr {number} flex-grow 51 | * @type {number} 52 | */ 53 | flexGrow: { 54 | type: Number, 55 | value: 0, 56 | }, 57 | 58 | /** 59 | * When true, the active gets automatically selected. 60 | * @attr {boolean} auto-select 61 | * @type {boolean} 62 | */ 63 | autoSelect: { 64 | type: Boolean, 65 | value: false, 66 | }, 67 | 68 | }; 69 | } 70 | 71 | static get observers() { 72 | return [ 73 | '_onHeaderRendererOrBindingChanged(path)', 74 | ]; 75 | } 76 | 77 | /** 78 | * Renders the Select Row radio button to the body cell. 79 | * 80 | * @override 81 | */ 82 | _defaultRenderer(root, _column, { item, selected }) { 83 | let radioButton = root.firstElementChild; 84 | if (!radioButton) { 85 | radioButton = document.createElement('vaadin-radio-button'); 86 | radioButton.setAttribute('aria-label', 'Select Row'); 87 | root.appendChild(radioButton); 88 | // Add listener after appending, so we can skip the initial change event 89 | radioButton.addEventListener('checked-changed', this.__onSelectRowCheckedChanged.bind(this)); 90 | } 91 | 92 | radioButton.__item = item; 93 | radioButton.__rendererChecked = selected; 94 | radioButton.checked = selected; 95 | } 96 | 97 | /** 98 | * Selects the row when the Select Row radio button is clicked. 99 | * The listener handles only user-fired events. 100 | * 101 | * @private 102 | */ 103 | __onSelectRowCheckedChanged(e) { 104 | // Skip if the state is changed by the renderer. 105 | if (e.target.checked === e.target.__rendererChecked) { 106 | return; 107 | } 108 | 109 | this._onItemClicked(e.target.__item); 110 | } 111 | 112 | _onItemClicked(item){ 113 | this._selectItem(item); 114 | } 115 | 116 | }; 117 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/grid-radio-selection-column-mixin.js: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | import { GridRadioSelectionColumnBaseMixin } from './grid-radio-selection-column-base-mixin.js'; 22 | 23 | /** 24 | * @polymerMixin 25 | * @mixes GridSelectionColumnBaseMixin 26 | */ 27 | export const GridRadioSelectionColumnMixin = (superClass) => 28 | class extends GridRadioSelectionColumnBaseMixin(superClass) { 29 | static get properties() { 30 | return { 31 | /** 32 | * The previous state of activeItem. When activeItem turns to `null`, 33 | * previousActiveItem will have an Object with just unselected activeItem 34 | * @private 35 | */ 36 | __previousActiveItem: Object, 37 | }; 38 | } 39 | 40 | constructor() { 41 | super(); 42 | 43 | this.__boundOnActiveItemChanged = this.__onActiveItemChanged.bind(this); 44 | this.__boundOnSelectedItemsChanged = this.__onSelectedItemsChanged.bind(this); 45 | } 46 | 47 | /** @protected */ 48 | disconnectedCallback() { 49 | this._grid.removeEventListener('active-item-changed', this.__boundOnActiveItemChanged); 50 | this._grid.removeEventListener('selected-items-changed', this.__boundOnSelectedItemsChanged); 51 | super.disconnectedCallback(); 52 | } 53 | 54 | /** @protected */ 55 | connectedCallback() { 56 | super.connectedCallback(); 57 | if (this._grid) { 58 | this._grid.addEventListener('active-item-changed', this.__boundOnActiveItemChanged); 59 | this._grid.addEventListener('selected-items-changed', this.__boundOnSelectedItemsChanged); 60 | } 61 | } 62 | 63 | /** 64 | * Override a method from `GridSelectionColumnBaseMixin` to handle the user 65 | * selecting an item. 66 | * 67 | * @param {Object} item the item to select 68 | * @protected 69 | * @override 70 | */ 71 | _selectItem(item) { 72 | this._grid.selectItem(item); 73 | } 74 | 75 | /** 76 | * Override a method from `GridSelectionColumnBaseMixin` to handle the user 77 | * deselecting an item. 78 | * 79 | * @param {Object} item the item to deselect 80 | * @protected 81 | * @override 82 | */ 83 | _deselectItem(item) { 84 | this._grid.deselectItem(item); 85 | } 86 | 87 | /** @private */ 88 | __onActiveItemChanged(e) { 89 | const activeItem = e.detail.value; 90 | this.__previousSelectionCleared = false; 91 | if (this.autoSelect && activeItem) { 92 | this._selectItem(activeItem); 93 | this.__previousActiveItem = activeItem; 94 | } 95 | } 96 | 97 | /** @private */ 98 | __onSelectedItemsChanged(e) { 99 | if(!this.__previousSelectionCleared && this.__previousActiveItem){ 100 | this.__previousSelectionCleared = true; 101 | this._deselectItem(this.__previousActiveItem); 102 | } 103 | } 104 | 105 | /** 106 | * Override a method from `GridRadioSelectionColumnBaseMixin` to handle the user clicked on an item. 107 | * 108 | * @param {Object} item the clicked item 109 | * @protected 110 | * @override 111 | */ 112 | _onItemClicked(item) { 113 | this.__previousSelectionCleared = false; 114 | super._onItemClicked(item); 115 | this.__previousActiveItem = item; 116 | } 117 | 118 | }; 119 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/grid-radio-selection-column.js: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | import '@vaadin/radio-group/vaadin-radio-button.js'; 22 | import { defineCustomElement } from '@vaadin/component-base/src/define.js'; 23 | import { GridColumn } from './vaadin-grid-column.js'; 24 | import { GridRadioSelectionColumnMixin } from './grid-radio-selection-column-mixin.js'; 25 | 26 | /** 27 | * `` is a helper element for the `` 28 | * that provides default renderers and functionality for item selection. 29 | * 30 | * #### Example: 31 | * ```html 32 | * 33 | * 34 | * 35 | * 36 | * ... 37 | * ``` 38 | * 39 | * By default the selection column displays `` elements in the 40 | * column cells. The radio button in the body rows toggle selection of the corresponding row item. 41 | * 42 | * __The default content can also be overridden__ 43 | * 44 | * @customElement 45 | * @extends GridColumn 46 | * @mixes GridSelectionColumnMixin 47 | */ 48 | class GridRadioSelectionColumn extends GridRadioSelectionColumnMixin(GridColumn) { 49 | static get is() { 50 | return 'grid-radio-selection-column'; 51 | } 52 | } 53 | 54 | defineCustomElement(GridRadioSelectionColumn); 55 | 56 | export { GridRadioSelectionColumn }; 57 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/vaadin-checkbox.css: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | :host([theme~='fcgh-checkbox-top']) .vaadin-checkbox-container [part="checkbox"] { 21 | grid-column: 1; 22 | grid-row: 1; 23 | justify-self: center; 24 | } 25 | 26 | :host([theme~='fcgh-checkbox-top']) ::slotted(input) { 27 | grid-column: 1; 28 | grid-row: 1; 29 | } 30 | 31 | :host([theme~='fcgh-checkbox-top']) .vaadin-checkbox-container ::slotted(label) { 32 | grid-column: 1; 33 | grid-row: 2; 34 | padding-inline: 0; 35 | } 36 | 37 | :host([theme~='fcgh-checkbox-bottom']) .vaadin-checkbox-container [part="checkbox"] { 38 | grid-column: 1; 39 | grid-row: 2; 40 | justify-self: center; 41 | } 42 | 43 | :host([theme~='fcgh-checkbox-bottom']) ::slotted(input) { 44 | grid-column: 1; 45 | grid-row: 2; 46 | } 47 | 48 | :host([theme~='fcgh-checkbox-bottom']) .vaadin-checkbox-container ::slotted(label) { 49 | grid-column: 1; 50 | grid-row: 1; 51 | padding-inline: 0; 52 | } 53 | 54 | :host([theme~='fcgh-checkbox-left']) .vaadin-checkbox-container [part="checkbox"], 55 | :host([theme~='fcgh-checkbox-left']) ::slotted(input) { 56 | grid-column: 1; 57 | grid-row: 1; 58 | } 59 | 60 | :host([theme~='fcgh-checkbox-left']) .vaadin-checkbox-container ::slotted(label) { 61 | grid-column: 2; 62 | grid-row: 1; 63 | } 64 | 65 | :host([theme~='fcgh-checkbox-right']) .vaadin-checkbox-container [part="checkbox"], 66 | :host([theme~='fcgh-checkbox-right']) ::slotted(input) { 67 | grid-column: 2; 68 | grid-row: 1; 69 | } 70 | 71 | :host([theme~='fcgh-checkbox-right']) .vaadin-checkbox-container ::slotted(label) { 72 | grid-column: 1; 73 | grid-row: 1; 74 | } 75 | 76 | :host([theme~='fcgh-small']) ::slotted(label) { 77 | font-size: var(--lumo-font-size-s); 78 | } 79 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/vaadin-context-menu-item.css: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | :host([theme~='gridHelperToggle'])::part(checkmark) { 21 | display: none; 22 | } 23 | 24 | :host([theme~='gridHelperToggle']) ::slotted(vaadin-checkbox) { 25 | width: 100%; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/vaadin-context-menu-list-box.css: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | :host([theme~='gridHelperToggle']) [part~="items"] ::slotted(.vaadin-menu-item) { 21 | padding: 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/vaadin-grid.css: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | /* 22 | * This file incorporates work licensed under the Apache License, Version 2.0 23 | * from Vaadin Cookbook https://github.com/vaadin/cookbook 24 | * Copyright 2020-2022 Vaadin Ltd. 25 | */ 26 | 27 | :host([theme~="fcGh-dense"]) [part~="cell"], 28 | :host([theme~="fcGh-dense"]:not([theme~='no-row-borders'])) [part~='first-row'] [part~="cell"] { 29 | min-height: var(--lumo-size-xxs); 30 | } 31 | 32 | :host([theme~="fcGh-dense"]) { 33 | font-size: var(--lumo-font-size-xs); 34 | } 35 | :host([theme~="fcGh-dense"]) [part~="cell"] ::slotted(vaadin-grid-cell-content) { 36 | padding: 1px var(--lumo-space-s); 37 | } 38 | :host([theme~="fcGh-dense"]:not([theme~="no-row-borders"])) 39 | [part="row"][first] 40 | [part~="cell"]:not([part~="details-cell"]) { 41 | border-top: 0; 42 | min-height: calc(var(--lumo-size-xxs) - var(--_lumo-grid-border-width)); 43 | } 44 | 45 | :host { 46 | --fcgh-toggle-right: 0; 47 | } 48 | 49 | :host([overflow~="right"]), :host([overflow~="left"]) { 50 | --fcgh-toggle-right: 24px; 51 | } 52 | 53 | table[aria-multiselectable="true"] .fcGh-noselect[first-column] ::slotted(*) { 54 | opacity: var(--fcgh-noselect-opacity, 0.5); 55 | pointer-events: none; 56 | } 57 | 58 | :host([theme~="hide-first-footer"]) tfoot [part="row"]:first-child { 59 | display: none; 60 | } 61 | 62 | :host([theme~="fcGh-hide-headers"]) #header { 63 | display: none; 64 | } 65 | 66 | :host([theme~="fcGh-hide-footers"]) #footer { 67 | display: none; 68 | } 69 | 70 | :host([theme~="height-by-rows"]) { 71 | height : var(--height-by-rows); 72 | max-height : var(--height-by-rows); 73 | } 74 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/vaadin-menu-bar-item.css: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | :host([theme~='gridHelperToggle'])::part(checkmark) { 21 | display: none; 22 | } 23 | 24 | :host([theme~='gridHelperToggle']) ::slotted(vaadin-checkbox) { 25 | width: 100%; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/vaadin-menu-bar-list-box.css: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | :host([theme~='gridHelperToggle']) [part~="items"] ::slotted(vaadin-menu-bar-item) { 21 | padding: 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/frontend/fcGridHelper/vaadin-menu-bar.css: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | :host([theme~="gridHelperToggle"]) { 22 | position: absolute; 23 | top: 0; 24 | right: var(--fcgh-toggle-right); 25 | height: 100%; 26 | } 27 | 28 | :host([theme~="gridHelperToggle"]) [part="container"] { 29 | vertical-align: middle; 30 | height: 100%; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/resources/static_addon_resources: -------------------------------------------------------------------------------- 1 | Place static addon resources in this folder -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/DemoLayout.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons; 22 | 23 | import com.vaadin.flow.component.html.Div; 24 | import com.vaadin.flow.router.RouterLayout; 25 | 26 | @SuppressWarnings("serial") 27 | public class DemoLayout extends Div implements RouterLayout { 28 | 29 | public DemoLayout() { 30 | setSizeFull(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/AddToolbarFooterDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.button.Button; 25 | import com.vaadin.flow.component.grid.Grid; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.component.icon.VaadinIcon; 28 | import com.vaadin.flow.component.notification.Notification; 29 | import com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode; 30 | import com.vaadin.flow.component.orderedlayout.HorizontalLayout; 31 | import com.vaadin.flow.router.PageTitle; 32 | import com.vaadin.flow.router.Route; 33 | 34 | @PageTitle("Toolbar Footer") 35 | @DemoSource 36 | @Route(value = "grid-helpers/toolbar-footer", layout = GridHelpersDemoView.class) 37 | public class AddToolbarFooterDemo extends Div { 38 | 39 | public AddToolbarFooterDemo() { 40 | setSizeFull(); 41 | 42 | Grid grid = new Grid<>(); 43 | grid.setItems(TestData.initializeData()); 44 | 45 | grid.addColumn(Person::getFirstName).setHeader("First name"); 46 | grid.addColumn(Person::getLastName).setHeader("Last name"); 47 | grid.addColumn(Person::getCountry).setHeader("Country"); 48 | 49 | HorizontalLayout hl = new HorizontalLayout(new Button(VaadinIcon.TOOLS.create(),ev->Notification.show("Not implemented"))); 50 | hl.setSizeFull(); 51 | hl.setJustifyContentMode(JustifyContentMode.END); 52 | 53 | GridHelper.addToolbarFooter(grid, hl); 54 | 55 | grid.setHeightFull(); 56 | add(grid); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/CheckboxColumnDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.flowingcode.vaadin.addons.gridhelpers.CheckboxColumn.CheckboxColumnConfiguration; 25 | import com.flowingcode.vaadin.addons.gridhelpers.CheckboxColumn.CheckboxPosition; 26 | import com.vaadin.flow.component.button.Button; 27 | import com.vaadin.flow.component.grid.Grid; 28 | import com.vaadin.flow.component.html.Span; 29 | import com.vaadin.flow.component.notification.Notification; 30 | import com.vaadin.flow.component.orderedlayout.HorizontalLayout; 31 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 32 | import com.vaadin.flow.data.provider.DataProvider; 33 | import com.vaadin.flow.router.PageTitle; 34 | import com.vaadin.flow.router.Route; 35 | 36 | @PageTitle("Checkbox Column") 37 | @DemoSource 38 | @Route(value = "grid-helpers/checkbox-column", layout = GridHelpersDemoView.class) 39 | public class CheckboxColumnDemo extends VerticalLayout { 40 | 41 | public CheckboxColumnDemo() { 42 | setSizeFull(); 43 | 44 | Span activeCount = new Span(); 45 | Span vipCount = new Span(); 46 | 47 | Grid grid = new Grid<>(); 48 | LazyTestData data = new LazyTestData(); 49 | grid.setItems(DataProvider.fromCallbacks( 50 | query -> data.filter(query.getOffset(), query.getPageSize()), query -> data.count())); 51 | 52 | grid.addColumn(Person::getFirstName).setHeader("First name"); 53 | grid.addColumn(Person::getLastName).setHeader("Last name"); 54 | CheckboxColumn activeColumn = GridHelper 55 | .addCheckboxColumn(grid, 56 | new CheckboxColumnConfiguration<>(Person::isActive) 57 | .header("Active") 58 | .checkboxPosition(CheckboxPosition.LEFT) 59 | .selectAllCheckboxVisible(true)) 60 | .checkboxClickListener((item, 61 | checked) -> Notification.show(item.getFirstName() + " " + item.getLastName() 62 | + " " + (checked ? "checked" : "unchecked"))) 63 | .checkedCountListener(count -> activeCount.setText("Active count: " + count)); 64 | GridHelper 65 | .addCheckboxColumn(grid, 66 | new CheckboxColumnConfiguration<>(Person::isVip) 67 | .header("VIP")) 68 | .checkboxClickListener((item, checked) -> Notification 69 | .show(item.getFirstName() + " " + item.getLastName() 70 | + " " + (checked ? "checked" : "unchecked"))) 71 | .checkedCountListener(count -> vipCount.setText("VIP count: " + count)); 72 | GridHelper 73 | .addCheckboxColumn(grid, 74 | new CheckboxColumnConfiguration<>(Person::isHidden) 75 | .header("Hidden") 76 | .readOnly(true)); 77 | 78 | grid.setSizeFull(); 79 | 80 | Button toggleVipColumn = new Button("Refresh grid data"); 81 | toggleVipColumn.addClickListener(e -> { 82 | LazyTestData newData = new LazyTestData(); 83 | grid.setItems(DataProvider.fromCallbacks( 84 | query -> newData.filter(query.getOffset(), query.getPageSize()), 85 | query -> newData.count())); 86 | activeColumn.refresh(); 87 | }); 88 | 89 | add(grid, toggleVipColumn, new HorizontalLayout(activeCount, vipCount)); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/ColumnToggleMenuDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.grid.Grid.Column; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.component.notification.Notification; 28 | import com.vaadin.flow.router.PageTitle; 29 | import com.vaadin.flow.router.Route; 30 | 31 | @PageTitle("Column Toggle Menu") 32 | @DemoSource 33 | @Route(value = "grid-helpers/column-toggle-menu", layout = GridHelpersDemoView.class) 34 | public class ColumnToggleMenuDemo extends Div { 35 | 36 | public ColumnToggleMenuDemo() { 37 | setSizeFull(); 38 | 39 | Grid grid = new Grid<>(); 40 | grid.setItems(TestData.initializeData()); 41 | 42 | Column firstNameColumn = grid.addColumn(Person::getFirstName).setHeader("First name"); 43 | Column lastNameColumn = grid.addColumn(Person::getLastName).setHeader("Last name"); 44 | Column countryColumn = grid.addColumn(Person::getCountry).setHeader("Country"); 45 | 46 | GridHelper.setHidingToggleCaption(firstNameColumn, "First name"); 47 | GridHelper.setHidingToggleCaption(lastNameColumn, "Last name"); 48 | GridHelper.setHidingToggleCaption(countryColumn, "Country"); 49 | 50 | GridHelper.setColumnToggleVisible(grid, isVisible()); 51 | 52 | GridHelper.addColumnToggleListener(grid, ev -> { 53 | String caption = GridHelper.getHidingToggleCaption(ev.getColumn()); 54 | String message = caption + " is now " + (ev.getColumn().isVisible() ? "visible" : "invisible"); 55 | new Notification(message).open(); 56 | }); 57 | 58 | grid.setHeightFull(); 59 | add(grid); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/DemoView.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 24 | import com.vaadin.flow.router.BeforeEnterEvent; 25 | import com.vaadin.flow.router.BeforeEnterObserver; 26 | import com.vaadin.flow.router.Route; 27 | 28 | @SuppressWarnings("serial") 29 | @Route("") 30 | public class DemoView extends VerticalLayout implements BeforeEnterObserver { 31 | 32 | @Override 33 | public void beforeEnter(BeforeEnterEvent event) { 34 | event.forwardTo(GridHelpersDemoView.class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/DenseThemeDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.router.PageTitle; 28 | import com.vaadin.flow.router.Route; 29 | 30 | @PageTitle("Dense Theme") 31 | @DemoSource 32 | @Route(value = "grid-helpers/dense-theme", layout = GridHelpersDemoView.class) 33 | public class DenseThemeDemo extends Div { 34 | 35 | public DenseThemeDemo() { 36 | setSizeFull(); 37 | 38 | Grid grid = new Grid<>(); 39 | grid.setItems(TestData.initializeData()); 40 | 41 | grid.setSelectionMode(SelectionMode.SINGLE); 42 | 43 | grid.addColumn(Person::getFirstName).setHeader("First name"); 44 | grid.addColumn(Person::getLastName).setHeader("Last name"); 45 | grid.addColumn(Person::getCountry).setHeader("Country"); 46 | 47 | grid.addThemeName(GridHelper.DENSE_THEME); 48 | 49 | grid.setHeightFull(); 50 | add(grid); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/EmptyGridLabelDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.flowingcode.vaadin.addons.gridhelpers.LazyTestData.PersonFilter; 25 | import com.vaadin.flow.component.Key; 26 | import com.vaadin.flow.component.Text; 27 | import com.vaadin.flow.component.button.Button; 28 | import com.vaadin.flow.component.formlayout.FormLayout; 29 | import com.vaadin.flow.component.formlayout.FormLayout.ResponsiveStep; 30 | import com.vaadin.flow.component.grid.Grid; 31 | import com.vaadin.flow.component.html.Div; 32 | import com.vaadin.flow.component.html.H3; 33 | import com.vaadin.flow.component.orderedlayout.HorizontalLayout; 34 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 35 | import com.vaadin.flow.component.textfield.TextField; 36 | import com.vaadin.flow.data.provider.DataProvider; 37 | import com.vaadin.flow.data.provider.Query; 38 | import com.vaadin.flow.router.PageTitle; 39 | import com.vaadin.flow.router.Route; 40 | import java.util.function.Function; 41 | 42 | @PageTitle("Empty Grid Label") 43 | @DemoSource 44 | @Route(value = "grid-helpers/empty-grid-label", layout = GridHelpersDemoView.class) 45 | public class EmptyGridLabelDemo extends VerticalLayout { 46 | 47 | public EmptyGridLabelDemo() { 48 | LazyTestData data = new LazyTestData(); 49 | 50 | setSpacing(false); 51 | setPadding(false); 52 | setSizeFull(); 53 | 54 | TextField firstName = new TextField("Firstname"); 55 | TextField lastName = new TextField("Lastname"); 56 | 57 | Function, PersonFilter> filterBuilder = query -> { 58 | PersonFilter filter = query.getFilter().orElse(new PersonFilter()); 59 | filter.setFirstName(firstName.getValue()); 60 | filter.setLastName(lastName.getValue()); 61 | return filter; 62 | }; 63 | 64 | DataProvider dataProvider = DataProvider.fromFilteringCallbacks( 65 | query -> data.filter(query.getOffset(), query.getPageSize(), filterBuilder.apply(query)), 66 | query -> data.count(filterBuilder.apply(query))); 67 | 68 | Grid grid = new Grid<>(); 69 | grid.setDataProvider(dataProvider); 70 | grid.addColumn(Person::getFirstName).setHeader("First name"); 71 | grid.addColumn(Person::getLastName).setHeader("Last name"); 72 | grid.addColumn(Person::getCountry).setHeader("Country"); 73 | grid.setSizeFull(); 74 | 75 | Div emptyGridLabel = new Div(new Text("No records found")); 76 | emptyGridLabel.setSizeFull(); 77 | emptyGridLabel.addClassName("empty-grid-label"); 78 | emptyGridLabel.setVisible(false); 79 | GridHelper.setEmptyGridLabel(grid, emptyGridLabel); 80 | 81 | Button filterButton = new Button("Filter"); 82 | filterButton.addClickShortcut(Key.ENTER); 83 | filterButton.addClickListener(e -> dataProvider.refreshAll()); 84 | 85 | Div gridContainer = new Div(grid, emptyGridLabel); 86 | gridContainer.getStyle().set("position", "relative"); 87 | gridContainer.setSizeFull(); 88 | 89 | FormLayout filtersForm = new FormLayout(firstName, lastName); 90 | filtersForm.setResponsiveSteps(new ResponsiveStep("0", 2)); 91 | filtersForm.setWidthFull(); 92 | 93 | HorizontalLayout filters = new HorizontalLayout(filtersForm, filterButton); 94 | filters.setAlignItems(Alignment.END); 95 | filters.setWidthFull(); 96 | filters.getStyle().set("padding-right", "4px"); 97 | 98 | add(filters, gridContainer); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/EnableArrowSelectionDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.router.PageTitle; 28 | import com.vaadin.flow.router.Route; 29 | 30 | @PageTitle("Enable Arrow Selection") 31 | @DemoSource 32 | @Route(value = "grid-helpers/enable-arrow-selection", layout = GridHelpersDemoView.class) 33 | public class EnableArrowSelectionDemo extends Div { 34 | 35 | public EnableArrowSelectionDemo() { 36 | setSizeFull(); 37 | 38 | Grid grid = new Grid<>(); 39 | grid.setItems(TestData.initializeData()); 40 | 41 | grid.setSelectionMode(SelectionMode.SINGLE); 42 | 43 | grid.addColumn(Person::getFirstName).setHeader("First name"); 44 | grid.addColumn(Person::getLastName).setHeader("Last name"); 45 | grid.addColumn(Person::getCountry).setHeader("Country"); 46 | 47 | GridHelper.setArrowSelectionEnabled(grid, true); 48 | 49 | grid.setHeightFull(); 50 | add(grid); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/EnableEnhancedSelectionDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.router.PageTitle; 28 | import com.vaadin.flow.router.Route; 29 | 30 | @PageTitle("Enable Enhanced Selection") 31 | @DemoSource 32 | @Route(value = "grid-helpers/enable-enhanced-selection", layout = GridHelpersDemoView.class) 33 | public class EnableEnhancedSelectionDemo extends Div { 34 | 35 | public EnableEnhancedSelectionDemo() { 36 | setSizeFull(); 37 | 38 | Grid grid = new Grid<>(); 39 | grid.setItems(TestData.initializeData()); 40 | 41 | grid.setSelectionMode(SelectionMode.MULTI); 42 | 43 | grid.addColumn(Person::getFirstName).setHeader("First name"); 44 | grid.addColumn(Person::getLastName).setHeader("Last name"); 45 | grid.addColumn(Person::getCountry).setHeader("Country"); 46 | 47 | GridHelper.setEnhancedSelectionEnabled(grid, true); 48 | 49 | grid.setHeightFull(); 50 | add(grid); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/EnableSelectionOnClickDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.router.PageTitle; 28 | import com.vaadin.flow.router.Route; 29 | 30 | @PageTitle("Row Selection On Click") 31 | @DemoSource 32 | @Route(value = "grid-helpers/row-selection-on-click", layout = GridHelpersDemoView.class) 33 | public class EnableSelectionOnClickDemo extends Div { 34 | 35 | public EnableSelectionOnClickDemo() { 36 | setSizeFull(); 37 | 38 | Grid grid = new Grid<>(); 39 | grid.setItems(TestData.initializeData()); 40 | 41 | grid.setSelectionMode(SelectionMode.MULTI); 42 | 43 | grid.addColumn(Person::getFirstName).setHeader("First name"); 44 | grid.addColumn(Person::getLastName).setHeader("Last name"); 45 | grid.addColumn(Person::getCountry).setHeader("Country"); 46 | 47 | GridHelper.setSelectOnClick(grid, true); 48 | 49 | grid.setHeightFull(); 50 | add(grid); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/FreezeSelectionColumnDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.router.PageTitle; 28 | import com.vaadin.flow.router.Route; 29 | 30 | @PageTitle("Freeze Selection Column") 31 | @DemoSource 32 | @Route(value = "grid-helpers/freeze-selection-column", layout = GridHelpersDemoView.class) 33 | public class FreezeSelectionColumnDemo extends Div { 34 | 35 | public FreezeSelectionColumnDemo() { 36 | setSizeFull(); 37 | 38 | Grid grid = new Grid<>(); 39 | grid.setItems(TestData.initializeData()); 40 | 41 | grid.setSelectionMode(SelectionMode.MULTI); 42 | 43 | grid.addColumn(Person::getFirstName).setHeader("First name"); 44 | grid.addColumn(Person::getLastName).setHeader("Last name"); 45 | grid.addColumn(Person::getTitle).setHeader("Title"); 46 | grid.addColumn(Person::getCountry).setHeader("Country"); 47 | grid.addColumn(Person::getCity).setHeader("City"); 48 | grid.addColumn(Person::getStreetAddress).setHeader("Street Address"); 49 | grid.addColumn(Person::getPhoneNumber).setHeader("Phone Number"); 50 | grid.getColumns().forEach(c -> c.setAutoWidth(true)); 51 | 52 | GridHelper.setSelectionColumnFrozen(grid, true); 53 | 54 | grid.setHeightFull(); 55 | add(grid); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/GetHeaderFooterDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers; 21 | 22 | import com.flowingcode.vaadin.addons.demo.DemoSource; 23 | import com.vaadin.flow.component.button.Button; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.grid.Grid.Column; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.component.icon.VaadinIcon; 28 | import com.vaadin.flow.component.notification.Notification; 29 | import com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode; 30 | import com.vaadin.flow.component.orderedlayout.HorizontalLayout; 31 | import com.vaadin.flow.router.PageTitle; 32 | import com.vaadin.flow.router.Route; 33 | 34 | @PageTitle("Get Header or Footer") 35 | @DemoSource 36 | @Route(value = "grid-helpers/get-header-or-footer", layout = GridHelpersDemoView.class) 37 | public class GetHeaderFooterDemo extends Div { 38 | 39 | public GetHeaderFooterDemo() { 40 | setSizeFull(); 41 | 42 | Grid grid = new Grid<>(); 43 | grid.setItems(TestData.initializeData()); 44 | 45 | Column firstName = grid.addColumn(Person::getFirstName).setHeader("First name").setFooter("First name footer"); 46 | Column lastName = grid.addColumn(Person::getLastName).setHeader("Last name").setFooter("Last name footer");; 47 | Column country = grid.addColumn(Person::getCountry).setHeader("Country").setFooter("Country footer");; 48 | 49 | HorizontalLayout hl = new HorizontalLayout(new Button(VaadinIcon.TOOLS.create(),ev->Notification.show("Not implemented"))); 50 | hl.setSizeFull(); 51 | hl.setJustifyContentMode(JustifyContentMode.END); 52 | 53 | Button getHeaders = new Button("Obtain headers", ev->Notification.show( 54 | "Header text column 1: " + GridHelper.getHeader(grid,firstName) + 55 | ", Header text column 2: " + GridHelper.getHeader(grid,lastName) + 56 | ", Header text column 3: " + GridHelper.getHeader(grid,country))); 57 | Button getFooters = new Button("Obtain footers", ev->Notification.show( 58 | "Footer text column 1: " + GridHelper.getFooter(grid,firstName) + 59 | ", Footer text column 2: " + GridHelper.getFooter(grid,lastName) + 60 | ", Footer text column 3: " + GridHelper.getFooter(grid,country))); 61 | 62 | grid.setHeightFull(); 63 | add(grid, getHeaders, getFooters); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelpersDemoView.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.DemoLayout; 24 | import com.flowingcode.vaadin.addons.GithubLink; 25 | import com.flowingcode.vaadin.addons.demo.TabbedDemo; 26 | import com.vaadin.flow.component.dependency.StyleSheet; 27 | import com.vaadin.flow.router.ParentLayout; 28 | import com.vaadin.flow.router.Route; 29 | 30 | @SuppressWarnings("serial") 31 | @ParentLayout(DemoLayout.class) 32 | @Route("grid-helpers") 33 | @GithubLink("https://github.com/FlowingCode/GridHelpers") 34 | @StyleSheet("context://gridhelpers/styles.css") 35 | public class GridHelpersDemoView extends TabbedDemo { 36 | 37 | public GridHelpersDemoView() { 38 | setSizeFull(); 39 | addDemo(AllFeaturesDemo.class); 40 | addDemo(ColumnToggleMenuDemo.class); 41 | addDemo(HeightByRowsDemo.class); 42 | addDemo(HideSelectionColumnDemo.class); 43 | addDemo(FreezeSelectionColumnDemo.class); 44 | addDemo(EnableArrowSelectionDemo.class); 45 | addDemo(EnableSelectionOnClickDemo.class); 46 | addDemo(EnableEnhancedSelectionDemo.class); 47 | addDemo(SelectionFilterDemo.class); 48 | addDemo(DenseThemeDemo.class); 49 | addDemo(LombokDemo.class); 50 | addDemo(AddToolbarFooterDemo.class); 51 | addDemo(GetHeaderFooterDemo.class); 52 | addDemo(LazyMultiSelectionDemo.class); 53 | addDemo(CheckboxColumnDemo.class); 54 | addDemo(EmptyGridLabelDemo.class); 55 | addDemo(GridRadioSelectionColumnDemo.class); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/GridRadioSelectionColumnDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.grid.GridSingleSelectionModel; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 28 | import com.vaadin.flow.data.provider.DataProvider; 29 | import com.vaadin.flow.router.PageTitle; 30 | import com.vaadin.flow.router.Route; 31 | 32 | @PageTitle("Radio Selection Column") 33 | @DemoSource 34 | @Route(value = "grid-helpers/radio-selection-column", layout = GridHelpersDemoView.class) 35 | public class GridRadioSelectionColumnDemo extends VerticalLayout { 36 | 37 | Div selection = new Div(); 38 | 39 | public GridRadioSelectionColumnDemo() { 40 | setSizeFull(); 41 | 42 | Grid grid = new Grid<>(); 43 | LazyTestData data = new LazyTestData(); 44 | grid.setItems(DataProvider.fromCallbacks( 45 | query -> data.filter(query.getOffset(), query.getPageSize()), query -> data.count())); 46 | 47 | grid.addColumn(Person::getFirstName).setHeader("First name"); 48 | grid.addColumn(Person::getLastName).setHeader("Last name"); 49 | grid.addColumn(Person::getPhoneNumber).setHeader("Phone"); 50 | 51 | GridHelper.showRadioSelectionColumn(grid).setFrozen(true); 52 | 53 | grid.setSizeFull(); 54 | ((GridSingleSelectionModel) grid.getSelectionModel()).setDeselectAllowed(false); 55 | grid.asSingleSelect().addValueChangeListener(e -> { 56 | if (e.getValue() != null) { 57 | selection.setText( 58 | "Selected row: " + e.getValue().getFirstName() + " " + e.getValue().getLastName()); 59 | } 60 | }); 61 | 62 | add(grid, selection); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/HeightByRowsDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.html.Div; 26 | import com.vaadin.flow.router.PageTitle; 27 | import com.vaadin.flow.router.Route; 28 | 29 | @PageTitle("Height By Rows") 30 | @DemoSource 31 | @Route(value = "grid-helpers/height-by-rows", layout = GridHelpersDemoView.class) 32 | public class HeightByRowsDemo extends Div { 33 | 34 | public HeightByRowsDemo() { 35 | setSizeFull(); 36 | 37 | Grid grid = new Grid<>(); 38 | grid.setItems(TestData.initializeData()); 39 | 40 | grid.addColumn(Person::getFirstName).setHeader("First name"); 41 | grid.addColumn(Person::getLastName).setHeader("Last name"); 42 | grid.addColumn(Person::getCountry).setHeader("Country"); 43 | 44 | GridHelper.setHeightMode(grid, HeightMode.ROW); 45 | GridHelper.setHeightByRows(grid, 7); 46 | 47 | add(grid); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/HideSelectionColumnDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.router.PageTitle; 28 | import com.vaadin.flow.router.Route; 29 | 30 | @PageTitle("Hide Selection Column") 31 | @DemoSource 32 | @Route(value = "grid-helpers/hide-selection-column", layout = GridHelpersDemoView.class) 33 | public class HideSelectionColumnDemo extends Div { 34 | 35 | public HideSelectionColumnDemo() { 36 | setSizeFull(); 37 | 38 | Grid grid = new Grid<>(); 39 | grid.setItems(TestData.initializeData()); 40 | 41 | grid.setSelectionMode(SelectionMode.MULTI); 42 | 43 | grid.addColumn(Person::getFirstName).setHeader("First name"); 44 | grid.addColumn(Person::getLastName).setHeader("Last name"); 45 | grid.addColumn(Person::getCountry).setHeader("Country"); 46 | 47 | GridHelper.setSelectionColumnHidden(grid, true); 48 | 49 | grid.setHeightFull(); 50 | add(grid); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/LazyMultiSelectionDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.checkbox.Checkbox; 25 | import com.vaadin.flow.component.grid.Grid; 26 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 27 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 28 | import com.vaadin.flow.data.provider.DataProvider; 29 | import com.vaadin.flow.router.PageTitle; 30 | import com.vaadin.flow.router.Route; 31 | 32 | @PageTitle("Lazy Multi Selection") 33 | @DemoSource 34 | @Route(value = "grid-helpers/lazy-multi-selection", layout = GridHelpersDemoView.class) 35 | public class LazyMultiSelectionDemo extends VerticalLayout { 36 | 37 | public LazyMultiSelectionDemo() { 38 | setSizeFull(); 39 | 40 | Grid grid = new Grid<>(); 41 | LazyTestData data = new LazyTestData(); 42 | grid.setItems(DataProvider.fromCallbacks( 43 | query -> data.filter(query.getOffset(), query.getPageSize()), query -> data.count())); 44 | 45 | grid.setSelectionMode(SelectionMode.MULTI); 46 | 47 | grid.addColumn(Person::getFirstName).setHeader("First name"); 48 | grid.addColumn(Person::getLastName).setHeader("Last name"); 49 | grid.addColumn(Person::getCountry).setHeader("Country"); 50 | 51 | grid.setSizeFull(); 52 | 53 | Checkbox toggleSelectAllCheckbox = new Checkbox("Show Select All checkbox"); 54 | toggleSelectAllCheckbox.setValue(false); 55 | toggleSelectAllCheckbox 56 | .addValueChangeListener(e -> GridHelper.toggleSelectAllCheckbox(grid, e.getValue())); 57 | 58 | add(grid, toggleSelectAllCheckbox); 59 | setFlexGrow(1, grid); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/LazyTestData.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.github.javafaker.Faker; 24 | import java.io.Serializable; 25 | import java.util.List; 26 | import java.util.stream.Collectors; 27 | import java.util.stream.Stream; 28 | import lombok.Getter; 29 | import lombok.Setter; 30 | import org.apache.commons.lang3.StringUtils; 31 | 32 | @SuppressWarnings("serial") 33 | class LazyTestData implements Serializable { 34 | 35 | private static final Faker faker = new Faker(); 36 | 37 | private static synchronized Person newPerson() { 38 | return Person.builder() 39 | .active(faker.random().nextBoolean()) 40 | .vip(faker.random().nextBoolean()) 41 | .hidden(faker.random().nextBoolean()) 42 | .firstName(faker.name().firstName()) 43 | .lastName(faker.name().lastName()) 44 | .country(generateCountry()) 45 | .city(faker.address().city()) 46 | .streetAddress(faker.address().streetAddress()) 47 | .phoneNumber(faker.phoneNumber().cellPhone()) 48 | .emailAddress(faker.internet().emailAddress()) 49 | .title(faker.name().title()) 50 | .build(); 51 | } 52 | 53 | private final List data; 54 | 55 | public LazyTestData() { 56 | data = Stream.generate(LazyTestData::newPerson).limit(400).collect(Collectors.toList()); 57 | } 58 | 59 | public Stream filter(int offset, int pageSize) { 60 | return filter(offset, pageSize, null); 61 | } 62 | 63 | public Stream filter(int offset, int pageSize, PersonFilter filter) { 64 | int from = Math.max(0, offset); 65 | if (filter != null) { 66 | return data.stream() 67 | .filter( 68 | item -> StringUtils.containsIgnoreCase(item.getFirstName(), filter.getFirstName())) 69 | .filter(item -> StringUtils.containsIgnoreCase(item.getLastName(), filter.getLastName())) 70 | .skip(from) 71 | .limit(pageSize); 72 | } 73 | return data.stream().skip(from).limit(pageSize); 74 | } 75 | 76 | public int count() { 77 | return data.size(); 78 | } 79 | 80 | public int count(PersonFilter filter) { 81 | return (int) data.stream() 82 | .filter(item -> StringUtils.containsIgnoreCase(item.getFirstName(), filter.getFirstName())) 83 | .filter(item -> StringUtils.containsIgnoreCase(item.getLastName(), filter.getLastName())) 84 | .count(); 85 | } 86 | 87 | private static String generateCountry() { 88 | String country = faker.address().country(); 89 | if (country.contains("South Georgia") || country.contains("Falkland")) { 90 | return "Argentina"; 91 | } else { 92 | return country; 93 | } 94 | } 95 | 96 | @Getter 97 | @Setter 98 | public static class PersonFilter { 99 | private String firstName; 100 | private String lastName; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/LombokDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.router.PageTitle; 28 | import com.vaadin.flow.router.Route; 29 | 30 | import lombok.experimental.ExtensionMethod; 31 | 32 | @PageTitle("Using Lombok") 33 | @DemoSource 34 | @Route(value = "grid-helpers/lombok-demo", layout = GridHelpersDemoView.class) 35 | @ExtensionMethod(GridHelper.class) 36 | public class LombokDemo extends Div { 37 | 38 | public LombokDemo() { 39 | setSizeFull(); 40 | 41 | Grid grid = new Grid<>(); 42 | grid.setItems(TestData.initializeData()); 43 | 44 | grid.setSelectionMode(SelectionMode.MULTI); 45 | 46 | grid.addColumn(Person::getFirstName) 47 | .setHeader("First name") 48 | .setHidingToggleCaption("First name"); 49 | grid.addColumn(Person::getLastName).setHeader("Last name").setHidingToggleCaption("Last name"); 50 | grid.addColumn(p -> p.isActive() ? "Yes" : "No").setHeader("Active"); 51 | grid.addColumn(Person::getTitle).setHeader("Title"); 52 | grid.addColumn(Person::getCountry).setHeader("Country"); 53 | grid.addColumn(Person::getCity).setHeader("City"); 54 | grid.addColumn(Person::getStreetAddress).setHeader("Street Address"); 55 | grid.getColumns().forEach(c -> c.setAutoWidth(true)); 56 | 57 | grid.setColumnToggleVisible(true); 58 | grid.setSelectionColumnFrozen(true); 59 | grid.setSelectOnClick(true); 60 | grid.setSelectionFilter(Person::isActive); 61 | 62 | grid.setHeightFull(); 63 | add(grid); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/Person.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import java.io.Serializable; 24 | import lombok.AccessLevel; 25 | import lombok.AllArgsConstructor; 26 | import lombok.Builder; 27 | import lombok.EqualsAndHashCode; 28 | import lombok.Getter; 29 | import lombok.Setter; 30 | import lombok.experimental.FieldDefaults; 31 | import lombok.experimental.NonFinal; 32 | 33 | @SuppressWarnings("serial") 34 | @Getter 35 | @AllArgsConstructor 36 | @FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) 37 | @EqualsAndHashCode 38 | @Builder 39 | public class Person implements Serializable { 40 | @Setter 41 | @NonFinal 42 | boolean active; 43 | @Setter 44 | @NonFinal 45 | boolean vip; 46 | @Setter 47 | @NonFinal 48 | boolean hidden; 49 | String firstName; 50 | String lastName; 51 | String country; 52 | String city; 53 | String streetAddress; 54 | String emailAddress; 55 | String phoneNumber; 56 | String title; 57 | 58 | @Override 59 | public String toString() { 60 | return firstName+" "+lastName+" - active: "+active; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/SelectionFilterDemo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.flowingcode.vaadin.addons.demo.DemoSource; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 26 | import com.vaadin.flow.component.html.Div; 27 | import com.vaadin.flow.router.PageTitle; 28 | import com.vaadin.flow.router.Route; 29 | 30 | @PageTitle("Selection Filter") 31 | @DemoSource 32 | @Route(value = "grid-helpers/selection-filter", layout = GridHelpersDemoView.class) 33 | public class SelectionFilterDemo extends Div { 34 | 35 | public SelectionFilterDemo() { 36 | setSizeFull(); 37 | 38 | Grid grid = new Grid<>(); 39 | grid.setItems(TestData.initializeData()); 40 | 41 | grid.setSelectionMode(SelectionMode.MULTI); 42 | 43 | grid.addColumn(Person::getFirstName).setHeader("First name"); 44 | grid.addColumn(Person::getLastName).setHeader("Last name"); 45 | grid.addColumn(p -> p.isActive() ? "Yes" : "No").setHeader("Active"); 46 | 47 | GridHelper.setSelectionFilter(grid, Person::isActive); 48 | 49 | grid.setHeightFull(); 50 | add(grid); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/TestData.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers; 22 | 23 | import com.github.javafaker.Faker; 24 | import java.util.List; 25 | import java.util.stream.Collectors; 26 | import java.util.stream.Stream; 27 | 28 | public class TestData { 29 | 30 | private static final Faker faker = new Faker(); 31 | 32 | private static synchronized Person newPerson() { 33 | return Person.builder() 34 | .active(faker.random().nextBoolean()) 35 | .vip(faker.random().nextBoolean()) 36 | .hidden(faker.random().nextBoolean()) 37 | .firstName(faker.name().firstName()) 38 | .lastName(faker.name().lastName()) 39 | .country(generateCountry()) 40 | .city(faker.address().city()) 41 | .streetAddress(faker.address().streetAddress()) 42 | .phoneNumber(faker.phoneNumber().cellPhone()) 43 | .emailAddress(faker.internet().emailAddress()) 44 | .title(faker.name().title()) 45 | .build(); 46 | } 47 | 48 | public static List initializeData() { 49 | return Stream.generate(TestData::newPerson).limit(40).collect(Collectors.toList()); 50 | } 51 | 52 | private static String generateCountry() { 53 | String country = faker.address().country(); 54 | if (country.contains("South Georgia") || country.contains("Falkland")) { 55 | return "Argentina"; 56 | } else { 57 | return country; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/AbstractViewTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers.it; 22 | 23 | import com.vaadin.testbench.ScreenshotOnFailureRule; 24 | import com.vaadin.testbench.TestBench; 25 | import com.vaadin.testbench.parallel.ParallelTest; 26 | import io.github.bonigarcia.wdm.WebDriverManager; 27 | import org.junit.Before; 28 | import org.junit.BeforeClass; 29 | import org.junit.Rule; 30 | import org.openqa.selenium.chrome.ChromeDriver; 31 | 32 | /** 33 | * Base class for ITs 34 | * 35 | *

The tests use Chrome driver (see pom.xml for integration-tests profile) to run integration 36 | * tests on a headless Chrome. If a property {@code test.use .hub} is set to true, {@code 37 | * AbstractViewTest} will assume that the TestBench test is running in a CI environment. In order to 38 | * keep the this class light, it makes certain assumptions about the CI environment (such as 39 | * available environment variables). It is not advisable to use this class as a base class for you 40 | * own TestBench tests. 41 | * 42 | *

To learn more about TestBench, visit Vaadin TestBench. 44 | */ 45 | public abstract class AbstractViewTest extends ParallelTest { 46 | private static final int SERVER_PORT = 8080; 47 | 48 | private final String route; 49 | 50 | @Rule public ScreenshotOnFailureRule rule = new ScreenshotOnFailureRule(this, true); 51 | 52 | public AbstractViewTest() { 53 | this(""); 54 | } 55 | 56 | protected AbstractViewTest(String route) { 57 | this.route = route; 58 | } 59 | 60 | @BeforeClass 61 | public static void setupClass() { 62 | WebDriverManager.chromedriver().setup(); 63 | } 64 | 65 | @Override 66 | @Before 67 | public void setup() throws Exception { 68 | if (isUsingHub()) { 69 | super.setup(); 70 | } else { 71 | setDriver(TestBench.createDriver(new ChromeDriver())); 72 | } 73 | getDriver().get(getURL(route)); 74 | } 75 | 76 | /** 77 | * Returns deployment host name concatenated with route. 78 | * 79 | * @return URL to route 80 | */ 81 | private static String getURL(String route) { 82 | return String.format("http://%s:%d/%s", getDeploymentHostname(), SERVER_PORT, route); 83 | } 84 | 85 | /** Property set to true when running on a test hub. */ 86 | private static final String USE_HUB_PROPERTY = "test.use.hub"; 87 | 88 | /** 89 | * Returns whether we are using a test hub. This means that the starter is running tests in 90 | * Vaadin's CI environment, and uses TestBench to connect to the testing hub. 91 | * 92 | * @return whether we are using a test hub 93 | */ 94 | private static boolean isUsingHub() { 95 | return Boolean.TRUE.toString().equals(System.getProperty(USE_HUB_PROPERTY)); 96 | } 97 | 98 | /** 99 | * If running on CI, get the host name from environment variable HOSTNAME 100 | * 101 | * @return the host name 102 | */ 103 | private static String getDeploymentHostname() { 104 | return isUsingHub() ? System.getenv("HOSTNAME") : "localhost"; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/ColumnToggleIT.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers.it; 22 | 23 | import static org.hamcrest.MatcherAssert.assertThat; 24 | import static org.hamcrest.Matchers.hasSize; 25 | import static org.junit.Assert.assertEquals; 26 | import static org.junit.Assert.assertNotNull; 27 | import static org.junit.Assert.assertNull; 28 | import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport; 29 | import com.vaadin.flow.component.grid.testbench.GridElement; 30 | import org.junit.Test; 31 | 32 | public class ColumnToggleIT extends AbstractViewTest implements HasRpcSupport { 33 | 34 | IntegrationViewCallables $server = createCallableProxy(IntegrationViewCallables.class); 35 | GridHelperElement grid; 36 | 37 | public ColumnToggleIT() { 38 | super("it"); 39 | } 40 | 41 | @Override 42 | public void setup() throws Exception { 43 | super.setup(); 44 | grid = new GridHelperElement($(GridElement.class).waitForFirst()); 45 | } 46 | 47 | @Test 48 | public void testColumnToggleVisible() { 49 | int nColumns = grid.getVisibleColumns().size(); 50 | assertNull("ColumnToggle should be absent", grid.getColumnToggleButton()); 51 | 52 | $server.setColumnToggleVisible(true); 53 | assertNotNull("ColumnToggle should be present", grid.getColumnToggleButton()); 54 | assertThat(grid.getVisibleColumns(), hasSize(nColumns + 1)); 55 | 56 | $server.setColumnToggleVisible(false); 57 | assertNull("ColumnToggle should be absent", grid.getColumnToggleButton()); 58 | assertThat(grid.getVisibleColumns(), hasSize(nColumns)); 59 | } 60 | 61 | @Test 62 | public void testColumnToggleClick() { 63 | int nColumns = grid.getVisibleColumns().size(); 64 | 65 | $server.setColumnToggleVisible(true); 66 | grid.getColumnToggleButton().click(); 67 | 68 | // the toggle is rendered in its own column 69 | assertThat(grid.getColumnToggleElements(), hasSize(nColumns)); 70 | assertThat(grid.getVisibleColumns(), hasSize(++nColumns)); 71 | 72 | grid.getColumnToggleElements().get(0).setChecked(false); 73 | assertThat(grid.getVisibleColumns(), hasSize(nColumns - 1)); 74 | 75 | grid.getColumnToggleElements().get(0).setChecked(true); 76 | assertThat(grid.getVisibleColumns(), hasSize(nColumns)); 77 | } 78 | 79 | @Test 80 | public void testColumnToggleListener() { 81 | $server.setColumnToggleVisible(true); 82 | assertNull($server.getToggledColumn()); 83 | 84 | grid.getColumnToggleButton().click(); 85 | 86 | grid.getColumnToggleElements().get(0).setChecked(false); 87 | assertEquals((Integer) 0, $server.getToggledColumn()); 88 | 89 | grid.getColumnToggleElements().get(1).setChecked(false); 90 | assertEquals((Integer) 1, $server.getToggledColumn()); 91 | 92 | grid.getColumnToggleElements().get(0).setChecked(true); 93 | assertEquals((Integer) 0, $server.getToggledColumn()); 94 | } 95 | 96 | 97 | @Test 98 | public void testColumnHidable() { 99 | int nColumns = grid.getVisibleColumns().size(); 100 | $server.setColumnToggleVisible(true); 101 | $server.setHidable(0, true); 102 | 103 | grid.getColumnToggleButton().click(); 104 | assertThat(grid.getColumnToggleElements(), hasSize(nColumns)); 105 | 106 | $server.setHidable(0, false); 107 | grid.getColumnToggleButton().click(); 108 | assertThat(grid.getColumnToggleElements(), hasSize(nColumns - 1)); 109 | } 110 | 111 | @Test 112 | public void testHidingToggleCaption() { 113 | String caption = "caption"; 114 | $server.setHidingToggleCaption(0, caption); 115 | $server.setColumnToggleVisible(true); 116 | grid.getColumnToggleButton().click(); 117 | assertEquals(caption, grid.getColumnToggleElements().get(0).getLabel()); 118 | } 119 | 120 | @Test 121 | public void testCustomHidingToggleCaption() { 122 | String caption = "HidingToggleCaption"; 123 | $server.setHidingToggleCaption(0, caption); 124 | $server.setColumnToggleVisible(true); 125 | grid.getColumnToggleButton().click(); 126 | assertEquals(caption, grid.getColumnToggleElements().get(0).getLabel()); 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/EmptyLabelIT.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers.it; 22 | 23 | import static org.junit.Assert.assertFalse; 24 | import static org.junit.Assert.assertTrue; 25 | import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport; 26 | import com.vaadin.flow.component.grid.testbench.GridElement; 27 | import org.junit.Test; 28 | import org.openqa.selenium.By; 29 | 30 | public class EmptyLabelIT extends AbstractViewTest implements HasRpcSupport { 31 | 32 | IntegrationViewCallables $server = createCallableProxy(IntegrationViewCallables.class); 33 | GridHelperElement grid; 34 | 35 | public EmptyLabelIT() { 36 | super("it"); 37 | } 38 | 39 | @Override 40 | public void setup() throws Exception { 41 | super.setup(); 42 | grid = new GridHelperElement($(GridElement.class).waitForFirst()); 43 | } 44 | 45 | private boolean findByText(String text) { 46 | return findElements(By.xpath(String.format("//*[text()='%s']", text))).stream().findFirst() 47 | .isPresent(); 48 | } 49 | 50 | @Test 51 | public void testEmptyGridLabel() { 52 | String label = "EmptyGridLabel"; 53 | $server.setEmptyGridLabel(label); 54 | 55 | // assert that label is not shown 56 | assertFalse("Label must not be visible", findByText(label)); 57 | 58 | $server.removeAllItems(); 59 | 60 | // assert that label is shown 61 | assertTrue("Label must be visible", findByText(label)); 62 | } 63 | 64 | @Test 65 | public void replaceEmptyGridLabel() { 66 | String label1 = "EmptyGridLabel1"; 67 | String label2 = "EmptyGridLabel2"; 68 | $server.setEmptyGridLabel(label1); 69 | $server.setEmptyGridLabel(label2); 70 | $server.removeAllItems(); 71 | 72 | // assert that only the second label is shown 73 | assertFalse("Label 1 must not be visible", findByText(label1)); 74 | assertTrue("Label 2 must be visible", findByText(label2)); 75 | 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/FooterToolbarIT.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers.it; 22 | 23 | import static org.junit.Assert.assertEquals; 24 | import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport; 25 | import com.vaadin.flow.component.grid.testbench.GridElement; 26 | import org.junit.Test; 27 | 28 | public class FooterToolbarIT extends AbstractViewTest implements HasRpcSupport { 29 | 30 | IntegrationViewCallables $server = createCallableProxy(IntegrationViewCallables.class); 31 | GridHelperElement grid; 32 | 33 | public FooterToolbarIT() { 34 | super("it"); 35 | } 36 | 37 | @Override 38 | public void setup() throws Exception { 39 | super.setup(); 40 | grid = new GridHelperElement($(GridElement.class).waitForFirst()); 41 | } 42 | 43 | @Test 44 | public void testToolbarFooter() { 45 | String footer = "footer"; 46 | $server.addToolbarFooter(footer); 47 | assertEquals(footer, grid.getToolbarFooter().getText()); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/GridHelperElement.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.it; 21 | 22 | import com.vaadin.flow.component.checkbox.testbench.CheckboxElement; 23 | import com.vaadin.flow.component.grid.testbench.GridElement; 24 | import com.vaadin.flow.component.menubar.testbench.MenuBarElement; 25 | import com.vaadin.testbench.ElementQuery; 26 | import com.vaadin.testbench.TestBenchElement; 27 | import java.util.Arrays; 28 | import java.util.Collections; 29 | import java.util.List; 30 | import java.util.NoSuchElementException; 31 | import java.util.Optional; 32 | import org.openqa.selenium.By; 33 | import org.openqa.selenium.TimeoutException; 34 | import org.openqa.selenium.WebElement; 35 | 36 | public class GridHelperElement extends MyGridElement { 37 | 38 | public GridHelperElement(GridElement e) { 39 | init(e.getWrappedElement(), e.getCommandExecutor()); 40 | } 41 | 42 | @Override 43 | public Object executeScript(String script, Object... arguments) { 44 | script = String.format( 45 | "return function(arguments){arguments.pop(); %s}.bind(arguments[arguments.length-1])([].slice.call(arguments))", 46 | script); 47 | arguments = Arrays.copyOf(arguments, arguments.length + 1); 48 | arguments[arguments.length - 1] = this; 49 | return getCommandExecutor().executeScript(script, arguments); 50 | } 51 | 52 | private MenuBarElement getMenuBar() { 53 | return $(MenuBarElement.class).waitForFirst(0); 54 | } 55 | 56 | public TestBenchElement getColumnToggleButton() { 57 | try { 58 | return getMenuBar().getButtons().get(0); 59 | } catch (TimeoutException e) { 60 | return null; 61 | } 62 | } 63 | 64 | public List getColumnToggleElements() { 65 | try { 66 | return new ElementQuery<>(TestBenchElement.class, 67 | "vaadin-context-menu-overlay, vaadin-menu-bar-overlay") 68 | .context(getDriver()) 69 | .waitForFirst(100) 70 | .$(CheckboxElement.class).all(); 71 | } catch (NoSuchElementException e) { 72 | return Collections.emptyList(); 73 | } 74 | } 75 | 76 | public TestBenchElement getToolbarFooter() { 77 | List elements = findElements(By.cssSelector("[fcgh-footer]")); 78 | return (TestBenchElement) elements.stream().findFirst().orElse(null); 79 | } 80 | 81 | public TestBenchElement getSelectionCheckbox(int rowIndex) { 82 | // assumes that Grid is in multi-selection mode 83 | TestBenchElement cell = getSlottedCell(getRow(rowIndex)); 84 | List elements = cell.findElements(By.tagName("vaadin-checkbox")); 85 | return (TestBenchElement) elements.stream().findFirst().orElse(null); 86 | } 87 | 88 | public TestBenchElement getSelectionRadioButton(int rowIndex) { 89 | // assumes that Grid is in single-selection mode 90 | TestBenchElement cell = getSlottedCell(getRow(rowIndex)); 91 | List elements = cell.findElements(By.tagName("vaadin-radio-button")); 92 | return (TestBenchElement) elements.stream().findFirst().orElse(null); 93 | } 94 | 95 | 96 | private TestBenchElement getSlottedCell(WebElement e) { 97 | String slot = e.findElement(By.tagName("slot")).getAttribute("name"); 98 | return findElement(By.cssSelector(String.format("[slot='%s']", slot))); 99 | } 100 | 101 | public boolean hasColumn(String headerText) { 102 | return getVisibleColumns().stream() 103 | .filter(column -> headerText.equals(column.getHeaderCell().getText())).findFirst() 104 | .isPresent(); 105 | } 106 | 107 | @Override 108 | public int getFirstVisibleRowIndex() { 109 | Long result = (Long) executeScript("return this._firstVisibleIndex"); 110 | return Optional.ofNullable(result).orElse(0L).intValue(); 111 | } 112 | 113 | @Override 114 | public int getLastVisibleRowIndex() { 115 | Long result = (Long) executeScript("return this._lastVisibleIndex"); 116 | return Optional.ofNullable(result).orElse(-1L).intValue(); 117 | } 118 | 119 | public Object getVisibleRowsCount() { 120 | return getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1; 121 | } 122 | 123 | public int getOffsetHeight() { 124 | return ((Long) executeScript("return this.offsetHeight")).intValue(); 125 | } 126 | 127 | public String getHeightByRowsSize() { 128 | return (String) executeScript("return this.style.getPropertyValue('--height-by-rows')"); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/GridRadioSelectionColumnIT.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers.it; 22 | 23 | import static java.time.temporal.ChronoUnit.SECONDS; 24 | import static org.hamcrest.MatcherAssert.assertThat; 25 | import static org.hamcrest.Matchers.contains; 26 | import static org.hamcrest.Matchers.empty; 27 | import static org.junit.Assert.assertFalse; 28 | import static org.junit.Assert.assertNotNull; 29 | import static org.junit.Assert.assertNull; 30 | import static org.junit.Assert.assertTrue; 31 | import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport; 32 | import com.vaadin.flow.component.grid.testbench.GridElement; 33 | import com.vaadin.testbench.TestBenchElement; 34 | import java.time.Duration; 35 | import org.junit.Test; 36 | import org.openqa.selenium.By; 37 | import org.openqa.selenium.support.ui.ExpectedConditions; 38 | import org.openqa.selenium.support.ui.WebDriverWait; 39 | 40 | public class GridRadioSelectionColumnIT extends AbstractViewTest implements HasRpcSupport { 41 | 42 | IntegrationViewCallables $server = createCallableProxy(IntegrationViewCallables.class); 43 | GridHelperElement grid; 44 | 45 | public GridRadioSelectionColumnIT() { 46 | super("it"); 47 | } 48 | 49 | @Override 50 | public void setup() throws Exception { 51 | super.setup(); 52 | grid = new GridHelperElement($(GridElement.class).waitForFirst()); 53 | } 54 | 55 | @Test 56 | public void testRadioSelectionColumnShown() { 57 | // assert that the first column is not the one with radio button 58 | assertNull("the first column has radio buttons", grid.getSelectionRadioButton(0)); 59 | 60 | $server.showRadioSelectionColumn(); 61 | 62 | waitUntil(ExpectedConditions 63 | .presenceOfElementLocated(By.tagName("grid-flow-radio-selection-column"))); 64 | 65 | // assert that the first column is the one with radio buttons 66 | assertNotNull("the first column has not any radio buttons", grid.getSelectionRadioButton(0)); 67 | } 68 | 69 | @Test 70 | public void testShouldSelectRowOnClick() { 71 | $server.showRadioSelectionColumn(); 72 | 73 | waitUntil(ExpectedConditions 74 | .presenceOfElementLocated(By.tagName("grid-flow-radio-selection-column"))); 75 | 76 | assertThat($server.getSelectedRows(), empty()); 77 | 78 | grid.getCell(0, 1).click(); 79 | assertThat($server.getSelectedRows(), contains(0)); 80 | 81 | grid.getCell(4, 1).click(); 82 | assertThat($server.getSelectedRows(), contains(4)); 83 | } 84 | 85 | @Test 86 | public void testShouldSelectRowOnRadioButtonClick() { 87 | $server.showRadioSelectionColumn(); 88 | 89 | waitUntil(ExpectedConditions 90 | .presenceOfElementLocated(By.tagName("grid-flow-radio-selection-column"))); 91 | 92 | 93 | assertThat($server.getSelectedRows(), empty()); 94 | 95 | TestBenchElement radioButton = grid.getSelectionRadioButton(0); 96 | radioButton.click(); 97 | assertThat($server.getSelectedRows(), contains(0)); 98 | 99 | 100 | radioButton = grid.getSelectionRadioButton(4); 101 | radioButton.click(); 102 | assertThat($server.getSelectedRows(), contains(4)); 103 | } 104 | 105 | @Test 106 | public void testRadioSelectionColumnFrozen() { 107 | $server.showRadioSelectionColumn(); 108 | 109 | waitUntil(ExpectedConditions 110 | .presenceOfElementLocated(By.tagName("grid-flow-radio-selection-column"))); 111 | 112 | TestBenchElement selectionColElement = grid.$("grid-flow-radio-selection-column").first(); 113 | 114 | String frozen = "return arguments[0].frozen"; 115 | 116 | 117 | new WebDriverWait(getDriver(), Duration.of(2, SECONDS)) 118 | .until(ExpectedConditions.attributeContains(selectionColElement, "frozen", "false")); 119 | 120 | // assert that the selection column is not frozen by default 121 | assertFalse("Selection column is frozen", (Boolean) executeScript(frozen, selectionColElement)); 122 | 123 | // make selection column frozen 124 | selectionColElement.setProperty("frozen", true); 125 | 126 | new WebDriverWait(getDriver(), Duration.of(2, SECONDS)) 127 | .until(ExpectedConditions.attributeContains(selectionColElement, "frozen", "true")); 128 | 129 | // assert that the selection column is now frozen 130 | assertTrue("Selection column is not frozen", 131 | (Boolean) executeScript(frozen, selectionColElement)); 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/HeaderFooterVisibilityIT.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.it; 21 | 22 | import static java.time.temporal.ChronoUnit.SECONDS; 23 | import static org.junit.Assert.assertTrue; 24 | import static org.openqa.selenium.support.ui.ExpectedConditions.invisibilityOf; 25 | import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf; 26 | import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport; 27 | import com.vaadin.flow.component.grid.testbench.GridElement; 28 | import com.vaadin.testbench.TestBenchElement; 29 | import java.time.Duration; 30 | import org.junit.Test; 31 | import org.openqa.selenium.support.ui.WebDriverWait; 32 | 33 | public class HeaderFooterVisibilityIT extends AbstractViewTest implements HasRpcSupport { 34 | 35 | IntegrationViewCallables $server = createCallableProxy(IntegrationViewCallables.class); 36 | 37 | GridHelperElement grid; 38 | 39 | public HeaderFooterVisibilityIT() { 40 | super("it"); 41 | } 42 | 43 | @Override 44 | public void setup() throws Exception { 45 | super.setup(); 46 | grid = new GridHelperElement($(GridElement.class).waitForFirst()); 47 | } 48 | 49 | @Test 50 | public void testHeaderVisible() { 51 | TestBenchElement thead = grid.$("thead").first(); 52 | assertTrue(thead.isDisplayed()); 53 | $server.setHeaderVisible(false); 54 | new WebDriverWait(getDriver(), Duration.of(2, SECONDS)).until(invisibilityOf(thead)); 55 | } 56 | 57 | @Test 58 | public void testFooterVisible() { 59 | $server.addToolbarFooter("footer"); 60 | TestBenchElement tfoot = grid.$("tfoot").first(); 61 | new WebDriverWait(getDriver(), Duration.of(2, SECONDS)).until(visibilityOf(tfoot)); 62 | $server.setFooterVisible(false); 63 | new WebDriverWait(getDriver(), Duration.of(2, SECONDS)).until(invisibilityOf(tfoot)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/HeightByRowsIT.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.it; 21 | 22 | import static com.flowingcode.vaadin.addons.gridhelpers.it.HeightByRowsITView.EMPTY; 23 | import static com.flowingcode.vaadin.addons.gridhelpers.it.HeightByRowsITView.FULLSIZE; 24 | import static org.junit.Assert.assertEquals; 25 | import com.flowingcode.vaadin.addons.gridhelpers.HeightMode; 26 | import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport; 27 | import com.vaadin.flow.component.grid.testbench.GridElement; 28 | import java.util.stream.Collectors; 29 | import java.util.stream.Stream; 30 | import org.junit.Test; 31 | 32 | public class HeightByRowsIT extends AbstractViewTest implements HasRpcSupport { 33 | 34 | private static int ROWS = 10; 35 | 36 | HeightByRowsITViewCallables $server = createCallableProxy(HeightByRowsITViewCallables.class); 37 | 38 | GridHelperElement grid; 39 | 40 | public HeightByRowsIT() { 41 | super(HeightByRowsITView.ROUTE); 42 | } 43 | 44 | private void open(Object... args) { 45 | if (grid != null) { 46 | throw new IllegalStateException(); 47 | } 48 | String params = Stream.of(args).map(Object::toString).collect(Collectors.joining(";")); 49 | getDriver().get(getDriver().getCurrentUrl() + "/" + params); 50 | grid = new GridHelperElement($(GridElement.class).waitForFirst()); 51 | $server.roundtrip(); 52 | } 53 | 54 | @Override 55 | public void setup() throws Exception { 56 | super.setup(); 57 | } 58 | 59 | @Test 60 | public void testOpenWithItemsDefaultSize() { 61 | open(ROWS); 62 | assertEquals(ROWS, grid.getVisibleRowsCount()); 63 | assertEquals(ROWS, $server.getHeightByRows(), 0); 64 | assertEquals(HeightMode.ROW, $server.getHeightMode()); 65 | assertEquals(453, grid.getOffsetHeight()); 66 | assertEquals("453px", grid.getHeightByRowsSize()); 67 | } 68 | 69 | @Test 70 | public void testOpenWithItemsFullSize() { 71 | open(ROWS, FULLSIZE); 72 | assertEquals(ROWS, grid.getVisibleRowsCount()); 73 | assertEquals(ROWS, $server.getHeightByRows(), 0); 74 | assertEquals(HeightMode.ROW, $server.getHeightMode()); 75 | assertEquals(453, grid.getOffsetHeight()); 76 | assertEquals("453px", grid.getHeightByRowsSize()); 77 | } 78 | 79 | @Test 80 | public void testOpenEmptyDefaultSize() { 81 | open(ROWS, EMPTY); 82 | assertEquals(0, grid.getVisibleRowsCount()); 83 | assertEquals(ROWS, $server.getHeightByRows(), 0); 84 | assertEquals(HeightMode.ROW, $server.getHeightMode()); 85 | assertEquals(94, grid.getOffsetHeight()); 86 | assertEquals("94px", grid.getHeightByRowsSize()); 87 | } 88 | 89 | @Test 90 | public void testOpenEmptyFullSize() { 91 | open(ROWS, EMPTY, FULLSIZE); 92 | assertEquals(0, grid.getVisibleRowsCount()); 93 | assertEquals(ROWS, $server.getHeightByRows(), 0); 94 | assertEquals(HeightMode.ROW, $server.getHeightMode()); 95 | assertEquals(94, grid.getOffsetHeight()); 96 | assertEquals("94px", grid.getHeightByRowsSize()); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/HeightByRowsITView.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.it; 21 | 22 | import com.flowingcode.vaadin.addons.gridhelpers.GridHelper; 23 | import com.flowingcode.vaadin.addons.gridhelpers.HeightMode; 24 | import com.vaadin.flow.component.ClientCallable; 25 | import com.vaadin.flow.component.grid.Grid; 26 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 27 | import com.vaadin.flow.router.BeforeEvent; 28 | import com.vaadin.flow.router.HasUrlParameter; 29 | import com.vaadin.flow.router.OptionalParameter; 30 | import com.vaadin.flow.router.Route; 31 | import elemental.json.JsonObject; 32 | import elemental.json.JsonValue; 33 | import java.util.Arrays; 34 | import java.util.List; 35 | import java.util.stream.IntStream; 36 | import lombok.experimental.ExtensionMethod; 37 | 38 | @ExtensionMethod(GridHelper.class) 39 | @Route(HeightByRowsITView.ROUTE) 40 | public class HeightByRowsITView extends VerticalLayout 41 | implements HeightByRowsITViewCallables, HasUrlParameter { 42 | 43 | public static final String ROUTE = "it/height-by-rows"; 44 | 45 | public static final String EMPTY = "empty"; 46 | 47 | public static final String FULLSIZE = "fullsize"; 48 | 49 | public static final String NO_COLUMNS = "nocolumns"; 50 | 51 | private Grid grid; 52 | 53 | @Override 54 | public void setParameter(BeforeEvent event, @OptionalParameter String parameter) { 55 | removeAll(); 56 | 57 | if (parameter == null) { 58 | return; 59 | } 60 | 61 | List params = Arrays.asList(parameter.split(";")); 62 | 63 | if (params.contains(FULLSIZE)) { 64 | setSizeFull(); 65 | } 66 | 67 | grid = new Grid<>(); 68 | 69 | if (!params.contains(NO_COLUMNS)) { 70 | grid.addColumn(x -> x).setHeader("Header").setFooter("Footer"); 71 | } 72 | 73 | if (!params.contains(EMPTY)) { 74 | grid.setItems(IntStream.range(1, 100).mapToObj(Integer::valueOf).toArray(Integer[]::new)); 75 | } 76 | 77 | params.stream() 78 | .filter(s -> s.matches("\\d+")) 79 | .findFirst().map(Integer::valueOf) 80 | .ifPresent(rows -> { 81 | grid.setHeightMode(HeightMode.ROW); 82 | grid.setHeightByRows(rows); 83 | }); 84 | 85 | add(grid); 86 | } 87 | 88 | @Override 89 | @ClientCallable 90 | public JsonValue $call(JsonObject invocation) { 91 | return HeightByRowsITViewCallables.super.$call(invocation); 92 | } 93 | 94 | @Override 95 | public HeightMode getHeightMode() { 96 | return grid.getHeightMode(); 97 | } 98 | 99 | @Override 100 | public void setHeightMode(HeightMode row) { 101 | grid.setHeightMode(row); 102 | } 103 | 104 | @Override 105 | public double getHeightByRows() { 106 | return grid.getHeightByRows(); 107 | } 108 | 109 | @Override 110 | public void setHeightByRows(int rows) { 111 | grid.setHeightByRows(rows); 112 | } 113 | 114 | @Override 115 | public void roundtrip() { 116 | // do nothing 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/HeightByRowsITViewCallables.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.it; 21 | 22 | import com.flowingcode.vaadin.addons.gridhelpers.HeightMode; 23 | import com.flowingcode.vaadin.testbench.rpc.RmiCallable; 24 | 25 | public interface HeightByRowsITViewCallables extends RmiCallable { 26 | 27 | double getHeightByRows(); 28 | 29 | void setHeightByRows(int heightByRows); 30 | 31 | HeightMode getHeightMode(); 32 | 33 | void setHeightMode(HeightMode row); 34 | 35 | void roundtrip(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/IntegrationView.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.it; 21 | 22 | import com.flowingcode.vaadin.addons.gridhelpers.GridHelper; 23 | import com.flowingcode.vaadin.addons.gridhelpers.GridRadioSelectionColumn; 24 | import com.flowingcode.vaadin.addons.gridhelpers.Person; 25 | import com.flowingcode.vaadin.addons.gridhelpers.TestData; 26 | import com.flowingcode.vaadin.testbench.rpc.JsonArrayList; 27 | import com.vaadin.flow.component.ClientCallable; 28 | import com.vaadin.flow.component.grid.Grid; 29 | import com.vaadin.flow.component.grid.Grid.Column; 30 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 31 | import com.vaadin.flow.component.html.Div; 32 | import com.vaadin.flow.component.html.Span; 33 | import com.vaadin.flow.data.provider.ListDataProvider; 34 | import com.vaadin.flow.router.Route; 35 | import elemental.json.JsonObject; 36 | import elemental.json.JsonValue; 37 | import java.util.List; 38 | import java.util.stream.Collectors; 39 | import lombok.Getter; 40 | import lombok.experimental.ExtensionMethod; 41 | 42 | @SuppressWarnings("serial") 43 | @Route("it") 44 | @ExtensionMethod(GridHelper.class) 45 | public class IntegrationView extends Div implements IntegrationViewCallables { 46 | 47 | private Grid grid; 48 | 49 | @Getter 50 | private Integer toggledColumn; 51 | 52 | public IntegrationView() { 53 | setSizeFull(); 54 | 55 | getElement().getStyle().set("flex-grow", "1"); 56 | 57 | grid = new Grid<>(); 58 | 59 | grid.addColumn(Person::getLastName).setHeader("Last name"); 60 | grid.addColumn(Person::getFirstName).setHeader("First name"); 61 | grid.addColumn(p -> p.isActive() ? "Yes" : "No").setHeader("Active"); 62 | grid.addColumn(Person::getTitle).setHeader("Title"); 63 | grid.addColumn(Person::getCountry).setHeader("Country"); 64 | grid.addColumn(Person::getCity).setHeader("City"); 65 | grid.addColumn(Person::getStreetAddress).setHeader("Street Address"); 66 | grid.addColumn(Person::getPhoneNumber).setHeader("Phone Number"); 67 | grid.addColumn(Person::getEmailAddress).setHeader("Email Address"); 68 | grid.getColumns().forEach(c -> c.setAutoWidth(true)); 69 | grid.getColumns().forEach(c -> c.setHidable(true)); 70 | 71 | grid.setItems(TestData.initializeData()); 72 | grid.addColumnToggleListener(ev -> { 73 | toggledColumn = grid.getColumns().indexOf(ev.getColumn()); 74 | }); 75 | 76 | add(grid); 77 | } 78 | 79 | @Override 80 | @ClientCallable 81 | public JsonValue $call(JsonObject invocation) { 82 | return IntegrationViewCallables.super.$call(invocation); 83 | } 84 | 85 | private List getItems() { 86 | return grid.getListDataView().getItems().collect(Collectors.toList()); 87 | } 88 | 89 | @Override 90 | public void setColumnToggleVisible(boolean value) { 91 | grid.setColumnToggleVisible(value); 92 | } 93 | 94 | @Override 95 | public void setSelectOnClick(boolean value) { 96 | grid.setSelectOnClick(value); 97 | } 98 | 99 | @Override 100 | public void setSelectionMode(SelectionMode selectionMode) { 101 | grid.setSelectionMode(selectionMode); 102 | } 103 | 104 | @Override 105 | public JsonArrayList getSelectedRows() { 106 | List items = getItems(); 107 | return JsonArrayList.fromIntegers( 108 | grid.getSelectedItems().stream().map(items::indexOf).sorted() 109 | .collect(Collectors.toList())); 110 | } 111 | 112 | @Override 113 | public void setHidable(int columnIndex, boolean hidable) { 114 | Column column = grid.getColumns().get(columnIndex); 115 | column.setHidable(hidable); 116 | } 117 | 118 | @Override 119 | public void setSelectionFilterEnabled(boolean enabled) { 120 | if (enabled) { 121 | List items = getItems(); 122 | grid.setSelectionFilter(item -> items.indexOf(item) % 2 == 0); 123 | } else { 124 | grid.setSelectionFilter(null); 125 | } 126 | } 127 | 128 | @Override 129 | public void setColumnHeader(int i, String header) { 130 | grid.getColumns().get(i).setHeader(header); 131 | } 132 | 133 | @Override 134 | public void setHidingToggleCaption(int i, String header) { 135 | Grid.Column col = grid.getColumns().get(i); 136 | GridHelper.setHidingToggleCaption(col, header); 137 | } 138 | 139 | @Override 140 | public void setEmptyGridLabel(String label) { 141 | Span span = new Span(label); 142 | span.setVisible(false); 143 | add(span); 144 | grid.setEmptyGridLabel(span); 145 | } 146 | 147 | @Override 148 | public void setSelectionColumnHidden(boolean b) { 149 | grid.setSelectionColumnHidden(b); 150 | } 151 | 152 | @Override 153 | public void setSelectionColumnFrozen(boolean b) { 154 | grid.setSelectionColumnFrozen(b); 155 | } 156 | 157 | @Override 158 | public void setArrowSelectionEnabled(boolean b) { 159 | grid.setArrowSelectionEnabled(b); 160 | } 161 | 162 | @Override 163 | public void addToolbarFooter(String footer) { 164 | grid.addToolbarFooter(new Span(footer)); 165 | } 166 | 167 | @Override 168 | public void removeAllItems() { 169 | ((ListDataProvider) grid.getDataProvider()).getItems().clear(); 170 | grid.getDataProvider().refreshAll(); 171 | } 172 | 173 | @Override 174 | public void setHeaderVisible(boolean visible) { 175 | grid.setHeaderVisible(visible); 176 | } 177 | 178 | @Override 179 | public void setFooterVisible(boolean visible) { 180 | grid.setFooterVisible(visible); 181 | } 182 | 183 | @Override 184 | public void showRadioSelectionColumn() { 185 | grid.showRadioSelectionColumn(); 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/IntegrationViewCallables.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.it; 21 | 22 | import com.flowingcode.vaadin.testbench.rpc.JsonArrayList; 23 | import com.flowingcode.vaadin.testbench.rpc.RmiCallable; 24 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 25 | 26 | public interface IntegrationViewCallables extends RmiCallable { 27 | 28 | void setColumnToggleVisible(boolean value); 29 | 30 | void setSelectOnClick(boolean value); 31 | 32 | void setSelectionMode(SelectionMode selectionMode); 33 | 34 | JsonArrayList getSelectedRows(); 35 | 36 | Integer getToggledColumn(); 37 | 38 | void setHidable(int columnIndex, boolean hidable); 39 | 40 | void setSelectionFilterEnabled(boolean enabled); 41 | 42 | void setColumnHeader(int i, String header); 43 | 44 | void setHidingToggleCaption(int i, String header); 45 | 46 | void setEmptyGridLabel(String label); 47 | 48 | void setSelectionColumnHidden(boolean b); 49 | 50 | void setSelectionColumnFrozen(boolean b); 51 | 52 | void setArrowSelectionEnabled(boolean b); 53 | 54 | void addToolbarFooter(String footer); 55 | 56 | void removeAllItems(); 57 | 58 | void setHeaderVisible(boolean visible); 59 | 60 | void setFooterVisible(boolean visible); 61 | 62 | void showRadioSelectionColumn(); 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/MyGridElement.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.it; 21 | 22 | import com.vaadin.flow.component.grid.testbench.GridElement; 23 | import com.vaadin.flow.component.grid.testbench.GridTRElement; 24 | import com.vaadin.testbench.TestBenchElement; 25 | 26 | /* 27 | * Workaround for bug https://github.com/vaadin/flow-components/issues/1598 28 | */ 29 | public class MyGridElement extends GridElement { 30 | 31 | @Override 32 | public void select(int rowIndex) { 33 | if (isMultiselect()) { 34 | // call @ClientCallable Grid.select() on server-side which will fire the selection event. 35 | GridTRElement row = getRow(rowIndex); 36 | executeScript("arguments[0].$server.select(arguments[1]._item.key)", this, row); 37 | } else { 38 | super.select(rowIndex); 39 | } 40 | } 41 | 42 | private boolean isMultiselect() { 43 | return (boolean) executeScript( 44 | "return arguments[0]._getColumns().filter(function(col) { return typeof col.selectAll != 'undefined';}).length > 0", 45 | this); 46 | } 47 | 48 | public void deselectAll() { 49 | TestBenchElement selectionCol = $("vaadin-grid-flow-selection-column").first(); 50 | executeScript("arguments[0].$server.deselectAll()", selectionCol); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/ResponsiveGridIT.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers.it; 22 | 23 | import static org.junit.Assert.assertEquals; 24 | import static org.junit.Assert.assertTrue; 25 | import com.flowingcode.vaadin.addons.gridhelpers.it.ResponsiveGridITViewCallables.IListenerRegistration; 26 | import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport; 27 | import com.vaadin.flow.component.grid.testbench.GridElement; 28 | import org.junit.Test; 29 | 30 | public class ResponsiveGridIT extends AbstractViewTest implements HasRpcSupport { 31 | 32 | ResponsiveGridITViewCallables $server = createCallableProxy(ResponsiveGridITViewCallables.class); 33 | GridHelperElement grid; 34 | 35 | public ResponsiveGridIT() { 36 | super(ResponsiveGridITView.ROUTE); 37 | } 38 | 39 | @Override 40 | public void setup() throws Exception { 41 | super.setup(); 42 | grid = new GridHelperElement($(GridElement.class).waitForFirst()); 43 | setWidth(500); 44 | } 45 | 46 | private void setWidth(int w) { 47 | executeScript("arguments[0].parentElement.style.width=" + w + "+'px';", grid); 48 | $server.roundtrip(); 49 | try { 50 | Thread.sleep(100); 51 | } catch (InterruptedException e) { 52 | return; 53 | } 54 | } 55 | 56 | @Test 57 | public void testCreateResponsiveStep() { 58 | $server.responsiveStep(300); 59 | $server.roundtrip(); 60 | assertEquals(300, $server.getCurrentStep()); 61 | } 62 | 63 | @Test 64 | public void testHide() { 65 | $server.responsiveStep(0).hide(0); 66 | $server.roundtrip(); 67 | assertTrue(!grid.hasColumn("Col 0")); 68 | } 69 | 70 | @Test 71 | public void testHideAll() throws InterruptedException { 72 | $server.responsiveStep(0).hideAll(); 73 | $server.roundtrip(); 74 | Thread.sleep(100); 75 | assertTrue(grid.getVisibleColumns().isEmpty()); 76 | } 77 | 78 | @Test 79 | public void testShow() { 80 | $server.responsiveStep(0).hide(0); 81 | $server.roundtrip(); 82 | assertTrue(!grid.hasColumn("Col 0")); 83 | 84 | $server.responsiveStep(100).show(0); 85 | $server.roundtrip(); 86 | assertTrue(grid.hasColumn("Col 0")); 87 | } 88 | 89 | @Test 90 | public void testShowAll() { 91 | $server.responsiveStep(0).hide(0); 92 | $server.roundtrip(); 93 | assertTrue(!grid.hasColumn("Col 0")); 94 | 95 | $server.responsiveStep(100).showAll(); 96 | $server.roundtrip(); 97 | assertTrue(grid.hasColumn("Col 0")); 98 | } 99 | 100 | @Test 101 | public void testRemove() throws InterruptedException { 102 | $server.responsiveStep(300); 103 | $server.responsiveStep(400); 104 | $server.roundtrip(); 105 | Thread.sleep(100); 106 | assertEquals(400, $server.getCurrentStep()); 107 | 108 | $server.responsiveStep(400).remove(); 109 | $server.roundtrip(); 110 | Thread.sleep(100); 111 | assertEquals(300, $server.getCurrentStep()); 112 | } 113 | 114 | @Test 115 | public void testAddListenerFireImmediately() { 116 | IListenerRegistration listener = $server.responsiveStep(200).addListener(); 117 | $server.roundtrip(); 118 | assertEquals(1, listener.getCount()); 119 | assertEquals(200, listener.getLastMinWidth()); 120 | } 121 | 122 | @Test 123 | public void testAddListenerAndResize() { 124 | setWidth(200); 125 | IListenerRegistration listener = $server.responsiveStep(300).addListener(); 126 | assertEquals(0, listener.getCount()); 127 | setWidth(400); 128 | $server.roundtrip(); 129 | assertEquals(1, listener.getCount()); 130 | assertEquals(300, listener.getLastMinWidth()); 131 | } 132 | 133 | @Test 134 | public void testListenerRemove() { 135 | setWidth(200); 136 | IListenerRegistration listener = $server.responsiveStep(300).addListener(); 137 | listener.remove(); 138 | setWidth(400); 139 | $server.roundtrip(); 140 | assertEquals(0, listener.getCount()); 141 | assertEquals(-1, listener.getLastMinWidth()); 142 | } 143 | 144 | @Test 145 | public void testListenerCumulative() throws InterruptedException { 146 | setWidth(200); 147 | IListenerRegistration listener = $server.responsiveStep(300).addListener(); 148 | $server.responsiveStep(400); 149 | listener.cumulative(); 150 | 151 | setWidth(500); 152 | $server.roundtrip(); 153 | assertEquals(1, listener.getCount()); 154 | assertEquals(400, listener.getLastMinWidth()); 155 | } 156 | 157 | @Test 158 | public void testListenerCumulativeFireImmediately() { 159 | $server.responsiveStep(300).addListener(); 160 | IListenerRegistration listener = $server.responsiveStep(200).addListener(); 161 | assertEquals(0, listener.getCount()); 162 | 163 | listener.cumulative(); 164 | assertEquals(1, listener.getCount()); 165 | assertEquals(300, listener.getLastMinWidth()); 166 | } 167 | 168 | 169 | } 170 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/ResponsiveGridITView.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.it; 21 | 22 | import com.flowingcode.vaadin.addons.gridhelpers.GridHelper; 23 | import com.flowingcode.vaadin.addons.gridhelpers.GridResponsiveStep; 24 | import com.flowingcode.vaadin.addons.gridhelpers.GridResponsiveStep.GridResponsiveStepListenerRegistration; 25 | import com.vaadin.flow.component.ClientCallable; 26 | import com.vaadin.flow.component.grid.Grid; 27 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 28 | import com.vaadin.flow.router.Route; 29 | import elemental.json.JsonObject; 30 | import elemental.json.JsonValue; 31 | import java.util.List; 32 | import java.util.stream.IntStream; 33 | import lombok.EqualsAndHashCode; 34 | import lombok.Getter; 35 | import lombok.RequiredArgsConstructor; 36 | import lombok.experimental.ExtensionMethod; 37 | 38 | @ExtensionMethod(GridHelper.class) 39 | @Route(ResponsiveGridITView.ROUTE) 40 | public class ResponsiveGridITView extends VerticalLayout implements ResponsiveGridITViewCallables { 41 | 42 | public static final String ROUTE = "it/responsive"; 43 | 44 | private Grid> grid; 45 | 46 | @Getter 47 | private int currentStep = -1; 48 | 49 | public ResponsiveGridITView() { 50 | grid = new Grid<>(); 51 | setPadding(false); 52 | setSpacing(false); 53 | add(grid); 54 | 55 | IntStream.range(0, 8) 56 | .forEach( 57 | i -> { 58 | grid.addColumn(list -> list.get(i)).setHeader("Col " + i); 59 | }); 60 | } 61 | 62 | @Override 63 | @ClientCallable 64 | public JsonValue $call(JsonObject invocation) { 65 | return ResponsiveGridITViewCallables.super.$call(invocation); 66 | } 67 | 68 | @Override 69 | public IResponsiveStep responsiveStep(int minWidth) { 70 | GridResponsiveStep step = grid.responsiveStep(minWidth); 71 | step.addListener(ev -> { 72 | currentStep = ev.getMinWidth(); 73 | }); 74 | return new IResponsiveStepImpl(step); 75 | } 76 | 77 | @RequiredArgsConstructor 78 | @EqualsAndHashCode 79 | private class IResponsiveStepImpl implements IResponsiveStep { 80 | final GridResponsiveStep delegate; 81 | 82 | @Override 83 | public void show(int colIndex) { 84 | delegate.show(grid.getColumns().get(colIndex)); 85 | } 86 | 87 | @Override 88 | public void hide(int colIndex) { 89 | delegate.hide(grid.getColumns().get(colIndex)); 90 | } 91 | 92 | @Override 93 | public void showAll() { 94 | delegate.showAll(); 95 | } 96 | 97 | @Override 98 | public void hideAll() { 99 | delegate.hideAll(); 100 | } 101 | 102 | @Override 103 | public void remove() { 104 | delegate.remove(); 105 | } 106 | 107 | @Override 108 | public IListenerRegistration addListener() { 109 | IListenerContext ctx = new IListenerContext(); 110 | return new IListenerRegistrationImpl( 111 | ctx, 112 | delegate.addListener( 113 | ev -> { 114 | ctx.count++; 115 | ctx.minWidth = ev.getMinWidth(); 116 | })); 117 | } 118 | } 119 | 120 | private class IListenerContext { 121 | int count; 122 | int minWidth = -1; 123 | } 124 | 125 | @RequiredArgsConstructor 126 | private class IListenerRegistrationImpl implements IListenerRegistration { 127 | 128 | private final IListenerContext ctx; 129 | 130 | private final GridResponsiveStepListenerRegistration registration; 131 | 132 | @Override 133 | public int getCount() { 134 | return ctx.count; 135 | } 136 | 137 | @Override 138 | public int getLastMinWidth() { 139 | return ctx.minWidth; 140 | } 141 | 142 | @Override 143 | public void remove() { 144 | registration.remove(); 145 | } 146 | 147 | @Override 148 | public void cumulative() { 149 | registration.cummulative(); 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/ResponsiveGridITViewCallables.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.it; 21 | 22 | import com.flowingcode.vaadin.testbench.rpc.RmiCallable; 23 | import com.flowingcode.vaadin.testbench.rpc.RmiRemote; 24 | 25 | public interface ResponsiveGridITViewCallables extends RmiCallable { 26 | 27 | IResponsiveStep responsiveStep(int minWidth); 28 | 29 | int getCurrentStep(); 30 | 31 | interface IResponsiveStep extends RmiRemote { 32 | void show(int colIndex); 33 | 34 | void hide(int colIndex); 35 | 36 | void showAll(); 37 | 38 | void hideAll(); 39 | 40 | void remove(); 41 | 42 | IListenerRegistration addListener(); 43 | } 44 | 45 | interface IListenerRegistration extends RmiRemote { 46 | int getCount(); 47 | 48 | int getLastMinWidth(); 49 | 50 | void remove(); 51 | 52 | void cumulative(); 53 | 54 | } 55 | 56 | default void roundtrip() {} 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/SelectOnClickIT.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers.it; 22 | 23 | import static org.hamcrest.MatcherAssert.assertThat; 24 | import static org.hamcrest.Matchers.empty; 25 | import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport; 26 | import com.flowingcode.vaadin.testbench.rpc.JsonArrayList; 27 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 28 | import com.vaadin.flow.component.grid.testbench.GridElement; 29 | import java.util.Arrays; 30 | import org.hamcrest.Matcher; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | public class SelectOnClickIT extends AbstractViewTest implements HasRpcSupport { 35 | 36 | IntegrationViewCallables $server = createCallableProxy(IntegrationViewCallables.class); 37 | GridHelperElement grid; 38 | 39 | public SelectOnClickIT() { 40 | super("it"); 41 | } 42 | 43 | @Override 44 | public void setup() throws Exception { 45 | super.setup(); 46 | grid = new GridHelperElement($(GridElement.class).waitForFirst()); 47 | } 48 | 49 | @SafeVarargs 50 | private static Matcher> equalToList(T... items) { 51 | return Matchers.equalTo(Arrays.asList(items)); 52 | } 53 | 54 | @Test 55 | public void testSelectOnClickMulti() { 56 | assertThat($server.getSelectedRows(), empty()); 57 | $server.setSelectionMode(SelectionMode.MULTI); 58 | $server.setSelectOnClick(true); 59 | grid.getCell(0, 1).click(); 60 | assertThat($server.getSelectedRows(), equalToList(0)); 61 | grid.getCell(1, 1).click(); 62 | assertThat($server.getSelectedRows(), equalToList(0, 1)); 63 | grid.getCell(3, 1).click(); 64 | assertThat($server.getSelectedRows(), equalToList(0, 1, 3)); 65 | } 66 | 67 | @Test 68 | public void testSelectOnClickSingle() { 69 | assertThat($server.getSelectedRows(), empty()); 70 | $server.setSelectionMode(SelectionMode.SINGLE); 71 | $server.setSelectOnClick(true); 72 | grid.getCell(0, 1).click(); 73 | assertThat($server.getSelectedRows(), equalToList(0)); 74 | grid.getCell(1, 1).click(); 75 | assertThat($server.getSelectedRows(), equalToList(1)); 76 | grid.getCell(3, 1).click(); 77 | assertThat($server.getSelectedRows(), equalToList(3)); 78 | } 79 | 80 | @Test 81 | public void testSelectOnClickNone() { 82 | assertThat($server.getSelectedRows(), empty()); 83 | $server.setSelectionMode(SelectionMode.NONE); 84 | $server.setSelectOnClick(true); 85 | grid.getCell(0, 1).click(); 86 | assertThat($server.getSelectedRows(), empty()); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/SelectionColumnIT.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers.it; 22 | 23 | import static org.junit.Assert.assertEquals; 24 | import static org.junit.Assert.assertNotNull; 25 | import static org.junit.Assert.assertNull; 26 | import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport; 27 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 28 | import com.vaadin.flow.component.grid.testbench.GridElement; 29 | import org.junit.Test; 30 | import org.openqa.selenium.By; 31 | import org.openqa.selenium.WebElement; 32 | 33 | public class SelectionColumnIT extends AbstractViewTest implements HasRpcSupport { 34 | 35 | IntegrationViewCallables $server = createCallableProxy(IntegrationViewCallables.class); 36 | GridHelperElement grid; 37 | 38 | public SelectionColumnIT() { 39 | super("it"); 40 | } 41 | 42 | @Override 43 | public void setup() throws Exception { 44 | super.setup(); 45 | grid = new GridHelperElement($(GridElement.class).waitForFirst()); 46 | } 47 | 48 | @Test 49 | public void testSelectionColumnHidden() { 50 | $server.setSelectionMode(SelectionMode.MULTI); 51 | // assert that the first column is the one with checkboxes 52 | assertNotNull("the first column does not have checkboxes", grid.getSelectionCheckbox(0)); 53 | 54 | // assert that the first column is not the one with checkboxes 55 | $server.setSelectionColumnHidden(true); 56 | assertNull("the first column has checkboxes", grid.getSelectionCheckbox(0)); 57 | } 58 | 59 | @Test 60 | public void testSelectionColumnFrozen() { 61 | $server.setSelectionMode(SelectionMode.MULTI); 62 | 63 | String frozen = "return arguments[0].frozen"; 64 | 65 | // find selection column 66 | WebElement idColumn = grid.findElements(By.tagName("vaadin-grid-flow-selection-column")).get(0); 67 | 68 | // assert that the selection column is not frozen by default 69 | assertEquals("Selection column is frozen", false, (Boolean) executeScript(frozen, idColumn)); 70 | 71 | // make selection column frozen 72 | $server.setSelectionColumnFrozen(true); 73 | 74 | // assert that the selection column is now frozen 75 | assertEquals("Selection column is not frozen", true, (Boolean) executeScript(frozen, idColumn)); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/SelectionFilterIT.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers.it; 22 | 23 | import static org.hamcrest.MatcherAssert.assertThat; 24 | import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport; 25 | import com.flowingcode.vaadin.testbench.rpc.JsonArrayList; 26 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 27 | import java.util.Arrays; 28 | import org.hamcrest.Matcher; 29 | import org.hamcrest.Matchers; 30 | import org.junit.Test; 31 | 32 | public class SelectionFilterIT extends AbstractViewTest implements HasRpcSupport { 33 | 34 | IntegrationViewCallables $server = createCallableProxy(IntegrationViewCallables.class); 35 | GridHelperElement grid; 36 | 37 | public SelectionFilterIT() { 38 | super("it"); 39 | } 40 | 41 | @Override 42 | public void setup() throws Exception { 43 | super.setup(); 44 | grid = new GridHelperElement($(MyGridElement.class).waitForFirst()); 45 | } 46 | 47 | @SafeVarargs 48 | private static Matcher> equalToList(T... items) { 49 | return Matchers.equalTo(Arrays.asList(items)); 50 | } 51 | 52 | @Test 53 | public void testFilteredSelectionMulti() { 54 | $server.setSelectionMode(SelectionMode.MULTI); 55 | $server.setSelectionFilterEnabled(true); 56 | grid.select(0); 57 | assertThat($server.getSelectedRows(), equalToList(0)); 58 | 59 | // odd items cannot be selected 60 | grid.select(1); 61 | assertThat($server.getSelectedRows(), equalToList(0)); 62 | 63 | grid.select(2); 64 | assertThat($server.getSelectedRows(), equalToList(0, 2)); 65 | } 66 | 67 | @Test 68 | public void testFilteredSelectionSingle() { 69 | $server.setSelectionMode(SelectionMode.SINGLE); 70 | $server.setSelectionFilterEnabled(true); 71 | grid.select(0); 72 | assertThat($server.getSelectedRows(), equalToList(0)); 73 | 74 | // odd items cannot be selected 75 | grid.select(1); 76 | // original selection is preserved 77 | assertThat($server.getSelectedRows(), equalToList(0)); 78 | 79 | grid.select(2); 80 | assertThat($server.getSelectedRows(), equalToList(2)); 81 | } 82 | 83 | @Test 84 | public void testUnfilteredSelection() { 85 | $server.setSelectionMode(SelectionMode.SINGLE); 86 | $server.setSelectionFilterEnabled(true); 87 | $server.setSelectionFilterEnabled(false); 88 | grid.getCell(0, 1).click(); 89 | assertThat($server.getSelectedRows(), equalToList(0)); 90 | grid.getCell(1, 1).click(); 91 | assertThat($server.getSelectedRows(), equalToList(1)); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/test/FooterToolbarTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.test; 21 | 22 | import com.flowingcode.vaadin.addons.gridhelpers.GridHelper; 23 | import com.vaadin.flow.component.grid.Grid; 24 | import com.vaadin.flow.component.orderedlayout.HorizontalLayout; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import org.junit.Test.None; 28 | 29 | public class FooterToolbarTest { 30 | 31 | private Grid grid; 32 | 33 | private HorizontalLayout toolbarFooter; 34 | 35 | private class Bean {} 36 | 37 | @Before 38 | public void before() { 39 | grid = new Grid<>(Bean.class, false); 40 | grid.addColumn(x -> x).setHeader("Header"); 41 | toolbarFooter = new HorizontalLayout(); 42 | } 43 | 44 | @Test(expected = None.class) 45 | public void addToolbarFooter_toolbarFooterIsShown() { 46 | GridHelper.addToolbarFooter(grid, toolbarFooter); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/test/GridHelperTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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.gridhelpers.test; 21 | 22 | import static org.junit.Assert.assertEquals; 23 | import static org.junit.Assert.assertFalse; 24 | import static org.junit.Assert.assertNotNull; 25 | import static org.junit.Assert.assertNull; 26 | import static org.junit.Assert.assertTrue; 27 | import com.flowingcode.vaadin.addons.gridhelpers.GridHelper; 28 | import com.vaadin.flow.component.Component; 29 | import com.vaadin.flow.component.grid.Grid; 30 | import com.vaadin.flow.component.grid.Grid.Column; 31 | import com.vaadin.flow.component.grid.Grid.SelectionMode; 32 | import com.vaadin.flow.component.html.Span; 33 | import com.vaadin.flow.function.SerializablePredicate; 34 | import lombok.experimental.ExtensionMethod; 35 | import org.junit.Before; 36 | import org.junit.Test; 37 | 38 | @ExtensionMethod(GridHelper.class) 39 | public class GridHelperTest { 40 | 41 | private static final String HEADER = "HEADER"; 42 | 43 | private Grid grid; 44 | 45 | private Column col0; 46 | 47 | private Column col1; 48 | 49 | private class Bean {} 50 | 51 | @Before 52 | public void before() { 53 | grid = new Grid<>(); 54 | col0 = grid.addColumn(x -> x).setHeader(HEADER); 55 | col1 = grid.addColumn(x -> x); 56 | } 57 | 58 | @Test 59 | public void testSelectionColumnFrozen() { 60 | 61 | grid.setSelectionMode(SelectionMode.MULTI); 62 | 63 | assertTrue(!grid.isSelectionColumnFrozen()); 64 | 65 | grid.setSelectionColumnFrozen(true); 66 | assertTrue(grid.isSelectionColumnFrozen()); 67 | 68 | grid.setSelectionColumnFrozen(false); 69 | assertTrue(!grid.isSelectionColumnFrozen()); 70 | } 71 | 72 | @Test 73 | public void testSelectionFilter() { 74 | SerializablePredicate predicate = t->true; 75 | assertNull(grid.getSelectionFilter()); 76 | 77 | grid.setSelectionFilter(predicate); 78 | assertEquals(predicate, grid.getSelectionFilter()); 79 | 80 | grid.setSelectionFilter(null); 81 | assertNull(grid.getSelectionFilter()); 82 | } 83 | 84 | @Test 85 | public void testHidingToggleCaption() { 86 | String caption = "caption"; 87 | assertEquals(HEADER, col0.getHidingToggleCaption()); 88 | 89 | col0.setHidingToggleCaption(caption); 90 | assertEquals(caption, col0.getHidingToggleCaption()); 91 | 92 | col0.setHidingToggleCaption(null); 93 | assertEquals(HEADER, col0.getHidingToggleCaption()); 94 | } 95 | 96 | @Test 97 | public void testSelectionMode() { 98 | for (SelectionMode selectionMode : SelectionMode.values()) { 99 | grid.setSelectionMode(selectionMode); 100 | assertEquals(selectionMode, grid.getSelectionMode()); 101 | } 102 | } 103 | 104 | @Test 105 | public void testEmptyGridLabel() { 106 | Component label = new Span("Empty"); 107 | assertNull(grid.getEmptyGridLabel()); 108 | 109 | grid.setEmptyGridLabel(label); 110 | assertEquals(label, grid.getEmptyGridLabel()); 111 | 112 | grid.setEmptyGridLabel(null); 113 | assertNull(grid.getEmptyGridLabel()); 114 | } 115 | 116 | @Test 117 | public void testHeader() { 118 | assertEquals(HEADER, grid.getHeader(col0)); 119 | assertEquals("", grid.getHeader(col1)); 120 | } 121 | 122 | @Test 123 | public void testFooter() { 124 | String footer = "footer"; 125 | assertNull(grid.getFooter(col0)); 126 | 127 | col0.setFooter(footer); 128 | assertEquals(footer, grid.getFooter(col0)); 129 | } 130 | 131 | @Test 132 | public void testHidable() { 133 | assertFalse(col0.isHidable()); 134 | 135 | col0.setHidable(true); 136 | assertTrue(col0.isHidable()); 137 | 138 | col0.setHidable(false); 139 | assertFalse(col0.isHidable()); 140 | } 141 | 142 | @Test 143 | public void testSelectionColumnHidden() { 144 | assertFalse(grid.isSelectionColumnHidden()); 145 | 146 | grid.setSelectionColumnHidden(true); 147 | assertTrue(grid.isSelectionColumnHidden()); 148 | 149 | grid.setSelectionColumnHidden(false); 150 | assertFalse(grid.isSelectionColumnHidden()); 151 | } 152 | 153 | @Test 154 | public void testColumnToggleVisible() { 155 | assertFalse(grid.isColumnToggleVisible()); 156 | 157 | grid.setColumnToggleVisible(true); 158 | assertTrue(grid.isColumnToggleVisible()); 159 | 160 | grid.setColumnToggleVisible(false); 161 | assertFalse(grid.isColumnToggleVisible()); 162 | } 163 | 164 | @Test 165 | public void testArrowSelectionEnabled() { 166 | assertFalse(grid.isArrowSelectionEnabled()); 167 | 168 | grid.setArrowSelectionEnabled(true); 169 | assertTrue(grid.isArrowSelectionEnabled()); 170 | 171 | grid.setArrowSelectionEnabled(false); 172 | assertFalse(grid.isArrowSelectionEnabled()); 173 | } 174 | 175 | @Test 176 | public void testSelectOnClick() { 177 | assertFalse(grid.isSelectOnClick()); 178 | 179 | grid.setSelectOnClick(true); 180 | assertTrue(grid.isSelectOnClick()); 181 | 182 | grid.setSelectOnClick(false); 183 | assertFalse(grid.isSelectOnClick()); 184 | } 185 | 186 | @Test 187 | public void testMenuToggleColumn() { 188 | grid.setColumnToggleVisible(true); 189 | 190 | Column toggleColumn=grid.getColumns().get(grid.getColumns().size()-1); 191 | assertTrue(GridHelper.isMenuToggleColumn(toggleColumn)); 192 | } 193 | 194 | @Test 195 | public void testShowRadioSelectionColumn() { 196 | assertNotNull(grid.showRadioSelectionColumn()); 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /src/test/java/com/flowingcode/vaadin/addons/gridhelpers/test/SerializationTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | package com.flowingcode.vaadin.addons.gridhelpers.test; 22 | 23 | import com.flowingcode.vaadin.addons.gridhelpers.GridHelper; 24 | import com.vaadin.flow.component.grid.Grid; 25 | import java.io.ByteArrayInputStream; 26 | import java.io.ByteArrayOutputStream; 27 | import java.io.IOException; 28 | import java.io.ObjectInputStream; 29 | import java.io.ObjectOutputStream; 30 | import org.junit.Assert; 31 | import org.junit.Test; 32 | 33 | public class SerializationTest { 34 | 35 | private void testSerializationOf(Object obj) throws IOException, ClassNotFoundException { 36 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 37 | try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { 38 | oos.writeObject(obj); 39 | } 40 | try (ObjectInputStream in = 41 | new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { 42 | obj.getClass().cast(in.readObject()); 43 | } 44 | } 45 | 46 | @Test 47 | public void testSerialization() throws ClassNotFoundException, IOException { 48 | try { 49 | Grid grid = new Grid<>(); 50 | GridHelper.setColumnToggleVisible(grid, false); 51 | GridHelper.showRadioSelectionColumn(grid); 52 | testSerializationOf(grid); 53 | } catch (Exception e) { 54 | Assert.fail("Problem while testing serialization: " + e.getMessage()); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/frontend/styles/shared-styles.css: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | /*Demo styles*/ 22 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/resources/gridhelpers/gridhelpers-demo.js: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | (function(){ 21 | window.Vaadin.Flow.fcGridHelperDemoConnector = { 22 | 23 | getViewportRowCount : grid => { 24 | //bisection method, f is monotonically increasing 25 | var f= x=>grid.fcGridHelper.computeHeightByRows(x) - grid.clientHeight; 26 | var a=1,b=1; 27 | if (f(a)>=0) return 1; 28 | while (f(b)<0) fb=f(b+=b); 29 | var find = (a,b) => { 30 | var m=Math.ceil((a+b)/2), fm=f(m); 31 | if (fm==0 || b-a<=2) return (fm>0) ? m-1 : m; 32 | return fm>0 ? find(a,m) : find(m,b); 33 | } 34 | return find(a,b); 35 | } 36 | 37 | } 38 | })(); 39 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/resources/gridhelpers/styles.css: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * Grid Helpers Add-on 4 | * %% 5 | * Copyright (C) 2022 - 2024 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 | 21 | label.label { 22 | color: var(--lumo-body-text-color); 23 | font-size: var(--lumo-font-size-s); 24 | font-weight: 500; 25 | line-height: 1; 26 | } 27 | 28 | .empty-grid-label { 29 | position: absolute; 30 | top: 0px; 31 | left: 0px; 32 | display: flex; 33 | justify-content: center; 34 | align-items: center; 35 | font-size: 32px; 36 | } 37 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/resources/static_addon_test_resources: -------------------------------------------------------------------------------- 1 | Place static addon test resources in this folder --------------------------------------------------------------------------------