From 1efedb45c5a68f4b53abd28a04fdc1595e1f88a9 Mon Sep 17 00:00:00 2001 From: Moritz Dieing <63721811+moritzdieing@users.noreply.github.com> Date: Wed, 27 Jan 2021 23:03:05 +0100 Subject: [PATCH] displayError + setInferenceView --- .../TypeInferenceView.java | 10 +++++++- .../kit/typicalc/view/main/MainViewImpl.java | 25 +++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java index 5e658f3..7ff33f6 100644 --- a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java +++ b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java @@ -4,13 +4,16 @@ import com.vaadin.flow.component.button.Button; 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.router.BeforeEvent; +import com.vaadin.flow.router.HasUrlParameter; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; +import edu.kit.typicalc.model.TypeInfererInterface; import edu.kit.typicalc.view.main.MainViewImpl; @Route(value = "visualize", layout = MainViewImpl.class) @PageTitle("TypeInferenceView") -public class TypeInferenceView extends HorizontalLayout { +public class TypeInferenceView extends HorizontalLayout implements HasUrlParameter { private TextField name; private Button sayHello; @@ -26,4 +29,9 @@ public class TypeInferenceView extends HorizontalLayout { }); } + @Override + public void setParameter(BeforeEvent event, TypeInfererInterface parameter) { + // TODO Auto-generated method stub + } + } diff --git a/src/main/java/edu/kit/typicalc/view/main/MainViewImpl.java b/src/main/java/edu/kit/typicalc/view/main/MainViewImpl.java index 60419dd..1ebea7e 100644 --- a/src/main/java/edu/kit/typicalc/view/main/MainViewImpl.java +++ b/src/main/java/edu/kit/typicalc/view/main/MainViewImpl.java @@ -2,19 +2,27 @@ package edu.kit.typicalc.view.main; import com.vaadin.flow.component.Component; import com.vaadin.flow.component.ComponentUtil; +import com.vaadin.flow.component.UI; import com.vaadin.flow.component.applayout.AppLayout; import com.vaadin.flow.component.applayout.DrawerToggle; import com.vaadin.flow.component.avatar.Avatar; +import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.dependency.JsModule; import com.vaadin.flow.component.html.H1; import com.vaadin.flow.component.html.Image; +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.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.component.tabs.Tab; import com.vaadin.flow.component.tabs.Tabs; import com.vaadin.flow.component.tabs.TabsVariant; +import com.vaadin.flow.i18n.LocaleChangeEvent; +import com.vaadin.flow.i18n.LocaleChangeObserver; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.RouterLink; import edu.kit.typicalc.model.TypeInfererInterface; @@ -32,7 +40,7 @@ public class MainViewImpl extends AppLayout implements MainView { private final Tabs menu; private H1 viewTitle; - + public MainViewImpl() { setDrawerOpened(false); addToNavbar(true, createHeaderContent()); @@ -107,12 +115,19 @@ public class MainViewImpl extends AppLayout implements MainView { } @Override - public void setTypeInferenceView(TypeInfererInterface typeInferer) { - // TODO Auto-generated method stub + public void setTypeInferenceView(final TypeInfererInterface typeInferer) { + this.getUI().get().navigate(TypeInferenceView.class, typeInferer); } @Override - public void displayError(ParseError error) { - // TODO Auto-generated method stub + public void displayError(final ParseError error) { + 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); + errorNotification.add(errorText, closeButton); + errorNotification.setPosition(Position.MIDDLE); + errorNotification.open(); } }