Set pattern attribute of field, show error border

This commit is contained in:
Arne Keller 2021-03-06 21:46:53 +01:00
parent 251d7a3fc2
commit de8b2c0fe3
4 changed files with 16 additions and 9 deletions

View File

@ -0,0 +1,3 @@
[part="value"] {
box-shadow: revert !important;
}

View File

@ -17,7 +17,7 @@ import java.util.regex.Pattern;
*/
public class TypeAssumptionParser {
private static final Pattern TYPE_NAME_PATTERN = Pattern.compile("[a-zA-Z][a-zA-Z0-9]*");
public static final Pattern TYPE_NAME_PATTERN = Pattern.compile("[a-zA-Z][a-zA-Z0-9]*");
private static final Pattern TYPE_VARIABLE_PATTERN = Pattern.compile("t(\\d+)");
/**

View File

@ -24,7 +24,7 @@ public class ErrorView extends VerticalLayout implements LocaleChangeObserver {
private static final int NO_ADDITIONAL_INFO = -1;
private final H3 heading;
private Div errorMessage;
private final Div errorMessage;
private final ParseError error;
public ErrorView(ParseError error) {

View File

@ -10,6 +10,7 @@ import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.i18n.LocaleChangeEvent;
import com.vaadin.flow.i18n.LocaleChangeObserver;
import edu.kit.typicalc.model.parser.TypeAssumptionParser;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
@ -21,6 +22,7 @@ import java.util.function.Consumer;
*/
@JsModule("./src/type-input-listener.js")
@CssImport("./styles/view/main/type-assumption-field.css")
@CssImport(value = "./styles/view/main/type-assumption-input-field.css", themeFor = "vaadin-text-field")
public class TypeAssumptionField extends HorizontalLayout implements LocaleChangeObserver {
private static final long serialVersionUID = -81579298585584658L;
@ -31,20 +33,20 @@ public class TypeAssumptionField extends HorizontalLayout implements LocaleChang
private static final String MINUS_ICON_ID = "minusIcon";
private static final String ASS_DELETE_BUTTON_ID = "assDeleteButton";
private static final String ASSUMPTIONS_FIELD_ID = "typeAssumptionField";
private static final String TYPE_FIELD_CLASS = "typeFieldClass";
/*
* Unicode of subscripted digits in increasing order
*/
private static final List<Character> SUBSCRIPTED_DIGITS =
private static final List<Character> SUBSCRIPTED_DIGITS =
List.of('\u2080', '\u2081', '\u2082', '\u2083', '\u2084',
'\u2085', '\u2086', '\u2087', '\u2088', '\u2089');
private static final char TAU = '\u03C4';
private final TextField variableInputField;
private final TextField typeInputField;
/**
* Creates a new TypeAssumptionField with initial values and a callback to remove this
* type assumption from the {@link TypeAssumptionsArea}.
@ -67,6 +69,8 @@ public class TypeAssumptionField extends HorizontalLayout implements LocaleChang
*/
protected TypeAssumptionField(Consumer<TypeAssumptionField> deleteSelf) {
variableInputField = new TextField();
variableInputField.getElement().setAttribute(
"pattern", TypeAssumptionParser.TYPE_NAME_PATTERN.pattern());
typeInputField = new TextField();
typeInputField.setClassName(TYPE_FIELD_CLASS);
UI.getCurrent().getPage().executeJs("window.addTypeInputListener($0)", TYPE_FIELD_CLASS);
@ -78,7 +82,7 @@ public class TypeAssumptionField extends HorizontalLayout implements LocaleChang
add(variableInputField, typeInputField, deleteButton);
setId(ASSUMPTIONS_FIELD_ID);
}
private String parseBackType(String type) {
String rawType = type.replace(TAU, 't');
char[] rawTypeArray = rawType.toCharArray();
@ -89,10 +93,10 @@ public class TypeAssumptionField extends HorizontalLayout implements LocaleChang
}
return new String(rawTypeArray);
}
/**
* This method is called when the dialog containing this field is reopened. Since Vaadin somehow detaches the
* event listener, it has to be added again.
* event listener, it has to be added again.
*/
protected void refresh() {
UI.getCurrent().getPage().executeJs("window.addTypeInputListener($0)", TYPE_FIELD_CLASS);