Skip to content

27 fix i18n problem #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ drivers/
# Error screenshots generated by TestBench for failed integration tests
error-screenshots/

webpack.generated.js
webpack.generated.js

#JRebel
rebel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package software.xdev.vaadin.daterange_picker;

import java.util.Arrays;

import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.Composite;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.GridVariant;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;

import software.xdev.vaadin.daterange_picker.example.DateRangePickerCustomizedDemo;
import software.xdev.vaadin.daterange_picker.example.DateRangePickerLocalizedDemo;
import software.xdev.vaadin.daterange_picker.example.DateRangePickerParameterDemo;

@PageTitle("DateRangePicker Examples")
@Route("")
public class HomeView extends Composite<VerticalLayout>
{
private final Grid<Example> grExamples = new Grid<>();

public HomeView()
{
// @formatter:off
this.grExamples
.addColumn(new ComponentRenderer<>(example -> {
final Anchor anchor = new Anchor(example.getRoute(), example.getName());

final Span spDesc = new Span(example.getDesc());
spDesc.getStyle().set("font-style", "italic");
spDesc.getStyle().set("font-size", "90%");

final VerticalLayout vl = new VerticalLayout(anchor, spDesc);
vl.setSpacing(false);
return vl;
}))
.setHeader("Available demos");

// @formatter:on

this.grExamples.setSizeFull();
this.grExamples.addThemeVariants(GridVariant.LUMO_COMPACT, GridVariant.LUMO_NO_BORDER);

this.getContent().add(this.grExamples);
this.getContent().setHeightFull();
}

@Override
protected void onAttach(final AttachEvent attachEvent)
{
// @formatter:off
this.grExamples.setItems(Arrays.asList(
new Example(DateRangePickerParameterDemo.NAV, "Parameter-Demo", "configuration is stored in QueryParameters"),
new Example(DateRangePickerLocalizedDemo.NAV, "Localized-Demo", "simple localization"),
new Example(DateRangePickerCustomizedDemo.NAV, "Customized-Demo", "usage of a customized DateRange")
));
// @formatter:on
}


static class Example
{
private final String route;
private final String name;
private final String desc;

public Example(final String route, final String name, final String desc)
{
super();
this.route = route;
this.name = name;
this.desc = desc;
}

public String getRoute()
{
return this.route;
}

public String getName()
{
return this.name;
}

public String getDesc()
{
return this.desc;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package software.xdev.vaadin.daterange_picker.example;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

import com.vaadin.flow.component.Composite;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextArea;
import com.vaadin.flow.router.Route;

import software.xdev.vaadin.daterange_picker.business.DateRangeModell;
import software.xdev.vaadin.daterange_picker.example.customized.CustomDateRange;
import software.xdev.vaadin.daterange_picker.example.customized.CustomDateRanges;
import software.xdev.vaadin.daterange_picker.ui.DateRangePicker;


@Route(DateRangePickerCustomizedDemo.NAV)
public class DateRangePickerCustomizedDemo extends Composite<VerticalLayout>
{
public static final String NAV = "customized";

protected static final List<CustomDateRange> DATERANGE_VALUES = Arrays.asList(CustomDateRanges.allValues());

private final DateRangePicker<CustomDateRange> dateRangePicker =
new DateRangePicker<>(
() -> new DateRangeModell<>(LocalDate.now(), LocalDate.now(), CustomDateRanges.DAY),
DATERANGE_VALUES);

private final TextArea taResult =
new TextArea("ValueChangeEvent", "Change something in the datepicker to see the result");

/*
* Fields
*/

public DateRangePickerCustomizedDemo()
{
this.initUI();
}

protected void initUI()
{
this.taResult.setSizeFull();
this.getContent().add(this.dateRangePicker, this.taResult);

this.dateRangePicker.addValueChangeListener(ev ->
{
final DateRangeModell<CustomDateRange> modell = ev.getModell();

this.taResult.clear();
// @formatter:off
this.taResult.setValue(
"DateRange: " + modell.getDateRange().getKey() + "\r\n" +
"DateRange-Tag: " + modell.getDateRange().getTag() + "\r\n" +
"Start: " + modell.getStart() + "\r\n" +
"End: " + modell.getEnd()
);
// @formatter:on
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package software.xdev.vaadin.daterange_picker.example;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.format.TextStyle;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.vaadin.flow.component.Composite;
import com.vaadin.flow.component.datepicker.DatePicker.DatePickerI18n;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextArea;
import com.vaadin.flow.router.Route;

import software.xdev.vaadin.daterange_picker.business.DateRangeModell;
import software.xdev.vaadin.daterange_picker.business.SimpleDateRange;
import software.xdev.vaadin.daterange_picker.business.SimpleDateRanges;
import software.xdev.vaadin.daterange_picker.ui.DateRangePicker;


@Route(DateRangePickerLocalizedDemo.NAV)
public class DateRangePickerLocalizedDemo extends Composite<VerticalLayout>
{
public static final String NAV = "localized";

protected static final List<SimpleDateRange> DATERANGE_VALUES = Arrays.asList(SimpleDateRanges.allValues());

// @formatter:off
private final DateRangePicker<SimpleDateRange> dateRangePicker =
new DateRangePicker<>(
() -> new DateRangeModell<>(LocalDate.now(), LocalDate.now(), SimpleDateRanges.TODAY),
DATERANGE_VALUES)
.withDatePickerI18n(getDatePickerI18n())
.withDateRangeLocalizerFunction(dr -> {
if(dr == SimpleDateRanges.TODAY)
{
return "Today - Heute";
}
else if(dr == SimpleDateRanges.DAY)
{
return "Day - Tag";
}
else if(dr == SimpleDateRanges.WEEK)
{
return "Week - Woche";
}
else if(dr == SimpleDateRanges.MONTH)
{
return "Month - Monat";
}
else if(dr == SimpleDateRanges.QUARTER)
{
return "Quarter - Quartal";
}
else if(dr == SimpleDateRanges.HALF_YEAR)
{
return "Half year - Halbjahr";
}
else if(dr == SimpleDateRanges.YEAR)
{
return "Year - Jahr";
}
else if(dr == SimpleDateRanges.FREE)
{
return "Free - Frei";
}

return "?";
})
.withStartLabel("Start - Anfang")
.withEndLabel("End - Ende")
.withDateRangeOptionsLabel("Period - Zeitraum");
// @formatter:on

private final TextArea taResult =
new TextArea("ValueChangeEvent", "Change something in the datepicker to see the result");

/*
* Fields
*/

public DateRangePickerLocalizedDemo()
{
this.initUI();
}

protected void initUI()
{
this.taResult.setSizeFull();
this.getContent().add(this.dateRangePicker, this.taResult);

this.dateRangePicker.addValueChangeListener(ev ->
{
final DateRangeModell<SimpleDateRange> modell = ev.getModell();

this.taResult.clear();
// @formatter:off
this.taResult.setValue(
"DateRange: " + modell.getDateRange().getKey() + "\r\n" +
"Start: " + modell.getStart() + "\r\n" +
"End: " + modell.getEnd()
);
// @formatter:on
});
}

// @formatter:off
// List Must start with Sunday and ends with Saturday... Americans...
private static List<DayOfWeek> daysOfWeekSortedForDatepicker =
Stream.concat(
Stream.of(DayOfWeek.SUNDAY),
Stream.of(DayOfWeek.values()).filter(dow -> !dow.equals(DayOfWeek.SUNDAY))
)
.collect(Collectors.toList());

private static List<String> weekdays =
daysOfWeekSortedForDatepicker.stream()
.map(dow -> dow.getDisplayName(TextStyle.FULL, Locale.GERMAN))
.collect(Collectors.toList());
private static List<String> weekdaysshort =
daysOfWeekSortedForDatepicker.stream()
.map(dow -> dow.getDisplayName(TextStyle.SHORT, Locale.GERMAN))
.collect(Collectors.toList());
private static List<String> months =
Stream.of(Month.values())
.map(m -> m.getDisplayName(TextStyle.FULL, Locale.GERMAN))
.collect(Collectors.toList());
// @formatter:on

/**
* Standard DatePickerI18N
*
* @return
*/
public static DatePickerI18n getDatePickerI18n()
{
final DatePickerI18n datepicker = new DatePickerI18n();
datepicker.setFirstDayOfWeek(1);

datepicker.setWeek("Woche");
datepicker.setCalendar("Kalender");

datepicker.setClear("Leeren");
datepicker.setCancel("Abbrechen");
datepicker.setToday("Heute");

datepicker.setMonthNames(months);
datepicker.setWeekdays(weekdays);
datepicker.setWeekdaysShort(weekdaysshort);
return datepicker;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package software.xdev.vaadin.daterange_picker;
package software.xdev.vaadin.daterange_picker.example;

import java.time.LocalDate;
import java.time.format.DateTimeParseException;
Expand All @@ -21,16 +21,16 @@
import com.vaadin.flow.router.QueryParameters;
import com.vaadin.flow.router.Route;

import software.xdev.vaadin.daterange_picker.buisness.DateRangeModell;
import software.xdev.vaadin.daterange_picker.buisness.SimpleDateRange;
import software.xdev.vaadin.daterange_picker.buisness.SimpleDateRanges;
import software.xdev.vaadin.daterange_picker.business.DateRangeModell;
import software.xdev.vaadin.daterange_picker.business.SimpleDateRange;
import software.xdev.vaadin.daterange_picker.business.SimpleDateRanges;
import software.xdev.vaadin.daterange_picker.ui.DateRangePicker;


@Route(DateRangePickerDemo.NAV)
public class DateRangePickerDemo extends Composite<VerticalLayout> implements AfterNavigationObserver
@Route(DateRangePickerParameterDemo.NAV)
public class DateRangePickerParameterDemo extends Composite<VerticalLayout> implements AfterNavigationObserver
{
public static final String NAV = "";
public static final String NAV = "parameter";

protected static final List<SimpleDateRange> DATERANGE_VALUES = Arrays.asList(SimpleDateRanges.allValues());

Expand All @@ -47,7 +47,7 @@ public class DateRangePickerDemo extends Composite<VerticalLayout> implements Af
*/
private boolean blockUpdates = true;

public DateRangePickerDemo()
public DateRangePickerParameterDemo()
{
this.initUI();
}
Expand Down Expand Up @@ -79,7 +79,7 @@ protected void onConfigChanged()

private void updateCurrentUrlSetDefault()
{
this.updateCurrentUrl(new Location(DateRangePickerDemo.NAV));
this.updateCurrentUrl(new Location(DateRangePickerParameterDemo.NAV));
}

private void updateCurrentUrl()
Expand All @@ -104,7 +104,7 @@ private void updateCurrentUrl()
queryParas.put(entry.getKey(), Collections.singletonList(entry.getValue()));
}

this.updateCurrentUrl(new Location(DateRangePickerDemo.NAV, new QueryParameters(queryParas)));
this.updateCurrentUrl(new Location(DateRangePickerParameterDemo.NAV, new QueryParameters(queryParas)));
}

private void updateCurrentUrl(final Location location)
Expand Down
Loading