Update ErrorNotification

This commit is contained in:
Moritz Dieing 2021-02-21 11:49:46 +01:00
parent d09345259a
commit c554f5e9f3

View File

@ -1,5 +1,6 @@
package edu.kit.typicalc.view.main; package edu.kit.typicalc.view.main;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.details.Details; import com.vaadin.flow.component.details.Details;
@ -25,6 +26,8 @@ public class ErrorNotification extends Notification {
private static final String ADDITIONAL_INFO_ID = "additionalInfo"; private static final String ADDITIONAL_INFO_ID = "additionalInfo";
private static final String ERROR_SUMMARY_ID = "errorSummary"; private static final String ERROR_SUMMARY_ID = "errorSummary";
private static final int NO_ADDITIONAL_INFO = -1;
/** /**
* Creates a new ErrorNotification with a specific error. * Creates a new ErrorNotification with a specific error.
* *
@ -42,20 +45,23 @@ public class ErrorNotification extends Notification {
setId(NOTIFICATION_ID); setId(NOTIFICATION_ID);
} }
private Details buildErrorMessage(ParseError error) { private Component buildErrorMessage(ParseError error) {
VerticalLayout additionalInformation = new VerticalLayout(); VerticalLayout additionalInformation = new VerticalLayout();
additionalInformation.setId(ADDITIONAL_INFO_ID); additionalInformation.setId(ADDITIONAL_INFO_ID);
Paragraph summary = new Paragraph(getTranslation("root." + error.toString())); Paragraph summary = new Paragraph(getTranslation("root." + error.toString()));
summary.setId(ERROR_SUMMARY_ID); summary.setId(ERROR_SUMMARY_ID);
Details errorMessage = new Details(summary, additionalInformation);
if (error == ParseError.TOO_FEW_TOKENS) { if (error == ParseError.TOO_FEW_TOKENS) {
additionalInformation.add(new Span(getTranslation("root.tooFewTokensHelp"))); additionalInformation.add(new Span(getTranslation("root.tooFewTokensHelp")));
} else {
if (error.getCause().getPos() == NO_ADDITIONAL_INFO) {
return summary;
} else { } else {
additionalInformation.add(new Span(getTranslation("root.wrongCharacter") + error.getCause().getText())); additionalInformation.add(new Span(getTranslation("root.wrongCharacter") + error.getCause().getText()));
additionalInformation.add(new Span(getTranslation("root.position") + error.getCause().getPos())); additionalInformation.add(new Span(getTranslation("root.position") + error.getCause().getPos()));
} }
}
return errorMessage; return new Details(summary, additionalInformation);
} }
} }