Skip to content

Commit

Permalink
refactor: run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Dec 20, 2024
1 parent 3f1bd78 commit 3c07967
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public BasicLayoutsExpandingItems() {
// end::snippet[]
layout.setPadding(true);
layout.add(item1);

Div item2 = new Div("Item 2");
item2.setClassName("example-item");
layout.add(item2);

Div item3 = new Div("Item 3");
item3.setClassName("example-item");
layout.add(item3);

this.add(layout);
this.setClassName("basic-layouts-example");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class BasicLayoutsHorizontalLayoutSpacing extends Div {
public BasicLayoutsHorizontalLayoutSpacing() {
add(new Paragraph("Horizontal layout without spacing:"));
// tag::snippet[]
// HorizontalLayout has spacing enabled by default, use setSpacing to disable it
// HorizontalLayout has spacing enabled by default, use setSpacing to
// disable it
HorizontalLayout layoutWithoutSpacing = new HorizontalLayout();
layoutWithoutSpacing.setSpacing(false);
// end::snippet[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public BasicLayoutsHorizontalLayoutWrapping() {
Div wrapItem5 = new Div("Item 5");
wrapItem5.setClassName("example-item");

layoutWithWrap.add(wrapItem1, wrapItem2, wrapItem3, wrapItem4, wrapItem5);
layoutWithWrap.add(wrapItem1, wrapItem2, wrapItem3, wrapItem4,
wrapItem5);

this.setClassName("basic-layouts-example");
this.add(layoutWithWrap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public BasicLayoutsPadding() {
parent.add(wrapper);

// tag::snippet[]
// VerticalLayout has padding enabled by default, use setPadding to disable it
// VerticalLayout has padding enabled by default, use setPadding to
// disable it
VerticalLayout layoutWithoutPadding = new VerticalLayout();
layoutWithoutPadding.setPadding(false);
// end::snippet[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public BasicLayoutsSpacing() {
parent.add(wrapper);

// tag::snippet[]
// VerticalLayout has spacing enabled by default, use setSpacing to disable it
// VerticalLayout has spacing enabled by default, use setSpacing to
// disable it
VerticalLayout layoutWithoutSpacing = new VerticalLayout();
layoutWithoutSpacing.setSpacing(false);
// end::snippet[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public BasicLayoutsVerticalLayoutWrapping() {
layoutWithoutWrap.setSpacing(true);
layoutWithoutWrap.setAlignItems(FlexComponent.Alignment.STRETCH);
layoutWithoutWrap.setHeight("200px");

Div item1 = new Div("Item 1");
item1.setClassName("example-item");
Div item2 = new Div("Item 2");
Expand All @@ -35,7 +35,7 @@ public BasicLayoutsVerticalLayoutWrapping() {
item3.setClassName("example-item");
Div item4 = new Div("Item 4");
item4.setClassName("example-item");

layoutWithoutWrap.add(item1, item2, item3, item4);
wrapper.add(layoutWithoutWrap);
parent.add(wrapper);
Expand All @@ -52,7 +52,7 @@ public BasicLayoutsVerticalLayoutWrapping() {
layoutWithWrap.setSpacing(true);
layoutWithWrap.setAlignItems(FlexComponent.Alignment.STRETCH);
layoutWithWrap.setHeight("200px");

Div wrapItem1 = new Div("Item 1");
wrapItem1.setClassName("example-item");
Div wrapItem2 = new Div("Item 2");
Expand All @@ -61,7 +61,7 @@ public BasicLayoutsVerticalLayoutWrapping() {
wrapItem3.setClassName("example-item");
Div wrapItem4 = new Div("Item 4");
wrapItem4.setClassName("example-item");

layoutWithWrap.add(wrapItem1, wrapItem2, wrapItem3, wrapItem4);
wrapper.add(layoutWithWrap);
parent.add(wrapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class ContextMenuDisableOnClick extends Div {

public ContextMenuDisableOnClick() {
Paragraph paragraph = new Paragraph();
paragraph.setText("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.");
paragraph.setText(
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.");
add(paragraph);

ContextMenu menu = new ContextMenu(paragraph);
Expand All @@ -33,6 +34,7 @@ public ContextMenuDisableOnClick() {
});
}

public static class Exporter extends DemoExporter<ContextMenuDisableOnClick> { // hidden-source-line
public static class Exporter
extends DemoExporter<ContextMenuDisableOnClick> { // hidden-source-line
} // hidden-source-line
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public DashboardAnnouncements() {
conversions.setContent(createWidgetContent());
dashboard.add(conversions);

DashboardWidget visitorsByCountry = new DashboardWidget("Visitors by country");
DashboardWidget visitorsByCountry = new DashboardWidget(
"Visitors by country");
visitorsByCountry.setContent(createWidgetContent());
visitorsByCountry.setRowspan(2);
dashboard.add(visitorsByCountry);
Expand All @@ -43,24 +44,26 @@ public DashboardAnnouncements() {
catImage.setContent(createWidgetContent());
dashboard.add(catImage);

DashboardWidget visitorsByBrowser = new DashboardWidget("Visitors by browser");
DashboardWidget visitorsByBrowser = new DashboardWidget(
"Visitors by browser");
visitorsByBrowser.setContent(createWidgetContent());
visitorsByBrowser.setColspan(2);
dashboard.add(visitorsByBrowser);

// tag::snippet[]
// Live region for screen reader announcements. Changing its text content will result
// in a new announcement. This element is only visible for demonstration purposes. In
// your application you should visually hide it using CSS, for example by using the
// sr-only Lumo utility class:
// Live region for screen reader announcements. Changing its text
// content will result in a new announcement. This element is only
// visible for demonstration purposes. In your application you should
// visually hide it using CSS, for example by using the sr-only Lumo
// utility class:
// liveRegion.addClassName(LumoUtility.Accessibility.SCREEN_READER_ONLY)
Div liveRegion = new Div();
liveRegion.getElement().setAttribute("aria-live", "polite");
add(liveRegion);

// This event is fired when the user starts or stops editing a widget
dashboard.addItemSelectedChangedListener(event -> {
String title = ((DashboardWidget)event.getItem()).getTitle();
String title = ((DashboardWidget) event.getItem()).getTitle();
String selected = event.isSelected() ? "selected" : "deselected";

liveRegion.setText("Widget " + title + " " + selected);
Expand Down Expand Up @@ -88,9 +91,10 @@ public DashboardAnnouncements() {
dashboard.addItemMovedListener(event -> {
int position = event.getItems().indexOf(event.getItem()) + 1;
int total = event.getItems().size();
String title = ((DashboardWidget)event.getItem()).getTitle();
String title = ((DashboardWidget) event.getItem()).getTitle();

liveRegion.setText("Moved widget " + title + " to position " + position + " of " + total);
liveRegion.setText("Moved widget " + title + " to position "
+ position + " of " + total);
});

// This event is fired when the user resizes a widget
Expand All @@ -99,12 +103,13 @@ public DashboardAnnouncements() {
int rowspan = event.getItem().getRowspan();
String title = event.getItem().getTitle();

liveRegion.setText("Resized widget " + title + " to " + colspan + " columns, " + rowspan + " rows");
liveRegion.setText("Resized widget " + title + " to " + colspan
+ " columns, " + rowspan + " rows");
});

// This event is fired when the user removes a widget
dashboard.addItemRemovedListener(event -> {
String title = ((DashboardWidget)event.getItem()).getTitle();
String title = ((DashboardWidget) event.getItem()).getTitle();

liveRegion.setText("Removed widget " + title);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public DashboardBasic() {
conversions.setContent(createWidgetContent());
dashboard.add(conversions);

DashboardWidget visitorsByCountry = new DashboardWidget("Visitors by country");
DashboardWidget visitorsByCountry = new DashboardWidget(
"Visitors by country");
visitorsByCountry.setContent(createWidgetContent());
visitorsByCountry.setRowspan(2);
dashboard.add(visitorsByCountry);
Expand All @@ -40,7 +41,8 @@ public DashboardBasic() {
catImage.setContent(createWidgetContent());
dashboard.add(catImage);

DashboardWidget visitorsByBrowser = new DashboardWidget("Visitors by browser");
DashboardWidget visitorsByBrowser = new DashboardWidget(
"Visitors by browser");
visitorsByBrowser.setContent(createWidgetContent());
visitorsByBrowser.setColspan(2);
dashboard.add(visitorsByBrowser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ public class DashboardEditable extends Div {
private Dashboard dashboard;

// tag::snippet[]
// NOTE: This example uses the additional classes WidgetConfig and DashboardStorage,
// which you can find by switching to the respective file tab.
// NOTE: This example uses the additional classes WidgetConfig and
// DashboardStorage, which you can find by switching to the respective file
// tab.

// Since the default DashboardWidget class doesn't allow setting custom data,
// we create a custom class that extends DashboardWidget, and add a
// Since the default DashboardWidget class doesn't allow setting custom
// data, we create a custom class that extends DashboardWidget, and add a
// field for storing the widget type.
public static class CustomWidget extends DashboardWidget {
private final WidgetConfig.WidgetType type;
Expand All @@ -37,17 +38,19 @@ public WidgetConfig.WidgetType getType() {
}
}

// This is the default configuration for the dashboard. Note that the order of the
// widgets in the list determines the order in which they are displayed in the dashboard.
// This is the default configuration for the dashboard. Note that the order
// of the widgets in the list determines the order in which they are
// displayed in the dashboard.
private final List<WidgetConfig> defaultConfig = List.of(
new WidgetConfig(WidgetConfig.WidgetType.VISITORS, 1, 1),
new WidgetConfig(WidgetConfig.WidgetType.DOWNLOADS, 1, 1),
new WidgetConfig(WidgetConfig.WidgetType.CONVERSIONS, 1, 1),
new WidgetConfig(WidgetConfig.WidgetType.VISITORS_BY_COUNTRY, 1, 2),
new WidgetConfig(WidgetConfig.WidgetType.BROWSER_DISTRIBUTION, 1, 1),
new WidgetConfig(WidgetConfig.WidgetType.BROWSER_DISTRIBUTION, 1,
1),
new WidgetConfig(WidgetConfig.WidgetType.CAT_IMAGE, 1, 1),
new WidgetConfig(WidgetConfig.WidgetType.VISITORS_BY_BROWSER, 2, 1)
);
new WidgetConfig(WidgetConfig.WidgetType.VISITORS_BY_BROWSER, 2,
1));

public DashboardEditable(DashboardStorage dashboardStorage) {
this.dashboardStorage = dashboardStorage;
Expand Down Expand Up @@ -89,8 +92,10 @@ private void createToolbar() {
load.addClickListener(event -> loadConfiguration());

MenuItem addWidget = toolbar.addItem("Add widget");
for (WidgetConfig.WidgetType widgetType : WidgetConfig.WidgetType.values()) {
addWidget.getSubMenu().addItem(widgetType.getLabel(), event -> addWidget(widgetType));
for (WidgetConfig.WidgetType widgetType : WidgetConfig.WidgetType
.values()) {
addWidget.getSubMenu().addItem(widgetType.getLabel(),
event -> addWidget(widgetType));
}

MenuItem restore = toolbar.addItem("Restore default");
Expand All @@ -101,13 +106,16 @@ private void createToolbar() {
}

private void saveConfiguration() {
// To save the dashboard configuration, we iterate over the current widgets
// in the dashboard and map them into configuration objects.
List<WidgetConfig> dashboardConfig = dashboard.getWidgets().stream().map(widget -> {
// Cast to our custom widget class and extract type, colspan, and rowspan
CustomWidget customWidget = (CustomWidget) widget;
return new WidgetConfig(customWidget.getType(), widget.getColspan(), widget.getRowspan());
}).toList();
// To save the dashboard configuration, we iterate over the current
// widgets in the dashboard and map them into configuration objects.
List<WidgetConfig> dashboardConfig = dashboard.getWidgets().stream()
.map(widget -> {
// Cast to our custom widget class and extract type,
// colspan, and rowspan
CustomWidget customWidget = (CustomWidget) widget;
return new WidgetConfig(customWidget.getType(),
widget.getColspan(), widget.getRowspan());
}).toList();

// Then save the configuration to the database or other storage
// In this example, we just store it in a session-scoped bean
Expand All @@ -127,8 +135,8 @@ private void loadConfiguration() {
}

private void applyConfiguration(List<WidgetConfig> dashboardConfig) {
// To apply a dashboard configuration, we first clear the dashboard and then
// create widgets based on the configuration
// To apply a dashboard configuration, we first clear the dashboard and
// then create widgets based on the configuration
dashboard.removeAll();
for (WidgetConfig config : dashboardConfig) {
CustomWidget widget = createWidget(config);
Expand All @@ -137,33 +145,37 @@ private void applyConfiguration(List<WidgetConfig> dashboardConfig) {
}

private CustomWidget createWidget(WidgetConfig config) {
// In this example all widget types have the same content, and the title is
// stored in the enum, so we can use generic logic to create a widget
CustomWidget widget = new CustomWidget(config.getType(), config.getType().getLabel());
// In this example all widget types have the same content, and the title
// is stored in the enum, so we can use generic logic to create a widget
CustomWidget widget = new CustomWidget(config.getType(),
config.getType().getLabel());
widget.setContent(createWidgetContent());
widget.setColspan(config.getColspan());
widget.setRowspan(config.getRowspan());

// In practice, different widget types will have different content. In that case
// you can use a switch statement to create the widget content based on the type.
// In practice, different widget types will have different content. In
// that case
// you can use a switch statement to create the widget content based on
// the type.
//
// @formatter:off hidden-source-line
// switch (config.type()) {
// case VISITORS:
// widget.setTitle("Visitors");
// widget.setContent(new VisitorsWidgetContent());
// break;
// ...
// }
// @formatter:on hidden-source-line
return widget;
}

private void addWidget(WidgetConfig.WidgetType widgetType) {
// For adding a new widget, we retrieve the default configuration for the widget type
// and create a widget based on that configuration
// For adding a new widget, we retrieve the default configuration for
// the widget type and create a widget based on that configuration
WidgetConfig defaultWidgetConfig = defaultConfig.stream()
.filter(widgetConfig -> widgetConfig.getType() == widgetType)
.findFirst()
.orElseThrow();
.findFirst().orElseThrow();
CustomWidget widget = createWidget(defaultWidgetConfig);

dashboard.add(widget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public DashboardSections() {
dashboard.setMaximumColumnCount(3);

// tag::snippet[]
DashboardSection statsSection = dashboard.addSection("Monthly Funnel Stats");
DashboardSection statsSection = dashboard
.addSection("Monthly Funnel Stats");

DashboardWidget visitors = new DashboardWidget("Visitors");
visitors.setContent(createWidgetContent());
Expand All @@ -31,8 +32,10 @@ public DashboardSections() {
statsSection.add(conversions);
// end::snippet[]

DashboardSection detailsSection = dashboard.addSection("Visitor Details");
DashboardWidget visitorsByCountry = new DashboardWidget("Visitors by country");
DashboardSection detailsSection = dashboard
.addSection("Visitor Details");
DashboardWidget visitorsByCountry = new DashboardWidget(
"Visitors by country");
visitorsByCountry.setContent(createWidgetContent());
visitorsByCountry.setRowspan(2);
detailsSection.add(visitorsByCountry);
Expand All @@ -45,7 +48,8 @@ public DashboardSections() {
catImage.setContent(createWidgetContent());
detailsSection.add(catImage);

DashboardWidget visitorsByBrowser = new DashboardWidget("Visitors by browser");
DashboardWidget visitorsByBrowser = new DashboardWidget(
"Visitors by browser");
visitorsByBrowser.setContent(createWidgetContent());
visitorsByBrowser.setColspan(2);
detailsSection.add(visitorsByBrowser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DateTimePickerCustomValidation() {
.setHelperText("Open Mondays-Fridays, 8:00-12:00, 13:00-16:00");
dateTimePicker.setStep(Duration.ofMinutes(30));
dateTimePicker.setI18n(new DateTimePickerI18n()
.setBadInputErrorMessage("Invalid date or time format"));
.setBadInputErrorMessage("Invalid date or time format"));
add(dateTimePicker);

String errorMessage = "The selected day of week or time is not available";
Expand Down
Loading

0 comments on commit 3c07967

Please sign in to comment.