From c554f5e9f38b001002749d5fbc60fd78e1bda37e Mon Sep 17 00:00:00 2001 From: Moritz Dieing <63721811+moritzdieing@users.noreply.github.com> Date: Sun, 21 Feb 2021 11:49:46 +0100 Subject: [PATCH] Update ErrorNotification --- .../typicalc/view/main/ErrorNotification.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/kit/typicalc/view/main/ErrorNotification.java b/src/main/java/edu/kit/typicalc/view/main/ErrorNotification.java index 65e94a0..c582f68 100644 --- a/src/main/java/edu/kit/typicalc/view/main/ErrorNotification.java +++ b/src/main/java/edu/kit/typicalc/view/main/ErrorNotification.java @@ -1,5 +1,6 @@ package edu.kit.typicalc.view.main; +import com.vaadin.flow.component.Component; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.details.Details; @@ -24,6 +25,8 @@ public class ErrorNotification extends Notification { private static final String NOTIFICATION_CONTENT_ID = "errorNotificationContent"; private static final String ADDITIONAL_INFO_ID = "additionalInfo"; private static final String ERROR_SUMMARY_ID = "errorSummary"; + + private static final int NO_ADDITIONAL_INFO = -1; /** * Creates a new ErrorNotification with a specific error. @@ -42,20 +45,23 @@ public class ErrorNotification extends Notification { setId(NOTIFICATION_ID); } - private Details buildErrorMessage(ParseError error) { + private Component buildErrorMessage(ParseError error) { VerticalLayout additionalInformation = new VerticalLayout(); additionalInformation.setId(ADDITIONAL_INFO_ID); Paragraph summary = new Paragraph(getTranslation("root." + error.toString())); summary.setId(ERROR_SUMMARY_ID); - Details errorMessage = new Details(summary, additionalInformation); if (error == ParseError.TOO_FEW_TOKENS) { additionalInformation.add(new Span(getTranslation("root.tooFewTokensHelp"))); } else { - additionalInformation.add(new Span(getTranslation("root.wrongCharacter") + error.getCause().getText())); - additionalInformation.add(new Span(getTranslation("root.position") + error.getCause().getPos())); + if (error.getCause().getPos() == NO_ADDITIONAL_INFO) { + return summary; + } else { + additionalInformation.add(new Span(getTranslation("root.wrongCharacter") + error.getCause().getText())); + additionalInformation.add(new Span(getTranslation("root.position") + error.getCause().getPos())); + } } - return errorMessage; + return new Details(summary, additionalInformation); } }