mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
Fix and improve languageSelect
This commit is contained in:
parent
8f0ca5d2ba
commit
2895f84988
@ -2,6 +2,7 @@ package edu.kit.typicalc.view.main;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.vaadin.flow.component.ItemLabelGenerator;
|
||||
import com.vaadin.flow.component.UI;
|
||||
import com.vaadin.flow.component.dependency.CssImport;
|
||||
import com.vaadin.flow.component.dialog.Dialog;
|
||||
@ -29,20 +30,22 @@ public class HelpDialog extends Dialog implements LocaleChangeObserver {
|
||||
|
||||
private final H3 heading;
|
||||
private final H5 inputSyntax;
|
||||
private final Select<String> languageSelect;
|
||||
private final Select<Locale> languageSelect;
|
||||
private final ItemLabelGenerator<Locale> renderer;
|
||||
|
||||
/**
|
||||
* Create a new HelpDialog.
|
||||
*/
|
||||
protected HelpDialog() {
|
||||
final HorizontalLayout headingLayout = new HorizontalLayout();
|
||||
renderer = item -> getTranslation("root." + item.getDisplayLanguage(Locale.ENGLISH).toLowerCase());
|
||||
heading = new H3(getTranslation("root.operatingHelp"));
|
||||
headingLayout.setId(HEADING_LAYOUT_ID);
|
||||
languageSelect = new Select<>(getTranslation("root.german"), getTranslation("root.english"));
|
||||
languageSelect = new Select<>(Locale.GERMAN, Locale.ENGLISH);
|
||||
languageSelect.setTextRenderer(renderer);
|
||||
languageSelect.setLabel(getTranslation("root.selectLanguage"));
|
||||
languageSelect.setValue(getTranslation("root."
|
||||
+ UI.getCurrent().getLocale().getDisplayLanguage(Locale.ENGLISH).toLowerCase()));
|
||||
languageSelect.addValueChangeListener(event -> onLanguageChange());
|
||||
languageSelect.setValue(UI.getCurrent().getLocale());
|
||||
languageSelect.addValueChangeListener(event -> UI.getCurrent().setLocale(event.getValue()));
|
||||
languageSelect.setId(LANGUAGE_SELECT_ID);
|
||||
headingLayout.add(heading, languageSelect);
|
||||
|
||||
@ -54,22 +57,11 @@ public class HelpDialog extends Dialog implements LocaleChangeObserver {
|
||||
add(headingLayout, contentLayout);
|
||||
}
|
||||
|
||||
private void onLanguageChange() {
|
||||
Locale newLocale;
|
||||
if (languageSelect.getValue().equals(getTranslation("root.german"))) {
|
||||
newLocale = Locale.GERMAN;
|
||||
} else if (languageSelect.getValue().equals(getTranslation("root.english"))) {
|
||||
newLocale = Locale.ENGLISH;
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
UI.getCurrent().setLocale(newLocale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void localeChange(LocaleChangeEvent event) {
|
||||
heading.setText(getTranslation("root.operatingHelp"));
|
||||
inputSyntax.setText(getTranslation("root.inputSyntax"));
|
||||
languageSelect.setLabel(getTranslation("root.selectLanguage"));
|
||||
languageSelect.setTextRenderer(renderer);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user