Immediately parse backslash to lambda

This commit is contained in:
Moritz Dieing 2021-02-04 12:58:09 +01:00
parent 8dc7fbe725
commit 8da5bf36a5
2 changed files with 11 additions and 20 deletions

View File

@ -10,8 +10,10 @@ import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.value.ValueChangeMode;
import com.vaadin.flow.i18n.LocaleChangeEvent;
import com.vaadin.flow.i18n.LocaleChangeObserver;
import org.apache.commons.lang3.StringUtils;
import java.util.Optional;
@ -53,6 +55,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
inputField = new TextField();
inputField.setId(INPUT_FIELD_ID);
inputField.setClearButtonVisible(true);
inputField.setValueChangeMode(ValueChangeMode.EAGER);
inputField.addValueChangeListener(event -> onInputFieldValueChange());
lambdaButton = new Button(getTranslation("root.lambda"), event -> onLambdaButtonClick());
exampleButton = new Button(getTranslation("root.examplebutton"), event -> onExampleButtonClick());
@ -65,14 +68,15 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
add(infoIcon, exampleButton, lambdaButton, inputField, inferTypeButton);
setId(INPUT_BAR_ID);
}
protected void reset() {
inputField.clear();
protected void inferTerm(final String term) {
inputField.setValue(term);
inferTypeButton.click();
}
private void onInputFieldValueChange() {
inputField.getOptionalValue().ifPresent(value -> inputField
.setValue(value.replace("\\", getTranslation("root.lambda"))));
inputField.getOptionalValue().ifPresent(value -> inputField
.setValue(value.replace("\\", getTranslation("root.lambda"))));
}
private void onTypeInferButtonClick(final Consumer<String> callback) {
@ -109,10 +113,4 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
public void localeChange(LocaleChangeEvent event) {
inferTypeButton.setText(getTranslation("root.typeInfer"));
}
//todo documentation
protected void inferTerm(String term) {
inputField.setValue(term);
inferTypeButton.click();
}
}

View File

@ -40,7 +40,6 @@ public class UpperBar extends HorizontalLayout {
private final Button rules;
private final transient MainViewListener presenter;
private final transient Consumer<Component> setContent;
private final transient Consumer<String> setTermInURL;
/**
@ -54,11 +53,10 @@ public class UpperBar extends HorizontalLayout {
final Consumer<String> setTermInURL) {
this.presenter = presenter;
this.setContent = setContent;
this.setTermInURL = setTermInURL;
this.viewTitle = new H1(getTranslation("root.typicalc"));
viewTitle.addClickListener(event -> routeToStartPage());
viewTitle.addClickListener(event -> routeToStartPage(setContent));
viewTitle.setId(VIEW_TITLE_ID);
this.inputBar = new InputBar(this::typeInfer);
inputBar.setId(INPUT_BAR_ID);
@ -80,16 +78,11 @@ public class UpperBar extends HorizontalLayout {
* @param lambdaString the lambda term to be type-inferred
*/
protected void typeInfer(final String lambdaString) {
// inputBar.reset(); //TODO should term remain in input field?
setTermInURL.accept(lambdaString);
presenter.typeInferLambdaString(lambdaString, new HashMap<>());
// todo ich finde es ohne Wechsel auf Startseite besser, man bekommt ja schon ne Warnung
// if (lambdaString.equals(StringUtils.EMPTY)) {
// routeToStartPage();
// }
}
private void routeToStartPage() {
private void routeToStartPage(Consumer<Component> setContent) {
setContent.accept(new StartPageView());
UI.getCurrent().getPage().getHistory().replaceState(null, new Location(StringUtils.EMPTY));
}