Skip to content

Instantly share code, notes, and snippets.

@Component
public class ThemeBoostrapListener implements
VaadinServiceInitListener, IndexHtmlRequestListener {
@Override
public void serviceInit(ServiceInitEvent event) {
event.addIndexHtmlRequestListener(this);
}
@Override
public enum ThemeVariant {
STANDARD("Standard"), CARROT_INC("Carrot Inc"), CLEAN("Clean");
private final String caption;
Theme(String caption) {
this.caption = caption;
}
public String getCaption() {
public class ThemeUtil {
private static final String THEME_ATTRIBUTE = "theme";
public static void selectThemeVariant(ThemeVariant themeVariant) {
VaadinSession.getCurrent().setAttribute(THEME_ATTRIBUTE, themeVariant);
UI ui = UI.getCurrent();
ui.getElement().setAttribute(THEME_ATTRIBUTE, themeVariant.getAttribute());
}
@eriklumme
eriklumme / TreeGridView.java
Last active January 7, 2021 14:01
A demonstration of how a Vaadin TreeGrid can be used to show details about an item selected in a Grid.
package org.vaadin.erik;
import com.vaadin.flow.component.AbstractField;
import com.vaadin.flow.component.HasValue;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.treegrid.TreeGrid;
import com.vaadin.flow.data.provider.hierarchy.TreeData;
import com.vaadin.flow.data.provider.hierarchy.TreeDataProvider;
@eriklumme
eriklumme / index.html
Created October 15, 2020 19:59
Stock Tracker 22
<custom-style><style include="lumo-color"></style></custom-style>
<custom-style><style include="lumo-typography"></style></custom-style>
...
<body theme="dark">
@eriklumme
eriklumme / stock-tracker.ts
Created October 15, 2020 19:57
Stock Tracker 21
private removeButtonRenderer: Function = this.renderRemoveButton.bind(this);
...
<vaadin-grid-column text-align="end" .renderer=${this.removeButtonRenderer}></vaadin-grid-column>
@eriklumme
eriklumme / stock-tracker.ts
Created October 15, 2020 19:54
Stock Tracker 19
private renderRemoveButton(root: any, _column: any, rowData: any) {
render(
html`<vaadin-button @click=${() => this.onRemoveFromList(rowData.item.symbol)}>Remove</vaadin-button>`,
root
);
}
@eriklumme
eriklumme / stock-tracker.ts
Created October 15, 2020 19:53
Stock Tracker 18
private onRemoveFromList(symbol: string) {
StockService.removeStock({ symbol }).then(_ => this.updateGrid());
}
@eriklumme
eriklumme / stock-tracker.ts
Created October 15, 2020 19:51
Stock Tracker 17
<vaadin-button theme="primary" @click=${this.onAddToList}>Add stock</vaadin-button>
...
private onAddToList() {
let symbol = this.stockSearchBox.selectedItem?.symbol;
if (symbol) {
StockService.addStock({ symbol }).then(_ => this.updateGrid());
}
@eriklumme
eriklumme / stock-tracker.ts
Created October 15, 2020 19:50
Stock Tracker 16
<vaadin-horizontal-layout theme="spacing" style="align-items: baseline">
<vaadin-combo-box
@filter-changed=${this.onStockSearchStringChanged}
.renderer=${this.renderSearchBoxItems}
id="stock-search"
label="Search for a stock symbol"
item-label-path="symbol">
</vaadin-combo-box>
<vaadin-button theme="primary">Add stock</vaadin-button>
</vaadin-horizontal-layout>