mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
setContent for startpage + exception handling
This commit is contained in:
parent
10cd63abb4
commit
edb025fafb
@ -13,7 +13,7 @@ import edu.kit.typicalc.view.content.typeinferencecontent.MathjaxUnification;
|
||||
import edu.kit.typicalc.view.main.MainViewImpl;
|
||||
import edu.kit.typicalc.view.main.MathjaxDisplay;
|
||||
|
||||
@Route(value = "home", layout = MainViewImpl.class)
|
||||
@Route(value = "", layout = MainViewImpl.class)
|
||||
@PageTitle("Typicalc")
|
||||
@JsModule("./src/mathjax-setup.js")
|
||||
public class StartPageView extends VerticalLayout implements ControlPanelView {
|
||||
|
@ -0,0 +1,25 @@
|
||||
package edu.kit.typicalc.view.main;
|
||||
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.html.Span;
|
||||
import com.vaadin.flow.component.notification.Notification;
|
||||
import com.vaadin.flow.component.notification.NotificationVariant;
|
||||
import com.vaadin.flow.component.orderedlayout.FlexComponent;
|
||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||
|
||||
public class ErrorNotification extends Notification {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected ErrorNotification(final String errorMessage) {
|
||||
final VerticalLayout container = new VerticalLayout();
|
||||
final Span errorSpan = new Span(errorMessage);
|
||||
final Button closeButton = new Button(getTranslation("root.close"), event -> this.close());
|
||||
|
||||
container.add(errorSpan, closeButton);
|
||||
container.setAlignItems(FlexComponent.Alignment.CENTER);
|
||||
addThemeVariants(NotificationVariant.LUMO_ERROR);
|
||||
add(container);
|
||||
setPosition(Position.MIDDLE);
|
||||
}
|
||||
}
|
@ -6,12 +6,15 @@ import java.util.function.Consumer;
|
||||
import com.vaadin.flow.component.textfield.TextField;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.vaadin.flow.component.Key;
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.button.ButtonVariant;
|
||||
import com.vaadin.flow.component.dependency.CssImport;
|
||||
import com.vaadin.flow.component.dialog.Dialog;
|
||||
import com.vaadin.flow.component.icon.Icon;
|
||||
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.i18n.LocaleChangeEvent;
|
||||
import com.vaadin.flow.i18n.LocaleChangeObserver;
|
||||
@ -28,6 +31,8 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
*/
|
||||
private static final String INPUT_FIELD_ID = "inputField";
|
||||
private static final String INPUT_BAR_ID = "inputBar";
|
||||
|
||||
private static final short MAX_INPUT_LENGTH = 1000;
|
||||
|
||||
private final Icon infoIcon;
|
||||
private final Button exampleButton;
|
||||
@ -48,26 +53,35 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
inputField = new TextField();
|
||||
inputField.setId(INPUT_FIELD_ID);
|
||||
inputField.setClearButtonVisible(true);
|
||||
//TODO seems to be the only solution to "immediately" parse backslash
|
||||
inputField.addValueChangeListener(event -> {
|
||||
if (inputField.getOptionalValue().isPresent()) {
|
||||
String value = inputField.getValue();
|
||||
value = value.replace("\\", "λ"); //TODO exchange magic strings
|
||||
inputField.setValue(value);
|
||||
}
|
||||
});
|
||||
inputField.addValueChangeListener(event -> onInputFieldValueChange());
|
||||
lambdaButton = new Button(getTranslation("root.lambda"), event -> onlambdaButtonClick());
|
||||
exampleButton = new Button(getTranslation("root.examplebutton"), event -> onExampleButtonClick());
|
||||
inferTypeButton = new Button(getTranslation("root.typeInfer"), event -> onTypeInferButtonClick(callback));
|
||||
inferTypeButton.addClickShortcut(Key.ENTER).listenOn(this);
|
||||
inferTypeButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||
|
||||
add(infoIcon, exampleButton, lambdaButton, inputField, inferTypeButton);
|
||||
setId(INPUT_BAR_ID);
|
||||
}
|
||||
|
||||
protected void reset() {
|
||||
inputField.clear();
|
||||
}
|
||||
|
||||
private void onInputFieldValueChange() {
|
||||
inputField.getOptionalValue().ifPresent(value -> inputField
|
||||
.setValue(value.replace(getTranslation("root.backslash"), getTranslation("root.lambda"))));
|
||||
}
|
||||
|
||||
private void onTypeInferButtonClick(final Consumer<String> callback) {
|
||||
final Optional<String> currentInput = inputField.getOptionalValue();
|
||||
currentInput.ifPresentOrElse(callback::accept, () -> callback.accept(StringUtils.EMPTY));
|
||||
final String currentInput = inputField.getOptionalValue().orElse(StringUtils.EMPTY);
|
||||
|
||||
if (currentInput.length() < MAX_INPUT_LENGTH) {
|
||||
callback.accept(currentInput);
|
||||
} else {
|
||||
final Notification errorNotification = new ErrorNotification(getTranslation("root.overlongInput"));
|
||||
errorNotification.open();
|
||||
}
|
||||
}
|
||||
|
||||
private void onlambdaButtonClick() {
|
||||
|
@ -2,16 +2,10 @@ package edu.kit.typicalc.view.main;
|
||||
|
||||
import com.vaadin.flow.component.UI;
|
||||
import com.vaadin.flow.component.applayout.AppLayout;
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.dependency.CssImport;
|
||||
import com.vaadin.flow.component.dependency.JavaScript;
|
||||
import com.vaadin.flow.component.dependency.JsModule;
|
||||
import com.vaadin.flow.component.html.Span;
|
||||
import com.vaadin.flow.component.notification.Notification;
|
||||
import com.vaadin.flow.component.notification.Notification.Position;
|
||||
import com.vaadin.flow.component.notification.NotificationVariant;
|
||||
import com.vaadin.flow.component.orderedlayout.FlexComponent;
|
||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||
import com.vaadin.flow.router.Location;
|
||||
import edu.kit.typicalc.model.ModelImpl;
|
||||
import edu.kit.typicalc.model.TypeInfererInterface;
|
||||
@ -41,7 +35,7 @@ public class MainViewImpl extends AppLayout implements MainView {
|
||||
public MainViewImpl() {
|
||||
setDrawerOpened(false);
|
||||
MainViewListener presenter = new Presenter(new ModelImpl(), this);
|
||||
addToNavbar(true, new UpperBar(presenter));
|
||||
addToNavbar(true, new UpperBar(presenter, this::setContent));
|
||||
addToDrawer(new DrawerContent());
|
||||
}
|
||||
|
||||
@ -55,16 +49,7 @@ public class MainViewImpl extends AppLayout implements MainView {
|
||||
@Override
|
||||
public void displayError(final ParseError error) {
|
||||
//TODO add error keys to bundle
|
||||
final VerticalLayout container = new VerticalLayout();
|
||||
final Span errorText = new Span(getTranslation("root." + error.toString()));
|
||||
final Notification errorNotification = new Notification();
|
||||
final Button closeButton = new Button(getTranslation("root.close"), event -> errorNotification.close());
|
||||
|
||||
errorNotification.addThemeVariants(NotificationVariant.LUMO_ERROR);
|
||||
container.add(errorText, closeButton);
|
||||
container.setAlignItems(FlexComponent.Alignment.CENTER);
|
||||
errorNotification.add(container);
|
||||
errorNotification.setPosition(Position.MIDDLE);
|
||||
final Notification errorNotification = new ErrorNotification(getTranslation("root." + error.toString()));
|
||||
errorNotification.open();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package edu.kit.typicalc.view.main;
|
||||
|
||||
import com.vaadin.flow.component.Component;
|
||||
import com.vaadin.flow.component.UI;
|
||||
import com.vaadin.flow.component.applayout.DrawerToggle;
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.dependency.CssImport;
|
||||
@ -8,10 +10,15 @@ import com.vaadin.flow.component.html.H1;
|
||||
import com.vaadin.flow.component.icon.Icon;
|
||||
import com.vaadin.flow.component.icon.VaadinIcon;
|
||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||
|
||||
import edu.kit.typicalc.view.content.infocontent.StartPageView;
|
||||
import edu.kit.typicalc.view.main.MainView.MainViewListener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Contains all the components constantly shown in the upper part of the webage.
|
||||
@ -34,17 +41,20 @@ public class UpperBar extends HorizontalLayout {
|
||||
private final Button rules;
|
||||
|
||||
private final transient MainViewListener presenter;
|
||||
|
||||
private final Consumer<Component> setContent;
|
||||
|
||||
/**
|
||||
* Initializes a new UpperBar with the provided mainViewListener.
|
||||
*
|
||||
* @param presenter the listener used to communicate with the model
|
||||
* @param setContent function to set the content of the application
|
||||
*/
|
||||
protected UpperBar(final MainViewListener presenter) {
|
||||
protected UpperBar(final MainViewListener presenter, final Consumer<Component> setContent) {
|
||||
this.presenter = presenter;
|
||||
|
||||
this.setContent = setContent;
|
||||
|
||||
this.viewTitle = new H1(getTranslation("root.typicalc"));
|
||||
viewTitle.addClickListener(event -> this.getUI().ifPresent(ui -> ui.navigate(StartPageView.class)));
|
||||
viewTitle.addClickListener(event -> routeToStartPage());
|
||||
viewTitle.setId(VIEW_TITLE_ID);
|
||||
this.inputBar = new InputBar(this::typeInfer);
|
||||
inputBar.setId(INPUT_BAR_ID);
|
||||
@ -66,7 +76,17 @@ public class UpperBar extends HorizontalLayout {
|
||||
* @param lambdaString the lambda term to be type-inferred
|
||||
*/
|
||||
protected void typeInfer(final String lambdaString) {
|
||||
presenter.typeInferLambdaString(lambdaString, new HashMap<>());
|
||||
inputBar.reset(); //TODO should term remain in input field?
|
||||
if (lambdaString.equals(StringUtils.EMPTY)) {
|
||||
routeToStartPage();
|
||||
} else {
|
||||
presenter.typeInferLambdaString(lambdaString, new HashMap<>());
|
||||
}
|
||||
}
|
||||
|
||||
private void routeToStartPage() {
|
||||
setContent.accept(new StartPageView());
|
||||
UI.getCurrent().getPage().getHistory().replaceState(null, StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
private void onHelpIconClick() {
|
||||
|
@ -1 +1,3 @@
|
||||
root.general=Hallo
|
||||
root.backslash=\\
|
||||
root.lambda=\u03BB
|
||||
root.home=home
|
||||
|
@ -1,7 +1,6 @@
|
||||
root.close=Schließen
|
||||
root.copyLatex=Kopiere Latex-Code
|
||||
root.typicalc=Typicalc
|
||||
root.lambda=\u03BB
|
||||
root.examplebutton=📂
|
||||
root.selectExample=Beispiel auswählen:
|
||||
root.typeInfer=Typisieren
|
||||
@ -9,6 +8,7 @@ root.operatingHelp=Bedienhilfen
|
||||
root.inputSyntax=Eingabe Syntax
|
||||
root.inferenceRules=Ableitungsregeln
|
||||
root.absRule=Abs-Regel
|
||||
root.overlongInput=Die maximale Länge der Eingabe beträgt 1000 Zeichen!
|
||||
|
||||
abs-rule=\
|
||||
\\begin{prooftree}\
|
||||
|
@ -1,7 +1,6 @@
|
||||
root.close=Close
|
||||
root.copyLatex=Copy latex code
|
||||
root.typicalc=Typicalc
|
||||
root.lambda=\u03BB
|
||||
root.examplebutton=📂
|
||||
root.selectExample=Select example:
|
||||
root.typeInfer=Type
|
||||
|
Loading…
Reference in New Issue
Block a user