Skip to content

Instantly share code, notes, and snippets.

View TatuLund's full-sized avatar

Tatu Lund TatuLund

View GitHub Profile
@TatuLund
TatuLund / PopupGrid.java
Created April 17, 2023 10:25
An example how to use Popup add-on with Grid with Vaadin 24
package org.vaadin.tatu;
// Add Popup to pom.xml
// <dependency>
// <groupId>com.vaadin.componentfactory</groupId>
// <artifactId>popup</artifactId>
// <version>4.0.0</version>
// </dependency>
import java.util.Arrays;
@TatuLund
TatuLund / tree-icons.css
Created May 11, 2023 06:41
Example of how to change TreeGrid expand/collapse icons to +/- in Vaadin 23/24
vaadin-grid-tree-toggle[expanded]::part(toggle)::before {
content: var(--lumo-icons-minus);
transform: unset;
}
vaadin-grid-tree-toggle::part(toggle)::before {
content: var(--lumo-icons-plus);
}
@TatuLund
TatuLund / ConfirmDialogView.java
Created May 11, 2023 06:44
An example how to use custom buttons and focus button with ConfirmDialog in Vaadin 23/24
@Route("")
public class ConfirmDialogView extends VerticalLayout
implements AfterNavigationObserver {
public ConfirmDialogView() {
add("Hello");
}
@Override
public void afterNavigation(AfterNavigationEvent event) {
@TatuLund
TatuLund / UploadField.java
Created May 11, 2023 06:55
A simple example of UploadField, custom field wrapping Upload component with HasValue and field component behavior for Vaadin 23/24.
public class UploadField extends CustomField<InputStream> {
InputStream is;
FileBuffer buffer = new FileBuffer();
public UploadField() {
Upload upload = new Upload(buffer);
upload.setAcceptedFileTypes("image/jpeg");
upload.setMaxFiles(1);
upload.addSucceededListener(event -> {
@TatuLund
TatuLund / connection-indicator.css
Created May 22, 2023 06:54
Vaadin Flow has built-in loading indicator which is shown when synchronous requests take long to handle. Normally it is shown on the top. If you want to show it prominently in the middle of the screen, use this CSS.
vaadin-connection-indicator {
position: fixed;
z-index: 251;
top: 50%;
width: 20%;
left: 40%;
}
.v-loading-indicator {
position: unset !important;
@TatuLund
TatuLund / TooltipUtils.java
Created May 28, 2023 15:50
Vaadin Tooltip API does not have method to set the CSS class name of a specific tooltip-overlay-element, which could be needed for specific styling cases. This JavaScript call is a workaround.
package com.example.application.views;
import com.vaadin.flow.component.Component;
public class TooltipUtils {
public static void setTooltipClassName(Component comp, String className) {
comp.getElement().executeJs(
"""
if ($0.getElementsByTagName('vaadin-tooltip').length == 1) {
@TatuLund
TatuLund / styles.css
Created July 12, 2023 07:43
Vaadin 7 Reindeer lookalike fields in Vaadin 23/24 Lumo
html {
--lumo-border-radius-l: 20px;
}
vaadin-combo-box::part(input-field) {
box-shadow: inset var(--lumo-box-shadow-xs);
border-top-right-radius: var(--lumo-border-radius-l);
border-bottom-right-radius: var(--lumo-border-radius-l);
}
@TatuLund
TatuLund / dense.css
Created July 12, 2023 07:45
Dense settings for Vaadin 23/24 global styles
[theme~="dense"] {
--lumo-border-radius-s: 0.1em;
--lumo-border-radius-m: 0.2em;
--lumo-border-radius: 0.2em;
--lumo-border-radius-l: 0.3em;
--lumo-space-xs: 0.25rem;
--lumo-space-s: 0.5rem;
--lumo-space-m: 1.5rem;
--lumo-space-l: 1.75rem;
--lumo-space-xl: 2rem;
@TatuLund
TatuLund / GridProView.java
Created July 14, 2023 10:17
This is an example of preventing enter key event of the GridPro cell editor bubbling to Shortcut listener hooked to GridPro.
package com.example.application.views;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.Shortcuts;
import com.vaadin.flow.component.UI;
@TatuLund
TatuLund / BigTable.java
Created July 14, 2023 13:51
Example of a complex table using BeanTable add-on with Vaadin.
package org.vaadin.tatu;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;