├── .config ├── checkstyle │ ├── checkstyle.xml │ └── suppressions.xml └── pmd │ └── ruleset.xml ├── .gitattributes ├── .github ├── .lycheeignore ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ ├── enhancement.yml │ └── question.yml ├── labels.yml └── workflows │ ├── broken-links.yml │ ├── check-build.yml │ ├── release.yml │ ├── sonar.yml │ ├── sync-labels.yml │ ├── test-deploy.yml │ └── update-from-template.yml ├── .gitignore ├── .idea ├── checkstyle-idea.xml ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── externalDependencies.xml ├── inspectionProfiles │ └── Project_Default.xml └── saveactions_settings.xml ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── .run └── Run Demo.run.xml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── assets ├── demo.avif └── demo.png ├── mvnw ├── mvnw.cmd ├── pom.xml ├── renovate.json5 ├── vaadin-simple-grid-filter-demo ├── pom.xml └── src │ └── main │ ├── java │ └── software │ │ └── xdev │ │ └── vaadin │ │ ├── Application.java │ │ ├── model │ │ ├── Department.java │ │ └── Person.java │ │ └── ui │ │ └── MainView.java │ └── resources │ └── application.yml └── vaadin-simple-grid-filter ├── pom.xml └── src └── main ├── java └── software │ └── xdev │ └── vaadin │ ├── FilterComponent.java │ ├── builder │ └── CustomizableFilterBuilder.java │ ├── comparators │ ├── ContainsComparator.java │ ├── EqualComparator.java │ ├── FilterComparator.java │ ├── GreaterThanComparator.java │ ├── GreaterThanOrEqualsComparator.java │ ├── IsAfterComparator.java │ ├── IsAfterOrEqualsComparator.java │ ├── IsBeforeComparator.java │ ├── IsBeforeOrEqualsComparator.java │ ├── IsBetweenComparator.java │ ├── LessThanComparator.java │ ├── LessThanOrEqualsComparator.java │ ├── NotContainsComparator.java │ ├── NotEqualComparator.java │ └── utl │ │ ├── DateHelper.java │ │ ├── IncorrectSearchQueryFormatException.java │ │ ├── MismatchingTypeException.java │ │ └── TypeHelper.java │ ├── model │ ├── ChipBadge.java │ ├── ChipBadgeExtension.java │ ├── CustomizationDegree.java │ ├── FilterCondition.java │ ├── FilterField.java │ ├── FilterFieldEnumExtension.java │ ├── FilterProvider.java │ └── SimpleFilterField.java │ └── utl │ ├── FilterComponentUtl.java │ └── QueryParameterUtil.java └── resources └── META-INF └── resources └── frontend └── styles └── filterComponent.css /.config/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /.config/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.config/pmd/ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | This ruleset checks the code for discouraged programming constructs. 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 202 | 203 | Do not used native HTML! Use Vaadin layouts and components to create required structure. 204 | If you are 100% sure that you escaped the value properly and you have no better options you can suppress this. 205 | 206 | 2 207 | 208 | 209 | 210 | 214 | 215 | 216 | 217 | 218 | 219 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Force sh files to have LF 5 | *.sh text eol=lf 6 | 7 | # Force MVN Wrapper Linux files LF 8 | mvnw text eol=lf 9 | .mvn/wrapper/maven-wrapper.properties text eol=lf 10 | -------------------------------------------------------------------------------- /.github/.lycheeignore: -------------------------------------------------------------------------------- 1 | # Ignorefile for broken link check 2 | localhost 3 | mvnrepository.com 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: 🐞 Bug 2 | description: Create a bug report for something that is broken 3 | labels: [bug] 4 | type: bug 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thank you for reporting a bug. 10 | 11 | Please fill in as much information as possible about your bug so that we don't have to play "information ping-pong" and can help you immediately. 12 | 13 | - type: checkboxes 14 | id: checklist 15 | attributes: 16 | label: "Checklist" 17 | options: 18 | - label: "I am able to reproduce the bug with the [latest version](https://github.com/xdev-software/vaadin-simple-grid-filter/releases/latest)" 19 | required: true 20 | - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/vaadin-simple-grid-filter/issues) or [closed](https://github.com/xdev-software/vaadin-simple-grid-filter/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." 21 | required: true 22 | - label: "I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise." 23 | required: true 24 | - label: "This issue contains only one bug." 25 | required: true 26 | 27 | - type: input 28 | id: app-version 29 | attributes: 30 | label: Affected version 31 | description: "In which version did you encounter the bug?" 32 | placeholder: "x.x.x" 33 | validations: 34 | required: true 35 | 36 | - type: textarea 37 | id: description 38 | attributes: 39 | label: Description of the problem 40 | description: | 41 | Describe as exactly as possible what is not working. 42 | validations: 43 | required: true 44 | 45 | - type: textarea 46 | id: steps-to-reproduce 47 | attributes: 48 | label: Steps to reproduce the bug 49 | description: | 50 | What did you do for the bug to show up? 51 | 52 | If you can't cause the bug to show up again reliably (and hence don't have a proper set of steps to give us), please still try to give as many details as possible on how you think you encountered the bug. 53 | placeholder: | 54 | 1. Use '...' 55 | 2. Do '...' 56 | validations: 57 | required: true 58 | 59 | - type: textarea 60 | id: additional-information 61 | attributes: 62 | label: Additional information 63 | description: | 64 | Any other relevant information you'd like to include 65 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: 💬 Contact support 3 | url: https://xdev.software/en/services/support 4 | about: "If you need support as soon as possible or/and you can't wait for any pull request" 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.yml: -------------------------------------------------------------------------------- 1 | name: ✨ Feature/Enhancement 2 | description: Suggest a new feature or enhancement 3 | labels: [enhancement] 4 | type: feature 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thank you for suggesting a new feature/enhancement. 10 | 11 | - type: checkboxes 12 | id: checklist 13 | attributes: 14 | label: "Checklist" 15 | options: 16 | - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/vaadin-simple-grid-filter/issues) or [closed](https://github.com/xdev-software/vaadin-simple-grid-filter/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." 17 | required: true 18 | - label: "I have taken the time to fill in all the required details. I understand that the feature request will be dismissed otherwise." 19 | required: true 20 | - label: "This issue contains only one feature request/enhancement." 21 | required: true 22 | 23 | - type: textarea 24 | id: description 25 | attributes: 26 | label: Description 27 | validations: 28 | required: true 29 | 30 | - type: textarea 31 | id: additional-information 32 | attributes: 33 | label: Additional information 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.yml: -------------------------------------------------------------------------------- 1 | name: ❓ Question 2 | description: Ask a question 3 | labels: [question] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Thanks for taking the time to fill out this form! 9 | 10 | - type: checkboxes 11 | id: checklist 12 | attributes: 13 | label: "Checklist" 14 | options: 15 | - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/vaadin-simple-grid-filter/issues) or [closed](https://github.com/xdev-software/vaadin-simple-grid-filter/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." 16 | required: true 17 | - label: "I have taken the time to fill in all the required details. I understand that the question will be dismissed otherwise." 18 | required: true 19 | 20 | - type: textarea 21 | id: what-is-the-question 22 | attributes: 23 | label: What is/are your question(s)? 24 | validations: 25 | required: true 26 | 27 | - type: textarea 28 | id: additional-information 29 | attributes: 30 | label: Additional information 31 | description: "Any other information you'd like to include - for instance logs, screenshots, etc." 32 | -------------------------------------------------------------------------------- /.github/labels.yml: -------------------------------------------------------------------------------- 1 | # Default 2 | ## Required for template 3 | - name: bug 4 | description: "Something isn't working" 5 | color: 'd73a4a' 6 | - name: enhancement 7 | description: New feature or request 8 | color: '#a2eeef' 9 | - name: question 10 | description: Information is requested 11 | color: '#d876e3' 12 | ## Others 13 | - name: duplicate 14 | description: This already exists 15 | color: '#cfd3d7' 16 | - name: good first issue 17 | description: Good for newcomers 18 | color: '#7057ff' 19 | - name: help wanted 20 | description: Extra attention is needed 21 | color: '#008672' 22 | - name: invalid 23 | description: "This doesn't seem right" 24 | color: '#e4e669' 25 | # Custom 26 | - name: automated 27 | description: Created by an automation 28 | color: '#000000' 29 | - name: "can't reproduce" 30 | color: '#e95f2c' 31 | - name: customer-requested 32 | description: Was requested by a customer of us 33 | color: '#068374' 34 | - name: stale 35 | color: '#ededed' 36 | - name: waiting-for-response 37 | description: If no response is received after a certain time the issue will be closed 38 | color: '#202020' 39 | -------------------------------------------------------------------------------- /.github/workflows/broken-links.yml: -------------------------------------------------------------------------------- 1 | name: Broken links 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: "23 23 * * 0" 7 | 8 | permissions: 9 | issues: write 10 | 11 | jobs: 12 | link-checker: 13 | runs-on: ubuntu-latest 14 | timeout-minutes: 15 15 | steps: 16 | - uses: actions/checkout@v4 17 | 18 | - run: mv .github/.lycheeignore .lycheeignore 19 | 20 | - name: Link Checker 21 | id: lychee 22 | uses: lycheeverse/lychee-action@82202e5e9c2f4ef1a55a3d02563e1cb6041e5332 # v2 23 | with: 24 | fail: false # Don't fail on broken links, create an issue instead 25 | 26 | - name: Find already existing issue 27 | id: find-issue 28 | run: | 29 | echo "number=$(gh issue list -l 'bug' -l 'automated' -L 1 -S 'in:title \"Link Checker Report\"' -s 'open' --json 'number' --jq '.[].number')" >> $GITHUB_OUTPUT 30 | env: 31 | GH_TOKEN: ${{ github.token }} 32 | 33 | - name: Close issue if everything is fine 34 | if: env.lychee_exit_code == 0 && steps.find-issue.outputs.number != '' 35 | run: gh issue close -r 'not planned' ${{ steps.find-issue.outputs.number }} 36 | env: 37 | GH_TOKEN: ${{ github.token }} 38 | 39 | - name: Create Issue From File 40 | if: env.lychee_exit_code != 0 41 | uses: peter-evans/create-issue-from-file@e8ef132d6df98ed982188e460ebb3b5d4ef3a9cd # v5 42 | with: 43 | issue-number: ${{ steps.find-issue.outputs.number }} 44 | title: Link Checker Report 45 | content-filepath: ./lychee/out.md 46 | labels: bug, automated 47 | -------------------------------------------------------------------------------- /.github/workflows/check-build.yml: -------------------------------------------------------------------------------- 1 | name: Check Build 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [ develop ] 7 | paths-ignore: 8 | - '**.md' 9 | - '.config/**' 10 | - '.github/**' 11 | - '.idea/**' 12 | - 'assets/**' 13 | pull_request: 14 | branches: [ develop ] 15 | paths-ignore: 16 | - '**.md' 17 | - '.config/**' 18 | - '.github/**' 19 | - '.idea/**' 20 | - 'assets/**' 21 | 22 | env: 23 | PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }} 24 | DEMO_MAVEN_MODULE: ${{ github.event.repository.name }}-demo 25 | 26 | jobs: 27 | build: 28 | runs-on: ubuntu-latest 29 | timeout-minutes: 30 30 | 31 | strategy: 32 | matrix: 33 | java: [17, 21] 34 | distribution: [temurin] 35 | 36 | steps: 37 | - uses: actions/checkout@v4 38 | 39 | - name: Set up JDK 40 | uses: actions/setup-java@v4 41 | with: 42 | distribution: ${{ matrix.distribution }} 43 | java-version: ${{ matrix.java }} 44 | cache: 'maven' 45 | 46 | - name: Build with Maven 47 | run: ./mvnw -B clean package -Pproduction 48 | 49 | - name: Check for uncommited changes 50 | run: | 51 | if [[ "$(git status --porcelain)" != "" ]]; then 52 | echo ---------------------------------------- 53 | echo git status 54 | echo ---------------------------------------- 55 | git status 56 | echo ---------------------------------------- 57 | echo git diff 58 | echo ---------------------------------------- 59 | git diff 60 | echo ---------------------------------------- 61 | echo Troubleshooting 62 | echo ---------------------------------------- 63 | echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && ./mvnw -B clean package -Pproduction" 64 | exit 1 65 | fi 66 | 67 | - name: Upload demo files 68 | uses: actions/upload-artifact@v4 69 | with: 70 | name: demo-files-java-${{ matrix.java }} 71 | path: ${{ env.DEMO_MAVEN_MODULE }}/target/${{ env.DEMO_MAVEN_MODULE }}.jar 72 | if-no-files-found: error 73 | 74 | checkstyle: 75 | runs-on: ubuntu-latest 76 | if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }} 77 | timeout-minutes: 15 78 | 79 | strategy: 80 | matrix: 81 | java: [17] 82 | distribution: [temurin] 83 | 84 | steps: 85 | - uses: actions/checkout@v4 86 | 87 | - name: Set up JDK 88 | uses: actions/setup-java@v4 89 | with: 90 | distribution: ${{ matrix.distribution }} 91 | java-version: ${{ matrix.java }} 92 | cache: 'maven' 93 | 94 | - name: Run Checkstyle 95 | run: ./mvnw -B checkstyle:check -P checkstyle -T2C 96 | 97 | pmd: 98 | runs-on: ubuntu-latest 99 | if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }} 100 | timeout-minutes: 15 101 | 102 | strategy: 103 | matrix: 104 | java: [17] 105 | distribution: [temurin] 106 | 107 | steps: 108 | - uses: actions/checkout@v4 109 | 110 | - name: Set up JDK 111 | uses: actions/setup-java@v4 112 | with: 113 | distribution: ${{ matrix.distribution }} 114 | java-version: ${{ matrix.java }} 115 | cache: 'maven' 116 | 117 | - name: Run PMD 118 | run: ./mvnw -B test pmd:aggregate-pmd-no-fork pmd:check -P pmd -DskipTests -T2C 119 | 120 | - name: Run CPD (Copy Paste Detector) 121 | run: ./mvnw -B pmd:aggregate-cpd pmd:cpd-check -P pmd -DskipTests -T2C 122 | 123 | - name: Upload report 124 | if: always() 125 | uses: actions/upload-artifact@v4 126 | with: 127 | name: pmd-report 128 | if-no-files-found: ignore 129 | path: | 130 | target/reports/** 131 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | 7 | env: 8 | PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }} 9 | 10 | permissions: 11 | contents: write 12 | pull-requests: write 13 | 14 | jobs: 15 | check-code: 16 | runs-on: ubuntu-latest 17 | timeout-minutes: 30 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - name: Set up JDK 22 | uses: actions/setup-java@v4 23 | with: 24 | java-version: '17' 25 | distribution: 'temurin' 26 | cache: 'maven' 27 | 28 | - name: Build with Maven 29 | run: ./mvnw -B clean package -Pproduction -T2C 30 | 31 | - name: Check for uncommited changes 32 | run: | 33 | if [[ "$(git status --porcelain)" != "" ]]; then 34 | echo ---------------------------------------- 35 | echo git status 36 | echo ---------------------------------------- 37 | git status 38 | echo ---------------------------------------- 39 | echo git diff 40 | echo ---------------------------------------- 41 | git diff 42 | echo ---------------------------------------- 43 | echo Troubleshooting 44 | echo ---------------------------------------- 45 | echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && ./mvnw -B clean package -Pproduction" 46 | exit 1 47 | fi 48 | 49 | prepare-release: 50 | runs-on: ubuntu-latest 51 | needs: [check-code] 52 | timeout-minutes: 10 53 | outputs: 54 | upload_url: ${{ steps.create_release.outputs.upload_url }} 55 | steps: 56 | - uses: actions/checkout@v4 57 | 58 | - name: Configure Git 59 | run: | 60 | git config --global user.email "actions@github.com" 61 | git config --global user.name "GitHub Actions" 62 | 63 | - name: Un-SNAP 64 | run: | 65 | mvnwPath=$(readlink -f ./mvnw) 66 | modules=("") # root 67 | modules+=($(grep -oP '(?<=)[^<]+' 'pom.xml')) 68 | for i in "${modules[@]}" 69 | do 70 | echo "Processing $i/pom.xml" 71 | (cd "$i" && $mvnwPath -B versions:set -DremoveSnapshot -DgenerateBackupPoms=false) 72 | done 73 | 74 | - name: Get version 75 | id: version 76 | run: | 77 | version=$(../mvnw help:evaluate -Dexpression=project.version -q -DforceStdout) 78 | echo "release=$version" >> $GITHUB_OUTPUT 79 | echo "releasenumber=${version//[!0-9]/}" >> $GITHUB_OUTPUT 80 | working-directory: ${{ env.PRIMARY_MAVEN_MODULE }} 81 | 82 | - name: Commit and Push 83 | run: | 84 | git add -A 85 | git commit -m "Release ${{ steps.version.outputs.release }}" 86 | git push origin 87 | git tag v${{ steps.version.outputs.release }} 88 | git push origin --tags 89 | 90 | - name: Create Release 91 | id: create_release 92 | uses: shogo82148/actions-create-release@e5f206451d4ace2da9916d01f1aef279997f8659 # v1 93 | with: 94 | tag_name: v${{ steps.version.outputs.release }} 95 | release_name: v${{ steps.version.outputs.release }} 96 | commitish: master 97 | body: | 98 | ## [Changelog](https://github.com/${{ github.repository }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) 99 | See [Changelog#v${{ steps.version.outputs.release }}](https://github.com/${{ github.repository }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) for more information. 100 | 101 | ## Installation 102 | Add the following lines to your pom: 103 | ```XML 104 | 105 | software.xdev 106 | ${{ env.PRIMARY_MAVEN_MODULE }} 107 | ${{ steps.version.outputs.release }} 108 | 109 | ``` 110 | 111 | ### Additional notes 112 | * [Spring-Boot] You may have to include ``software/xdev`` inside [``vaadin.allowed-packages``](https://vaadin.com/docs/latest/integrations/spring/configuration#configure-the-scanning-of-packages) 113 | 114 | publish-maven: 115 | runs-on: ubuntu-latest 116 | needs: [prepare-release] 117 | timeout-minutes: 60 118 | steps: 119 | - uses: actions/checkout@v4 120 | 121 | - name: Init Git and pull 122 | run: | 123 | git config --global user.email "actions@github.com" 124 | git config --global user.name "GitHub Actions" 125 | git pull 126 | 127 | - name: Set up JDK 128 | uses: actions/setup-java@v4 129 | with: # running setup-java again overwrites the settings.xml 130 | java-version: '17' 131 | distribution: 'temurin' 132 | server-id: sonatype-central-portal 133 | server-username: MAVEN_CENTRAL_USERNAME 134 | server-password: MAVEN_CENTRAL_TOKEN 135 | gpg-passphrase: MAVEN_GPG_PASSPHRASE 136 | gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} 137 | 138 | - name: Publish to Central Portal 139 | run: ../mvnw -B deploy -P publish-sonatype-central-portal -DskipTests 140 | env: 141 | MAVEN_CENTRAL_USERNAME: ${{ secrets.SONATYPE_MAVEN_CENTRAL_PORTAL_USERNAME }} 142 | MAVEN_CENTRAL_TOKEN: ${{ secrets.SONATYPE_MAVEN_CENTRAL_PORTAL_TOKEN }} 143 | MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} 144 | working-directory: ${{ env.PRIMARY_MAVEN_MODULE }} 145 | 146 | publish-pages: 147 | runs-on: ubuntu-latest 148 | needs: [prepare-release] 149 | timeout-minutes: 15 150 | steps: 151 | - uses: actions/checkout@v4 152 | 153 | - name: Init Git and pull 154 | run: | 155 | git config --global user.email "actions@github.com" 156 | git config --global user.name "GitHub Actions" 157 | git pull 158 | 159 | - name: Setup - Java 160 | uses: actions/setup-java@v4 161 | with: 162 | java-version: '17' 163 | distribution: 'temurin' 164 | cache: 'maven' 165 | 166 | - name: Build site 167 | run: ../mvnw -B compile site -DskipTests -T2C 168 | working-directory: ${{ env.PRIMARY_MAVEN_MODULE }} 169 | 170 | - name: Deploy to Github pages 171 | uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 172 | with: 173 | github_token: ${{ secrets.GITHUB_TOKEN }} 174 | publish_dir: ./${{ env.PRIMARY_MAVEN_MODULE }}/target/site 175 | force_orphan: true 176 | 177 | after-release: 178 | runs-on: ubuntu-latest 179 | needs: [publish-maven] 180 | timeout-minutes: 10 181 | steps: 182 | - uses: actions/checkout@v4 183 | 184 | - name: Init Git and pull 185 | run: | 186 | git config --global user.email "actions@github.com" 187 | git config --global user.name "GitHub Actions" 188 | git pull 189 | 190 | - name: Inc Version and SNAP 191 | run: | 192 | mvnwPath=$(readlink -f ./mvnw) 193 | modules=("") # root 194 | modules+=($(grep -oP '(?<=)[^<]+' 'pom.xml')) 195 | for i in "${modules[@]}" 196 | do 197 | echo "Processing $i/pom.xml" 198 | (cd "$i" && $mvnwPath -B build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} -DgenerateBackupPoms=false -DnextSnapshot=true -DupdateMatchingVersions=false) 199 | done 200 | 201 | - name: Git Commit and Push 202 | run: | 203 | git add -A 204 | git commit -m "Preparing for next development iteration" 205 | git push origin 206 | 207 | - name: pull-request 208 | env: 209 | GH_TOKEN: ${{ github.token }} 210 | run: | 211 | gh_pr_up() { 212 | gh pr create "$@" || gh pr edit "$@" 213 | } 214 | gh_pr_up -B "develop" \ 215 | --title "Sync back" \ 216 | --body "An automated PR to sync changes back" 217 | -------------------------------------------------------------------------------- /.github/workflows/sonar.yml: -------------------------------------------------------------------------------- 1 | name: Sonar 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [ develop ] 7 | paths-ignore: 8 | - '**.md' 9 | - '.config/**' 10 | - '.github/**' 11 | - '.idea/**' 12 | - 'assets/**' 13 | pull_request: 14 | branches: [ develop ] 15 | paths-ignore: 16 | - '**.md' 17 | - '.config/**' 18 | - '.github/**' 19 | - '.idea/**' 20 | - 'assets/**' 21 | 22 | env: 23 | SONARCLOUD_ORG: ${{ github.event.organization.login }} 24 | SONARCLOUD_HOST: https://sonarcloud.io 25 | 26 | jobs: 27 | token-check: 28 | runs-on: ubuntu-latest 29 | if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'renovate/')) }} 30 | timeout-minutes: 5 31 | outputs: 32 | hasToken: ${{ steps.check-token.outputs.has }} 33 | steps: 34 | - id: check-token 35 | run: | 36 | [ -z $SONAR_TOKEN ] && echo "has=false" || echo "has=true" >> "$GITHUB_OUTPUT" 37 | env: 38 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 39 | 40 | sonar-scan: 41 | runs-on: ubuntu-latest 42 | needs: token-check 43 | if: ${{ needs.token-check.outputs.hasToken }} 44 | timeout-minutes: 30 45 | steps: 46 | - uses: actions/checkout@v4 47 | with: 48 | fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis 49 | 50 | - name: Set up JDK 51 | uses: actions/setup-java@v4 52 | with: 53 | distribution: 'temurin' 54 | java-version: 17 55 | 56 | - name: Cache SonarCloud packages 57 | uses: actions/cache@v4 58 | with: 59 | path: ~/.sonar/cache 60 | key: ${{ runner.os }}-sonar 61 | restore-keys: ${{ runner.os }}-sonar 62 | 63 | - name: Cache Maven packages 64 | uses: actions/cache@v4 65 | with: 66 | path: ~/.m2 67 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 68 | restore-keys: ${{ runner.os }}-m2 69 | 70 | - name: Build with Maven 71 | run: | 72 | ./mvnw -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ 73 | -DskipTests \ 74 | -Dsonar.projectKey=${{ env.SONARCLOUD_ORG }}_${{ github.event.repository.name }} \ 75 | -Dsonar.organization=${{ env.SONARCLOUD_ORG }} \ 76 | -Dsonar.host.url=${{ env.SONARCLOUD_HOST }} 77 | env: 78 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any 79 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 80 | -------------------------------------------------------------------------------- /.github/workflows/sync-labels.yml: -------------------------------------------------------------------------------- 1 | name: Sync labels 2 | 3 | on: 4 | push: 5 | branches: develop 6 | paths: 7 | - .github/labels.yml 8 | 9 | workflow_dispatch: 10 | 11 | permissions: 12 | issues: write 13 | 14 | jobs: 15 | labels: 16 | runs-on: ubuntu-latest 17 | timeout-minutes: 10 18 | steps: 19 | - uses: actions/checkout@v4 20 | with: 21 | sparse-checkout: .github/labels.yml 22 | 23 | - uses: EndBug/label-sync@52074158190acb45f3077f9099fea818aa43f97a # v2 24 | with: 25 | config-file: .github/labels.yml 26 | -------------------------------------------------------------------------------- /.github/workflows/test-deploy.yml: -------------------------------------------------------------------------------- 1 | name: Test Deployment 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | env: 7 | PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }} 8 | 9 | jobs: 10 | publish-maven: 11 | runs-on: ubuntu-latest 12 | timeout-minutes: 60 13 | steps: 14 | - uses: actions/checkout@v4 15 | 16 | - name: Set up JDK 17 | uses: actions/setup-java@v4 18 | with: # running setup-java again overwrites the settings.xml 19 | distribution: 'temurin' 20 | java-version: '17' 21 | server-id: sonatype-central-portal 22 | server-username: MAVEN_CENTRAL_USERNAME 23 | server-password: MAVEN_CENTRAL_TOKEN 24 | gpg-passphrase: MAVEN_GPG_PASSPHRASE 25 | gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} 26 | 27 | - name: Publish to Central Portal 28 | run: ../mvnw -B deploy -P publish-sonatype-central-portal -DskipTests 29 | working-directory: ${{ env.PRIMARY_MAVEN_MODULE }} 30 | env: 31 | MAVEN_CENTRAL_USERNAME: ${{ secrets.SONATYPE_MAVEN_CENTRAL_PORTAL_USERNAME }} 32 | MAVEN_CENTRAL_TOKEN: ${{ secrets.SONATYPE_MAVEN_CENTRAL_PORTAL_TOKEN }} 33 | MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} 34 | -------------------------------------------------------------------------------- /.github/workflows/update-from-template.yml: -------------------------------------------------------------------------------- 1 | name: Update from Template 2 | 3 | # This workflow keeps the repo up to date with changes from the template repo (REMOTE_URL) 4 | # It duplicates the REMOTE_BRANCH (into UPDATE_BRANCH) and tries to merge it into 5 | # this repos default branch (which is checked out here) 6 | # Note that this requires a PAT (Personal Access Token) - at best from a servicing account 7 | # PAT permissions: read:discussion, read:org, repo, workflow 8 | # Also note that you should have at least once merged the template repo into the current repo manually 9 | # otherwise a "refusing to merge unrelated histories" error might occur. 10 | 11 | on: 12 | schedule: 13 | - cron: '55 2 * * 1' 14 | workflow_dispatch: 15 | inputs: 16 | no_automatic_merge: 17 | type: boolean 18 | description: 'No automatic merge' 19 | default: false 20 | 21 | env: 22 | UPDATE_BRANCH: update-from-template 23 | UPDATE_BRANCH_MERGED: update-from-template-merged 24 | REMOTE_URL: https://github.com/xdev-software/vaadin-addon-template.git 25 | REMOTE_BRANCH: master 26 | 27 | permissions: 28 | contents: write 29 | pull-requests: write 30 | 31 | jobs: 32 | update: 33 | runs-on: ubuntu-latest 34 | timeout-minutes: 60 35 | outputs: 36 | update_branch_merged_commit: ${{ steps.manage-branches.outputs.update_branch_merged_commit }} 37 | create_update_branch_merged_pr: ${{ steps.manage-branches.outputs.create_update_branch_merged_pr }} 38 | steps: 39 | - uses: actions/checkout@v4 40 | with: 41 | # Required because otherwise there are always changes detected when executing diff/rev-list 42 | fetch-depth: 0 43 | # If no PAT is used the following error occurs on a push: 44 | # refusing to allow a GitHub App to create or update workflow `.github/workflows/xxx.yml` without `workflows` permission 45 | token: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} 46 | 47 | - name: Init Git 48 | run: | 49 | git config --global user.email "111048771+xdev-gh-bot@users.noreply.github.com" 50 | git config --global user.name "XDEV Bot" 51 | 52 | - name: Manage branches 53 | id: manage-branches 54 | run: | 55 | echo "Adding remote template-repo" 56 | git remote add template ${{ env.REMOTE_URL }} 57 | 58 | echo "Fetching remote template repo" 59 | git fetch template 60 | 61 | echo "Deleting local branches that will contain the updates - if present" 62 | git branch -D ${{ env.UPDATE_BRANCH }} || true 63 | git branch -D ${{ env.UPDATE_BRANCH_MERGED }} || true 64 | 65 | echo "Checking if the remote template repo has new commits" 66 | git rev-list ..template/${{ env.REMOTE_BRANCH }} 67 | 68 | if [ $(git rev-list --count ..template/${{ env.REMOTE_BRANCH }}) -eq 0 ]; then 69 | echo "There are no commits new commits on the template repo" 70 | 71 | echo "Deleting origin branch(es) that contain the updates - if present" 72 | git push -f origin --delete ${{ env.UPDATE_BRANCH }} || true 73 | git push -f origin --delete ${{ env.UPDATE_BRANCH_MERGED }} || true 74 | 75 | echo "create_update_branch_pr=0" >> $GITHUB_OUTPUT 76 | echo "create_update_branch_merged_pr=0" >> $GITHUB_OUTPUT 77 | exit 0 78 | fi 79 | 80 | echo "Found new commits on the template repo" 81 | 82 | echo "Creating update branch" 83 | git branch ${{ env.UPDATE_BRANCH }} template/${{ env.REMOTE_BRANCH }} 84 | git branch --unset-upstream ${{ env.UPDATE_BRANCH }} 85 | 86 | echo "Pushing update branch" 87 | git push -f -u origin ${{ env.UPDATE_BRANCH }} 88 | 89 | echo "Getting base branch" 90 | base_branch=$(git branch --show-current) 91 | echo "Base branch is $base_branch" 92 | echo "base_branch=$base_branch" >> $GITHUB_OUTPUT 93 | 94 | echo "Trying to create auto-merged branch ${{ env.UPDATE_BRANCH_MERGED }}" 95 | git branch ${{ env.UPDATE_BRANCH_MERGED }} ${{ env.UPDATE_BRANCH }} 96 | git checkout ${{ env.UPDATE_BRANCH_MERGED }} 97 | 98 | echo "Merging branch $base_branch into ${{ env.UPDATE_BRANCH_MERGED }}" 99 | git merge $base_branch && merge_exit_code=$? || merge_exit_code=$? 100 | if [ $merge_exit_code -ne 0 ]; then 101 | echo "Auto merge failed! Manual merge required" 102 | echo "::notice ::Auto merge failed - Manual merge required" 103 | 104 | echo "Cleaning up failed merge" 105 | git merge --abort 106 | git checkout $base_branch 107 | git branch -D ${{ env.UPDATE_BRANCH_MERGED }} || true 108 | 109 | echo "Deleting auto-merge branch - if present" 110 | git push -f origin --delete ${{ env.UPDATE_BRANCH_MERGED }} || true 111 | 112 | echo "create_update_branch_pr=1" >> $GITHUB_OUTPUT 113 | echo "create_update_branch_merged_pr=0" >> $GITHUB_OUTPUT 114 | exit 0 115 | fi 116 | 117 | echo "Post processing: Trying to automatically fill in template variables" 118 | find . -type f \ 119 | -not -path "./.git/**" \ 120 | -not -path "./.github/workflows/update-from-template.yml" -print0 \ 121 | | xargs -0 sed -i "s/template-placeholder/${GITHUB_REPOSITORY#*/}/g" 122 | 123 | git status 124 | git add --all 125 | 126 | if [[ "$(git status --porcelain)" != "" ]]; then 127 | echo "Filled in template; Committing" 128 | 129 | git commit -m "Fill in template" 130 | fi 131 | 132 | echo "Pushing auto-merged branch" 133 | git push -f -u origin ${{ env.UPDATE_BRANCH_MERGED }} 134 | 135 | echo "update_branch_merged_commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT 136 | 137 | echo "Restoring base branch $base_branch" 138 | git checkout $base_branch 139 | 140 | echo "create_update_branch_pr=0" >> $GITHUB_OUTPUT 141 | echo "create_update_branch_merged_pr=1" >> $GITHUB_OUTPUT 142 | echo "try_close_update_branch_pr=1" >> $GITHUB_OUTPUT 143 | 144 | - name: Create/Update PR update_branch 145 | if: steps.manage-branches.outputs.create_update_branch_pr == 1 146 | env: 147 | GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} 148 | run: | 149 | gh_pr_up() { 150 | gh pr create -H "${{ env.UPDATE_BRANCH }}" "$@" || (git checkout "${{ env.UPDATE_BRANCH }}" && gh pr edit "$@") 151 | } 152 | gh_pr_up -B "${{ steps.manage-branches.outputs.base_branch }}" \ 153 | --title "Update from template" \ 154 | --body "An automated PR to sync changes from the template into this repo" 155 | 156 | # Ensure that only a single PR is open (otherwise confusion and spam) 157 | - name: Close PR update_branch 158 | if: steps.manage-branches.outputs.try_close_update_branch_pr == 1 159 | env: 160 | GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} 161 | run: | 162 | gh pr close "${{ env.UPDATE_BRANCH }}" || true 163 | 164 | - name: Create/Update PR update_branch_merged 165 | if: steps.manage-branches.outputs.create_update_branch_merged_pr == 1 166 | env: 167 | GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} 168 | run: | 169 | gh_pr_up() { 170 | gh pr create -H "${{ env.UPDATE_BRANCH_MERGED }}" "$@" || (git checkout "${{ env.UPDATE_BRANCH_MERGED }}" && gh pr edit "$@") 171 | } 172 | gh_pr_up -B "${{ steps.manage-branches.outputs.base_branch }}" \ 173 | --title "Update from template (auto-merged)" \ 174 | --body "An automated PR to sync changes from the template into this repo" 175 | 176 | # Wait a moment so that checks of PR have higher prio than following job 177 | sleep 3 178 | 179 | # Split into two jobs to help with executor starvation 180 | auto-merge: 181 | needs: [update] 182 | if: needs.update.outputs.create_update_branch_merged_pr == 1 183 | runs-on: ubuntu-latest 184 | timeout-minutes: 60 185 | steps: 186 | - uses: actions/checkout@v4 187 | with: 188 | # Required because otherwise there are always changes detected when executing diff/rev-list 189 | fetch-depth: 0 190 | # If no PAT is used the following error occurs on a push: 191 | # refusing to allow a GitHub App to create or update workflow `.github/workflows/xxx.yml` without `workflows` permission 192 | token: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} 193 | 194 | - name: Init Git 195 | run: | 196 | git config --global user.email "111048771+xdev-gh-bot@users.noreply.github.com" 197 | git config --global user.name "XDEV Bot" 198 | 199 | - name: Checking if auto-merge for PR update_branch_merged can be done 200 | id: auto-merge-check 201 | env: 202 | GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} 203 | run: | 204 | not_failed_conclusion="skipped|neutral|success" 205 | not_relevant_app_slug="dependabot|github-pages|sonarqubecloud" 206 | 207 | echo "Waiting for checks to start..." 208 | sleep 40s 209 | 210 | for i in {1..20}; do 211 | echo "Checking if PR can be auto-merged. Try: $i" 212 | 213 | echo "Checking if update-branch-merged exists" 214 | git fetch 215 | if [[ $(git ls-remote --heads origin refs/heads/${{ env.UPDATE_BRANCH_MERGED }}) ]]; then 216 | echo "Branch still exists; Continuing..." 217 | else 218 | echo "Branch origin/${{ env.UPDATE_BRANCH_MERGED }} is missing" 219 | exit 0 220 | fi 221 | 222 | echo "Fetching checks" 223 | cs_response=$(curl -sL \ 224 | --fail-with-body \ 225 | --connect-timeout 60 \ 226 | --max-time 120 \ 227 | -H "Accept: application/vnd.github+json" \ 228 | -H "Authorization: Bearer $GH_TOKEN" \ 229 | -H "X-GitHub-Api-Version: 2022-11-28" \ 230 | https://api.github.com/repos/${{ github.repository }}/commits/${{ needs.update.outputs.update_branch_merged_commit }}/check-suites) 231 | 232 | cs_data=$(echo $cs_response | jq '.check_suites[] | { conclusion: .conclusion, slug: .app.slug, check_runs_url: .check_runs_url }') 233 | echo $cs_data 234 | 235 | if [[ -z "$cs_data" ]]; then 236 | echo "No check suite data - Assuming that there are no checks to run" 237 | 238 | echo "perform=1" >> $GITHUB_OUTPUT 239 | exit 0 240 | fi 241 | 242 | cs_failed=$(echo $cs_data | jq --arg x "$not_failed_conclusion" 'select ((.conclusion == null or (.conclusion | test($x))) | not)') 243 | if [[ -z "$cs_failed" ]]; then 244 | echo "No check failed so far; Checking if relevant checks are still running" 245 | 246 | cs_relevant_still_running=$(echo $cs_data | jq --arg x "$not_relevant_app_slug" 'select (.conclusion == null and (.slug | test($x) | not))') 247 | if [[ -z $cs_relevant_still_running ]]; then 248 | echo "All relevant checks finished - PR can be merged" 249 | 250 | echo "perform=1" >> $GITHUB_OUTPUT 251 | exit 0 252 | else 253 | echo "Relevant checks are still running" 254 | echo $cs_relevant_still_running 255 | fi 256 | else 257 | echo "Detected failed check" 258 | echo $cs_failed 259 | 260 | echo "perform=0" >> $GITHUB_OUTPUT 261 | exit 0 262 | fi 263 | 264 | echo "Waiting before next run..." 265 | sleep 30s 266 | done 267 | 268 | echo "Timed out - Assuming executor starvation - Forcing merge" 269 | echo "perform=1" >> $GITHUB_OUTPUT 270 | 271 | - name: Auto-merge update_branch_merged 272 | if: steps.auto-merge-check.outputs.perform == 1 273 | run: | 274 | echo "Getting base branch" 275 | base_branch=$(git branch --show-current) 276 | echo "Base branch is $base_branch" 277 | 278 | echo "Fetching..." 279 | git fetch 280 | if [[ $(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }}) ]]; then 281 | echo "Branch still exists; Continuing..." 282 | else 283 | echo "Branch origin/${{ env.UPDATE_BRANCH_MERGED }} is missing" 284 | exit 0 285 | fi 286 | 287 | expected_commit="${{ needs.update.outputs.update_branch_merged_commit }}" 288 | actual_commit=$(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }}) 289 | if [[ "$expected_commit" != "$actual_commit" ]]; then 290 | echo "Branch ${{ env.UPDATE_BRANCH_MERGED }} contains unexpected commit $actual_commit" 291 | echo "Expected: $expected_commit" 292 | 293 | exit 0 294 | fi 295 | 296 | echo "Ensuring that current branch $base_branch is up-to-date" 297 | git pull 298 | 299 | echo "Merging origin/${{ env.UPDATE_BRANCH_MERGED }} into $base_branch" 300 | git merge origin/${{ env.UPDATE_BRANCH_MERGED }} && merge_exit_code=$? || merge_exit_code=$? 301 | if [ $merge_exit_code -ne 0 ]; then 302 | echo "Unexpected merge failure $merge_exit_code - Requires manual resolution" 303 | 304 | exit 0 305 | fi 306 | 307 | if [[ "${{ inputs.no_automatic_merge }}" == "true" ]]; then 308 | echo "Exiting due no_automatic_merge" 309 | 310 | exit 0 311 | fi 312 | 313 | echo "Pushing" 314 | git push 315 | 316 | echo "Cleaning up" 317 | git branch -D ${{ env.UPDATE_BRANCH }} || true 318 | git branch -D ${{ env.UPDATE_BRANCH_MERGED }} || true 319 | git push -f origin --delete ${{ env.UPDATE_BRANCH }} || true 320 | git push -f origin --delete ${{ env.UPDATE_BRANCH_MERGED }} || true 321 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Maven 2 | target/ 3 | pom.xml.tag 4 | pom.xml.releaseBackup 5 | pom.xml.versionsBackup 6 | pom.xml.next 7 | release.properties 8 | dependency-reduced-pom.xml 9 | buildNumber.properties 10 | .mvn/timing.properties 11 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar 12 | .mvn/wrapper/maven-wrapper.jar 13 | 14 | 15 | # Compiled class file 16 | *.class 17 | 18 | # Log file 19 | *.log 20 | 21 | # BlueJ files 22 | *.ctxt 23 | 24 | # Mobile Tools for Java (J2ME) 25 | .mtj.tmp/ 26 | 27 | # Package/Binary Files don't belong into a git repo 28 | *.jar 29 | *.war 30 | *.nar 31 | *.ear 32 | *.zip 33 | *.tar.gz 34 | *.rar 35 | *.dll 36 | *.exe 37 | *.bin 38 | 39 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 40 | hs_err_pid* 41 | 42 | # JRebel 43 | **/resources/rebel.xml 44 | **/resources/rebel-remote.xml 45 | 46 | # eclispe stuff for root 47 | /.settings/ 48 | /.classpath 49 | /.project 50 | 51 | 52 | # eclispe stuff for modules 53 | /*/.metadata/ 54 | /*/.apt_generated_tests/ 55 | /*/.settings/ 56 | /*/.classpath 57 | /*/.project 58 | /*/RemoteSystemsTempFiles/ 59 | 60 | 61 | #vaadin/node webpack/frontend stuff 62 | # Ignore Node 63 | node/ 64 | 65 | # The following files are generated/updated by vaadin-maven-plugin 66 | node_modules/ 67 | 68 | # Vaadin 69 | package.json 70 | package-lock.json 71 | webpack.generated.js 72 | webpack.config.js 73 | tsconfig.json 74 | types.d.ts 75 | vite.config.ts 76 | vite.generated.ts 77 | /*/src/main/frontend/generated/ 78 | /*/src/main/frontend/index.html 79 | /*/src/main/dev-bundle/ 80 | /*/src/main/bundles/ 81 | *.lock 82 | 83 | #custom 84 | .flattened-pom.xml 85 | .tern-project 86 | 87 | # == IntelliJ == 88 | *.iml 89 | *.ipr 90 | 91 | # Some files are user/installation independent and are used for configuring the IDE 92 | # See also https://stackoverflow.com/a/35279076 93 | 94 | .idea/* 95 | !.idea/saveactions_settings.xml 96 | !.idea/checkstyle-idea.xml 97 | !.idea/externalDependencies.xml 98 | 99 | !.idea/inspectionProfiles/ 100 | .idea/inspectionProfiles/* 101 | !.idea/inspectionProfiles/Project_Default.xml 102 | 103 | !.idea/codeStyles/ 104 | .idea/codeStyles/* 105 | !.idea/codeStyles/codeStyleConfig.xml 106 | !.idea/codeStyles/Project.xml 107 | -------------------------------------------------------------------------------- /.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10.21.0 5 | JavaOnlyWithTests 6 | true 7 | true 8 | 12 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 99 | 100 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/externalDependencies.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/saveactions_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 18 | -------------------------------------------------------------------------------- /.run/Run Demo.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 1.0.2 2 | * Migrated deployment to _Sonatype Maven Central Portal_ [#155](https://github.com/xdev-software/standard-maven-template/issues/155) 3 | * Updated dependencies 4 | 5 | # 1.0.1 6 | * Added customization degree 7 | * Makes it possible that certain filters or parts of them are read-only 8 | * Correctly set url when handling query parameters 9 | * Fix faulty reset-button-behaviour 10 | * Fix error when URL is disabled and fields are edited 11 | * Updated Vaadin to v24.6.0 and XDEV Date range picker to v4.2.0 12 | 13 | # 1.0.0 14 | _Initial release_ 15 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | We would absolutely love to get the community involved, and we welcome any form of contributions – comments and questions on different communication channels, issues and pull request and anything that you build and share using our components. 4 | 5 | ### Communication channels 6 | * Communication is primarily done using issues. 7 | * If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support). 8 | * As a last resort measure or on otherwise important matter you may also [contact us directly](https://xdev.software/en/about-us/contact). 9 | 10 | ### Ways to help 11 | * **Report bugs**
Create an issue or send a pull request 12 | * **Send pull requests**
If you want to contribute code, check out the development instructions below. 13 | * However when contributing larger new features, please first discuss the change you wish to make via issue with the owners of this repository before making it.
Otherwise your work might be rejected and your effort was pointless. 14 | 15 | We also encourage you to read the [contribution instructions by GitHub](https://docs.github.com/en/get-started/quickstart/contributing-to-projects). 16 | 17 | ## Developing 18 | 19 | ### Software Requirements 20 | You should have the following things installed: 21 | * Git 22 | * Java 21 - should be as unmodified as possible (Recommended: [Eclipse Adoptium](https://adoptium.net/temurin/releases/)) 23 | * Maven (Note that the [Maven Wrapper](https://maven.apache.org/wrapper/) is shipped with the repo) 24 | 25 | ### Recommended setup 26 | * Install ``IntelliJ`` (Community Edition is sufficient) 27 | * Install the following plugins: 28 | * [Save Actions](https://plugins.jetbrains.com/plugin/22113) - Provides save actions, like running the formatter or adding ``final`` to fields 29 | * [SonarLint](https://plugins.jetbrains.com/plugin/7973-sonarlint) - CodeStyle/CodeAnalysis 30 | * You may consider disabling telemetry in the settings under ``Tools > Sonarlint -> About`` 31 | * [Checkstyle-IDEA](https://plugins.jetbrains.com/plugin/1065-checkstyle-idea) - CodeStyle/CodeAnalysis 32 | * Import the project 33 | * Ensure that everything is encoded in ``UTF-8`` 34 | * Ensure that the JDK/Java-Version is correct 35 | * To enable AUTOMATIC reloading/restarting while developing and running the app do this (further information in " 36 | SpringBoot-Devtools" section below; [Source](https://stackoverflow.com/q/33349456)): 37 | * ``Settings > Build, Execution, Deployment > Compiler``:
38 | Enable [``Build project automatically``](https://www.jetbrains.com/help/idea/compiling-applications.html#auto-build) 39 | * ``Settings > Advanced Settings``:
40 | Enable [``Allow auto-make to start even if developed application is currently running``](https://www.jetbrains.com/help/idea/advanced-settings.html#advanced_compiler) 41 | * To launch the Demo execute the predefined (launch) configuration ``Run Demo`` 42 | 43 | #### [SpringBoot-Developer-Tools](https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools) 44 | ... should automatically be enabled.
45 | If you are changing a file and build the project, parts of the app get restarted.
46 | Bigger changes may require a complete restart. 47 | * [Vaadin automatically reloads the UI on each restart](https://vaadin.com/docs/latest/configuration/live-reload/spring-boot).
48 | You can control this behavior with the ``vaadin.devmode.liveReload.enabled`` property (default: ``true``). 49 | 50 | ## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/vaadin-simple-grid-filter/release.yml?branch=master)](https://github.com/xdev-software/vaadin-simple-grid-filter/actions/workflows/release.yml) 51 | 52 | Before releasing: 53 | * Consider doing a [test-deployment](https://github.com/xdev-software/vaadin-simple-grid-filter/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing. 54 | * Check the [changelog](CHANGELOG.md) 55 | 56 | If the ``develop`` is ready for release, create a pull request to the ``master``-Branch and merge the changes 57 | 58 | When the release is finished do the following: 59 | * Merge the auto-generated PR (with the incremented version number) back into the ``develop`` 60 | * Ensure that [Vaadin Directory](https://vaadin.com/directory) syncs the update and maybe update the component / version there 61 | 62 | ### Release failures 63 | 64 | There are 2 modes of release failure: 65 | 1. The remote server was e.g. down and non of the artifacts got published 66 | 2. There was a build failure during release and only parts of the artifacts got released 67 | 68 | In case 1 we can re-release the existing version,
in case 2 we have to release a new version when we can't get the artifacts deleted (as is the case with Maven Central) 69 | 70 | #### How-to: Re-Releasing an existing version 71 | 72 | 1. Delete the release on GitHub 73 | 2. Delete the release Git tag from the repo (locally and remote!) 74 | 3. Delete the ``master``-Branch and re-create it from the ``develop`` branch (or reset it to the state before the release-workflow commits have been done) 75 | * This requires __temporarily__ removing the branch protection 76 | * Once this was done a new release is triggered immediately! 77 | 78 | #### How-to: Releasing a new version 79 | 80 | 1. Merge the ``master`` branch back into ``develop`` (or another temporary branch) 81 | 2. Make sure all master branch versions are prepared for a new release
e.g. if the broken release was ``1.0.0`` the version should now be at ``1.0.1-SNAPSHOT`` - the ``SNAPSHOT`` is important for the workflow! 82 | 3. Mark the broken release as broken e.g. inside the Changelog, GitHub Release page, etc.
83 | You can use something like this: 84 | ``` 85 | > [!WARNING] 86 | > This release is broken as my cat accidentally clicked the abort button during the process 87 | ``` 88 | 4. Merge the changes back into the ``master`` branch to trigger a new release 89 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2024 XDEV Software 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0?logo=vaadin)](https://vaadin.com/directory/component/simple-grid-filter-for-vaadin) 2 | [![Latest version](https://img.shields.io/maven-central/v/software.xdev/vaadin-simple-grid-filter?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/vaadin-simple-grid-filter) 3 | [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/vaadin-simple-grid-filter/check-build.yml?branch=develop)](https://github.com/xdev-software/vaadin-simple-grid-filter/actions/workflows/check-build.yml?query=branch%3Adevelop) 4 | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_vaadin-simple-grid-filter&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_vaadin-simple-grid-filter) 5 | ![Vaadin 24+](https://img.shields.io/badge/Vaadin%20Platform/Flow-24+-00b4f0) 6 | 7 | # vaadin-simple-grid-filter 8 | 9 | A simple Vaadin Flow component for filtering Grids. 10 | 11 | ![demo](assets/demo.png) 12 | 13 | > [!NOTE] 14 | > If you are looking for a more advanced component you may check out our [grid-filter](https://github.com/xdev-software/vaadin-grid-filter). 15 | 16 | ## Usage 17 | 18 | Here is a very simple example how the FilterComponent can be used: 19 | ```java 20 | Grid grid = createGrid(); 21 | 22 | FilterComponent filter = new FilterComponent<>(grid) 23 | .withFilter(new SimpleFilterField<>(Person::getLastName, "Lastname")); 24 | 25 | this.add(filter, grid); 26 | ``` 27 | 28 | To get started further it's recommended to have a look at the [demo](./vaadin-simple-grid-filter-demo).
29 | A description how to get it running can be found [below](#run-the-demo). 30 | 31 | > [!IMPORTANT] 32 | > This component is designed for "in memory" filtering of small to medium sized amounts of data. 33 | 34 | > [!NOTE] 35 | > Filtering multiple thousand items with complex filtering conditions can drastically impact performance and make the UI unresponsive!
In these cases it's recommended to use backend filtering solutions like database queries or search engines like [ElasticSearch](https://en.wikipedia.org/wiki/Elasticsearch) in combination with a customized UI search framework. If you need help in implementing these feel free to [contact us](https://xdev.software/en/services/support). 36 | 37 | ## Installation 38 | [Installation guide for the latest release](https://github.com/xdev-software/vaadin-simple-grid-filter/releases/latest#Installation) 39 | 40 | #### Compatibility with Vaadin 41 | 42 | | Vaadin version | Grid-Filter version | 43 | | --- | --- | 44 | | Vaadin 24+ (latest) | ``1+`` | 45 | 46 | ### Spring-Boot 47 | * You may have to include ``software/xdev`` inside [``vaadin.allowed-packages``](https://vaadin.com/docs/latest/integrations/spring/configuration#configure-the-scanning-of-packages) 48 | 49 | ## Run the Demo 50 | * Checkout the repo 51 | * Run ``mvn install && mvn -f vaadin-simple-grid-filter-demo spring-boot:run`` 52 | * Open http://localhost:8080 53 | 54 |
55 | Show example 56 | 57 | ![demo](assets/demo.avif) 58 |
59 | 60 | ## Support 61 | If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support). 62 | 63 | ## Contributing 64 | See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how to get started with our project. 65 | 66 | ## Dependencies and Licenses 67 | View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/vaadin-simple-grid-filter/dependencies) 68 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/vaadin-simple-grid-filter/security/advisories/new). 6 | -------------------------------------------------------------------------------- /assets/demo.avif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdev-software/vaadin-simple-grid-filter/7fc927f0843b995f90a99aea2a6dccd6f30edaa5/assets/demo.avif -------------------------------------------------------------------------------- /assets/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdev-software/vaadin-simple-grid-filter/7fc927f0843b995f90a99aea2a6dccd6f30edaa5/assets/demo.png -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. 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, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Apache Maven Wrapper startup batch script, version 3.3.0 23 | # 24 | # Optional ENV vars 25 | # ----------------- 26 | # JAVA_HOME - location of a JDK home dir, required when download maven via java source 27 | # MVNW_REPOURL - repo url base for downloading maven distribution 28 | # MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 29 | # MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output 30 | # ---------------------------------------------------------------------------- 31 | 32 | set -euf 33 | [ "${MVNW_VERBOSE-}" != debug ] || set -x 34 | 35 | # OS specific support. 36 | native_path() { printf %s\\n "$1"; } 37 | case "$(uname)" in 38 | CYGWIN* | MINGW*) 39 | [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" 40 | native_path() { cygpath --path --windows "$1"; } 41 | ;; 42 | esac 43 | 44 | # set JAVACMD and JAVACCMD 45 | set_java_home() { 46 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched 47 | if [ -n "${JAVA_HOME-}" ]; then 48 | if [ -x "$JAVA_HOME/jre/sh/java" ]; then 49 | # IBM's JDK on AIX uses strange locations for the executables 50 | JAVACMD="$JAVA_HOME/jre/sh/java" 51 | JAVACCMD="$JAVA_HOME/jre/sh/javac" 52 | else 53 | JAVACMD="$JAVA_HOME/bin/java" 54 | JAVACCMD="$JAVA_HOME/bin/javac" 55 | 56 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then 57 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 58 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 59 | return 1 60 | fi 61 | fi 62 | else 63 | JAVACMD="$( 64 | 'set' +e 65 | 'unset' -f command 2>/dev/null 66 | 'command' -v java 67 | )" || : 68 | JAVACCMD="$( 69 | 'set' +e 70 | 'unset' -f command 2>/dev/null 71 | 'command' -v javac 72 | )" || : 73 | 74 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then 75 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 76 | return 1 77 | fi 78 | fi 79 | } 80 | 81 | # hash string like Java String::hashCode 82 | hash_string() { 83 | str="${1:-}" h=0 84 | while [ -n "$str" ]; do 85 | char="${str%"${str#?}"}" 86 | h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) 87 | str="${str#?}" 88 | done 89 | printf %x\\n $h 90 | } 91 | 92 | verbose() { :; } 93 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } 94 | 95 | die() { 96 | printf %s\\n "$1" >&2 97 | exit 1 98 | } 99 | 100 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties 101 | while IFS="=" read -r key value; do 102 | case "${key-}" in 103 | distributionUrl) distributionUrl="${value-}" ;; 104 | distributionSha256Sum) distributionSha256Sum="${value-}" ;; 105 | esac 106 | done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" 107 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" 108 | 109 | case "${distributionUrl##*/}" in 110 | maven-mvnd-*bin.*) 111 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ 112 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in 113 | *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; 114 | :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; 115 | :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; 116 | :Linux*x86_64*) distributionPlatform=linux-amd64 ;; 117 | *) 118 | echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 119 | distributionPlatform=linux-amd64 120 | ;; 121 | esac 122 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" 123 | ;; 124 | maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; 125 | *) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; 126 | esac 127 | 128 | # apply MVNW_REPOURL and calculate MAVEN_HOME 129 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 130 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" 131 | distributionUrlName="${distributionUrl##*/}" 132 | distributionUrlNameMain="${distributionUrlName%.*}" 133 | distributionUrlNameMain="${distributionUrlNameMain%-bin}" 134 | MAVEN_HOME="$HOME/.m2/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" 135 | 136 | exec_maven() { 137 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : 138 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" 139 | } 140 | 141 | if [ -d "$MAVEN_HOME" ]; then 142 | verbose "found existing MAVEN_HOME at $MAVEN_HOME" 143 | exec_maven "$@" 144 | fi 145 | 146 | case "${distributionUrl-}" in 147 | *?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; 148 | *) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; 149 | esac 150 | 151 | # prepare tmp dir 152 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then 153 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } 154 | trap clean HUP INT TERM EXIT 155 | else 156 | die "cannot create temp dir" 157 | fi 158 | 159 | mkdir -p -- "${MAVEN_HOME%/*}" 160 | 161 | # Download and Install Apache Maven 162 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 163 | verbose "Downloading from: $distributionUrl" 164 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 165 | 166 | # select .zip or .tar.gz 167 | if ! command -v unzip >/dev/null; then 168 | distributionUrl="${distributionUrl%.zip}.tar.gz" 169 | distributionUrlName="${distributionUrl##*/}" 170 | fi 171 | 172 | # verbose opt 173 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' 174 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v 175 | 176 | # normalize http auth 177 | case "${MVNW_PASSWORD:+has-password}" in 178 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;; 179 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; 180 | esac 181 | 182 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then 183 | verbose "Found wget ... using wget" 184 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" 185 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then 186 | verbose "Found curl ... using curl" 187 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" 188 | elif set_java_home; then 189 | verbose "Falling back to use Java to download" 190 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" 191 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" 192 | cat >"$javaSource" <<-END 193 | public class Downloader extends java.net.Authenticator 194 | { 195 | protected java.net.PasswordAuthentication getPasswordAuthentication() 196 | { 197 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); 198 | } 199 | public static void main( String[] args ) throws Exception 200 | { 201 | setDefault( new Downloader() ); 202 | java.nio.file.Files.copy( new java.net.URL( args[0] ).openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); 203 | } 204 | } 205 | END 206 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java 207 | verbose " - Compiling Downloader.java ..." 208 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" 209 | verbose " - Running Downloader.java ..." 210 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" 211 | fi 212 | 213 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 214 | if [ -n "${distributionSha256Sum-}" ]; then 215 | distributionSha256Result=false 216 | if [ "$MVN_CMD" = mvnd.sh ]; then 217 | echo "Checksum validation is not supported for maven-mvnd." >&2 218 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 219 | exit 1 220 | elif command -v sha256sum >/dev/null; then 221 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then 222 | distributionSha256Result=true 223 | fi 224 | elif command -v shasum >/dev/null; then 225 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then 226 | distributionSha256Result=true 227 | fi 228 | else 229 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 230 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 231 | exit 1 232 | fi 233 | if [ $distributionSha256Result = false ]; then 234 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 235 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 236 | exit 1 237 | fi 238 | fi 239 | 240 | # unzip and move 241 | if command -v unzip >/dev/null; then 242 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" 243 | else 244 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" 245 | fi 246 | printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" 247 | mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" 248 | 249 | clean || : 250 | exec_maven "$@" 251 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | <# : batch portion 2 | @REM ---------------------------------------------------------------------------- 3 | @REM Licensed to the Apache Software Foundation (ASF) under one 4 | @REM or more contributor license agreements. See the NOTICE file 5 | @REM distributed with this work for additional information 6 | @REM regarding copyright ownership. The ASF licenses this file 7 | @REM to you under the Apache License, Version 2.0 (the 8 | @REM "License"); you may not use this file except in compliance 9 | @REM with the License. You may obtain a copy of the License at 10 | @REM 11 | @REM http://www.apache.org/licenses/LICENSE-2.0 12 | @REM 13 | @REM Unless required by applicable law or agreed to in writing, 14 | @REM software distributed under the License is distributed on an 15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | @REM KIND, either express or implied. See the License for the 17 | @REM specific language governing permissions and limitations 18 | @REM under the License. 19 | @REM ---------------------------------------------------------------------------- 20 | 21 | @REM ---------------------------------------------------------------------------- 22 | @REM Apache Maven Wrapper startup batch script, version 3.3.0 23 | @REM 24 | @REM Optional ENV vars 25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution 26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output 28 | @REM ---------------------------------------------------------------------------- 29 | 30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) 31 | @SET __MVNW_CMD__= 32 | @SET __MVNW_ERROR__= 33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath% 34 | @SET PSModulePath= 35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( 36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) 37 | ) 38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE% 39 | @SET __MVNW_PSMODULEP_SAVE= 40 | @SET __MVNW_ARG0_NAME__= 41 | @SET MVNW_USERNAME= 42 | @SET MVNW_PASSWORD= 43 | @IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) 44 | @echo Cannot start maven from wrapper >&2 && exit /b 1 45 | @GOTO :EOF 46 | : end batch / begin powershell #> 47 | 48 | $ErrorActionPreference = "Stop" 49 | if ($env:MVNW_VERBOSE -eq "true") { 50 | $VerbosePreference = "Continue" 51 | } 52 | 53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties 54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl 55 | if (!$distributionUrl) { 56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" 57 | } 58 | 59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { 60 | "maven-mvnd-*" { 61 | $USE_MVND = $true 62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" 63 | $MVN_CMD = "mvnd.cmd" 64 | break 65 | } 66 | default { 67 | $USE_MVND = $false 68 | $MVN_CMD = $script -replace '^mvnw','mvn' 69 | break 70 | } 71 | } 72 | 73 | # apply MVNW_REPOURL and calculate MAVEN_HOME 74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 75 | if ($env:MVNW_REPOURL) { 76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } 77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" 78 | } 79 | $distributionUrlName = $distributionUrl -replace '^.*/','' 80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' 81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" 82 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' 83 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" 84 | 85 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { 86 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" 87 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 88 | exit $? 89 | } 90 | 91 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { 92 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" 93 | } 94 | 95 | # prepare tmp dir 96 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile 97 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" 98 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null 99 | trap { 100 | if ($TMP_DOWNLOAD_DIR.Exists) { 101 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 102 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 103 | } 104 | } 105 | 106 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null 107 | 108 | # Download and Install Apache Maven 109 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 110 | Write-Verbose "Downloading from: $distributionUrl" 111 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 112 | 113 | $webclient = New-Object System.Net.WebClient 114 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { 115 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) 116 | } 117 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 118 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null 119 | 120 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 121 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum 122 | if ($distributionSha256Sum) { 123 | if ($USE_MVND) { 124 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." 125 | } 126 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash 127 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { 128 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." 129 | } 130 | } 131 | 132 | # unzip and move 133 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null 134 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null 135 | try { 136 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null 137 | } catch { 138 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { 139 | Write-Error "fail to move MAVEN_HOME" 140 | } 141 | } finally { 142 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 143 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 144 | } 145 | 146 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 147 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | software.xdev 8 | vaadin-simple-grid-filter-root 9 | 1.0.3-SNAPSHOT 10 | pom 11 | 12 | 13 | XDEV Software 14 | https://xdev.software 15 | 16 | 17 | 18 | vaadin-simple-grid-filter 19 | vaadin-simple-grid-filter-demo 20 | 21 | 22 | 23 | UTF-8 24 | UTF-8 25 | 26 | 27 | 28 | 29 | Apache-2.0 30 | https://www.apache.org/licenses/LICENSE-2.0.txt 31 | repo 32 | 33 | 34 | 35 | 36 | 37 | checkstyle 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-checkstyle-plugin 43 | 3.6.0 44 | 45 | 46 | com.puppycrawl.tools 47 | checkstyle 48 | 10.24.0 49 | 50 | 51 | 52 | .config/checkstyle/checkstyle.xml 53 | true 54 | 55 | 56 | 57 | 58 | check 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | pmd 68 | 69 | 70 | 71 | org.apache.maven.plugins 72 | maven-pmd-plugin 73 | 3.26.0 74 | 75 | true 76 | true 77 | 78 | .config/pmd/ruleset.xml 79 | 80 | 81 | 82 | 83 | net.sourceforge.pmd 84 | pmd-core 85 | 7.13.0 86 | 87 | 88 | net.sourceforge.pmd 89 | pmd-java 90 | 7.13.0 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | org.apache.maven.plugins 101 | maven-jxr-plugin 102 | 3.6.0 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /renovate.json5: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "rebaseWhen": "behind-base-branch", 4 | "packageRules": [ 5 | { 6 | "description": "Ignore project internal dependencies", 7 | "packagePattern": "^software.xdev:vaadin-simple-grid-filter", 8 | "datasources": [ 9 | "maven" 10 | ], 11 | "enabled": false 12 | }, 13 | { 14 | "description": "Group net.sourceforge.pmd", 15 | "matchPackagePatterns": [ 16 | "^net.sourceforge.pmd" 17 | ], 18 | "datasources": [ 19 | "maven" 20 | ], 21 | "groupName": "net.sourceforge.pmd" 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | software.xdev 9 | vaadin-simple-grid-filter-root 10 | 1.0.3-SNAPSHOT 11 | 12 | 13 | vaadin-simple-grid-filter-demo 14 | 1.0.3-SNAPSHOT 15 | jar 16 | 17 | 18 | XDEV Software 19 | https://xdev.software 20 | 21 | 22 | 23 | 17 24 | ${javaVersion} 25 | 26 | UTF-8 27 | UTF-8 28 | 29 | software.xdev.vaadin.Application 30 | 31 | 32 | 24.7.4 33 | 34 | 3.4.5 35 | 36 | 37 | 38 | 39 | 40 | com.vaadin 41 | vaadin-bom 42 | pom 43 | import 44 | ${vaadin.version} 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-dependencies 53 | ${org.springframework.boot.version} 54 | pom 55 | import 56 | 57 | 58 | 59 | 60 | 61 | 62 | com.vaadin 63 | vaadin-core 64 | 65 | 66 | com.vaadin 67 | hilla-dev 68 | 69 | 70 | 71 | 72 | software.xdev 73 | vaadin-simple-grid-filter 74 | ${project.version} 75 | 76 | 77 | 78 | 79 | com.vaadin 80 | vaadin-spring-boot-starter 81 | 82 | 83 | com.vaadin 84 | hilla 85 | 86 | 87 | 88 | 89 | 90 | org.yaml 91 | snakeyaml 92 | 93 | 94 | org.springframework.boot 95 | spring-boot-devtools 96 | true 97 | 98 | 99 | 100 | 101 | ${project.artifactId} 102 | 103 | 104 | 105 | 106 | org.springframework.boot 107 | spring-boot-maven-plugin 108 | ${org.springframework.boot.version} 109 | 110 | 111 | 112 | 113 | 114 | 115 | com.vaadin 116 | vaadin-maven-plugin 117 | ${vaadin.version} 118 | 119 | 120 | 121 | prepare-frontend 122 | 123 | 124 | 125 | 126 | 127 | org.apache.maven.plugins 128 | maven-compiler-plugin 129 | 3.14.0 130 | 131 | ${maven.compiler.release} 132 | 133 | -proc:none 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | production 143 | 144 | 145 | 146 | com.vaadin 147 | vaadin-core 148 | 149 | 150 | com.vaadin 151 | vaadin-dev 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | com.vaadin 160 | vaadin-maven-plugin 161 | ${vaadin.version} 162 | 163 | 164 | 165 | prepare-frontend 166 | build-frontend 167 | 168 | 169 | 170 | 171 | 172 | org.springframework.boot 173 | spring-boot-maven-plugin 174 | 175 | ${mainClass} 176 | 177 | 178 | 179 | repackage 180 | 181 | repackage 182 | 183 | package 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter-demo/src/main/java/software/xdev/vaadin/Application.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 6 | 7 | import com.vaadin.flow.component.page.AppShellConfigurator; 8 | import com.vaadin.flow.component.page.Push; 9 | import com.vaadin.flow.spring.annotation.EnableVaadin; 10 | 11 | 12 | @SuppressWarnings({"checkstyle:HideUtilityClassConstructor", "PMD.UseUtilityClass"}) 13 | @SpringBootApplication 14 | @EnableVaadin 15 | @Push 16 | public class Application extends SpringBootServletInitializer implements AppShellConfigurator 17 | { 18 | public static void main(final String[] args) 19 | { 20 | SpringApplication.run(Application.class, args); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter-demo/src/main/java/software/xdev/vaadin/model/Department.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.model; 2 | 3 | public enum Department 4 | { 5 | IT, 6 | HR, 7 | ACCOUNTING 8 | } 9 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter-demo/src/main/java/software/xdev/vaadin/model/Person.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.model; 2 | 3 | import java.time.LocalDate; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | 8 | /** 9 | * Represents a person with attributes such as first name, last name, birthday, subscription status, and an identifier. 10 | */ 11 | public class Person 12 | { 13 | private Integer id; 14 | private String firstName; 15 | private String lastName; 16 | private LocalDate birthday; 17 | private boolean married; 18 | private double salary; 19 | private Department department; 20 | 21 | /** 22 | * Constructs a new instance of the Person class with the provided attributes. 23 | * 24 | * @param id The unique identifier of the person. 25 | * @param firstName The first name of the person. 26 | * @param lastName The last name of the person. 27 | * @param birthday The birthdate of the person. 28 | * @param married Whether the person is a married (true) or not (false). 29 | * @param salary The paid salary 30 | * @param department The associated department 31 | */ 32 | public Person( 33 | final Integer id, 34 | final String firstName, 35 | final String lastName, 36 | final LocalDate birthday, 37 | final boolean married, 38 | final double salary, 39 | final Department department) 40 | { 41 | this.id = id; 42 | this.firstName = firstName; 43 | this.lastName = lastName; 44 | this.birthday = birthday; 45 | this.married = married; 46 | this.salary = salary; 47 | this.department = department; 48 | } 49 | 50 | /** 51 | * Gets the first name of the person. 52 | * 53 | * @return The first name of the person. 54 | */ 55 | public String getFirstName() 56 | { 57 | return this.firstName; 58 | } 59 | 60 | /** 61 | * Sets the first name of the person. 62 | * 63 | * @param firstName The new first name to set. 64 | */ 65 | public void setFirstName(final String firstName) 66 | { 67 | this.firstName = firstName; 68 | } 69 | 70 | /** 71 | * Gets the last name of the person. 72 | * 73 | * @return The last name of the person. 74 | */ 75 | public String getLastName() 76 | { 77 | return this.lastName; 78 | } 79 | 80 | /** 81 | * Sets the last name of the person. 82 | * 83 | * @param lastName The new last name to set. 84 | */ 85 | public void setLastName(final String lastName) 86 | { 87 | this.lastName = lastName; 88 | } 89 | 90 | /** 91 | * Gets the birthdate of the person. 92 | * 93 | * @return The birthdate of the person. 94 | */ 95 | public LocalDate getBirthday() 96 | { 97 | return this.birthday; 98 | } 99 | 100 | /** 101 | * Sets the birthdate of the person. 102 | * 103 | * @param birthday The new birthdate to set. 104 | */ 105 | public void setBirthday(final LocalDate birthday) 106 | { 107 | this.birthday = birthday; 108 | } 109 | 110 | /** 111 | * Gets the unique identifier of the person. 112 | * 113 | * @return The unique identifier of the person. 114 | */ 115 | public Integer getId() 116 | { 117 | return this.id; 118 | } 119 | 120 | /** 121 | * Sets the unique identifier of the person. 122 | * 123 | * @param id The new unique identifier to set. 124 | */ 125 | public void setId(final Integer id) 126 | { 127 | this.id = id; 128 | } 129 | 130 | /** 131 | * Checks if the person is married. 132 | * 133 | * @return True if the person is married, false otherwise. 134 | */ 135 | public boolean isMarried() 136 | { 137 | return this.married; 138 | } 139 | 140 | /** 141 | * Sets person's married status. 142 | * 143 | * @param married True to mark the person as married, false to mark the person as unmarried. 144 | */ 145 | public void setMarried(final boolean married) 146 | { 147 | this.married = married; 148 | } 149 | 150 | /** 151 | * Gets the salary of the person. 152 | * 153 | * @return The salary of the person. 154 | */ 155 | 156 | public double getSalary() 157 | { 158 | return this.salary; 159 | } 160 | 161 | /** 162 | * Sets the salary of the person. 163 | * 164 | * @param salary The new salary to set. 165 | */ 166 | public void setSalary(final double salary) 167 | { 168 | this.salary = salary; 169 | } 170 | 171 | /** 172 | * Gets the associated department of the person. 173 | * 174 | * @return The associated department of the person. 175 | */ 176 | public Department getDepartment() 177 | { 178 | return this.department; 179 | } 180 | 181 | /** 182 | * Sets the associated department of the person. 183 | * 184 | * @param department The associated department to set. 185 | */ 186 | public void setDepartment(final Department department) 187 | { 188 | this.department = department; 189 | } 190 | 191 | /** 192 | * Retrieves a list of sample Person objects. 193 | * 194 | * @return A List containing sample Person objects. 195 | */ 196 | @SuppressWarnings("checkstyle:MagicNumber") 197 | public static List getPersons() 198 | { 199 | final List lst = new ArrayList<>(); 200 | 201 | lst.add(new Person(0, "Siegbert", "Schmidt", LocalDate.of(1990, 12, 17), false, 1000, Department.HR)); 202 | lst.add(new Person(1, "Herbert", "Maier", LocalDate.of(1967, 10, 13), false, 1000, Department.HR)); 203 | lst.add(new Person(2, "Hans", "Lang", LocalDate.of(2002, 5, 9), true, 9050.60, Department.HR)); 204 | lst.add(new Person(3, "Anton", "Meier", LocalDate.of(1985, 1, 24), true, 8000.75, Department.HR)); 205 | lst.add(new Person(4, "Sarah", "Smith", LocalDate.of(1999, 6, 1), false, 5000, Department.IT)); 206 | lst.add(new Person(5, "Niklas", "Sommer", LocalDate.of(1994, 11, 8), true, 4000.33, Department.HR)); 207 | lst.add(new Person(6, "Hanna", "Neubaum", LocalDate.of(1986, 8, 15), true, 3000, Department.HR)); 208 | lst.add(new Person(8, "Laura", "Fels", LocalDate.of(1996, 3, 20), true, 1000.50, Department.HR)); 209 | lst.add(new Person(7, "Sofia", "Sommer", LocalDate.of(1972, 4, 14), false, 2000, Department.ACCOUNTING)); 210 | 211 | return lst; 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter-demo/src/main/java/software/xdev/vaadin/ui/MainView.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.ui; 2 | 3 | import java.time.LocalDate; 4 | import java.util.List; 5 | import java.util.Locale; 6 | 7 | import com.vaadin.flow.component.datepicker.DatePicker; 8 | import com.vaadin.flow.component.grid.Grid; 9 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 10 | import com.vaadin.flow.data.provider.ListDataProvider; 11 | import com.vaadin.flow.router.AfterNavigationEvent; 12 | import com.vaadin.flow.router.AfterNavigationObserver; 13 | import com.vaadin.flow.router.Route; 14 | 15 | import software.xdev.vaadin.FilterComponent; 16 | import software.xdev.vaadin.builder.CustomizableFilterBuilder; 17 | import software.xdev.vaadin.comparators.EqualComparator; 18 | import software.xdev.vaadin.comparators.IsBetweenComparator; 19 | import software.xdev.vaadin.comparators.NotEqualComparator; 20 | import software.xdev.vaadin.daterange_picker.business.DateRangeModel; 21 | import software.xdev.vaadin.daterange_picker.business.SimpleDateRanges; 22 | import software.xdev.vaadin.model.CustomizationDegree; 23 | import software.xdev.vaadin.model.Department; 24 | import software.xdev.vaadin.model.Person; 25 | import software.xdev.vaadin.model.SimpleFilterField; 26 | 27 | 28 | /** 29 | * Primary UI with filter component and grid. 30 | */ 31 | @Route("") 32 | public class MainView extends VerticalLayout implements AfterNavigationObserver 33 | { 34 | private final Grid dataGrid = new Grid<>(Person.class, true); 35 | 36 | public MainView() 37 | { 38 | super(); 39 | this.initUI(); 40 | } 41 | 42 | private void initUI() 43 | { 44 | // Grid configuration. 45 | this.dataGrid.setSelectionMode(Grid.SelectionMode.NONE); 46 | this.dataGrid.setSizeFull(); 47 | 48 | // Fill grid with dummy data. 49 | this.dataGrid.setDataProvider(new ListDataProvider<>(Person.getPersons())); 50 | 51 | final DatePicker.DatePickerI18n datePickerI18n = new DatePicker.DatePickerI18n() 52 | .setDateFormat("dd.MM.yyyy"); 53 | 54 | // Create the FilterComponent. 55 | final FilterComponent filterComponent = new FilterComponent<>(this.dataGrid) 56 | .withFilter(new SimpleFilterField<>(Person::getLastName, "Lastname")) 57 | .withFilter(new SimpleFilterField<>(Person::getSalary, "Salary")) 58 | .withFilter( 59 | CustomizableFilterBuilder.builder() 60 | .withValueProvider(Person::getId, "Personnel number") 61 | .withEqualComparator() 62 | .withGreaterThanComparator() 63 | .withLessThanComparator() 64 | ) 65 | .withFilter( 66 | CustomizableFilterBuilder.builder() 67 | .withValueProvider(Person::isMarried, "Married") 68 | .withEqualComparator() 69 | .withAvailableComparator(NotEqualComparator.getInstance()) 70 | ) 71 | .withFilter( 72 | CustomizableFilterBuilder.builder() 73 | .withValueProvider(Person::getDepartment, "Department", Department.values()) 74 | .withContainsComparator() 75 | .withEqualComparator() 76 | ) 77 | .withFilter( 78 | CustomizableFilterBuilder.builder() 79 | .withValueProvider(Person::getBirthday, "Birthday") 80 | .withIsAfterComparator() 81 | .withIsAfterOrEqualsComparator() 82 | .withIsBeforeComparator() 83 | .withIsBeforeOrEqualsComparator() 84 | .withIsBetweenComparator() 85 | ) 86 | .withDatePickerI18n(datePickerI18n) 87 | .withDateTimePickerLocale(Locale.GERMANY) 88 | .withFilterButtonText("Add filter") 89 | .withUrlParameters("filter1") 90 | .withCustomDateRangeModel( 91 | new DateRangeModel<>(LocalDate.now(), LocalDate.now().plusDays(5), SimpleDateRanges.FREE), 92 | List.of(SimpleDateRanges.allValues())) 93 | .withInitialFilter( 94 | CustomizableFilterBuilder.builder().withValueProvider(Person::getBirthday, "Birthday"), 95 | IsBetweenComparator.getInstance(), "2000-01-01#2002-08-12", 96 | true, 97 | true 98 | ) 99 | .withInitialFilter( 100 | CustomizableFilterBuilder.builder().withValueProvider(Person::isMarried, "Married"), 101 | EqualComparator.getInstance(), 102 | "true", 103 | false, 104 | true, 105 | CustomizationDegree.INPUT_VALUE 106 | ); 107 | 108 | this.add(filterComponent, this.dataGrid); 109 | this.setSizeFull(); 110 | } 111 | 112 | @Override 113 | public void afterNavigation(final AfterNavigationEvent event) 114 | { 115 | 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter-demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | vaadin: 2 | allowed-packages: software/xdev,com/vaadin/flow 3 | devmode: 4 | usageStatistics: 5 | enabled: false 6 | 7 | spring: 8 | devtools: 9 | restart: 10 | poll-interval: 2s 11 | quiet-period: 1s 12 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | software.xdev 8 | vaadin-simple-grid-filter 9 | 1.0.3-SNAPSHOT 10 | jar 11 | 12 | Simple Grid Filter for Vaadin 13 | Simple Grid Filter for Vaadin 14 | https://github.com/xdev-software/vaadin-simple-grid-filter 15 | 16 | 17 | https://github.com/xdev-software/vaadin-simple-grid-filter 18 | scm:git:https://github.com/xdev-software/vaadin-simple-grid-filter.git 19 | 20 | 21 | 2024 22 | 23 | 24 | XDEV Software 25 | https://xdev.software 26 | 27 | 28 | 29 | 30 | XDEV Software 31 | XDEV Software 32 | https://xdev.software 33 | 34 | 35 | 36 | 37 | 38 | Apache-2.0 39 | https://www.apache.org/licenses/LICENSE-2.0.txt 40 | repo 41 | 42 | 43 | 44 | 45 | 17 46 | ${javaVersion} 47 | 48 | UTF-8 49 | UTF-8 50 | 51 | 52 | 24.7.4 53 | 54 | 55 | 56 | 57 | 58 | com.vaadin 59 | vaadin-bom 60 | pom 61 | import 62 | ${vaadin.version} 63 | 64 | 65 | 66 | 67 | 68 | 69 | com.vaadin 70 | vaadin-core 71 | 72 | 73 | software.xdev 74 | vaadin-date-range-picker 75 | 4.2.0 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-site-plugin 85 | 4.0.0-M16 86 | 87 | 88 | org.apache.maven.plugins 89 | maven-project-info-reports-plugin 90 | 3.9.0 91 | 92 | 93 | 94 | 95 | 96 | com.mycila 97 | license-maven-plugin 98 | 5.0.0 99 | 100 | 101 | ${project.organization.url} 102 | 103 | 104 | 105 |
com/mycila/maven/plugin/license/templates/APACHE-2.txt
106 | 107 | src/main/java/** 108 | src/test/java/** 109 | 110 |
111 |
112 |
113 | 114 | 115 | first 116 | 117 | format 118 | 119 | process-sources 120 | 121 | 122 |
123 | 124 | 126 | 127 | com.vaadin 128 | vaadin-maven-plugin 129 | ${vaadin.version} 130 | 131 | 132 | 133 | prepare-frontend 134 | 135 | 136 | 137 | 138 | 139 | 140 | org.apache.maven.plugins 141 | maven-compiler-plugin 142 | 3.14.0 143 | 144 | ${maven.compiler.release} 145 | 146 | -proc:none 147 | 148 | 149 | 150 | 151 | org.apache.maven.plugins 152 | maven-javadoc-plugin 153 | 3.11.2 154 | 155 | 156 | attach-javadocs 157 | package 158 | 159 | jar 160 | 161 | 162 | 163 | 164 | true 165 | none 166 | 167 | 168 | 169 | org.apache.maven.plugins 170 | maven-source-plugin 171 | 3.3.1 172 | 173 | 174 | attach-sources 175 | package 176 | 177 | jar-no-fork 178 | 179 | 180 | 181 | 182 | 183 | org.apache.maven.plugins 184 | maven-jar-plugin 185 | 3.4.2 186 | 187 | 188 | true 189 | 190 | false 191 | true 192 | 193 | 194 | 195 | 1 196 | 197 | 198 | 199 | 200 | 201 | META-INF/VAADIN/ 202 | 203 | 204 | 205 | 206 |
207 |
208 | 209 | 210 | publish-sonatype-central-portal 211 | 212 | 213 | 214 | org.codehaus.mojo 215 | flatten-maven-plugin 216 | 1.7.0 217 | 218 | ossrh 219 | 220 | 221 | 222 | flatten 223 | process-resources 224 | 225 | flatten 226 | 227 | 228 | 229 | 230 | 231 | org.apache.maven.plugins 232 | maven-gpg-plugin 233 | 3.2.7 234 | 235 | 236 | sign-artifacts 237 | verify 238 | 239 | sign 240 | 241 | 242 | 243 | 244 | 245 | --pinentry-mode 246 | loopback 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | org.sonatype.central 255 | central-publishing-maven-plugin 256 | 0.7.0 257 | true 258 | 259 | sonatype-central-portal 260 | true 261 | 262 | 263 | 264 | 265 | 266 | 267 | checkstyle 268 | 269 | 270 | 271 | org.apache.maven.plugins 272 | maven-checkstyle-plugin 273 | 3.6.0 274 | 275 | 276 | com.puppycrawl.tools 277 | checkstyle 278 | 10.24.0 279 | 280 | 281 | 282 | ../.config/checkstyle/checkstyle.xml 283 | true 284 | 285 | 286 | 287 | 288 | check 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | pmd 298 | 299 | 300 | 301 | org.apache.maven.plugins 302 | maven-pmd-plugin 303 | 3.26.0 304 | 305 | true 306 | true 307 | 308 | ../.config/pmd/ruleset.xml 309 | 310 | 311 | 312 | 313 | net.sourceforge.pmd 314 | pmd-core 315 | 7.13.0 316 | 317 | 318 | net.sourceforge.pmd 319 | pmd-java 320 | 7.13.0 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | org.apache.maven.plugins 331 | maven-jxr-plugin 332 | 3.6.0 333 | 334 | 335 | 336 | 337 | 338 |
339 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/builder/CustomizableFilterBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.builder; 17 | 18 | import java.time.LocalDate; 19 | import java.time.LocalDateTime; 20 | import java.util.ArrayList; 21 | import java.util.Objects; 22 | 23 | import com.vaadin.flow.function.ValueProvider; 24 | 25 | import software.xdev.vaadin.model.FilterField; 26 | import software.xdev.vaadin.model.FilterFieldEnumExtension; 27 | import software.xdev.vaadin.model.FilterProvider; 28 | 29 | 30 | /** 31 | * Used to create a customizable FilterField. 32 | * 33 | * @see FilterField 34 | */ 35 | public class CustomizableFilterBuilder 36 | { 37 | public static CustomizableFilterBuilder builder() 38 | { 39 | return new CustomizableFilterBuilder(); 40 | } 41 | 42 | public FilterField withValueProvider( 43 | final FilterProvider.StringProvider provider, 44 | final String description) 45 | { 46 | return this.withValueProvider(provider, description, String.class); 47 | } 48 | 49 | public FilterField withValueProvider( 50 | final FilterProvider.NumberProvider provider, 51 | final String description) 52 | { 53 | return this.withValueProvider(provider, description, Number.class); 54 | } 55 | 56 | public FilterField withValueProvider( 57 | final FilterProvider.LocalDateProvider provider, 58 | final String description) 59 | { 60 | return this.withValueProvider(provider, description, LocalDate.class); 61 | } 62 | 63 | public FilterField withValueProvider( 64 | final FilterProvider.LocalDateTimeProvider provider, 65 | final String description) 66 | { 67 | return this.withValueProvider(provider, description, LocalDateTime.class); 68 | } 69 | 70 | public FilterField withValueProvider( 71 | final FilterProvider.BooleanProvider provider, 72 | final String description) 73 | { 74 | return this.withValueProvider(provider, description, Boolean.class); 75 | } 76 | 77 | public FilterField withValueProvider( 78 | final FilterProvider.EnumProvider provider, 79 | final String description, 80 | final Enum[] enumValues) 81 | { 82 | return new FilterFieldEnumExtension<>(provider, description, Enum.class, new ArrayList<>(), enumValues); 83 | } 84 | 85 | public FilterField withValueProvider( 86 | final ValueProvider provider, 87 | final String description, 88 | final Class type) 89 | { 90 | Objects.requireNonNull(provider); 91 | Objects.requireNonNull(description); 92 | 93 | return new FilterField<>(provider, description, type, new ArrayList<>()); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/ContainsComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.util.function.Predicate; 19 | 20 | import com.vaadin.flow.function.ValueProvider; 21 | 22 | import software.xdev.vaadin.comparators.utl.TypeHelper; 23 | 24 | // CPD-OFF - Fixed in v2 25 | /** 26 | * Used for comparison with contains. 27 | */ 28 | public final class ContainsComparator implements FilterComparator 29 | { 30 | public static final String CONTAINS_COMPARATOR_DESCRIPTION = "contains"; 31 | 32 | private static ContainsComparator instance; 33 | 34 | private ContainsComparator() 35 | { 36 | } 37 | 38 | public static ContainsComparator getInstance() 39 | { 40 | if(instance == null) 41 | { 42 | instance = new ContainsComparator(); 43 | } 44 | 45 | return instance; 46 | } 47 | 48 | @Override 49 | public String getDescription() 50 | { 51 | return CONTAINS_COMPARATOR_DESCRIPTION; 52 | } 53 | 54 | @Override 55 | public boolean isApplicable(final Class clazz) 56 | { 57 | return String.class.isAssignableFrom(clazz) 58 | || Number.class.isAssignableFrom(clazz) 59 | || Enum.class.isAssignableFrom(clazz); 60 | } 61 | 62 | @Override 63 | public Predicate compare(final ValueProvider provider, final String searchQuery) 64 | { 65 | return item -> 66 | { 67 | final T apply = provider.apply(item); 68 | 69 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 70 | 71 | if(apply instanceof final String strValue) 72 | { 73 | return strValue.contains(searchQuery); 74 | } 75 | 76 | if(apply instanceof final Number numb && TypeHelper.isDouble(searchQuery)) 77 | { 78 | return numb.toString().contains(searchQuery); 79 | } 80 | 81 | if(apply instanceof final Enum enm) 82 | { 83 | return enm.toString().contains(searchQuery); 84 | } 85 | 86 | return false; 87 | }; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/EqualComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.time.LocalDate; 19 | import java.time.LocalDateTime; 20 | import java.time.temporal.TemporalAccessor; 21 | import java.util.function.Predicate; 22 | 23 | import com.vaadin.flow.function.ValueProvider; 24 | 25 | import software.xdev.vaadin.comparators.utl.TypeHelper; 26 | 27 | // CPD-OFF - Fixed in v2 28 | /** 29 | * Used for comparison with equals. 30 | */ 31 | public final class EqualComparator implements FilterComparator 32 | { 33 | private static EqualComparator instance; 34 | 35 | private EqualComparator() 36 | { 37 | } 38 | 39 | public static EqualComparator getInstance() 40 | { 41 | if(instance == null) 42 | { 43 | instance = new EqualComparator(); 44 | } 45 | 46 | return instance; 47 | } 48 | 49 | @Override 50 | public String getDescription() 51 | { 52 | return "is equals to"; 53 | } 54 | 55 | @Override 56 | public boolean isApplicable(final Class clazz) 57 | { 58 | return Number.class.isAssignableFrom(clazz) 59 | || String.class.isAssignableFrom(clazz) 60 | || TemporalAccessor.class.isAssignableFrom(clazz) 61 | || Enum.class.isAssignableFrom(clazz) 62 | || Boolean.class.isAssignableFrom(clazz); 63 | } 64 | 65 | @SuppressWarnings({"PMD.CognitiveComplexity", "PMD.NPathComplexity"}) // Fixed in v2 66 | @Override 67 | public Predicate compare(final ValueProvider provider, final String searchQuery) 68 | { 69 | return item -> 70 | { 71 | final T apply = provider.apply(item); 72 | 73 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 74 | 75 | if(apply instanceof final String strValue) 76 | { 77 | return strValue.equalsIgnoreCase(searchQuery); 78 | } 79 | 80 | if(apply instanceof final Number numb && TypeHelper.isDouble(searchQuery)) 81 | { 82 | return numb.doubleValue() == (Double.parseDouble(searchQuery)); 83 | } 84 | 85 | if(apply instanceof final LocalDate date && TypeHelper.isLocalDate(searchQuery)) 86 | { 87 | return LocalDate.from(date).equals(LocalDate.parse(searchQuery)); 88 | } 89 | 90 | if(apply instanceof final LocalDateTime date && TypeHelper.isLocalDateTime(searchQuery)) 91 | { 92 | return LocalDateTime.from(date).equals(LocalDateTime.parse(searchQuery)); 93 | } 94 | 95 | if(apply instanceof final Enum enm) 96 | { 97 | return enm.toString().equals(searchQuery); 98 | } 99 | 100 | if(apply instanceof final Boolean bool) 101 | { 102 | return bool == Boolean.parseBoolean(searchQuery); 103 | } 104 | 105 | return apply.equals(searchQuery); 106 | }; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/FilterComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.util.function.Predicate; 19 | 20 | import com.vaadin.flow.function.ValueProvider; 21 | 22 | 23 | /** 24 | * Interface for comparator. 25 | */ 26 | public interface FilterComparator 27 | { 28 | String getDescription(); 29 | 30 | boolean isApplicable(Class clazz); 31 | 32 | Predicate compare(ValueProvider provider, String searchQuery); 33 | } 34 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/GreaterThanComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.util.function.Predicate; 19 | 20 | import com.vaadin.flow.function.ValueProvider; 21 | 22 | import software.xdev.vaadin.comparators.utl.TypeHelper; 23 | 24 | // CPD-OFF - Fixed in v2 25 | /** 26 | * Used for comparison with greater than. 27 | */ 28 | public final class GreaterThanComparator implements FilterComparator 29 | { 30 | private static GreaterThanComparator instance; 31 | 32 | private GreaterThanComparator() 33 | { 34 | } 35 | 36 | public static GreaterThanComparator getInstance() 37 | { 38 | if (instance == null) 39 | { 40 | instance = new GreaterThanComparator(); 41 | } 42 | 43 | return instance; 44 | } 45 | 46 | @Override 47 | public String getDescription() 48 | { 49 | return "is greater than"; 50 | } 51 | 52 | @Override 53 | public boolean isApplicable(final Class clazz) 54 | { 55 | return Number.class.isAssignableFrom(clazz); 56 | } 57 | 58 | @Override 59 | public Predicate compare(final ValueProvider provider, final String searchQuery) 60 | { 61 | return item -> 62 | { 63 | final T apply = provider.apply(item); 64 | 65 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 66 | 67 | if (apply instanceof final Number numb && TypeHelper.isDouble(searchQuery)) 68 | { 69 | return numb.doubleValue() > (Double.parseDouble(searchQuery)); 70 | } 71 | 72 | return false; 73 | }; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/GreaterThanOrEqualsComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.util.function.Predicate; 19 | 20 | import com.vaadin.flow.function.ValueProvider; 21 | 22 | import software.xdev.vaadin.comparators.utl.TypeHelper; 23 | 24 | 25 | // CPD-OFF - Fixed in v2 26 | public final class GreaterThanOrEqualsComparator implements FilterComparator 27 | { 28 | public static final String GREATER_THAN_OR_EQUALS_COMPARATOR_DESCRIPTION = "is greater than or equals"; 29 | 30 | private static GreaterThanOrEqualsComparator instance; 31 | 32 | private GreaterThanOrEqualsComparator() 33 | { 34 | } 35 | 36 | public static GreaterThanOrEqualsComparator getInstance() 37 | { 38 | if(instance == null) 39 | { 40 | instance = new GreaterThanOrEqualsComparator(); 41 | } 42 | 43 | return instance; 44 | } 45 | 46 | @Override 47 | public String getDescription() 48 | { 49 | return GREATER_THAN_OR_EQUALS_COMPARATOR_DESCRIPTION; 50 | } 51 | 52 | @Override 53 | public boolean isApplicable(final Class clazz) 54 | { 55 | return Number.class.isAssignableFrom(clazz); 56 | } 57 | 58 | @Override 59 | public Predicate compare(final ValueProvider provider, final String searchQuery) 60 | { 61 | return item -> 62 | { 63 | final T apply = provider.apply(item); 64 | 65 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 66 | 67 | if(apply instanceof final Number numb && TypeHelper.isDouble(searchQuery)) 68 | { 69 | return numb.doubleValue() >= (Double.parseDouble(searchQuery)); 70 | } 71 | 72 | return false; 73 | }; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/IsAfterComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.time.LocalDate; 19 | import java.time.LocalDateTime; 20 | import java.time.temporal.TemporalAccessor; 21 | import java.util.function.Predicate; 22 | 23 | import com.vaadin.flow.function.ValueProvider; 24 | 25 | import software.xdev.vaadin.comparators.utl.TypeHelper; 26 | 27 | // CPD-OFF - Fixed in v2 28 | /** 29 | * Used for comparison with is after. 30 | */ 31 | public final class IsAfterComparator implements FilterComparator 32 | { 33 | private static IsAfterComparator instance; 34 | 35 | private IsAfterComparator() 36 | { 37 | } 38 | 39 | public static IsAfterComparator getInstance() 40 | { 41 | if(instance == null) 42 | { 43 | instance = new IsAfterComparator(); 44 | } 45 | 46 | return instance; 47 | } 48 | 49 | @Override 50 | public String getDescription() 51 | { 52 | return "is after"; 53 | } 54 | 55 | @Override 56 | public boolean isApplicable(final Class clazz) 57 | { 58 | return TemporalAccessor.class.isAssignableFrom(clazz); 59 | } 60 | 61 | @Override 62 | public Predicate compare(final ValueProvider provider, final String searchQuery) 63 | { 64 | return item -> 65 | { 66 | final T apply = provider.apply(item); 67 | 68 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 69 | 70 | if(apply instanceof final LocalDate date && TypeHelper.isLocalDate(searchQuery)) 71 | { 72 | return LocalDate.from(date).isAfter(LocalDate.parse(searchQuery)); 73 | } 74 | 75 | if(apply instanceof final LocalDateTime date && TypeHelper.isLocalDateTime(searchQuery)) 76 | { 77 | return LocalDateTime.from(date).isAfter(LocalDateTime.parse(searchQuery)); 78 | } 79 | 80 | return apply.equals(searchQuery); 81 | }; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/IsAfterOrEqualsComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.time.LocalDate; 19 | import java.time.LocalDateTime; 20 | import java.time.temporal.TemporalAccessor; 21 | import java.util.function.Predicate; 22 | 23 | import com.vaadin.flow.function.ValueProvider; 24 | 25 | import software.xdev.vaadin.comparators.utl.TypeHelper; 26 | 27 | // CPD-OFF - Fixed in v2 28 | /** 29 | * Used for comparison with is after. 30 | */ 31 | public final class IsAfterOrEqualsComparator implements FilterComparator 32 | { 33 | public static final String IS_AFTER_OR_EQUALS_COMPARATOR_DESCRIPTION = "is after or equals"; 34 | 35 | private static IsAfterOrEqualsComparator instance; 36 | 37 | private IsAfterOrEqualsComparator() 38 | { 39 | } 40 | 41 | public static IsAfterOrEqualsComparator getInstance() 42 | { 43 | if(instance == null) 44 | { 45 | instance = new IsAfterOrEqualsComparator(); 46 | } 47 | 48 | return instance; 49 | } 50 | 51 | @Override 52 | public String getDescription() 53 | { 54 | return IS_AFTER_OR_EQUALS_COMPARATOR_DESCRIPTION; 55 | } 56 | 57 | @Override 58 | public boolean isApplicable(final Class clazz) 59 | { 60 | return TemporalAccessor.class.isAssignableFrom(clazz); 61 | } 62 | 63 | @Override 64 | public Predicate compare(final ValueProvider provider, final String searchQuery) 65 | { 66 | return item -> 67 | { 68 | final T apply = provider.apply(item); 69 | 70 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 71 | 72 | if(apply instanceof final LocalDate date && TypeHelper.isLocalDate(searchQuery)) 73 | { 74 | final LocalDate dateInstance = LocalDate.from(date); 75 | final LocalDate parsedSearchQuery = LocalDate.parse(searchQuery); 76 | 77 | return dateInstance.isAfter(parsedSearchQuery) 78 | || dateInstance.isEqual(parsedSearchQuery); 79 | } 80 | 81 | if(apply instanceof final LocalDateTime dateTime && TypeHelper.isLocalDateTime(searchQuery)) 82 | { 83 | final LocalDateTime dateTimeInstance = LocalDateTime.from(dateTime); 84 | final LocalDateTime parsedSearchQuery = LocalDateTime.parse(searchQuery); 85 | 86 | return dateTimeInstance.isAfter(parsedSearchQuery) 87 | || dateTimeInstance.isEqual(parsedSearchQuery); 88 | } 89 | 90 | return apply.equals(searchQuery); 91 | }; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/IsBeforeComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.time.LocalDate; 19 | import java.time.LocalDateTime; 20 | import java.time.temporal.TemporalAccessor; 21 | import java.util.function.Predicate; 22 | 23 | import com.vaadin.flow.function.ValueProvider; 24 | 25 | import software.xdev.vaadin.comparators.utl.TypeHelper; 26 | 27 | // CPD-OFF - Fixed in v2 28 | /** 29 | * Used for comparison with is before. 30 | */ 31 | public final class IsBeforeComparator implements FilterComparator 32 | { 33 | private static IsBeforeComparator instance; 34 | 35 | private IsBeforeComparator() 36 | { 37 | } 38 | 39 | public static IsBeforeComparator getInstance() 40 | { 41 | if(instance == null) 42 | { 43 | instance = new IsBeforeComparator(); 44 | } 45 | 46 | return instance; 47 | } 48 | 49 | @Override 50 | public String getDescription() 51 | { 52 | return "is before"; 53 | } 54 | 55 | @Override 56 | public boolean isApplicable(final Class clazz) 57 | { 58 | return TemporalAccessor.class.isAssignableFrom(clazz); 59 | } 60 | 61 | @Override 62 | public Predicate compare(final ValueProvider provider, final String searchQuery) 63 | { 64 | return item -> 65 | { 66 | final T apply = provider.apply(item); 67 | 68 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 69 | 70 | if(apply instanceof final LocalDate date && TypeHelper.isLocalDate(searchQuery)) 71 | { 72 | return LocalDate.from(date).isBefore(LocalDate.parse(searchQuery)); 73 | } 74 | 75 | if(apply instanceof final LocalDateTime date && TypeHelper.isLocalDateTime(searchQuery)) 76 | { 77 | return LocalDateTime.from(date).isBefore(LocalDateTime.parse(searchQuery)); 78 | } 79 | 80 | return apply.equals(searchQuery); 81 | }; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/IsBeforeOrEqualsComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.time.LocalDate; 19 | import java.time.LocalDateTime; 20 | import java.time.temporal.TemporalAccessor; 21 | import java.util.function.Predicate; 22 | 23 | import com.vaadin.flow.function.ValueProvider; 24 | 25 | import software.xdev.vaadin.comparators.utl.TypeHelper; 26 | 27 | // CPD-OFF - Fixed in v2 28 | /** 29 | * Used for comparison with is before. 30 | */ 31 | public final class IsBeforeOrEqualsComparator implements FilterComparator 32 | { 33 | public static final String IS_BEFORE_OR_EQUALS_COMPARATOR_DESCRIPTION = "is before or equals"; 34 | 35 | private static IsBeforeOrEqualsComparator instance; 36 | 37 | private IsBeforeOrEqualsComparator() 38 | { 39 | } 40 | 41 | public static IsBeforeOrEqualsComparator getInstance() 42 | { 43 | if(instance == null) 44 | { 45 | instance = new IsBeforeOrEqualsComparator(); 46 | } 47 | 48 | return instance; 49 | } 50 | 51 | @Override 52 | public String getDescription() 53 | { 54 | return IS_BEFORE_OR_EQUALS_COMPARATOR_DESCRIPTION; 55 | } 56 | 57 | @Override 58 | public boolean isApplicable(final Class clazz) 59 | { 60 | return TemporalAccessor.class.isAssignableFrom(clazz); 61 | } 62 | 63 | @Override 64 | public Predicate compare(final ValueProvider provider, final String searchQuery) 65 | { 66 | return item -> 67 | { 68 | final T apply = provider.apply(item); 69 | 70 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 71 | 72 | if(apply instanceof final LocalDate date && TypeHelper.isLocalDate(searchQuery)) 73 | { 74 | final LocalDate dateInstance = LocalDate.from(date); 75 | final LocalDate parsedSearchQuery = LocalDate.parse(searchQuery); 76 | 77 | return dateInstance.isBefore(parsedSearchQuery) 78 | || dateInstance.isEqual(parsedSearchQuery); 79 | } 80 | 81 | if(apply instanceof final LocalDateTime dateTime && TypeHelper.isLocalDateTime(searchQuery)) 82 | { 83 | final LocalDateTime dateTimeInstance = LocalDateTime.from(dateTime); 84 | final LocalDateTime parsedSearchQuery = LocalDateTime.parse(searchQuery); 85 | 86 | return dateTimeInstance.isBefore(parsedSearchQuery) 87 | || dateTimeInstance.isEqual(parsedSearchQuery); 88 | } 89 | 90 | return apply.equals(searchQuery); 91 | }; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/IsBetweenComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.time.LocalDate; 19 | import java.util.function.Predicate; 20 | 21 | import com.vaadin.flow.function.ValueProvider; 22 | 23 | import software.xdev.vaadin.comparators.utl.IncorrectSearchQueryFormatException; 24 | import software.xdev.vaadin.comparators.utl.TypeHelper; 25 | 26 | 27 | /** 28 | * Used for comparison with is after. 29 | */ 30 | public final class IsBetweenComparator implements FilterComparator 31 | { 32 | public static final String IS_BETWEEN_COMPARATOR_DESCRIPTION = "is between"; 33 | public static final String IS_BETWEEN_COMPARATOR_SEPARATOR = "#"; 34 | 35 | private static IsBetweenComparator instance; 36 | 37 | private IsBetweenComparator() 38 | { 39 | } 40 | 41 | public static IsBetweenComparator getInstance() 42 | { 43 | if(instance == null) 44 | { 45 | instance = new IsBetweenComparator(); 46 | } 47 | 48 | return instance; 49 | } 50 | 51 | @Override 52 | public String getDescription() 53 | { 54 | return IS_BETWEEN_COMPARATOR_DESCRIPTION; 55 | } 56 | 57 | @Override 58 | public boolean isApplicable(final Class clazz) 59 | { 60 | return LocalDate.class.isAssignableFrom(clazz); 61 | } 62 | 63 | @SuppressWarnings("PMD.PreserveStackTrace") // Fixed in v2 64 | @Override 65 | public Predicate compare(final ValueProvider provider, final String searchQuery) 66 | { 67 | return item -> 68 | { 69 | final T apply = provider.apply(item); 70 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 71 | 72 | final String startDate; 73 | final String endDate; 74 | 75 | try 76 | { 77 | if(searchQuery == null || searchQuery.isBlank()) 78 | { 79 | return true; 80 | } 81 | 82 | final String[] dates = searchQuery.split(IS_BETWEEN_COMPARATOR_SEPARATOR); 83 | startDate = dates[0]; 84 | endDate = dates[1]; 85 | } 86 | catch(final ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) 87 | { 88 | throw new IncorrectSearchQueryFormatException( 89 | "Format of the following search query is not correct: '" + searchQuery + "'"); 90 | } 91 | 92 | if(apply instanceof final LocalDate date 93 | && TypeHelper.isLocalDate(startDate) 94 | && TypeHelper.isLocalDate(endDate)) 95 | { 96 | return (LocalDate.from(date).isAfter(LocalDate.parse(startDate)) 97 | || LocalDate.from(date).isEqual(LocalDate.parse(startDate))) 98 | && (LocalDate.from(date).isBefore(LocalDate.parse(endDate)) 99 | || LocalDate.from(date).isEqual(LocalDate.parse(endDate))); 100 | } 101 | 102 | return apply.equals(startDate) && apply.equals(endDate); 103 | }; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/LessThanComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.util.function.Predicate; 19 | 20 | import com.vaadin.flow.function.ValueProvider; 21 | 22 | import software.xdev.vaadin.comparators.utl.TypeHelper; 23 | 24 | // CPD-OFF - Fixed in v2 25 | /** 26 | * Used for comparison with less than. 27 | */ 28 | public final class LessThanComparator implements FilterComparator 29 | { 30 | private static LessThanComparator instance; 31 | 32 | private LessThanComparator() 33 | { 34 | } 35 | 36 | public static LessThanComparator getInstance() 37 | { 38 | if(instance == null) 39 | { 40 | instance = new LessThanComparator(); 41 | } 42 | 43 | return instance; 44 | } 45 | 46 | @Override 47 | public String getDescription() 48 | { 49 | return "is less than"; 50 | } 51 | 52 | @Override 53 | public boolean isApplicable(final Class clazz) 54 | { 55 | return Number.class.isAssignableFrom(clazz); 56 | } 57 | 58 | @Override 59 | public Predicate compare(final ValueProvider provider, final String searchQuery) 60 | { 61 | return item -> 62 | { 63 | final T apply = provider.apply(item); 64 | 65 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 66 | 67 | if(apply instanceof final Number numb && TypeHelper.isDouble(searchQuery)) 68 | { 69 | return numb.doubleValue() < (Double.parseDouble(searchQuery)); 70 | } 71 | 72 | return false; 73 | }; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/LessThanOrEqualsComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.util.function.Predicate; 19 | 20 | import com.vaadin.flow.function.ValueProvider; 21 | 22 | import software.xdev.vaadin.comparators.utl.TypeHelper; 23 | 24 | 25 | // CPD-OFF - Fixed in v2 26 | public final class LessThanOrEqualsComparator implements FilterComparator 27 | { 28 | public static final String LESS_THAN_OR_EQUALS_COMPARATOR_DESCRIPTION = "is less than or equals"; 29 | 30 | private static LessThanOrEqualsComparator instance; 31 | 32 | private LessThanOrEqualsComparator() 33 | { 34 | } 35 | 36 | public static LessThanOrEqualsComparator getInstance() 37 | { 38 | if(instance == null) 39 | { 40 | instance = new LessThanOrEqualsComparator(); 41 | } 42 | 43 | return instance; 44 | } 45 | 46 | @Override 47 | public String getDescription() 48 | { 49 | return LESS_THAN_OR_EQUALS_COMPARATOR_DESCRIPTION; 50 | } 51 | 52 | @Override 53 | public boolean isApplicable(final Class clazz) 54 | { 55 | return Number.class.isAssignableFrom(clazz); 56 | } 57 | 58 | @Override 59 | public Predicate compare(final ValueProvider provider, final String searchQuery) 60 | { 61 | return item -> 62 | { 63 | final T apply = provider.apply(item); 64 | 65 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 66 | 67 | if(apply instanceof final Number numb && TypeHelper.isDouble(searchQuery)) 68 | { 69 | return numb.doubleValue() <= (Double.parseDouble(searchQuery)); 70 | } 71 | 72 | return false; 73 | }; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/NotContainsComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.util.function.Predicate; 19 | 20 | import com.vaadin.flow.function.ValueProvider; 21 | 22 | import software.xdev.vaadin.comparators.utl.TypeHelper; 23 | 24 | // CPD-OFF - Fixed in v2 25 | /** 26 | * Used for comparison with does not contain. 27 | */ 28 | public final class NotContainsComparator implements FilterComparator 29 | { 30 | private static NotContainsComparator instance; 31 | 32 | private NotContainsComparator() 33 | { 34 | } 35 | 36 | public static NotContainsComparator getInstance() 37 | { 38 | if(instance == null) 39 | { 40 | instance = new NotContainsComparator(); 41 | } 42 | 43 | return instance; 44 | } 45 | 46 | @Override 47 | public String getDescription() 48 | { 49 | return "not contains"; 50 | } 51 | 52 | @Override 53 | public boolean isApplicable(final Class clazz) 54 | { 55 | return String.class.isAssignableFrom(clazz) 56 | || Number.class.isAssignableFrom(clazz) 57 | || Enum.class.isAssignableFrom(clazz); 58 | } 59 | 60 | @Override 61 | public Predicate compare(final ValueProvider provider, final String searchQuery) 62 | { 63 | return item -> 64 | { 65 | final T apply = provider.apply(item); 66 | 67 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 68 | 69 | if(apply instanceof final String strValue) 70 | { 71 | return !strValue.contains(searchQuery); 72 | } 73 | 74 | if(apply instanceof final Number numb && TypeHelper.isDouble(searchQuery)) 75 | { 76 | return !numb.toString().contains(searchQuery); 77 | } 78 | 79 | if(apply instanceof final Enum enm) 80 | { 81 | return !enm.toString().contains(searchQuery); 82 | } 83 | 84 | return false; 85 | }; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/NotEqualComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators; 17 | 18 | import java.time.LocalDate; 19 | import java.time.LocalDateTime; 20 | import java.time.temporal.TemporalAccessor; 21 | import java.util.function.Predicate; 22 | 23 | import com.vaadin.flow.function.ValueProvider; 24 | 25 | import software.xdev.vaadin.comparators.utl.TypeHelper; 26 | 27 | // CPD-OFF - Fixed in v2 28 | /** 29 | * Used for comparison with does not equal. 30 | */ 31 | public final class NotEqualComparator implements FilterComparator 32 | { 33 | private static NotEqualComparator instance; 34 | 35 | private NotEqualComparator() 36 | { 37 | } 38 | 39 | public static NotEqualComparator getInstance() 40 | { 41 | if (instance == null) 42 | { 43 | instance = new NotEqualComparator(); 44 | } 45 | 46 | return instance; 47 | } 48 | 49 | @Override 50 | public String getDescription() 51 | { 52 | return "is not equals to"; 53 | } 54 | 55 | @Override 56 | public boolean isApplicable(final Class clazz) 57 | { 58 | return Number.class.isAssignableFrom(clazz) 59 | || String.class.isAssignableFrom(clazz) 60 | || TemporalAccessor.class.isAssignableFrom(clazz) 61 | || Enum.class.isAssignableFrom(clazz) 62 | || Boolean.class.isAssignableFrom(clazz); 63 | } 64 | 65 | @SuppressWarnings({"PMD.CognitiveComplexity", "PMD.NPathComplexity"}) // Fixed in v2 66 | @Override 67 | public Predicate compare(final ValueProvider provider, final String searchQuery) 68 | { 69 | return item -> 70 | { 71 | final T apply = provider.apply(item); 72 | 73 | TypeHelper.checkIfTypeIsApplicable(this, apply.getClass()); 74 | 75 | if (apply instanceof final String strValue) 76 | { 77 | return !strValue.equalsIgnoreCase(searchQuery); 78 | } 79 | 80 | if (apply instanceof final Number numb && TypeHelper.isDouble(searchQuery)) 81 | { 82 | return numb.doubleValue() != (Double.parseDouble(searchQuery)); 83 | } 84 | 85 | if (apply instanceof final LocalDate date && TypeHelper.isLocalDate(searchQuery)) 86 | { 87 | return !LocalDate.from(date).equals(LocalDate.parse(searchQuery)); 88 | } 89 | 90 | if (apply instanceof final LocalDateTime date && TypeHelper.isLocalDateTime(searchQuery)) 91 | { 92 | return !LocalDateTime.from(date).equals(LocalDateTime.parse(searchQuery)); 93 | } 94 | 95 | if (apply instanceof final Enum enm) 96 | { 97 | return !enm.toString().equals(searchQuery); 98 | } 99 | 100 | if (apply instanceof final Boolean bool) 101 | { 102 | return bool != Boolean.parseBoolean(searchQuery); 103 | } 104 | 105 | return apply.equals(searchQuery); 106 | }; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/utl/DateHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators.utl; 17 | 18 | import java.time.format.DateTimeFormatter; 19 | import java.util.Objects; 20 | 21 | import com.vaadin.flow.component.datepicker.DatePicker; 22 | 23 | 24 | /** 25 | * Used to build the date pattern from I18n. 26 | */ 27 | public final class DateHelper 28 | { 29 | private DateHelper() 30 | { 31 | } 32 | 33 | public static DateTimeFormatter getDatePattern(final DatePicker.DatePickerI18n datePickerI18n) 34 | { 35 | Objects.requireNonNull(datePickerI18n); 36 | 37 | final StringBuilder patternString = new StringBuilder(); 38 | 39 | for(final String pattern : datePickerI18n.getDateFormats()) 40 | { 41 | patternString.append('[').append(pattern).append(']'); 42 | } 43 | 44 | return DateTimeFormatter.ofPattern(patternString.toString()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/utl/IncorrectSearchQueryFormatException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators.utl; 17 | 18 | public class IncorrectSearchQueryFormatException extends RuntimeException 19 | { 20 | public IncorrectSearchQueryFormatException(final String message) 21 | { 22 | super(message); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/utl/MismatchingTypeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators.utl; 17 | 18 | /** 19 | * Exception if type is not applicable for a comparator. 20 | */ 21 | public class MismatchingTypeException extends RuntimeException 22 | { 23 | public MismatchingTypeException(final String message) 24 | { 25 | super(message); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/comparators/utl/TypeHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.comparators.utl; 17 | 18 | import java.time.LocalDate; 19 | import java.time.LocalDateTime; 20 | import java.time.format.DateTimeFormatter; 21 | import java.time.format.DateTimeParseException; 22 | import java.util.Objects; 23 | 24 | import software.xdev.vaadin.comparators.FilterComparator; 25 | 26 | /** 27 | * Used for checking if the string can be parsed to another datatype. 28 | */ 29 | public final class TypeHelper 30 | { 31 | private TypeHelper() 32 | { 33 | } 34 | 35 | public static boolean isDouble(final String str) 36 | { 37 | Objects.requireNonNull(str); 38 | 39 | try 40 | { 41 | Double.parseDouble(str); 42 | return true; 43 | } 44 | catch (final NumberFormatException e) 45 | { 46 | return false; 47 | } 48 | } 49 | 50 | @SuppressWarnings("PMD.UselessOperationOnImmutable") 51 | public static boolean isLocalDate(final String str) 52 | { 53 | Objects.requireNonNull(str); 54 | 55 | try 56 | { 57 | LocalDate.parse(str); 58 | return true; 59 | } 60 | catch (final DateTimeParseException e) 61 | { 62 | return false; 63 | } 64 | } 65 | 66 | @SuppressWarnings("PMD.UselessOperationOnImmutable") 67 | public static boolean isLocalDateTime(final String str) 68 | { 69 | Objects.requireNonNull(str); 70 | 71 | try 72 | { 73 | LocalDateTime.parse(str, DateTimeFormatter.ISO_DATE_TIME); 74 | return true; 75 | } 76 | catch (final DateTimeParseException e) 77 | { 78 | return false; 79 | } 80 | } 81 | 82 | public static void checkIfTypeIsApplicable(final FilterComparator filterComparator, final Class otherType) 83 | { 84 | Objects.requireNonNull(filterComparator); 85 | 86 | if (!filterComparator.isApplicable(otherType)) 87 | { 88 | throw new MismatchingTypeException("Type " + otherType + " is not applicable."); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/model/ChipBadge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.model; 17 | 18 | import com.vaadin.flow.component.AttachEvent; 19 | import com.vaadin.flow.component.ClickEvent; 20 | import com.vaadin.flow.component.ComponentEventListener; 21 | import com.vaadin.flow.component.Composite; 22 | import com.vaadin.flow.component.HasSize; 23 | import com.vaadin.flow.component.HasStyle; 24 | import com.vaadin.flow.component.ItemLabelGenerator; 25 | import com.vaadin.flow.component.button.Button; 26 | import com.vaadin.flow.component.button.ButtonVariant; 27 | import com.vaadin.flow.component.dependency.CssImport; 28 | import com.vaadin.flow.component.html.Span; 29 | import com.vaadin.flow.component.icon.VaadinIcon; 30 | import com.vaadin.flow.shared.Registration; 31 | 32 | 33 | /** 34 | * Represents a chip badge shown underneath the {@link software.xdev.vaadin.FilterComponent} 35 | */ 36 | @CssImport("./styles/filterComponent.css") 37 | public class ChipBadge extends Composite implements HasSize, HasStyle 38 | { 39 | private static final String CHIP_BADGE_CONTAINER_CSS = "chipbadge-container"; 40 | private static final String CHIP_BADGE_LABEL_CSS = "chipbadge-label"; 41 | private static final String CHIP_BADGE_DELETE_BTN_CSS = "chipbadge-delete-btn"; 42 | 43 | protected T item; 44 | protected ItemLabelGenerator itemLabelGenerator = Object::toString; 45 | 46 | protected final Button btnDelete = new Button(VaadinIcon.CLOSE_CIRCLE.create()); 47 | protected final Span label = new Span(); 48 | 49 | protected String badgeId; 50 | 51 | public ChipBadge(final T item) 52 | { 53 | this.item = item; 54 | 55 | this.initUI(); 56 | } 57 | 58 | private void initUI() 59 | { 60 | this.setClassName(CHIP_BADGE_CONTAINER_CSS); 61 | 62 | this.label.setClassName(CHIP_BADGE_LABEL_CSS); 63 | 64 | this.btnDelete.addThemeVariants(ButtonVariant.LUMO_SMALL, ButtonVariant.LUMO_TERTIARY_INLINE); 65 | this.btnDelete.setClassName(CHIP_BADGE_DELETE_BTN_CSS); 66 | 67 | this.label.setSizeUndefined(); 68 | this.btnDelete.setSizeUndefined(); 69 | 70 | this.getContent().add(this.label, this.btnDelete); 71 | } 72 | 73 | @Override 74 | protected void onAttach(final AttachEvent attachEvent) 75 | { 76 | this.updateTextFromItemLabelGenerator(); 77 | } 78 | 79 | public T getItem() 80 | { 81 | return this.item; 82 | } 83 | 84 | public String getBadgeId() 85 | { 86 | return this.badgeId; 87 | } 88 | 89 | public void setBadgeId(final String badgeId) 90 | { 91 | this.badgeId = badgeId; 92 | } 93 | 94 | public void setItem(final T item) 95 | { 96 | this.item = item; 97 | } 98 | 99 | public void setItemLabelGenerator(final ItemLabelGenerator itemLabelGenerator) 100 | { 101 | this.itemLabelGenerator = itemLabelGenerator; 102 | } 103 | 104 | /** 105 | * Updates the text of the {@link Span} from the integrated {@link ItemLabelGenerator} 106 | */ 107 | public void updateTextFromItemLabelGenerator() 108 | { 109 | this.label.setText(this.itemLabelGenerator.apply(this.item)); 110 | } 111 | 112 | public Registration addBtnDeleteClickListener(final ComponentEventListener> listener) 113 | { 114 | return this.btnDelete.addClickListener(listener); 115 | } 116 | 117 | public void setReadonly(final boolean readOnly) 118 | { 119 | this.btnDelete.setEnabled(!readOnly); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/model/ChipBadgeExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.model; 17 | 18 | import com.vaadin.flow.component.ClickEvent; 19 | import com.vaadin.flow.component.ComponentEventListener; 20 | import com.vaadin.flow.component.button.Button; 21 | import com.vaadin.flow.component.button.ButtonVariant; 22 | import com.vaadin.flow.component.icon.VaadinIcon; 23 | import com.vaadin.flow.shared.Registration; 24 | 25 | 26 | public class ChipBadgeExtension extends ChipBadge 27 | { 28 | public static final String BTN_DELETE_CHIP_COMPONENT = "btnDeleteChipComponent"; 29 | public static final String BTN_EDIT_CHIP_COMPONENT = "btnEditChipComponent"; 30 | 31 | protected final Button btnEdit = new Button(VaadinIcon.PENCIL.create()); 32 | 33 | private CustomizationDegree customizationDegree = CustomizationDegree.EVERYTHING; 34 | 35 | public ChipBadgeExtension(final T item) 36 | { 37 | super(item); 38 | 39 | this.initBtnEdit(); 40 | } 41 | 42 | private void initBtnEdit() 43 | { 44 | this.btnDelete.setEnabled(true); 45 | this.btnDelete.setVisible(true); 46 | this.btnDelete.setId(BTN_DELETE_CHIP_COMPONENT); 47 | 48 | this.btnEdit.setEnabled(false); 49 | this.btnEdit.setVisible(false); 50 | this.btnEdit.setId(BTN_EDIT_CHIP_COMPONENT); 51 | 52 | this.btnEdit.addThemeVariants(ButtonVariant.LUMO_SMALL, ButtonVariant.LUMO_TERTIARY_INLINE); 53 | this.btnEdit.getStyle().set("font-size", "var(--lumo-font-size-m)"); 54 | this.btnEdit.setSizeUndefined(); 55 | 56 | this.getContent().add(this.btnEdit); 57 | } 58 | 59 | public void setBtnEditEnabled(final boolean enabled) 60 | { 61 | this.btnEdit.setEnabled(enabled); 62 | this.btnEdit.setVisible(enabled); 63 | } 64 | 65 | public boolean isBtnEditEnabled() 66 | { 67 | return this.btnEdit.isEnabled(); 68 | } 69 | 70 | public void setBtnDeleteEnabled(final boolean enabled) 71 | { 72 | this.btnDelete.setEnabled(enabled); 73 | this.btnDelete.setVisible(enabled); 74 | } 75 | 76 | public boolean isBtnDeleteEnabled() 77 | { 78 | return this.btnDelete.isEnabled(); 79 | } 80 | 81 | public CustomizationDegree getCustomizationRating() 82 | { 83 | return this.customizationDegree; 84 | } 85 | 86 | public void setCustomizationRating(final CustomizationDegree customizationDegree) 87 | { 88 | this.customizationDegree = customizationDegree; 89 | } 90 | 91 | public Registration addBtnEditClickListener(final ComponentEventListener> listener) 92 | { 93 | return this.btnEdit.addClickListener(listener); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/model/CustomizationDegree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.model; 17 | 18 | /** 19 | * When editing a condition, the developer can specify how much of the condition can be edited. 20 | */ 21 | public enum CustomizationDegree 22 | { 23 | EVERYTHING, 24 | CONDITION_AND_INPUT_VALUE, 25 | INPUT_VALUE 26 | } 27 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/model/FilterCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.model; 17 | 18 | import software.xdev.vaadin.comparators.FilterComparator; 19 | 20 | 21 | /** 22 | * @param The bean. 23 | * @param The type or field to use. 24 | */ 25 | public class FilterCondition 26 | { 27 | private final FilterField item; 28 | private final FilterComparator selectedCondition; 29 | private final String inputValue; 30 | 31 | public FilterCondition( 32 | final FilterField item, 33 | final FilterComparator selectedCondition, 34 | final String inputValue) 35 | { 36 | this.item = item; 37 | this.selectedCondition = selectedCondition; 38 | this.inputValue = inputValue; 39 | } 40 | 41 | public FilterField getItem() 42 | { 43 | return this.item; 44 | } 45 | 46 | public FilterComparator getSelectedCondition() 47 | { 48 | return this.selectedCondition; 49 | } 50 | 51 | public String getInputValue() 52 | { 53 | return this.inputValue; 54 | } 55 | 56 | @Override 57 | public String toString() 58 | { 59 | return this.item.getDescription() 60 | + " " + this.selectedCondition.getDescription() 61 | + " " + this.inputValue; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/model/FilterField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.model; 17 | 18 | import java.util.List; 19 | 20 | import com.vaadin.flow.function.ValueProvider; 21 | 22 | import software.xdev.vaadin.comparators.ContainsComparator; 23 | import software.xdev.vaadin.comparators.EqualComparator; 24 | import software.xdev.vaadin.comparators.FilterComparator; 25 | import software.xdev.vaadin.comparators.GreaterThanComparator; 26 | import software.xdev.vaadin.comparators.GreaterThanOrEqualsComparator; 27 | import software.xdev.vaadin.comparators.IsAfterComparator; 28 | import software.xdev.vaadin.comparators.IsAfterOrEqualsComparator; 29 | import software.xdev.vaadin.comparators.IsBeforeComparator; 30 | import software.xdev.vaadin.comparators.IsBeforeOrEqualsComparator; 31 | import software.xdev.vaadin.comparators.IsBetweenComparator; 32 | import software.xdev.vaadin.comparators.LessThanComparator; 33 | import software.xdev.vaadin.comparators.LessThanOrEqualsComparator; 34 | import software.xdev.vaadin.comparators.NotContainsComparator; 35 | import software.xdev.vaadin.comparators.NotEqualComparator; 36 | 37 | 38 | /** 39 | * @param The bean. 40 | * @param The type or field to use. 41 | */ 42 | public class FilterField 43 | { 44 | private final ValueProvider valueProvider; 45 | private final String description; 46 | private final Class type; 47 | private final List availableComparators; 48 | 49 | public FilterField( 50 | final ValueProvider valueProvider, 51 | final String description, 52 | final Class type, 53 | final List availableComparators) 54 | { 55 | this.valueProvider = valueProvider; 56 | this.description = description; 57 | this.type = type; 58 | this.availableComparators = availableComparators; 59 | } 60 | 61 | public ValueProvider getValueProvider() 62 | { 63 | return this.valueProvider; 64 | } 65 | 66 | public String getDescription() 67 | { 68 | return this.description; 69 | } 70 | 71 | public Class getType() 72 | { 73 | return this.type; 74 | } 75 | 76 | public List getAvailableComparators() 77 | { 78 | return this.availableComparators; 79 | } 80 | 81 | /** 82 | * Used to make a custom comparator available for selection. 83 | * 84 | * @param comparator The custom comparator. 85 | * @return Returns a new filter field. 86 | */ 87 | public FilterField withAvailableComparator(final FilterComparator comparator) 88 | { 89 | if(this.availableComparators.stream().noneMatch(c -> c.getClass() == comparator.getClass())) 90 | { 91 | this.availableComparators.add(comparator); 92 | } 93 | 94 | return new FilterField<>(this.valueProvider, this.description, this.type, this.availableComparators); 95 | } 96 | 97 | public FilterField withEqualComparator() 98 | { 99 | return this.withAvailableComparator(EqualComparator.getInstance()); 100 | } 101 | 102 | public FilterField withNotEqualComparator() 103 | { 104 | return this.withAvailableComparator(NotEqualComparator.getInstance()); 105 | } 106 | 107 | public FilterField withContainsComparator() 108 | { 109 | return this.withAvailableComparator(ContainsComparator.getInstance()); 110 | } 111 | 112 | public FilterField withGreaterThanComparator() 113 | { 114 | return this.withAvailableComparator(GreaterThanComparator.getInstance()); 115 | } 116 | 117 | public FilterField withIsAfterComparator() 118 | { 119 | return this.withAvailableComparator(IsAfterComparator.getInstance()); 120 | } 121 | 122 | public FilterField withIsBeforeComparator() 123 | { 124 | return this.withAvailableComparator(IsBeforeComparator.getInstance()); 125 | } 126 | 127 | public FilterField withLessThanComparator() 128 | { 129 | return this.withAvailableComparator(LessThanComparator.getInstance()); 130 | } 131 | 132 | public FilterField withNotContainsComparator() 133 | { 134 | return this.withAvailableComparator(NotContainsComparator.getInstance()); 135 | } 136 | 137 | public FilterField withIsBetweenComparator() 138 | { 139 | return this.withAvailableComparator(IsBetweenComparator.getInstance()); 140 | } 141 | 142 | public FilterField withLessThanOrEqualsComparator() 143 | { 144 | return this.withAvailableComparator(LessThanOrEqualsComparator.getInstance()); 145 | } 146 | 147 | public FilterField withGreaterThanOrEqualsComparator() 148 | { 149 | return this.withAvailableComparator(GreaterThanOrEqualsComparator.getInstance()); 150 | } 151 | 152 | public FilterField withIsAfterOrEqualsComparator() 153 | { 154 | return this.withAvailableComparator(IsAfterOrEqualsComparator.getInstance()); 155 | } 156 | 157 | public FilterField withIsBeforeOrEqualsComparator() 158 | { 159 | return this.withAvailableComparator(IsBeforeOrEqualsComparator.getInstance()); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/model/FilterFieldEnumExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.model; 17 | 18 | import java.util.List; 19 | 20 | import com.vaadin.flow.function.ValueProvider; 21 | 22 | import software.xdev.vaadin.comparators.FilterComparator; 23 | 24 | 25 | /** 26 | * Extension of the FilterField with enum compatibility. 27 | * 28 | * @param The bean. 29 | * @param The type or field to use. 30 | */ 31 | public class FilterFieldEnumExtension> extends FilterField 32 | { 33 | private final Enum[] enumValues; 34 | 35 | public FilterFieldEnumExtension( 36 | final ValueProvider valueProvider, 37 | final String description, 38 | final Class type, 39 | final List availableComparators, 40 | final Enum[] enumValues) 41 | { 42 | super(valueProvider, description, type, availableComparators); 43 | this.enumValues = enumValues; 44 | } 45 | 46 | public Enum[] getEnumValues() 47 | { 48 | return this.enumValues; 49 | } 50 | 51 | @Override 52 | public FilterFieldEnumExtension withAvailableComparator(final FilterComparator comparator) 53 | { 54 | if(this.getAvailableComparators().stream().noneMatch(c -> c.getClass() == comparator.getClass())) 55 | { 56 | this.getAvailableComparators().add(comparator); 57 | } 58 | 59 | return new FilterFieldEnumExtension<>( 60 | this.getValueProvider(), 61 | this.getDescription(), 62 | this.getType(), 63 | this.getAvailableComparators(), 64 | this.enumValues); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/model/FilterProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.model; 17 | 18 | import java.time.LocalDate; 19 | import java.time.LocalDateTime; 20 | 21 | import com.vaadin.flow.function.ValueProvider; 22 | 23 | 24 | public final class FilterProvider 25 | { 26 | private FilterProvider() 27 | { 28 | } 29 | 30 | public interface StringProvider extends ValueProvider 31 | { 32 | } 33 | 34 | 35 | public interface NumberProvider extends ValueProvider 36 | { 37 | } 38 | 39 | 40 | public interface LocalDateProvider extends ValueProvider 41 | { 42 | } 43 | 44 | 45 | public interface LocalDateTimeProvider extends ValueProvider 46 | { 47 | } 48 | 49 | 50 | public interface BooleanProvider extends ValueProvider 51 | { 52 | } 53 | 54 | 55 | public interface EnumProvider extends ValueProvider 56 | { 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/model/SimpleFilterField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.model; 17 | 18 | import software.xdev.vaadin.builder.CustomizableFilterBuilder; 19 | 20 | 21 | /** 22 | * Class for creating a FilterField with preconfigured conditions. 23 | * 24 | * @param The bean. 25 | */ 26 | public class SimpleFilterField 27 | { 28 | private static final CustomizableFilterBuilder BUILDER = CustomizableFilterBuilder.builder(); 29 | private final FilterField filterField; 30 | 31 | public SimpleFilterField( 32 | final FilterProvider.StringProvider provider, 33 | final String description) 34 | { 35 | this.filterField = 36 | BUILDER.withValueProvider(provider, description) 37 | .withNotEqualComparator() 38 | .withEqualComparator() 39 | .withContainsComparator() 40 | .withNotContainsComparator(); 41 | } 42 | 43 | public SimpleFilterField( 44 | final FilterProvider.EnumProvider provider, 45 | final String description, 46 | final Enum[] enumValues) 47 | { 48 | this.filterField = BUILDER 49 | .withValueProvider(provider, description, enumValues) 50 | .withEqualComparator() 51 | .withNotEqualComparator() 52 | .withContainsComparator() 53 | .withNotContainsComparator(); 54 | } 55 | 56 | public SimpleFilterField( 57 | final FilterProvider.NumberProvider provider, 58 | final String description) 59 | { 60 | this.filterField = BUILDER 61 | .withValueProvider(provider, description) 62 | .withEqualComparator() 63 | .withNotEqualComparator() 64 | .withContainsComparator() 65 | .withNotContainsComparator() 66 | .withLessThanComparator() 67 | .withLessThanOrEqualsComparator() 68 | .withGreaterThanComparator() 69 | .withGreaterThanOrEqualsComparator(); 70 | } 71 | 72 | public SimpleFilterField( 73 | final FilterProvider.LocalDateProvider provider, 74 | final String description) 75 | { 76 | this.filterField = BUILDER 77 | .withValueProvider(provider, description) 78 | .withIsBeforeComparator() 79 | .withIsBeforeOrEqualsComparator() 80 | .withIsAfterComparator() 81 | .withIsAfterOrEqualsComparator() 82 | .withIsBetweenComparator(); 83 | } 84 | 85 | public SimpleFilterField( 86 | final FilterProvider.LocalDateTimeProvider provider, 87 | final String description) 88 | { 89 | this.filterField = BUILDER 90 | .withValueProvider(provider, description) 91 | .withIsBeforeComparator() 92 | .withIsBeforeOrEqualsComparator() 93 | .withIsAfterComparator() 94 | .withIsAfterOrEqualsComparator(); 95 | } 96 | 97 | public SimpleFilterField( 98 | final FilterProvider.BooleanProvider provider, 99 | final String description) 100 | { 101 | this.filterField = BUILDER 102 | .withValueProvider(provider, description) 103 | .withEqualComparator() 104 | .withNotEqualComparator(); 105 | } 106 | 107 | public FilterField getFilterField() 108 | { 109 | return this.filterField; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/utl/FilterComponentUtl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.utl; 17 | 18 | import java.util.List; 19 | import java.util.stream.Collectors; 20 | 21 | import software.xdev.vaadin.model.ChipBadge; 22 | import software.xdev.vaadin.model.ChipBadgeExtension; 23 | import software.xdev.vaadin.model.FilterCondition; 24 | 25 | 26 | public final class FilterComponentUtl 27 | { 28 | public FilterComponentUtl() 29 | { 30 | } 31 | 32 | /** 33 | * Check if the lists contains the same chip badges objects 34 | * 35 | * @param one List one 36 | * @param two List two 37 | * @return True if the lists contains the same objects 38 | */ 39 | public boolean equalLists( 40 | final List>> one, 41 | final List>> two) 42 | { 43 | return one.stream() 44 | .map(ChipBadge::getBadgeId) 45 | .collect(Collectors.toSet()) 46 | .equals(two.stream() 47 | .map(ChipBadge::getBadgeId) 48 | .collect(Collectors.toSet())); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/utl/QueryParameterUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2024 XDEV Software (https://xdev.software) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package software.xdev.vaadin.utl; 17 | 18 | import java.util.Collection; 19 | import java.util.Collections; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.Set; 24 | 25 | import com.vaadin.flow.router.QueryParameters; 26 | 27 | import software.xdev.vaadin.model.FilterCondition; 28 | 29 | 30 | public final class QueryParameterUtil 31 | { 32 | private static final int BIGGEST_PARAMETER_COUNT = 7; 33 | 34 | public static final String QUERY_COMPONENT_ID_STRING = "id"; 35 | public static final String QUERY_FIELD_STRING = "field"; 36 | public static final String QUERY_CONDITION_STRING = "condition"; 37 | public static final String QUERY_INPUT_STRING = "input"; 38 | public static final String QUERY_BADGE_ID_STRING = "badgeId"; 39 | public static final String QUERY_BADGE_EDITABLE_STRING = "editable"; 40 | public static final String QUERY_BADGE_DELETABLE_STRING = "deletable"; 41 | public static final String NO_BADGE_ID_STRING = "noBadgeId"; 42 | 43 | private QueryParameterUtil() 44 | { 45 | } 46 | 47 | /** 48 | * Used to check if the query parameters are not null, blank and have the correct number of parameters. 49 | * 50 | * @param parametersMap The query parameters which should be validated. 51 | * @return Returns if parameters are valid. 52 | */ 53 | public static boolean parametersAreValid(final Map> parametersMap) 54 | { 55 | boolean rightParameters = false; 56 | 57 | final List idList = parametersMap.get(QUERY_COMPONENT_ID_STRING); 58 | final List fieldList = parametersMap.get(QUERY_FIELD_STRING); 59 | final List conditionList = parametersMap.get(QUERY_CONDITION_STRING); 60 | final List inputList = parametersMap.get(QUERY_INPUT_STRING); 61 | 62 | if((parametersMap.size() == 4 || parametersMap.size() == 5 || parametersMap.size() == BIGGEST_PARAMETER_COUNT) 63 | && isNotNullOrEmpty(idList) 64 | && isNotNullOrEmpty(fieldList) 65 | && isNotNullOrEmpty(conditionList) 66 | && isNotNullOrEmpty(inputList) 67 | && idList.size() == fieldList.size() 68 | && idList.size() == conditionList.size() 69 | && idList.size() == inputList.size()) 70 | { 71 | final Set parametersToCheck = Set.of( 72 | QUERY_INPUT_STRING, 73 | QUERY_COMPONENT_ID_STRING, 74 | QUERY_FIELD_STRING, 75 | QUERY_CONDITION_STRING, 76 | QUERY_BADGE_ID_STRING, 77 | QUERY_BADGE_EDITABLE_STRING, 78 | QUERY_BADGE_DELETABLE_STRING); 79 | for(final Map.Entry> entry : parametersMap.entrySet()) 80 | { 81 | // Conditions and fields cannot be null or empty 82 | if(parametersToCheck.contains(entry.getKey()) 83 | && entry.getValue().stream().noneMatch(String::isBlank)) 84 | { 85 | rightParameters = true; 86 | } 87 | else 88 | { 89 | return false; 90 | } 91 | } 92 | } 93 | 94 | return rightParameters; 95 | } 96 | 97 | /** 98 | * Used to a create query parameter. 99 | * 100 | * @param Bean type of the condition. 101 | * @param componentIdentifier The identifier of the filter component. 102 | * @param filterCondition The condition which should be converted to a query parameter. 103 | * @param badgeId The id of the initial filter badge. 104 | * @return Returns new query parameters. 105 | */ 106 | public static String createQueryParameterString( 107 | final String componentIdentifier, 108 | final FilterCondition filterCondition, 109 | final String badgeId, 110 | final Boolean badgeDeletable, 111 | final Boolean badgeEditable) 112 | { 113 | final Map> query = new HashMap<>(); 114 | query.put( 115 | QUERY_COMPONENT_ID_STRING, 116 | Collections.singletonList(componentIdentifier)); 117 | query.put( 118 | QUERY_FIELD_STRING, 119 | Collections.singletonList(filterCondition.getItem().getDescription())); 120 | query.put( 121 | QUERY_CONDITION_STRING, 122 | Collections.singletonList(filterCondition.getSelectedCondition().getDescription())); 123 | query.put( 124 | QUERY_INPUT_STRING, 125 | Collections.singletonList(filterCondition.getInputValue())); 126 | 127 | // Set the badge id for the condition 128 | String finalBadgeId = badgeId; 129 | 130 | if(finalBadgeId == null || finalBadgeId.isBlank()) 131 | { 132 | // Just the initial filter have a badgeId 133 | finalBadgeId = NO_BADGE_ID_STRING; 134 | } 135 | 136 | query.put(QUERY_BADGE_ID_STRING, Collections.singletonList(finalBadgeId)); 137 | query.put(QUERY_BADGE_DELETABLE_STRING, Collections.singletonList(badgeDeletable.toString())); 138 | query.put(QUERY_BADGE_EDITABLE_STRING, Collections.singletonList(badgeEditable.toString())); 139 | 140 | return new QueryParameters(query).getQueryString(); 141 | } 142 | 143 | public static boolean isNotNullOrEmpty(final Collection c) 144 | { 145 | return c != null && !c.isEmpty(); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /vaadin-simple-grid-filter/src/main/resources/META-INF/resources/frontend/styles/filterComponent.css: -------------------------------------------------------------------------------- 1 | .chipbadge-container { 2 | background-color: var(--lumo-contrast-10pct); 3 | border-radius: var(--lumo-font-size-s); 4 | margin: var(--lumo-space-xs); 5 | padding-left: var(--lumo-space-s); 6 | } 7 | 8 | .chipbadge-label { 9 | font-size: var(--lumo-font-size-s); 10 | } 11 | 12 | .chipbadge-delete-btn { 13 | font-size: var(--lumo-font-size-m); 14 | } 15 | --------------------------------------------------------------------------------