├── .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-date-range-picker-demo ├── pom.xml └── src │ └── main │ ├── java │ └── software │ │ └── xdev │ │ └── vaadin │ │ ├── Application.java │ │ └── daterange_picker │ │ ├── HomeView.java │ │ └── example │ │ ├── AbstractSimpleChangeDemo.java │ │ ├── DateRangePickerCustomizedDemo.java │ │ ├── DateRangePickerLocalizedDemo.java │ │ ├── DateRangePickerParameterDemo.java │ │ ├── DateRangePickerRangeExceedingDemo.java │ │ ├── DateRangePickerStyledDemo.java │ │ └── customized │ │ ├── CustomDateRange.java │ │ └── CustomDateRanges.java │ └── resources │ └── application.yml └── vaadin-date-range-picker ├── pom.xml └── src └── main ├── java └── software │ └── xdev │ └── vaadin │ └── daterange_picker │ ├── business │ ├── AbstractDateRange.java │ ├── DateRange.java │ ├── DateRangeActions.java │ ├── DateRangeModel.java │ ├── DateRangeResult.java │ ├── SimpleDateRange.java │ ├── SimpleDateRangeResult.java │ └── SimpleDateRanges.java │ └── ui │ ├── DateRangePicker.java │ ├── DateRangePickerOverlay.java │ ├── DateRangePickerStyles.java │ └── DateRangeValueChangeEvent.java └── resources └── META-INF └── resources └── frontend └── styles └── dateRangePicker.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-date-range-picker/releases/latest)" 19 | required: true 20 | - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/vaadin-date-range-picker/issues) or [closed](https://github.com/xdev-software/vaadin-date-range-picker/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-date-range-picker/issues) or [closed](https://github.com/xdev-software/vaadin-date-range-picker/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-date-range-picker/issues) or [closed](https://github.com/xdev-software/vaadin-date-range-picker/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 | # 4.2.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 | # 4.2.1 6 | * Fix naming so that Vaadin Directory sync works [#318](https://github.com/xdev-software/vaadin-addon-template/issues/318) 7 | * Updated dependencies 8 | 9 | # 4.2.0 10 | * Improved styling 11 | * Overlay now has the same minimum width as the underlying DateRangePicker 12 | * The default is ``20em``, this can be changed using ``--date-range-picker-min-width`` 13 | * Layouts inside the overlay now use the full available width 14 | * Removed excess top padding from input components 15 | * Refactored CSS class names (should cause less conflicts now) 16 | * Updated to Vaadin 24.5 17 | 18 | # 4.1.1 19 | * Only use client-side locale for formatting when no ``formatLocale`` has been set #353 20 | 21 | # 4.1.0 22 | * Updated to Vaadin 24.4 23 | * Minor code improvements 24 | 25 | # 4.0.2 26 | * ⚠️ GroupId changed from ``com.xdev-software`` to ``software.xdev`` 27 | * Updated dependencies 28 | 29 | # 4.0.1 30 | * Various dependency updates including Vaadin 24.1 31 | 32 | # 4.0.0 33 | ⚠️This release contains breaking changes 34 | 35 | * Adds support for Vaadin 24+, drops support for Vaadin 23
36 | If you are still using Vaadin 23, use the ``3.x`` versions. 37 | * Requires Java 17+ 38 | * Fixed Broken overlay detection on Vaadin 24 #224 39 | * Added ``AllowRangeLimitExceeding``; default value is ``true`` 40 | * Updated dependencies 41 | 42 | # 3.0.3 43 | * Renamed ``defaultModel`` to ``initialModel`` 44 | * Updated dependencies 45 | 46 | # 3.0.2 47 | * Updated dependencies 48 | * Vaadin 23.3 49 | 50 | # 3.0.1 51 | * Updated dependencies 52 | * Vaadin 23.2 53 | 54 | # 3.0.0 55 | ⚠️This release contains breaking changes 56 | 57 | * Adds support for Vaadin 23+, drops support for Vaadin 14 #155
58 | If you are still using Vaadin 14, use the ``2.x`` versions. 59 | * Requires Java 11+ 60 | * Updated dependencies 61 | -------------------------------------------------------------------------------- /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-date-range-picker/release.yml?branch=master)](https://github.com/xdev-software/vaadin-date-range-picker/actions/workflows/release.yml) 51 | 52 | Before releasing: 53 | * Consider doing a [test-deployment](https://github.com/xdev-software/vaadin-date-range-picker/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/daterangepicker-for-vaadin) 2 | [![Latest version](https://img.shields.io/maven-central/v/software.xdev/vaadin-date-range-picker?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/vaadin-date-range-picker) 3 | [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/vaadin-date-range-picker/check-build.yml?branch=develop)](https://github.com/xdev-software/vaadin-date-range-picker/actions/workflows/check-build.yml?query=branch%3Adevelop) 4 | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_vaadin-date-range-picker&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_vaadin-date-range-picker) 5 | ![Vaadin 24+](https://img.shields.io/badge/Vaadin%20Platform/Flow-24+-00b4f0) 6 | 7 | # DateRangePicker for Vaadin 8 | A Vaadin Flow DateRangePicker implementation 9 | 10 | ![demo](assets/demo.png) 11 | 12 | 13 | ## Installation 14 | [Installation guide for the latest release](https://github.com/xdev-software/vaadin-date-range-picker/releases/latest#Installation) 15 | 16 | #### Compatibility with Vaadin 17 | 18 | | Vaadin version | DateRangePicker version | 19 | | --- | --- | 20 | | Vaadin 24+ (latest) | ``4+`` | 21 | | Vaadin 23 | ``3.x`` | 22 | | Vaadin 14 | ``2.x`` | 23 | 24 | ### Spring-Boot 25 | * You may have to include ``software/xdev`` inside [``vaadin.allowed-packages``](https://vaadin.com/docs/latest/integrations/spring/configuration#configure-the-scanning-of-packages) 26 | 27 | ## Run the Demo 28 | * Checkout the repo 29 | * Run ``mvn install && mvn -f vaadin-date-range-picker-demo spring-boot:run`` 30 | * Open http://localhost:8080 31 | 32 |
33 | Show example 34 | 35 | ![demo](assets/demo.avif) 36 |
37 | 38 | ## Support 39 | 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). 40 | 41 | ## Contributing 42 | See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how to get started with our project. 43 | 44 | ## Dependencies and Licenses 45 | View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/vaadin-date-range-picker/dependencies) 46 | -------------------------------------------------------------------------------- /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-date-range-picker/security/advisories/new). 6 | -------------------------------------------------------------------------------- /assets/demo.avif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdev-software/vaadin-date-range-picker/bb21659ba27eb94ebf751ddc3ea6aed45493e9ee/assets/demo.avif -------------------------------------------------------------------------------- /assets/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdev-software/vaadin-date-range-picker/bb21659ba27eb94ebf751ddc3ea6aed45493e9ee/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-date-range-picker-root 9 | 4.2.3-SNAPSHOT 10 | pom 11 | 12 | 13 | XDEV Software 14 | https://xdev.software 15 | 16 | 17 | 18 | vaadin-date-range-picker 19 | vaadin-date-range-picker-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-date-range-picker", 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-date-range-picker-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | software.xdev 9 | vaadin-date-range-picker-root 10 | 4.2.3-SNAPSHOT 11 | 12 | 13 | vaadin-date-range-picker-demo 14 | 4.2.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-date-range-picker 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-date-range-picker-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-date-range-picker-demo/src/main/java/software/xdev/vaadin/daterange_picker/HomeView.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.daterange_picker; 2 | 3 | import java.util.Arrays; 4 | 5 | import com.vaadin.flow.component.AttachEvent; 6 | import com.vaadin.flow.component.Composite; 7 | import com.vaadin.flow.component.grid.Grid; 8 | import com.vaadin.flow.component.grid.GridVariant; 9 | import com.vaadin.flow.component.html.Anchor; 10 | import com.vaadin.flow.component.html.Span; 11 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 12 | import com.vaadin.flow.data.renderer.ComponentRenderer; 13 | import com.vaadin.flow.router.PageTitle; 14 | import com.vaadin.flow.router.Route; 15 | 16 | import software.xdev.vaadin.daterange_picker.example.DateRangePickerCustomizedDemo; 17 | import software.xdev.vaadin.daterange_picker.example.DateRangePickerLocalizedDemo; 18 | import software.xdev.vaadin.daterange_picker.example.DateRangePickerParameterDemo; 19 | import software.xdev.vaadin.daterange_picker.example.DateRangePickerRangeExceedingDemo; 20 | import software.xdev.vaadin.daterange_picker.example.DateRangePickerStyledDemo; 21 | 22 | 23 | @PageTitle("DateRangePicker Examples") 24 | @Route("") 25 | public class HomeView extends Composite 26 | { 27 | private final Grid grExamples = new Grid<>(); 28 | 29 | public HomeView() 30 | { 31 | this.grExamples 32 | .addColumn(new ComponentRenderer<>(example -> { 33 | final Anchor anchor = new Anchor(example.route(), example.name()); 34 | 35 | final Span spDesc = new Span(example.desc()); 36 | spDesc.getStyle().set("font-size", "90%"); 37 | 38 | final VerticalLayout vl = new VerticalLayout(anchor, spDesc); 39 | vl.setSpacing(false); 40 | return vl; 41 | })) 42 | .setHeader("Available demos"); 43 | 44 | this.grExamples.setSizeFull(); 45 | this.grExamples.addThemeVariants(GridVariant.LUMO_COMPACT, GridVariant.LUMO_NO_BORDER); 46 | 47 | this.getContent().add(this.grExamples); 48 | this.getContent().setHeightFull(); 49 | } 50 | 51 | @Override 52 | protected void onAttach(final AttachEvent attachEvent) 53 | { 54 | this.grExamples.setItems(Arrays.asList( 55 | new Example( 56 | DateRangePickerStyledDemo.NAV, 57 | "Styled-Demo", 58 | "dark mode 🌑 and more"), 59 | new Example( 60 | DateRangePickerParameterDemo.NAV, 61 | "Parameter-Demo", 62 | "configuration is stored in QueryParameters"), 63 | new Example( 64 | DateRangePickerLocalizedDemo.NAV, 65 | "Localized-Demo", 66 | "🌐 simple localization"), 67 | new Example( 68 | DateRangePickerRangeExceedingDemo.NAV, 69 | "RangeExceeding-Demo", 70 | "usage of a range exceeding DateRange"), 71 | new Example( 72 | DateRangePickerCustomizedDemo.NAV, 73 | "Customized-Demo", 74 | "usage of a customized DateRange") 75 | )); 76 | } 77 | 78 | record Example(String route, String name, String desc) 79 | { 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /vaadin-date-range-picker-demo/src/main/java/software/xdev/vaadin/daterange_picker/example/AbstractSimpleChangeDemo.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.daterange_picker.example; 2 | 3 | import java.time.LocalDate; 4 | import java.util.Arrays; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.stream.Collectors; 9 | 10 | import com.vaadin.flow.component.Composite; 11 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 12 | import com.vaadin.flow.component.textfield.TextArea; 13 | 14 | import software.xdev.vaadin.daterange_picker.business.DateRangeModel; 15 | import software.xdev.vaadin.daterange_picker.business.SimpleDateRange; 16 | import software.xdev.vaadin.daterange_picker.business.SimpleDateRanges; 17 | import software.xdev.vaadin.daterange_picker.ui.DateRangePicker; 18 | 19 | 20 | public abstract class AbstractSimpleChangeDemo extends Composite 21 | { 22 | protected static final List DATERANGE_VALUES = Arrays.asList(SimpleDateRanges.allValues()); 23 | 24 | protected final DateRangePicker dateRangePicker = 25 | new DateRangePicker<>( 26 | () -> new DateRangeModel<>(LocalDate.now(), LocalDate.now(), SimpleDateRanges.TODAY), 27 | DATERANGE_VALUES); 28 | 29 | protected final TextArea taResult = 30 | new TextArea("ValueChangeEvent", "Change something in the date-picker to see the result"); 31 | 32 | protected void registerDefaultValueChangeListener() 33 | { 34 | this.dateRangePicker.addValueChangeListener(ev -> 35 | { 36 | final DateRangeModel modell = ev.getValue(); 37 | 38 | this.taResult.clear(); 39 | 40 | final Map results = new HashMap<>(Map.of( 41 | "DateRange", modell.getDateRange().getKey(), 42 | "Start", modell.getStart().toString(), 43 | "End", modell.getEnd().toString(), 44 | "IsFromClient", String.valueOf(ev.isFromClient()) 45 | )); 46 | if(ev.getOldValue() != null) 47 | { 48 | results.putAll(Map.of( 49 | "OldValue-DateRange", ev.getOldValue().getDateRange().getKey(), 50 | "OldValue-Start", ev.getOldValue().getStart().toString(), 51 | "OldValue-End", ev.getOldValue().getEnd().toString())); 52 | } 53 | else 54 | { 55 | results.put("OldValue", "null"); 56 | } 57 | this.taResult.setValue(results.entrySet() 58 | .stream() 59 | .map(e -> e.getKey() + ": " + e.getValue()) 60 | .collect(Collectors.joining("\r\n"))); 61 | }); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vaadin-date-range-picker-demo/src/main/java/software/xdev/vaadin/daterange_picker/example/DateRangePickerCustomizedDemo.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.daterange_picker.example; 2 | 3 | import java.time.LocalDate; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.stream.Collectors; 8 | 9 | import com.vaadin.flow.component.Composite; 10 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 11 | import com.vaadin.flow.component.textfield.TextArea; 12 | import com.vaadin.flow.router.Route; 13 | 14 | import software.xdev.vaadin.daterange_picker.business.DateRangeModel; 15 | import software.xdev.vaadin.daterange_picker.example.customized.CustomDateRange; 16 | import software.xdev.vaadin.daterange_picker.example.customized.CustomDateRanges; 17 | import software.xdev.vaadin.daterange_picker.ui.DateRangePicker; 18 | 19 | 20 | @Route(DateRangePickerCustomizedDemo.NAV) 21 | public class DateRangePickerCustomizedDemo extends Composite 22 | { 23 | public static final String NAV = "customized"; 24 | 25 | protected static final List DATERANGE_VALUES = Arrays.asList(CustomDateRanges.allValues()); 26 | 27 | private final DateRangePicker dateRangePicker = 28 | new DateRangePicker<>( 29 | () -> new DateRangeModel<>(LocalDate.now(), LocalDate.now(), CustomDateRanges.DAY), 30 | DATERANGE_VALUES); 31 | 32 | private final TextArea taResult = 33 | new TextArea("ValueChangeEvent", "Change something in the datepicker to see the result"); 34 | 35 | public DateRangePickerCustomizedDemo() 36 | { 37 | this.initUI(); 38 | } 39 | 40 | protected void initUI() 41 | { 42 | this.taResult.setSizeFull(); 43 | this.getContent().add(this.dateRangePicker, this.taResult); 44 | 45 | this.dateRangePicker.addValueChangeListener(ev -> 46 | { 47 | final DateRangeModel modell = ev.getValue(); 48 | 49 | this.taResult.clear(); 50 | this.taResult.setValue(Map.of( 51 | "DateRange", modell.getDateRange().getKey(), 52 | "DateRange-Tag", modell.getDateRange().getTag(), 53 | "Start", modell.getStart().toString(), 54 | "End", modell.getEnd().toString() 55 | ).entrySet() 56 | .stream() 57 | .map(e -> e.getKey() + ": " + e.getValue()) 58 | .collect(Collectors.joining("\r\n"))); 59 | }); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /vaadin-date-range-picker-demo/src/main/java/software/xdev/vaadin/daterange_picker/example/DateRangePickerLocalizedDemo.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.daterange_picker.example; 2 | 3 | import java.time.DayOfWeek; 4 | import java.time.LocalDate; 5 | import java.time.Month; 6 | import java.time.format.TextStyle; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | import java.util.Locale; 10 | import java.util.Map; 11 | import java.util.stream.Collectors; 12 | import java.util.stream.Stream; 13 | 14 | import com.vaadin.flow.component.Composite; 15 | import com.vaadin.flow.component.button.Button; 16 | import com.vaadin.flow.component.datepicker.DatePicker.DatePickerI18n; 17 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 18 | import com.vaadin.flow.component.textfield.TextArea; 19 | import com.vaadin.flow.router.Route; 20 | 21 | import software.xdev.vaadin.daterange_picker.business.DateRangeModel; 22 | import software.xdev.vaadin.daterange_picker.business.SimpleDateRange; 23 | import software.xdev.vaadin.daterange_picker.business.SimpleDateRanges; 24 | import software.xdev.vaadin.daterange_picker.ui.DateRangePicker; 25 | 26 | 27 | @Route(DateRangePickerLocalizedDemo.NAV) 28 | public class DateRangePickerLocalizedDemo extends Composite 29 | { 30 | public static final String NAV = "localized"; 31 | 32 | protected static final List DATERANGE_VALUES = Arrays.asList(SimpleDateRanges.allValues()); 33 | 34 | private final DateRangePicker dateRangePicker = 35 | new DateRangePicker<>( 36 | () -> new DateRangeModel<>(LocalDate.now(), LocalDate.now(), SimpleDateRanges.TODAY), 37 | DATERANGE_VALUES) 38 | .withDatePickerI18n(getDatePickerI18n()) 39 | .withDateRangeLocalizerFunction(dr -> { 40 | if(dr == SimpleDateRanges.TODAY) 41 | { 42 | return "Today - Heute"; 43 | } 44 | else if(dr == SimpleDateRanges.DAY) 45 | { 46 | return "Day - Tag"; 47 | } 48 | else if(dr == SimpleDateRanges.WEEK) 49 | { 50 | return "Week - Woche"; 51 | } 52 | else if(dr == SimpleDateRanges.MONTH) 53 | { 54 | return "Month - Monat"; 55 | } 56 | else if(dr == SimpleDateRanges.QUARTER) 57 | { 58 | return "Quarter - Quartal"; 59 | } 60 | else if(dr == SimpleDateRanges.HALF_YEAR) 61 | { 62 | return "Half year - Halbjahr"; 63 | } 64 | else if(dr == SimpleDateRanges.YEAR) 65 | { 66 | return "Year - Jahr"; 67 | } 68 | else if(dr == SimpleDateRanges.FREE) 69 | { 70 | return "Free - Frei"; 71 | } 72 | 73 | return "?"; 74 | }) 75 | .withStartLabel("Start - Anfang") 76 | .withEndLabel("End - Ende") 77 | .withDateRangeOptionsLabel("Period - Zeitraum"); 78 | 79 | private final TextArea taResult = 80 | new TextArea("ValueChangeEvent", "Change something in the datepicker to see the result"); 81 | 82 | private final Button btnToogleReadonly = new Button("Toogle Readonly"); 83 | 84 | public DateRangePickerLocalizedDemo() 85 | { 86 | this.initUI(); 87 | } 88 | 89 | protected void initUI() 90 | { 91 | this.taResult.setSizeFull(); 92 | this.getContent().add(this.dateRangePicker, this.taResult, this.btnToogleReadonly); 93 | 94 | this.btnToogleReadonly.addClickListener(ev -> 95 | this.dateRangePicker.setReadOnly(!this.dateRangePicker.isReadOnly())); 96 | 97 | this.dateRangePicker.addValueChangeListener(ev -> 98 | { 99 | final DateRangeModel modell = ev.getValue(); 100 | 101 | this.taResult.clear(); 102 | this.taResult.setValue(Map.of( 103 | "DateRange", modell.getDateRange().getKey(), 104 | "Start", modell.getStart().toString(), 105 | "End", modell.getEnd().toString() 106 | ).entrySet() 107 | .stream() 108 | .map(e -> e.getKey() + ": " + e.getValue()) 109 | .collect(Collectors.joining("\r\n"))); 110 | }); 111 | } 112 | 113 | // List Must start with Sunday and ends with Saturday... Americans... 114 | private static final List DAYS_OF_WEEK_SORTED_FOR_DATEPICKER = 115 | Stream.concat( 116 | Stream.of(DayOfWeek.SUNDAY), 117 | Stream.of(DayOfWeek.values()).filter(dow -> !dow.equals(DayOfWeek.SUNDAY))) 118 | .toList(); 119 | 120 | private static final List WEEKDAYS = DAYS_OF_WEEK_SORTED_FOR_DATEPICKER.stream() 121 | .map(dow -> dow.getDisplayName(TextStyle.FULL, Locale.GERMAN)) 122 | .toList(); 123 | private static final List WEEKDAYS_SHORT = DAYS_OF_WEEK_SORTED_FOR_DATEPICKER.stream() 124 | .map(dow -> dow.getDisplayName(TextStyle.SHORT, Locale.GERMAN)) 125 | .toList(); 126 | private static final List MONTHS = Stream.of(Month.values()) 127 | .map(m -> m.getDisplayName(TextStyle.FULL, Locale.GERMAN)) 128 | .toList(); 129 | 130 | /** 131 | * Standard DatePickerI18N 132 | */ 133 | public static DatePickerI18n getDatePickerI18n() 134 | { 135 | final DatePickerI18n datepicker = new DatePickerI18n(); 136 | datepicker.setFirstDayOfWeek(1); 137 | 138 | datepicker.setCancel("Abbrechen"); 139 | datepicker.setToday("Heute"); 140 | 141 | datepicker.setMonthNames(MONTHS); 142 | datepicker.setWeekdays(WEEKDAYS); 143 | datepicker.setWeekdaysShort(WEEKDAYS_SHORT); 144 | return datepicker; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /vaadin-date-range-picker-demo/src/main/java/software/xdev/vaadin/daterange_picker/example/DateRangePickerParameterDemo.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.daterange_picker.example; 2 | 3 | import java.time.LocalDate; 4 | import java.time.format.DateTimeParseException; 5 | import java.time.temporal.ChronoUnit; 6 | import java.util.Arrays; 7 | import java.util.Collections; 8 | import java.util.LinkedHashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.Map.Entry; 12 | import java.util.Optional; 13 | 14 | import com.vaadin.flow.component.Composite; 15 | import com.vaadin.flow.component.UI; 16 | import com.vaadin.flow.component.notification.Notification; 17 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 18 | import com.vaadin.flow.router.AfterNavigationEvent; 19 | import com.vaadin.flow.router.AfterNavigationObserver; 20 | import com.vaadin.flow.router.Location; 21 | import com.vaadin.flow.router.QueryParameters; 22 | import com.vaadin.flow.router.Route; 23 | 24 | import software.xdev.vaadin.daterange_picker.business.DateRangeModel; 25 | import software.xdev.vaadin.daterange_picker.business.SimpleDateRange; 26 | import software.xdev.vaadin.daterange_picker.business.SimpleDateRanges; 27 | import software.xdev.vaadin.daterange_picker.ui.DateRangePicker; 28 | 29 | 30 | @Route(DateRangePickerParameterDemo.NAV) 31 | public class DateRangePickerParameterDemo extends Composite implements AfterNavigationObserver 32 | { 33 | public static final String NAV = "parameter"; 34 | 35 | protected static final List DATERANGE_VALUES = Arrays.asList(SimpleDateRanges.allValues()); 36 | 37 | public static final String QP_RANGE = "range"; 38 | public static final String QP_RANGE_START = "range_start"; 39 | public static final String QP_RANGE_END = "range_end"; 40 | 41 | private final DateRangePicker dateRangePicker = new DateRangePicker<>( 42 | () -> new DateRangeModel<>(LocalDate.now(), LocalDate.now(), SimpleDateRanges.TODAY), 43 | DATERANGE_VALUES); 44 | 45 | private boolean blockUpdates = true; 46 | 47 | public DateRangePickerParameterDemo() 48 | { 49 | this.initUI(); 50 | } 51 | 52 | protected void initUI() 53 | { 54 | this.dateRangePicker.addValueChangeListener(ev -> this.onConfigChanged()); 55 | 56 | this.getContent().add(this.dateRangePicker); 57 | } 58 | 59 | @SuppressWarnings("checkstyle:MagicNumber") 60 | protected void onConfigChanged() 61 | { 62 | if(this.blockUpdates) 63 | { 64 | return; 65 | } 66 | 67 | final DateRangeModel dateRangeModell = this.dateRangePicker.getValue(); 68 | if(ChronoUnit.DAYS.between(dateRangeModell.getStart(), dateRangeModell.getEnd()) >= 400) 69 | { 70 | Notification.show("Selected period too long"); 71 | this.updateCurrentUrlSetDefault(); 72 | return; 73 | } 74 | 75 | this.updateCurrentUrl(); 76 | } 77 | 78 | private void updateCurrentUrlSetDefault() 79 | { 80 | this.updateCurrentUrl(new Location(DateRangePickerParameterDemo.NAV)); 81 | } 82 | 83 | private void updateCurrentUrl() 84 | { 85 | final Map queryParaMap = new LinkedHashMap<>(); 86 | queryParaMap.put(QP_RANGE, this.dateRangePicker.getDateRange().getKey().toLowerCase()); 87 | 88 | if(this.dateRangePicker.getDateRange() != SimpleDateRanges.TODAY) 89 | { 90 | queryParaMap.put(QP_RANGE_START, this.dateRangePicker.getStart().toString()); 91 | } 92 | 93 | if(this.dateRangePicker.getDateRange() == SimpleDateRanges.FREE) 94 | { 95 | queryParaMap.put(QP_RANGE_END, this.dateRangePicker.getEnd().toString()); 96 | } 97 | 98 | 99 | final Map> queryParas = new LinkedHashMap<>(); 100 | for(final Entry entry : queryParaMap.entrySet()) 101 | { 102 | queryParas.put(entry.getKey(), Collections.singletonList(entry.getValue())); 103 | } 104 | 105 | this.updateCurrentUrl(new Location(DateRangePickerParameterDemo.NAV, new QueryParameters(queryParas))); 106 | } 107 | 108 | private void updateCurrentUrl(final Location location) 109 | { 110 | UI.getCurrent().getPage().getHistory().replaceState(null, location); 111 | } 112 | 113 | @SuppressWarnings({"PMD.CognitiveComplexity", "PMD.NPathComplexity"}) 114 | @Override 115 | public void afterNavigation(final AfterNavigationEvent event) 116 | { 117 | boolean invalidParameter = false; 118 | 119 | final Map> paras = event.getLocation().getQueryParameters().getParameters(); 120 | 121 | // --- DateRange-Values --- 122 | SimpleDateRange dateRange = SimpleDateRanges.TODAY; 123 | LocalDate start = LocalDate.now(); 124 | LocalDate end = null; 125 | 126 | if(paras.containsKey(QP_RANGE) && !paras.get(QP_RANGE).isEmpty()) 127 | { 128 | final Optional optQueryDR = 129 | DATERANGE_VALUES 130 | .stream() 131 | .filter(dr -> dr.getKey().equalsIgnoreCase(paras.get(QP_RANGE).get(0))) 132 | .findFirst(); 133 | 134 | if(optQueryDR.isPresent()) 135 | { 136 | dateRange = optQueryDR.get(); 137 | } 138 | else 139 | { 140 | invalidParameter = true; 141 | } 142 | } 143 | 144 | if(paras.containsKey(QP_RANGE_START) && !paras.get(QP_RANGE_START).isEmpty()) 145 | { 146 | if(dateRange != SimpleDateRanges.TODAY) 147 | { 148 | try 149 | { 150 | start = LocalDate.parse(paras.get(QP_RANGE_START).get(0)); 151 | } 152 | catch(final DateTimeParseException e) 153 | { 154 | invalidParameter = true; 155 | } 156 | } 157 | else 158 | { 159 | invalidParameter = true; 160 | } 161 | } 162 | 163 | if(paras.containsKey(QP_RANGE_END) && !paras.get(QP_RANGE_END).isEmpty()) 164 | { 165 | if(dateRange == SimpleDateRanges.FREE) 166 | { 167 | try 168 | { 169 | end = LocalDate.parse(paras.get(QP_RANGE_END).get(0)); 170 | } 171 | catch(final DateTimeParseException e) 172 | { 173 | invalidParameter = true; 174 | } 175 | } 176 | else 177 | { 178 | invalidParameter = true; 179 | } 180 | } 181 | 182 | // Check if free range is valid 183 | if(dateRange == SimpleDateRanges.FREE) 184 | { 185 | if(end != null && !start.isAfter(end)) 186 | { 187 | this.dateRangePicker.setValue(new DateRangeModel<>(start, end, dateRange)); 188 | } 189 | else 190 | { 191 | invalidParameter = true; 192 | } 193 | } 194 | else 195 | { 196 | final SimpleDateRange dr = dateRange; 197 | 198 | dateRange.calcFor(start) 199 | .ifPresent(drcr -> 200 | this.dateRangePicker.setValue( 201 | new DateRangeModel<>(drcr.getStart(), drcr.getEnd(), dr))); 202 | 203 | if(dateRange != this.dateRangePicker.getDateRange() || !start.equals(this.dateRangePicker.getStart())) 204 | { 205 | invalidParameter = true; 206 | } 207 | } 208 | 209 | 210 | if(invalidParameter) 211 | { 212 | Notification.show("Invalid parameter"); 213 | } 214 | 215 | this.blockUpdates = false; 216 | 217 | this.onConfigChanged(); 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /vaadin-date-range-picker-demo/src/main/java/software/xdev/vaadin/daterange_picker/example/DateRangePickerRangeExceedingDemo.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.daterange_picker.example; 2 | 3 | import com.vaadin.flow.component.HasSize; 4 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 5 | import com.vaadin.flow.router.Route; 6 | 7 | 8 | @Route(DateRangePickerRangeExceedingDemo.NAV) 9 | public class DateRangePickerRangeExceedingDemo extends AbstractSimpleChangeDemo 10 | { 11 | public static final String NAV = "rangeExceeding"; 12 | 13 | public DateRangePickerRangeExceedingDemo() 14 | { 15 | this.dateRangePicker.withAllowRangeLimitExceeding(true); 16 | this.initUI(); 17 | } 18 | 19 | protected void initUI() 20 | { 21 | this.taResult.setSizeFull(); 22 | 23 | this.getContent().setPadding(false); 24 | this.getContent().add(new VerticalLayout(this.dateRangePicker), new VerticalLayout(this.taResult)); 25 | this.getContent().getChildren().forEach(comp -> ((HasSize)comp).setHeight("50%")); 26 | this.getContent().setHeightFull(); 27 | 28 | this.registerDefaultValueChangeListener(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /vaadin-date-range-picker-demo/src/main/java/software/xdev/vaadin/daterange_picker/example/DateRangePickerStyledDemo.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.daterange_picker.example; 2 | 3 | import com.vaadin.flow.component.HasSize; 4 | import com.vaadin.flow.component.UI; 5 | import com.vaadin.flow.component.button.Button; 6 | import com.vaadin.flow.component.html.Div; 7 | import com.vaadin.flow.component.icon.VaadinIcon; 8 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 9 | import com.vaadin.flow.component.splitlayout.SplitLayout; 10 | import com.vaadin.flow.dom.ThemeList; 11 | import com.vaadin.flow.router.Route; 12 | import com.vaadin.flow.theme.lumo.Lumo; 13 | 14 | 15 | @Route(DateRangePickerStyledDemo.NAV) 16 | public class DateRangePickerStyledDemo extends AbstractSimpleChangeDemo 17 | { 18 | public static final String NAV = "styled"; 19 | 20 | private final Button btnDarkMode = new Button("Toggle theme"); 21 | 22 | public DateRangePickerStyledDemo() 23 | { 24 | this.initUI(); 25 | } 26 | 27 | @SuppressWarnings("checkstyle:MagicNumber") 28 | protected void initUI() 29 | { 30 | this.dateRangePicker.setWidthFull(); 31 | 32 | this.taResult.setSizeFull(); 33 | 34 | this.btnDarkMode.addClickListener(ev -> 35 | { 36 | final ThemeList themeList = UI.getCurrent().getElement().getThemeList(); 37 | 38 | if(themeList.contains(Lumo.DARK)) 39 | { 40 | themeList.remove(Lumo.DARK); 41 | } 42 | else 43 | { 44 | themeList.add(Lumo.DARK); 45 | } 46 | 47 | this.updateBtnDarkMode(); 48 | }); 49 | 50 | final SplitLayout splitLayout = new SplitLayout(this.dateRangePicker, new Div()); 51 | splitLayout.setSplitterPosition(25); 52 | splitLayout.setWidthFull(); 53 | 54 | this.getContent().setPadding(false); 55 | this.getContent().add( 56 | splitLayout, 57 | new VerticalLayout(this.taResult, this.btnDarkMode)); 58 | this.getContent().getChildren().forEach(comp -> ((HasSize)comp).setHeight("50%")); 59 | this.getContent().setHeightFull(); 60 | 61 | this.registerDefaultValueChangeListener(); 62 | 63 | this.updateBtnDarkMode(); 64 | } 65 | 66 | protected void updateBtnDarkMode() 67 | { 68 | final boolean isDarkMode = UI.getCurrent().getElement().getThemeList().contains(Lumo.DARK); 69 | this.btnDarkMode.setText(!isDarkMode ? "Enter the darkness" : "Turn the light on"); 70 | this.btnDarkMode.setIcon(!isDarkMode ? VaadinIcon.MOON_O.create() : VaadinIcon.SUN_O.create()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /vaadin-date-range-picker-demo/src/main/java/software/xdev/vaadin/daterange_picker/example/customized/CustomDateRange.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.daterange_picker.example.customized; 2 | 3 | import software.xdev.vaadin.daterange_picker.business.AbstractDateRange; 4 | 5 | public class CustomDateRange extends AbstractDateRange 6 | { 7 | /** 8 | * Stores some data 9 | */ 10 | private String tag; 11 | 12 | public CustomDateRange withTag(final String tag) 13 | { 14 | this.tag = tag != null ? tag : ""; 15 | return this; 16 | } 17 | 18 | public String getTag() 19 | { 20 | return this.tag; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /vaadin-date-range-picker-demo/src/main/java/software/xdev/vaadin/daterange_picker/example/customized/CustomDateRanges.java: -------------------------------------------------------------------------------- 1 | package software.xdev.vaadin.daterange_picker.example.customized; 2 | 3 | import software.xdev.vaadin.daterange_picker.business.SimpleDateRanges; 4 | 5 | 6 | public final class CustomDateRanges 7 | { 8 | private CustomDateRanges() 9 | { 10 | } 11 | 12 | // No Today-DateRange 13 | 14 | public static final CustomDateRange DAY = new CustomDateRange() 15 | .from(SimpleDateRanges.DAY) 16 | .withTag("has 24 hours"); 17 | 18 | public static final CustomDateRange WEEK = new CustomDateRange() 19 | .from(SimpleDateRanges.WEEK) 20 | .withTag("has 7 days"); 21 | 22 | public static final CustomDateRange MONTH = new CustomDateRange() 23 | .from(SimpleDateRanges.MONTH) 24 | .withTag("has 28-31 days"); 25 | 26 | public static final CustomDateRange QUARTER = new CustomDateRange() 27 | .from(SimpleDateRanges.QUARTER) 28 | .withTag("has 3 months"); 29 | 30 | public static final CustomDateRange HALF_YEAR = new CustomDateRange() 31 | .from(SimpleDateRanges.HALF_YEAR) 32 | .withTag("has 6 months"); 33 | 34 | public static final CustomDateRange YEAR = new CustomDateRange() 35 | .from(SimpleDateRanges.YEAR) 36 | .withTag("has 12 months"); 37 | 38 | // No Free-DateRange 39 | 40 | public static CustomDateRange[] allValues() 41 | { 42 | return new CustomDateRange[] { 43 | DAY, WEEK, MONTH, QUARTER, HALF_YEAR, YEAR 44 | }; 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /vaadin-date-range-picker-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-date-range-picker/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | software.xdev 8 | vaadin-date-range-picker 9 | 4.2.3-SNAPSHOT 10 | jar 11 | 12 | DateRangePicker for Vaadin 13 | DateRangePicker for Vaadin 14 | https://github.com/xdev-software/vaadin-date-range-picker 15 | 16 | 17 | https://github.com/xdev-software/vaadin-date-range-picker 18 | scm:git:https://github.com/xdev-software/vaadin-date-range-picker.git 19 | 20 | 21 | 2020 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 | 74 | 75 | 76 | 77 | 78 | org.apache.maven.plugins 79 | maven-site-plugin 80 | 4.0.0-M16 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-project-info-reports-plugin 85 | 3.9.0 86 | 87 | 88 | 89 | 90 | 91 | com.mycila 92 | license-maven-plugin 93 | 5.0.0 94 | 95 | 96 | ${project.organization.url} 97 | 98 | 99 | 100 |
com/mycila/maven/plugin/license/templates/APACHE-2.txt
101 | 102 | src/main/java/** 103 | src/test/java/** 104 | 105 |
106 |
107 |
108 | 109 | 110 | first 111 | 112 | format 113 | 114 | process-sources 115 | 116 | 117 |
118 | 119 | 121 | 122 | com.vaadin 123 | vaadin-maven-plugin 124 | ${vaadin.version} 125 | 126 | 127 | 128 | prepare-frontend 129 | 130 | 131 | 132 | 133 | 134 | 135 | org.apache.maven.plugins 136 | maven-compiler-plugin 137 | 3.14.0 138 | 139 | ${maven.compiler.release} 140 | 141 | -proc:none 142 | 143 | 144 | 145 | 146 | org.apache.maven.plugins 147 | maven-javadoc-plugin 148 | 3.11.2 149 | 150 | 151 | attach-javadocs 152 | package 153 | 154 | jar 155 | 156 | 157 | 158 | 159 | true 160 | none 161 | 162 | 163 | 164 | org.apache.maven.plugins 165 | maven-source-plugin 166 | 3.3.1 167 | 168 | 169 | attach-sources 170 | package 171 | 172 | jar-no-fork 173 | 174 | 175 | 176 | 177 | 178 | org.apache.maven.plugins 179 | maven-jar-plugin 180 | 3.4.2 181 | 182 | 183 | true 184 | 185 | false 186 | true 187 | 188 | 189 | 190 | 1 191 | 192 | 193 | 194 | 195 | 196 | META-INF/VAADIN/ 197 | 198 | 199 | 200 | 201 |
202 |
203 | 204 | 205 | publish-sonatype-central-portal 206 | 207 | 208 | 209 | org.codehaus.mojo 210 | flatten-maven-plugin 211 | 1.7.0 212 | 213 | ossrh 214 | 215 | 216 | 217 | flatten 218 | process-resources 219 | 220 | flatten 221 | 222 | 223 | 224 | 225 | 226 | org.apache.maven.plugins 227 | maven-gpg-plugin 228 | 3.2.7 229 | 230 | 231 | sign-artifacts 232 | verify 233 | 234 | sign 235 | 236 | 237 | 238 | 239 | 240 | --pinentry-mode 241 | loopback 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | org.sonatype.central 250 | central-publishing-maven-plugin 251 | 0.7.0 252 | true 253 | 254 | sonatype-central-portal 255 | true 256 | 257 | 258 | 259 | 260 | 261 | 262 | checkstyle 263 | 264 | 265 | 266 | org.apache.maven.plugins 267 | maven-checkstyle-plugin 268 | 3.6.0 269 | 270 | 271 | com.puppycrawl.tools 272 | checkstyle 273 | 10.24.0 274 | 275 | 276 | 277 | ../.config/checkstyle/checkstyle.xml 278 | true 279 | 280 | 281 | 282 | 283 | check 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | pmd 293 | 294 | 295 | 296 | org.apache.maven.plugins 297 | maven-pmd-plugin 298 | 3.26.0 299 | 300 | true 301 | true 302 | 303 | ../.config/pmd/ruleset.xml 304 | 305 | 306 | 307 | 308 | net.sourceforge.pmd 309 | pmd-core 310 | 7.13.0 311 | 312 | 313 | net.sourceforge.pmd 314 | pmd-java 315 | 7.13.0 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | org.apache.maven.plugins 326 | maven-jxr-plugin 327 | 3.6.0 328 | 329 | 330 | 331 | 332 | 333 |
334 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/business/AbstractDateRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.business; 17 | 18 | import java.time.LocalDate; 19 | import java.time.Period; 20 | import java.util.Optional; 21 | import java.util.function.BiFunction; 22 | import java.util.function.Function; 23 | 24 | /** 25 | * Basic implementation of {@link DateRange} 26 | * 27 | * @param implementer 28 | */ 29 | @SuppressWarnings("java:S119") 30 | public abstract class AbstractDateRange> implements DateRange 31 | { 32 | private String key; 33 | private Optional optMovePeriod = Optional.empty(); 34 | private String defaultDesc; 35 | private Function> calcForFunc; 36 | private BiFunction> moveFunc = (date, count) -> 37 | { 38 | if(this.optMovePeriod.isEmpty()) 39 | { 40 | return Optional.empty(); 41 | } 42 | 43 | return this.calcForFunc.apply(count != 0 ? date.plus(this.optMovePeriod.get().multipliedBy(count)) : date); 44 | }; 45 | private boolean movable = true; 46 | private boolean calcable = true; 47 | private boolean setable = true; 48 | 49 | @SuppressWarnings("unchecked") 50 | public SELF self() 51 | { 52 | return (SELF)this; 53 | } 54 | 55 | // -- CONFIGURE 56 | public SELF withKey(final String key) 57 | { 58 | this.key = key; 59 | return this.self(); 60 | } 61 | 62 | public SELF withMovePeriod(final Period period) 63 | { 64 | this.optMovePeriod = Optional.ofNullable(period); 65 | return this.self(); 66 | } 67 | 68 | public SELF withDefaultDesc(final String defaultDesc) 69 | { 70 | this.defaultDesc = defaultDesc; 71 | return this.self(); 72 | } 73 | 74 | public SELF withCalcForFunc(final Function calcForFunc) 75 | { 76 | return this.withOptCalcForFunc(date -> Optional.ofNullable(calcForFunc.apply(date))); 77 | } 78 | 79 | public SELF withOptCalcForFunc(final Function> calcForFunc) 80 | { 81 | this.calcForFunc = calcForFunc; 82 | return this.self(); 83 | } 84 | 85 | public SELF withMoveFunc(final BiFunction> moveFunc) 86 | { 87 | this.moveFunc = moveFunc; 88 | return this.self(); 89 | } 90 | 91 | public SELF withMovable(final boolean movable) 92 | { 93 | this.movable = movable; 94 | return this.self(); 95 | } 96 | 97 | public SELF withCalcable(final boolean calcable) 98 | { 99 | this.calcable = calcable; 100 | return this.self(); 101 | } 102 | 103 | public SELF withSettable(final boolean settable) 104 | { 105 | this.setable = settable; 106 | return this.self(); 107 | } 108 | 109 | public SELF from(final AbstractDateRange dateRange) 110 | { 111 | this.key = dateRange.getKey(); 112 | this.optMovePeriod = dateRange.getOptMovePeriod(); 113 | this.defaultDesc = dateRange.getDefaultDescription(); 114 | this.calcForFunc = dateRange.getCalcForFunc(); 115 | this.moveFunc = dateRange.getMoveFunc(); 116 | this.movable = dateRange.isMovable(); 117 | this.calcable = dateRange.isCalcable(); 118 | this.setable = dateRange.isSettable(); 119 | 120 | return this.self(); 121 | } 122 | 123 | // -- GETTER 124 | 125 | @Override 126 | public String getKey() 127 | { 128 | return this.key; 129 | } 130 | 131 | @Override 132 | public Optional getOptMovePeriod() 133 | { 134 | return this.optMovePeriod; 135 | } 136 | 137 | @Override 138 | public String getDefaultDescription() 139 | { 140 | return this.defaultDesc; 141 | } 142 | 143 | @Override 144 | public boolean isMovable() 145 | { 146 | return this.movable && this.isCalcable(); 147 | } 148 | 149 | @Override 150 | public boolean isCalcable() 151 | { 152 | return this.calcable; 153 | } 154 | 155 | @Override 156 | public boolean isSettable() 157 | { 158 | return this.setable; 159 | } 160 | 161 | public Function> getCalcForFunc() 162 | { 163 | return this.calcForFunc; 164 | } 165 | 166 | public BiFunction> getMoveFunc() 167 | { 168 | return this.moveFunc; 169 | } 170 | 171 | @Override 172 | public Optional calcFor(final LocalDate date) 173 | { 174 | if(!this.isCalcable()) 175 | { 176 | return Optional.empty(); 177 | } 178 | return this.calcForFunc.apply(date); 179 | } 180 | 181 | @Override 182 | public Optional moveDateRange(final LocalDate date, final int dif) 183 | { 184 | if(!this.isMovable()) 185 | { 186 | return Optional.empty(); 187 | } 188 | return this.moveFunc.apply(date, dif); 189 | } 190 | 191 | } 192 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/business/DateRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.business; 17 | 18 | import java.time.LocalDate; 19 | import java.time.Period; 20 | import java.util.Optional; 21 | 22 | public interface DateRange 23 | { 24 | /** 25 | * Returns the identification key, e.g. DAY, MONTH, etc 26 | * @return identification key 27 | */ 28 | String getKey(); 29 | 30 | /** 31 | * Returns the {@link Period} to move the date, if any 32 | * @return {@link Period} to move the date 33 | */ 34 | Optional getOptMovePeriod(); 35 | 36 | /** 37 | * Retunns the default description, e.g. "Day" or "Half year" 38 | * @return default description 39 | */ 40 | String getDefaultDescription(); 41 | 42 | /** 43 | * Trys to return the calculated {@link DateRangeResult} for the supplied date 44 | * @param date date that is used for calculation 45 | * @return calculated {@link DateRangeResult} 46 | */ 47 | Optional calcFor(LocalDate date); 48 | 49 | /** 50 | * Trys to return a moved {@link DateRangeResult} 51 | * @param baseDate Date that is used as a base 52 | * @param dif Count of moves 53 | * @return moved {@link DateRangeResult} 54 | */ 55 | Optional moveDateRange(LocalDate baseDate, int dif); 56 | 57 | /** 58 | * Returns if the {@link DateRange} is movable
59 | * Example: 60 | *
    61 | *
  • false for TODAY
  • 62 | *
  • true for MONTH
  • 63 | *
  • false for FREE
  • 64 | *
65 | * @return if the {@link DateRange} is movable 66 | */ 67 | boolean isMovable(); 68 | 69 | /** 70 | * Returns if the {@link DateRange} is calcable
71 | * Example: 72 | *
    73 | *
  • true for TODAY
  • 74 | *
  • true for MONTH
  • 75 | *
  • false for FREE
  • 76 | *
77 | * @return if the {@link DateRange} is calcable 78 | */ 79 | boolean isCalcable(); 80 | 81 | /** 82 | * Returns if the {@link DateRange} is settable from a date
83 | * Example: 84 | *
    85 | *
  • false for TODAY
  • 86 | *
  • true for MONTH
  • 87 | *
  • true for FREE
  • 88 | *
89 | * @return if the {@link DateRange} is settable from a date 90 | */ 91 | boolean isSettable(); 92 | } 93 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/business/DateRangeActions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.business; 17 | 18 | import java.time.LocalDate; 19 | 20 | /** 21 | * Actions which can be done with a {@link DateRangeModel} 22 | * 23 | * @param DateRange 24 | * @param Implementer; returned as "Builder" 25 | */ 26 | public interface DateRangeActions 27 | { 28 | LocalDate getStart(); 29 | T setStart(final LocalDate start); 30 | 31 | LocalDate getEnd(); 32 | T setEnd(final LocalDate end); 33 | 34 | D getDateRange(); 35 | T setDateRange(final D dateRange); 36 | } 37 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/business/DateRangeModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.business; 17 | 18 | import java.time.LocalDate; 19 | import java.util.Objects; 20 | 21 | import software.xdev.vaadin.daterange_picker.ui.DateRangePicker; 22 | 23 | /** 24 | * Model for {@link DateRangePicker} 25 | */ 26 | public class DateRangeModel implements DateRangeActions> 27 | { 28 | private LocalDate start; 29 | private LocalDate end; 30 | private D dateRange; 31 | 32 | public DateRangeModel(final LocalDate start, final LocalDate end, final D dateRange) 33 | { 34 | super(); 35 | this.start = start; 36 | this.end = end; 37 | this.dateRange = dateRange; 38 | } 39 | 40 | @Override 41 | public LocalDate getStart() 42 | { 43 | return this.start; 44 | } 45 | 46 | @Override 47 | public DateRangeModel setStart(final LocalDate start) 48 | { 49 | this.start = start; 50 | return this; 51 | } 52 | 53 | @Override 54 | public LocalDate getEnd() 55 | { 56 | return this.end; 57 | } 58 | 59 | @Override 60 | public DateRangeModel setEnd(final LocalDate end) 61 | { 62 | this.end = end; 63 | return this; 64 | } 65 | 66 | @Override 67 | public D getDateRange() 68 | { 69 | return this.dateRange; 70 | } 71 | 72 | @Override 73 | public DateRangeModel setDateRange(final D dateRange) 74 | { 75 | this.dateRange = dateRange; 76 | return this; 77 | } 78 | 79 | @Override 80 | public boolean equals(final Object o) 81 | { 82 | if(this == o) 83 | { 84 | return true; 85 | } 86 | if(!(o instanceof final DateRangeModel that)) 87 | { 88 | return false; 89 | } 90 | return Objects.equals(this.getStart(), that.getStart()) 91 | && Objects.equals(this.getEnd(), that.getEnd()) 92 | && Objects.equals(this.getDateRange(), that.getDateRange()); 93 | } 94 | 95 | @Override 96 | public int hashCode() 97 | { 98 | return Objects.hash(this.getStart(), this.getEnd(), this.getDateRange()); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/business/DateRangeResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.business; 17 | 18 | import java.time.LocalDate; 19 | 20 | /** 21 | * Result of a {@link DateRange} calculation 22 | */ 23 | public interface DateRangeResult 24 | { 25 | LocalDate getStart(); 26 | LocalDate getEnd(); 27 | } 28 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/business/SimpleDateRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.business; 17 | 18 | /** 19 | * Simple implementation if {@link AbstractDateRange} 20 | */ 21 | public class SimpleDateRange extends AbstractDateRange 22 | { 23 | // Simple impl 24 | } 25 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/business/SimpleDateRangeResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.business; 17 | 18 | import java.time.LocalDate; 19 | 20 | /** 21 | * Simple implementation of {@link DateRangeResult} 22 | */ 23 | public class SimpleDateRangeResult implements DateRangeResult 24 | { 25 | private final LocalDate start; 26 | private final LocalDate end; 27 | 28 | public SimpleDateRangeResult(final LocalDate start, final LocalDate end) 29 | { 30 | super(); 31 | this.start = start; 32 | this.end = end; 33 | } 34 | 35 | @Override 36 | public LocalDate getStart() 37 | { 38 | return this.start; 39 | } 40 | 41 | @Override 42 | public LocalDate getEnd() 43 | { 44 | return this.end; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/business/SimpleDateRanges.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.business; 17 | 18 | import java.time.DayOfWeek; 19 | import java.time.LocalDate; 20 | import java.time.Period; 21 | import java.time.temporal.TemporalAdjusters; 22 | 23 | /** 24 | * Contains predefined {@link SimpleDateRange SimpleDateRanges} 25 | */ 26 | @SuppressWarnings("checkstyle:MagicNumber") 27 | public final class SimpleDateRanges 28 | { 29 | private SimpleDateRanges() 30 | { 31 | } 32 | 33 | public static final SimpleDateRange TODAY = new SimpleDateRange() 34 | .withKey("TODAY") 35 | .withDefaultDesc("Today") 36 | .withMovable(false) 37 | .withSettable(false) 38 | .withCalcForFunc(date -> new SimpleDateRangeResult(LocalDate.now(), LocalDate.now())); 39 | 40 | public static final SimpleDateRange DAY = new SimpleDateRange() 41 | .withKey("DAY") 42 | .withDefaultDesc("Day") 43 | .withMovePeriod(Period.ofDays(1)) 44 | .withCalcForFunc(date -> new SimpleDateRangeResult(date, date)); 45 | 46 | public static final SimpleDateRange WEEK = new SimpleDateRange() 47 | .withKey("WEEK") 48 | .withDefaultDesc("Week") 49 | .withMovePeriod(Period.ofWeeks(1)) 50 | .withCalcForFunc(date -> { 51 | final LocalDate start = date.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); 52 | return new SimpleDateRangeResult(start, start.plusDays(6)); 53 | }); 54 | 55 | public static final SimpleDateRange MONTH = new SimpleDateRange() 56 | .withKey("MONTH") 57 | .withDefaultDesc("Month") 58 | .withMovePeriod(Period.ofMonths(1)) 59 | .withCalcForFunc(date -> 60 | new SimpleDateRangeResult( 61 | date.with(TemporalAdjusters.firstDayOfMonth()), 62 | date.with(TemporalAdjusters.lastDayOfMonth()))); 63 | 64 | public static final SimpleDateRange QUARTER = new SimpleDateRange() 65 | .withKey("QUARTER") 66 | .withDefaultDesc("Quarter") 67 | .withMovePeriod(Period.ofMonths(3)) 68 | .withCalcForFunc(date -> { 69 | final int startMonth = (int)Math.floor((date.getMonthValue() - 1) / 3.0) * 3 + 1; 70 | final int endMonth = startMonth + 2; 71 | 72 | return new SimpleDateRangeResult( 73 | LocalDate.of(date.getYear(), startMonth, 1), 74 | LocalDate.of(date.getYear(), endMonth, 1).with(TemporalAdjusters.lastDayOfMonth())); 75 | }); 76 | 77 | public static final SimpleDateRange HALF_YEAR = new SimpleDateRange() 78 | .withKey("HALF_YEAR") 79 | .withDefaultDesc("Half year") 80 | .withMovePeriod(Period.ofMonths(6)) 81 | .withCalcForFunc(date -> { 82 | final int startMonth = (int)Math.floor((date.getMonthValue() - 1) / 6.0) * 6 + 1; 83 | final int endMonth = startMonth + 5; 84 | 85 | return new SimpleDateRangeResult( 86 | LocalDate.of(date.getYear(), startMonth, 1), 87 | LocalDate.of(date.getYear(), endMonth, 1).with(TemporalAdjusters.lastDayOfMonth())); 88 | }); 89 | 90 | public static final SimpleDateRange YEAR = new SimpleDateRange() 91 | .withKey("YEAR") 92 | .withDefaultDesc("Years") 93 | .withMovePeriod(Period.ofYears(1)) 94 | .withCalcForFunc(date -> 95 | new SimpleDateRangeResult( 96 | date.with(TemporalAdjusters.firstDayOfYear()), 97 | date.with(TemporalAdjusters.lastDayOfYear()))); 98 | 99 | public static final SimpleDateRange FREE = new SimpleDateRange() 100 | .withKey("FREE") 101 | .withDefaultDesc("Free") 102 | .withMovable(false) 103 | .withCalcable(false); 104 | 105 | public static SimpleDateRange[] allValues() 106 | { 107 | return new SimpleDateRange[] { 108 | TODAY, DAY, WEEK, MONTH, QUARTER, HALF_YEAR, YEAR, FREE 109 | }; 110 | 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/ui/DateRangePicker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.ui; 17 | 18 | import java.time.LocalDate; 19 | import java.time.format.DateTimeFormatter; 20 | import java.time.format.FormatStyle; 21 | import java.util.ArrayList; 22 | import java.util.Arrays; 23 | import java.util.Collection; 24 | import java.util.Locale; 25 | import java.util.Objects; 26 | import java.util.Optional; 27 | import java.util.concurrent.atomic.AtomicInteger; 28 | import java.util.function.Supplier; 29 | 30 | import com.vaadin.flow.component.AttachEvent; 31 | import com.vaadin.flow.component.ClientCallable; 32 | import com.vaadin.flow.component.ComponentEventListener; 33 | import com.vaadin.flow.component.ComponentUtil; 34 | import com.vaadin.flow.component.Composite; 35 | import com.vaadin.flow.component.HasValue; 36 | import com.vaadin.flow.component.ItemLabelGenerator; 37 | import com.vaadin.flow.component.button.Button; 38 | import com.vaadin.flow.component.datepicker.DatePicker.DatePickerI18n; 39 | import com.vaadin.flow.component.dependency.CssImport; 40 | import com.vaadin.flow.component.html.Div; 41 | import com.vaadin.flow.component.icon.VaadinIcon; 42 | import com.vaadin.flow.component.orderedlayout.FlexComponent; 43 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 44 | import com.vaadin.flow.data.binder.HasItems; 45 | import com.vaadin.flow.server.VaadinService; 46 | import com.vaadin.flow.shared.Registration; 47 | 48 | import software.xdev.vaadin.daterange_picker.business.DateRange; 49 | import software.xdev.vaadin.daterange_picker.business.DateRangeActions; 50 | import software.xdev.vaadin.daterange_picker.business.DateRangeModel; 51 | 52 | 53 | /** 54 | * Represents a Date-Range-Picker 55 | */ 56 | @SuppressWarnings({"PMD.GodClass", "java:S1948"}) 57 | @CssImport(DateRangePickerStyles.LOCATION) 58 | public class DateRangePicker extends Composite implements 59 | FlexComponent, 60 | HasItems, 61 | DateRangeActions>, 62 | HasValue, DateRangeModel> 63 | { 64 | public static final Locale DEFAULT_LOCALE = Locale.US; 65 | protected static AtomicInteger nextID = new AtomicInteger(0); 66 | 67 | /* 68 | * Fields 69 | */ 70 | protected boolean expanded; 71 | protected DateRangeModel model; 72 | 73 | /* 74 | * Config 75 | */ 76 | protected boolean useClientSideLocale = true; 77 | protected Optional formatLocale = Optional.empty(); 78 | protected ItemLabelGenerator dateRangeLocalizerFunction = DateRange::getDefaultDescription; 79 | protected Optional datePickerI18n = Optional.empty(); 80 | protected boolean closeOnOutsideClick = true; 81 | protected boolean allowRangeLimitExceeding = true; 82 | 83 | /* 84 | * UI-Components 85 | */ 86 | protected final Button btnOverview = new Button(); 87 | 88 | protected final Div overlayContainer = new Div(); 89 | protected final DateRangePickerOverlay overlay = new DateRangePickerOverlay<>(this); 90 | 91 | public DateRangePicker(final DateRangeModel initialModel) 92 | { 93 | this(initialModel, new ArrayList<>()); 94 | } 95 | 96 | public DateRangePicker(final DateRangeModel initialModel, final D[] items) 97 | { 98 | this(initialModel, new ArrayList<>(Arrays.asList(items))); 99 | } 100 | 101 | public DateRangePicker(final DateRangeModel initialModel, final Collection items) 102 | { 103 | this.model = Objects.requireNonNull(initialModel); 104 | this.overlay.setItems(items); 105 | 106 | this.initUI(); 107 | this.registerListeners(); 108 | } 109 | 110 | public DateRangePicker(final Supplier> initialModelSupplier) 111 | { 112 | this(initialModelSupplier.get()); 113 | } 114 | 115 | public DateRangePicker(final Supplier> initialModelSupplier, final D[] items) 116 | { 117 | this(initialModelSupplier.get(), items); 118 | } 119 | 120 | public DateRangePicker(final Supplier> initialModelSupplier, final Collection items) 121 | { 122 | this(initialModelSupplier.get(), items); 123 | } 124 | 125 | // region Initializers 126 | 127 | public DateRangePicker withCloseOnOutsideClick(final boolean closeOnOutsideClick) 128 | { 129 | this.closeOnOutsideClick = closeOnOutsideClick; 130 | return this; 131 | } 132 | 133 | public boolean isCloseOnOutsideClick() 134 | { 135 | return this.closeOnOutsideClick; 136 | } 137 | 138 | public DateRangePicker withDatePickerI18n(final DatePickerI18n datePickerI18n) 139 | { 140 | this.datePickerI18n = Optional.ofNullable(datePickerI18n); 141 | return this; 142 | } 143 | 144 | public Optional getDatePickerI18n() 145 | { 146 | return this.datePickerI18n; 147 | } 148 | 149 | /** 150 | * Sets the locale used for formatting the "expand" button. 151 | *

If the locale is null (default) the clientside locale will be used or {@link Locale#US} if none 152 | * could be detected. 153 | *

154 | */ 155 | public DateRangePicker withFormatLocale(final Locale locale) 156 | { 157 | this.useClientSideLocale = locale == null; 158 | this.formatLocale = Optional.ofNullable(locale); 159 | return this; 160 | } 161 | 162 | public Locale getFormatLocale() 163 | { 164 | return this.formatLocale.orElse(DEFAULT_LOCALE); 165 | } 166 | 167 | public DateRangePicker withDateRangeLocalizerFunction(final ItemLabelGenerator dateRangeLocalizerFunction) 168 | { 169 | this.dateRangeLocalizerFunction = dateRangeLocalizerFunction; 170 | return this; 171 | } 172 | 173 | public ItemLabelGenerator getDateRangeLocalizerFunction() 174 | { 175 | return this.dateRangeLocalizerFunction; 176 | } 177 | 178 | /** 179 | * Shortcut for {@link DateRangePicker#setStartLabel(String)} 180 | */ 181 | public DateRangePicker withStartLabel(final String label) 182 | { 183 | this.setStartLabel(label); 184 | return this; 185 | } 186 | 187 | /** 188 | * Shortcut for {@link DateRangePicker#setEndLabel(String)} 189 | */ 190 | public DateRangePicker withEndLabel(final String label) 191 | { 192 | this.setEndLabel(label); 193 | return this; 194 | } 195 | 196 | /** 197 | * Shortcut for {@link DateRangePicker#setDateRangeOptionsLabel(String)} 198 | */ 199 | public DateRangePicker withDateRangeOptionsLabel(final String label) 200 | { 201 | this.setDateRangeOptionsLabel(label); 202 | return this; 203 | } 204 | 205 | /** 206 | * Shortcut for {@link DateRangePicker#setAllowRangeLimitExceeding(boolean)} 207 | */ 208 | public DateRangePicker withAllowRangeLimitExceeding(final boolean allowRangeLimitExceeding) 209 | { 210 | this.setAllowRangeLimitExceeding(allowRangeLimitExceeding); 211 | return this; 212 | } 213 | 214 | // endregion 215 | 216 | protected void initUI() 217 | { 218 | // Set an unique ID for each element 219 | this.setId("DateRangePickerID" + nextID.incrementAndGet()); 220 | 221 | this.btnOverview.addClassNames(DateRangePickerStyles.BUTTON, DateRangePickerStyles.CLICKABLE); 222 | this.btnOverview.setWidthFull(); 223 | 224 | this.btnOverview.setDisableOnClick(true); 225 | 226 | this.overlay.addClassName(DateRangePickerStyles.OVERLAY_LAYOUT); 227 | 228 | this.overlay.setWidthFull(); 229 | this.overlay.setHeight("auto"); 230 | 231 | this.overlayContainer.setWidthFull(); 232 | this.overlayContainer.addClassName(DateRangePickerStyles.OVERLAY_BASE); 233 | this.overlayContainer.add(this.overlay); 234 | 235 | this.getContent().setSpacing(false); 236 | this.getContent().setPadding(false); 237 | this.setSizeUndefined(); 238 | this.add(this.btnOverview, this.overlayContainer); 239 | 240 | this.setExpanded(false); 241 | } 242 | 243 | protected void registerListeners() 244 | { 245 | this.btnOverview.addClickListener(ev -> 246 | { 247 | this.toggle(); 248 | ev.getSource().setEnabled(true); 249 | }); 250 | this.overlay.addValueChangeListener(ev -> 251 | { 252 | this.model = ev.getSource().getModel(); 253 | 254 | this.updateFromModel(false); 255 | this.fireEvent(new DateRangeValueChangeEvent<>(this, ev.getOldValue(), ev.isFromClient())); 256 | }); 257 | } 258 | 259 | @Override 260 | protected void onAttach(final AttachEvent attachEvent) 261 | { 262 | this.setLocaleFromClient(); 263 | 264 | this.updateFromModel(true); 265 | 266 | this.addClickOutsideListener(); 267 | } 268 | 269 | protected void setLocaleFromClient() 270 | { 271 | if(this.useClientSideLocale) 272 | { 273 | this.formatLocale = Optional.ofNullable(VaadinService.getCurrentRequest().getLocale()); 274 | } 275 | } 276 | 277 | protected void addClickOutsideListener() 278 | { 279 | if(!this.isCloseOnOutsideClick()) 280 | { 281 | return; 282 | } 283 | 284 | final String funcName = "outsideClickFunc" + this.getId().orElseThrow(); 285 | 286 | final String jsCommand = String.join( 287 | "\r\n", 288 | // Define Click-Function 289 | "var " + funcName + " = function(event) {", 290 | // Get the current Element 291 | " var spEl = document.getElementById('" + this.getId().orElseThrow() + "');", 292 | " if (!spEl) {", 293 | // If the element got detached/removed, then als delete the listener of the base element 294 | " document.removeEventListener('click'," + funcName + ");", 295 | " return;", 296 | " }", 297 | // Check if a Vaadin overlay caused the click 298 | " let parent = event.target;", 299 | // Check all parents of clicked element 300 | " while(parent) {", 301 | // Check if a vaadin overlay was clicked: 302 | // Fist check if the tagName indicates a Vaadin overlay 303 | // If not fallback to id='overlay' 304 | " let tagName = parent.tagName.toLowerCase();", 305 | " if((tagName.includes('vaadin') && tagName.includes('overlay')) || parent.id == 'overlay') {", 306 | " return;", 307 | " }", 308 | " parent = parent.parentElement;", 309 | " }", 310 | // Check if the click was done on this element 311 | " var isClickInside = spEl.contains(event.target);", 312 | " if (!isClickInside) {", 313 | " spEl.$server.clickOutsideOccurred();", 314 | " }", 315 | "}; ", 316 | "document.body.addEventListener('click'," + funcName + ");" 317 | ); 318 | 319 | this.getContent().getElement().executeJs(jsCommand); 320 | } 321 | 322 | @ClientCallable 323 | protected void clickOutsideOccurred() 324 | { 325 | if(!this.isCloseOnOutsideClick()) 326 | { 327 | return; 328 | } 329 | 330 | if(this.isExpanded()) 331 | { 332 | this.setExpanded(false); 333 | } 334 | } 335 | 336 | protected void updateFromModel(final boolean updateOverlay) 337 | { 338 | if(updateOverlay) 339 | { 340 | this.tryFixInvalidModel(); 341 | } 342 | 343 | final DateTimeFormatter formatter = 344 | DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withLocale(this.getFormatLocale()); 345 | 346 | this.btnOverview.setText(this.model.getStart().format(formatter) 347 | + (this.model.getStart().equals(this.model.getEnd()) ? "" : " - " + this.model.getEnd().format(formatter)) 348 | ); 349 | 350 | if(updateOverlay) 351 | { 352 | this.overlay.setModel(this.model); 353 | } 354 | } 355 | 356 | protected void tryFixInvalidModel() 357 | { 358 | this.model.getDateRange() 359 | .calcFor(this.model.getStart()) 360 | .ifPresent(result -> { 361 | this.model.setStart(result.getStart()); 362 | this.model.setEnd(result.getEnd()); 363 | }); 364 | } 365 | 366 | protected void toggle() 367 | { 368 | this.setExpanded(!this.isExpanded()); 369 | } 370 | 371 | protected synchronized void setExpanded(final boolean expanded) 372 | { 373 | this.expanded = expanded; 374 | this.btnOverview.setIcon(expanded ? VaadinIcon.CARET_DOWN.create() : VaadinIcon.CARET_UP.create()); 375 | 376 | this.overlay.setVisible(expanded); 377 | } 378 | 379 | public synchronized boolean isExpanded() 380 | { 381 | return this.expanded; 382 | } 383 | 384 | // region Get UI elements 385 | 386 | public DateRangePickerOverlay getOverlay() 387 | { 388 | return this.overlay; 389 | } 390 | 391 | public Button getBtnOverview() 392 | { 393 | return this.btnOverview; 394 | } 395 | 396 | public Div getOverlayContainer() 397 | { 398 | return this.overlayContainer; 399 | } 400 | 401 | // endregion 402 | 403 | // region Labels 404 | 405 | /** 406 | * Sets the label for the overlay Start-DatePicker 407 | */ 408 | public void setStartLabel(final String label) 409 | { 410 | Objects.requireNonNull(label); 411 | this.getOverlay().getDpStart().setLabel(label); 412 | } 413 | 414 | /** 415 | * Sets the label for the overlay End-DatePicker 416 | */ 417 | public void setEndLabel(final String label) 418 | { 419 | Objects.requireNonNull(label); 420 | this.getOverlay().getDpEnd().setLabel(label); 421 | } 422 | 423 | /** 424 | * Sets the label for the overlay DateRange-ComboBox 425 | */ 426 | public void setDateRangeOptionsLabel(final String label) 427 | { 428 | Objects.requireNonNull(label); 429 | this.getOverlay().getCbDateRange().setLabel(label); 430 | } 431 | 432 | // endregion 433 | 434 | // region AllowRangeLimitExceeding 435 | 436 | /** 437 | * Allows the maximum start and end date to be greater or less than the configured end or start date. 438 | *

439 | * This is only the case when {@link DateRange#isCalcable()} is true. Otherwise incorrect values (e.g. 440 | * start before end) could be set. 441 | */ 442 | public void setAllowRangeLimitExceeding(final boolean allowRangeLimitExceeding) 443 | { 444 | this.allowRangeLimitExceeding = allowRangeLimitExceeding; 445 | } 446 | 447 | public boolean isAllowRangeLimitExceeding() 448 | { 449 | return this.allowRangeLimitExceeding; 450 | } 451 | 452 | // endregion 453 | 454 | // region Data 455 | 456 | /** 457 | * Uses the given {@link DateRange} and calculates with the current Date the {@link DateRangeModel}, which is then 458 | * set by {@link DateRangePicker#setValue(DateRangeModel)} 459 | */ 460 | public void setDateRangeForToday(final D range) 461 | { 462 | range.calcFor(LocalDate.now()).ifPresent( 463 | result -> this.setValue(new DateRangeModel<>(result.getStart(), result.getEnd(), range))); 464 | } 465 | 466 | @Override 467 | public void setItems(final Collection items) 468 | { 469 | this.overlay.setItems(items); 470 | } 471 | 472 | @Override 473 | public LocalDate getStart() 474 | { 475 | return this.model.getStart(); 476 | } 477 | 478 | @Override 479 | public DateRangePicker setStart(final LocalDate start) 480 | { 481 | this.model.setStart(start); 482 | this.updateFromModel(true); 483 | return this; 484 | } 485 | 486 | @Override 487 | public LocalDate getEnd() 488 | { 489 | return this.model.getEnd(); 490 | } 491 | 492 | @Override 493 | public DateRangePicker setEnd(final LocalDate end) 494 | { 495 | this.model.setEnd(end); 496 | this.updateFromModel(true); 497 | return this; 498 | } 499 | 500 | @Override 501 | public D getDateRange() 502 | { 503 | return this.model.getDateRange(); 504 | } 505 | 506 | @Override 507 | public DateRangePicker setDateRange(final D dateRange) 508 | { 509 | this.model.setDateRange(dateRange); 510 | this.updateFromModel(true); 511 | return this; 512 | } 513 | 514 | @Override 515 | public void setValue(final DateRangeModel value) 516 | { 517 | Objects.requireNonNull(value); 518 | 519 | this.model = value; 520 | this.updateFromModel(true); 521 | } 522 | 523 | @Override 524 | public DateRangeModel getValue() 525 | { 526 | return this.model; 527 | } 528 | 529 | @SuppressWarnings("unchecked") 530 | @Override 531 | public Registration addValueChangeListener(final ValueChangeListener> listener) 532 | { 533 | @SuppressWarnings("rawtypes") 534 | final ComponentEventListener componentListener = 535 | event -> listener.valueChanged((DateRangeValueChangeEvent)event); 536 | 537 | return ComponentUtil.addListener(this, DateRangeValueChangeEvent.class, componentListener); 538 | } 539 | 540 | /** 541 | * DateRangePicker always has a value
542 | * However for compatibility reasons (with Vaadin) this returns {@code null} 543 | * @return {@code null} 544 | */ 545 | @Override 546 | public DateRangeModel getEmptyValue() 547 | { 548 | return null; 549 | } 550 | 551 | /** 552 | * DateRangePicker always has a value
553 | * Therefore this always returns {@code false} 554 | * 555 | * @return {@code false} 556 | */ 557 | @Override 558 | public boolean isEmpty() 559 | { 560 | return false; 561 | } 562 | 563 | /** 564 | * Do not use this method, as it throws a {@link UnsupportedOperationException}
565 | * The calling of clear is not supported because DateRangePicker always has a value
566 | * Use {@link DateRangePicker#setValue(DateRangeModel)} instead. 567 | * 568 | * @throws UnsupportedOperationException DateRangePicker always has a value 569 | */ 570 | @Override 571 | public void clear() 572 | { 573 | throw new UnsupportedOperationException( 574 | "The calling of clear is not supported because DateRangePicker always has a value"); 575 | } 576 | 577 | @Override 578 | public void setReadOnly(final boolean readOnly) 579 | { 580 | this.getOverlay().setReadOnly(readOnly); 581 | } 582 | 583 | @Override 584 | public boolean isReadOnly() 585 | { 586 | return this.getOverlay().isReadOnly(); 587 | } 588 | 589 | /** 590 | * The required indicator is not implemented
591 | *
592 | * This method doesn't have any functionallity 593 | */ 594 | @Override 595 | public void setRequiredIndicatorVisible(final boolean requiredIndicatorVisible) 596 | { 597 | // Not required/implemented 598 | } 599 | 600 | /** 601 | * The required indicator is not implemented
This will always return {@code false} 602 | * 603 | * @return {@code false} 604 | */ 605 | @Override 606 | public boolean isRequiredIndicatorVisible() 607 | { 608 | return false; 609 | } 610 | 611 | // endregion 612 | } 613 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/ui/DateRangePickerOverlay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.ui; 17 | 18 | import java.time.LocalDate; 19 | import java.util.Collection; 20 | import java.util.Objects; 21 | import java.util.Optional; 22 | import java.util.function.Function; 23 | 24 | import com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent; 25 | import com.vaadin.flow.component.AttachEvent; 26 | import com.vaadin.flow.component.ComponentEvent; 27 | import com.vaadin.flow.component.ComponentEventListener; 28 | import com.vaadin.flow.component.Composite; 29 | import com.vaadin.flow.component.HasStyle; 30 | import com.vaadin.flow.component.button.Button; 31 | import com.vaadin.flow.component.combobox.ComboBox; 32 | import com.vaadin.flow.component.datepicker.DatePicker; 33 | import com.vaadin.flow.component.dependency.CssImport; 34 | import com.vaadin.flow.component.icon.VaadinIcon; 35 | import com.vaadin.flow.component.orderedlayout.FlexComponent; 36 | import com.vaadin.flow.component.orderedlayout.HorizontalLayout; 37 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 38 | import com.vaadin.flow.data.binder.HasItems; 39 | import com.vaadin.flow.shared.Registration; 40 | 41 | import software.xdev.vaadin.daterange_picker.business.DateRange; 42 | import software.xdev.vaadin.daterange_picker.business.DateRangeModel; 43 | import software.xdev.vaadin.daterange_picker.business.DateRangeResult; 44 | 45 | 46 | /** 47 | * Overlay of the expanded {@link DateRangePicker} 48 | */ 49 | @SuppressWarnings("java:S1948") 50 | @CssImport(DateRangePickerStyles.LOCATION) 51 | public class DateRangePickerOverlay extends Composite implements 52 | HasItems, 53 | FlexComponent 54 | { 55 | /* 56 | * Fields 57 | */ 58 | protected boolean readOnly; 59 | 60 | protected DateRangePicker dateRangePicker; 61 | protected DateRangeModel currentModel; 62 | 63 | /* 64 | * UI-Comp 65 | */ 66 | protected final Button btnBackwardRange = new Button(VaadinIcon.ANGLE_LEFT.create()); 67 | protected ComboBox cbDateRange = new ComboBox<>("Period"); 68 | protected final Button btnForwardRange = new Button(VaadinIcon.ANGLE_RIGHT.create()); 69 | 70 | protected DatePicker dpStart = new DatePicker("Start"); 71 | protected DatePicker dpEnd = new DatePicker("End"); 72 | 73 | public DateRangePickerOverlay(final DateRangePicker dateRangePicker) 74 | { 75 | this.dateRangePicker = Objects.requireNonNull(dateRangePicker); 76 | this.currentModel = this.dateRangePicker.getValue(); 77 | 78 | this.initUI(); 79 | this.registerListeners(); 80 | } 81 | 82 | protected void initUI() 83 | { 84 | this.btnBackwardRange 85 | .addClassNames(DateRangePickerStyles.FLEX_CHILD_CONTENTSIZE, DateRangePickerStyles.CLICKABLE); 86 | 87 | this.cbDateRange.addClassNames( 88 | DateRangePickerStyles.FLEX_CHILD_AUTOGROW, 89 | DateRangePickerStyles.PADDING_TOP_XS); 90 | this.setTextFieldDefaultWidthFlexConform(this.cbDateRange); 91 | 92 | this.btnForwardRange 93 | .addClassNames(DateRangePickerStyles.FLEX_CHILD_CONTENTSIZE, DateRangePickerStyles.CLICKABLE); 94 | 95 | final HorizontalLayout hlRange = new HorizontalLayout(); 96 | hlRange.addClassNames(DateRangePickerStyles.OVERLAY_LAYOUT_ROW); 97 | hlRange.setAlignItems(Alignment.BASELINE); 98 | hlRange.setJustifyContentMode(JustifyContentMode.BETWEEN); 99 | hlRange.setMargin(false); 100 | hlRange.setSpacing(true); 101 | hlRange.setPadding(false); 102 | hlRange.add(this.btnBackwardRange, this.cbDateRange, this.btnForwardRange); 103 | 104 | this.initDatePicker(this.dpStart); 105 | this.initDatePicker(this.dpEnd); 106 | 107 | final HorizontalLayout hlDatepickers = new HorizontalLayout(); 108 | hlDatepickers.addClassNames(DateRangePickerStyles.OVERLAY_LAYOUT_ROW); 109 | hlDatepickers.setMargin(false); 110 | hlDatepickers.setSpacing(true); 111 | hlDatepickers.setPadding(false); 112 | hlDatepickers.add(this.dpStart, this.dpEnd); 113 | 114 | this.add(hlRange, hlDatepickers); 115 | this.getContent().setPadding(true); 116 | } 117 | 118 | protected void initDatePicker(final DatePicker dp) 119 | { 120 | this.setTextFieldDefaultWidthFlexConform(dp); 121 | dp.addClassNames(DateRangePickerStyles.FLEX_CHILD_AUTOGROW, DateRangePickerStyles.PADDING_TOP_XS); 122 | dp.setWeekNumbersVisible(true); 123 | } 124 | 125 | @Override 126 | protected void onAttach(final AttachEvent attachEvent) 127 | { 128 | this.cbDateRange.setItemLabelGenerator(this.dateRangePicker.getDateRangeLocalizerFunction()); 129 | 130 | this.dateRangePicker.getDatePickerI18n() 131 | .ifPresent(i18n -> 132 | { 133 | this.dpStart.setI18n(i18n); 134 | this.dpEnd.setI18n(i18n); 135 | }); 136 | } 137 | 138 | protected void setTextFieldDefaultWidthFlexConform(final HasStyle component) 139 | { 140 | component.getStyle().set("--vaadin-field-default-width", "auto"); 141 | } 142 | 143 | protected void registerListeners() 144 | { 145 | this.cbDateRange.addValueChangeListener(this::onComboBoxDateRangeValueChanged); 146 | this.btnBackwardRange.addClickListener(ev -> this.moveRange(-1)); 147 | this.btnForwardRange.addClickListener(ev -> this.moveRange(+1)); 148 | this.dpStart.addValueChangeListener(this::onDatePickerValueChanged); 149 | this.dpEnd.addValueChangeListener(this::onDatePickerValueChanged); 150 | } 151 | 152 | protected void onComboBoxDateRangeValueChanged(final ComponentValueChangeEvent, D> ev) 153 | { 154 | if(!ev.isFromClient()) 155 | { 156 | return; 157 | } 158 | this.onValueChange(model -> model.getDateRange().calcFor(model.getStart())); 159 | } 160 | 161 | protected void onDatePickerValueChanged(final ComponentValueChangeEvent ev) 162 | { 163 | if(!ev.isFromClient()) 164 | { 165 | return; 166 | } 167 | this.onValueChange(model -> model.getDateRange().calcFor(ev.getValue())); 168 | } 169 | 170 | protected void moveRange(final int dif) 171 | { 172 | this.onValueChange(model -> model.getDateRange().moveDateRange(model.getStart(), dif)); 173 | } 174 | 175 | protected void calcModel(final Optional optResult, final DateRangeModel model) 176 | { 177 | if(optResult.isEmpty()) 178 | { 179 | return; 180 | } 181 | 182 | final DateRangeResult result = optResult.get(); 183 | model.setStart(result.getStart()); 184 | model.setEnd(result.getEnd()); 185 | } 186 | 187 | protected void onValueChange(final Function, Optional> calcFunc) 188 | { 189 | final DateRangeModel model = this.getModelFromComponents(); 190 | 191 | this.calcModel(calcFunc.apply(model), model); 192 | this.updateComponentsFromModel(model); 193 | 194 | final DateRangeModel oldValue = this.currentModel; 195 | this.setCurrentModel(model); 196 | 197 | this.fireValueChanged(oldValue, true); 198 | } 199 | 200 | protected DateRangeModel getModelFromComponents() 201 | { 202 | return new DateRangeModel<>(this.dpStart.getValue(), this.dpEnd.getValue(), this.cbDateRange.getValue()); 203 | } 204 | 205 | protected void updateComponentsFromModel(final DateRangeModel model) 206 | { 207 | final boolean datepickerReadonly = !model.getDateRange().isSettable(); 208 | this.dpStart.setReadOnly(datepickerReadonly); 209 | this.dpEnd.setReadOnly(datepickerReadonly); 210 | 211 | final boolean fastNavEnabled = model.getDateRange().isMovable(); 212 | this.btnBackwardRange.setEnabled(fastNavEnabled); 213 | this.btnForwardRange.setEnabled(fastNavEnabled); 214 | 215 | final boolean allowRangeLimitExceeding = 216 | this.dateRangePicker.isAllowRangeLimitExceeding() 217 | // If it's not calcable we can't verify that the set value is correct (e.g. when it's a free value) 218 | && model.getDateRange().isCalcable(); 219 | this.dpEnd.setMin(allowRangeLimitExceeding ? null : model.getStart()); 220 | this.dpStart.setMax(allowRangeLimitExceeding ? null : model.getEnd()); 221 | 222 | this.cbDateRange.setValue(model.getDateRange()); 223 | this.dpStart.setValue(model.getStart()); 224 | this.dpEnd.setValue(model.getEnd()); 225 | } 226 | 227 | protected void setCurrentModel(final DateRangeModel model) 228 | { 229 | this.currentModel = model; 230 | } 231 | 232 | protected void fireValueChanged(final DateRangeModel oldValue, final boolean isFromClient) 233 | { 234 | this.fireEvent(new DateRangeOverlayValueChangeEvent(this, oldValue, isFromClient)); 235 | } 236 | 237 | @Override 238 | public void setItems(final Collection items) 239 | { 240 | Objects.requireNonNull(items); 241 | 242 | this.getCbDateRange().setItems(items); 243 | } 244 | 245 | // region UI Getter 246 | public ComboBox getCbDateRange() 247 | { 248 | return this.cbDateRange; 249 | } 250 | 251 | public DatePicker getDpStart() 252 | { 253 | return this.dpStart; 254 | } 255 | 256 | public DatePicker getDpEnd() 257 | { 258 | return this.dpEnd; 259 | } 260 | 261 | // endregion 262 | 263 | // region Manage Data externally 264 | public DateRangeModel getModel() 265 | { 266 | return this.currentModel; 267 | } 268 | 269 | public void setModel(final DateRangeModel model) 270 | { 271 | final DateRangeModel oldValue = this.currentModel; 272 | 273 | this.currentModel = model; 274 | this.updateComponentsFromModel(this.currentModel); 275 | 276 | this.fireValueChanged(oldValue, false); 277 | } 278 | 279 | public void setReadOnly(final boolean readOnly) 280 | { 281 | this.readOnly = readOnly; 282 | 283 | this.cbDateRange.setReadOnly(readOnly); 284 | 285 | this.btnBackwardRange.setEnabled(!readOnly); 286 | this.btnForwardRange.setEnabled(!readOnly); 287 | 288 | if(readOnly) 289 | { 290 | this.dpStart.setReadOnly(true); 291 | this.dpEnd.setReadOnly(true); 292 | } 293 | else 294 | { 295 | // Fix read-only if e.g. TODAY is selected 296 | this.updateComponentsFromModel(this.getModelFromComponents()); 297 | } 298 | } 299 | 300 | public boolean isReadOnly() 301 | { 302 | return this.readOnly; 303 | } 304 | 305 | @SuppressWarnings({"unchecked", "rawtypes"}) 306 | public Registration addValueChangeListener(final ComponentEventListener listener) 307 | { 308 | return this.addListener(DateRangeOverlayValueChangeEvent.class, (ComponentEventListener)listener); 309 | } 310 | 311 | // endregion 312 | 313 | public class DateRangeOverlayValueChangeEvent extends ComponentEvent> 314 | { 315 | private final DateRangeModel oldValue; 316 | private final boolean isFromClient; 317 | 318 | public DateRangeOverlayValueChangeEvent( 319 | final DateRangePickerOverlay source, 320 | final DateRangeModel oldValue, 321 | final boolean isFromClient) 322 | { 323 | super(source, false); 324 | this.oldValue = oldValue; 325 | this.isFromClient = isFromClient; 326 | } 327 | 328 | public DateRangeModel getOldValue() 329 | { 330 | return this.oldValue; 331 | } 332 | 333 | @Override 334 | public boolean isFromClient() 335 | { 336 | return this.isFromClient; 337 | } 338 | } 339 | } 340 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/ui/DateRangePickerStyles.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.ui; 17 | 18 | /** 19 | * Styles for the {@link DateRangePicker} 20 | */ 21 | public final class DateRangePickerStyles 22 | { 23 | private DateRangePickerStyles() 24 | { 25 | } 26 | 27 | public static final String LOCATION = "./styles/dateRangePicker.css"; 28 | 29 | public static final String CLICKABLE = "date-range-picker-clickable"; 30 | 31 | public static final String BUTTON = "date-range-picker-button"; 32 | public static final String OVERLAY_BASE = "date-range-picker-overlay-base"; 33 | public static final String OVERLAY_LAYOUT = "date-range-picker-overlay-layout"; 34 | public static final String OVERLAY_LAYOUT_ROW = "date-range-picker-overlay-layout-row"; 35 | 36 | /* 37 | * FLEX 38 | */ 39 | public static final String FLEX_CHILD_AUTOGROW = "date-range-picker-flex-child-autogrow"; 40 | public static final String FLEX_CHILD_CONTENTSIZE = "date-range-picker-flex-child-contentsize"; 41 | 42 | // Used to remove Vaadin's default padding which adds a lot of blank space to the overlay 43 | public static final String PADDING_TOP_XS = "date-range-picker-padding-top-xs"; 44 | } 45 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/ui/DateRangeValueChangeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 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.daterange_picker.ui; 17 | 18 | import com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent; 19 | 20 | import software.xdev.vaadin.daterange_picker.business.DateRange; 21 | import software.xdev.vaadin.daterange_picker.business.DateRangeModel; 22 | 23 | 24 | public class DateRangeValueChangeEvent 25 | extends ComponentValueChangeEvent, DateRangeModel> 26 | { 27 | public DateRangeValueChangeEvent( 28 | final DateRangePicker source, 29 | final DateRangeModel oldValue, 30 | final boolean isFromClient) 31 | { 32 | super(source, source, oldValue, isFromClient); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /vaadin-date-range-picker/src/main/resources/META-INF/resources/frontend/styles/dateRangePicker.css: -------------------------------------------------------------------------------- 1 | .date-range-picker-clickable { 2 | cursor: pointer; 3 | } 4 | 5 | .date-range-picker-button { 6 | margin-bottom: 0; 7 | border-radius: 0; 8 | color: var(--lumo-body-text-color); 9 | min-width: var(--date-range-picker-min-width, 20em); 10 | } 11 | 12 | .date-range-picker-overlay-base { 13 | position: relative; 14 | } 15 | 16 | .date-range-picker-overlay-layout { 17 | display: flex; 18 | position: absolute; 19 | left: 0; 20 | right: 0; 21 | z-index: 1; 22 | background-color: var(--lumo-base-color); 23 | border: 1px solid var(--lumo-contrast-5pct); 24 | border-top: none; 25 | min-width: var(--date-range-picker-min-width, 20em); 26 | } 27 | 28 | .date-range-picker-overlay-layout-row { 29 | width: 100%; 30 | flex: 1 1 auto; 31 | display: flex; 32 | } 33 | 34 | .date-range-picker-flex-child-autogrow { 35 | flex: 1 1 auto; 36 | } 37 | 38 | .date-range-picker-flex-child-contentsize { 39 | flex: 0 1 auto; 40 | } 41 | 42 | .date-range-picker-padding-top-xs { 43 | padding-top: var(--lumo-space-xs); 44 | } 45 | --------------------------------------------------------------------------------