Skip to content

Instantly share code, notes, and snippets.

View TatuLund's full-sized avatar

Tatu Lund TatuLund

View GitHub Profile
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
public class VersionedMap<KEY,VALUE> implements Map<KEY,VALUE> {
private Map<KEY, ArrayDeque<VALUE>> store = new HashMap<>();
@TatuLund
TatuLund / DataCommunicator.java
Last active November 19, 2021 11:41
Modified version of Flow DataCommunicator that adds async mode that works with Grid updates, V14 version
/*
* Copyright 2000-2021 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@TatuLund
TatuLund / ComboBoxLight.java
Last active April 22, 2022 05:52
Light version of Vaadin's ComboBox without lazy loading, custom value, etc.
package org.tatu.vaadin20.components.simplecombo;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.DetachEvent;
import com.vaadin.flow.component.HasHelper;
@TatuLund
TatuLund / CustomComponent.java
Last active April 14, 2022 07:27
This simple class for Vaadin 14/23 implements web component wrapper for HTML & Html component
package org.tatu.vaadin20.components;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Html;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.dom.ShadowRoot;
public class CustomComponent extends Component {
/**
@TatuLund
TatuLund / MyTextArea.java
Last active April 14, 2022 07:27
Vaadin 14/23 TextArea component augmented with cursor and selection API
public class MyTextArea extends TextArea {
int position;
public MyTextArea() {
getElement().addEventListener("keyup", event -> {
getElement().executeJs("return this.inputElement.selectionStart").then(Integer.class, pos -> {
position = pos;
System.out.println(position);
});
@TatuLund
TatuLund / BinderDemoView.java
Created May 11, 2022 08:02
How to update "has-value" attribute in the custom field.
package org.tatu.vaadin20.views;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.customfield.CustomField;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.router.Route;
@TatuLund
TatuLund / GridCsvExportDialog.java
Last active June 21, 2024 13:12
Grid CSV export with Download button in a Dialog. You need have Anchor attached to view in order to not detach it while Dialog is closed by Button click.
package org.vaadin.tatu;
/*
* Dependencies to pom.xml
*
* <dependency>
* <groupId>org.vaadin.artur.exampledata</groupId>
* <artifactId>exampledata</artifactId>
* <version>1.1.0</version>
* </dependency>
@TatuLund
TatuLund / SettingsCookieUI.java
Created July 22, 2022 11:00
This app demonstrates how to store some settings to cookie and retrieve them in Vaadin 8 app
package com.example.settingscookie;
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.RequestHandler;
@TatuLund
TatuLund / loading-indicator.ts
Created November 11, 2022 06:50
Hilla: Utility function for displaying integrated loading indicator programmatically
export function loadingIndicator(percent : number) : void {
const indicator = document.getElementsByClassName("v-loading-indicator")[0] as HTMLElement;
if (percent > 0) {
indicator.style.display = "block";
indicator.style.opacity = "1";
indicator.style.animation = "unset";
indicator.style.width = percent+"%";
} else {
indicator.style.display = "none";
}
@TatuLund
TatuLund / vaadin-tabsheet-binder.css
Created January 16, 2023 14:41
"binder" variant for vaadin-tabsheet
vaadin-tabs[theme~="binder"] > vaadin-tab {
background: var(--lumo-contrast-10pct);
}
vaadin-tabs[theme~="binder"][orientation="horizontal"] > vaadin-tab {
border: 1px solid var(--lumo-contrast-30pct);
border-bottom: none;
border-top-left-radius: var(--lumo-border-radius-m);
border-top-right-radius: var(--lumo-border-radius-m);
}