This commit is contained in:
ucrhh 2021-02-09 22:09:57 +01:00
commit 363646f6d2
3 changed files with 49 additions and 0 deletions

View File

@ -96,6 +96,11 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
UI.getCurrent().getPage().executeJs("document.getElementById($0).click()", INFER_BUTTON_ID);
}
/**
* Sets the type assumptions displayed in the type assumptions area.
*
* @param typeAssumptions the type assumptions as a map
*/
protected void setTypeAssumptions(Map<String, String> typeAssumptions) {
typeAssumptionsArea = new TypeAssumptionsArea(typeAssumptions);
}

View File

@ -13,6 +13,9 @@ import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.i18n.LocaleChangeEvent;
import com.vaadin.flow.i18n.LocaleChangeObserver;
/**
* Represents a single type assumption. Each TypeAssumptionField is displayed in the TypeAssumptionsArea.
*/
@CssImport("./styles/view/main/type-assumption-field.css")
public class TypeAssumptionField extends HorizontalLayout implements LocaleChangeObserver {
@ -28,12 +31,26 @@ public class TypeAssumptionField extends HorizontalLayout implements LocaleChang
private final TextField variableInputField;
private final TextField typeInputField;
/**
* Creates a new TypeAssumptionField with initial values and a Consumer-object to remove this
* type assumption from the {@link edu.kit.typicalc.view.main.TypeAssumptionsArea}.
*
* @param deleteSelf deletes this object from the TypeAssumptionsArea
* @param variable variable of the type assumption
* @param type type of the type assumption
*/
protected TypeAssumptionField(Consumer<TypeAssumptionField> deleteSelf, String variable, String type) {
this(deleteSelf);
variableInputField.setValue(variable);
typeInputField.setValue(type);
}
/**
* Creates a new TypeAssumptionField with a Consumer-object to remove this
* type assumption from the {@link edu.kit.typicalc.view.main.TypeAssumptionsArea}.
*
* @param deleteSelf deletes this object from the TypeAssumptionsArea
*/
protected TypeAssumptionField(Consumer<TypeAssumptionField> deleteSelf) {
variableInputField = new TextField();
variableInputField.setLabel(getTranslation("root.variable"));
@ -47,10 +64,20 @@ public class TypeAssumptionField extends HorizontalLayout implements LocaleChang
setId(ASSUMPTIONS_FIELD_ID);
}
/**
* Gets the variable of the type assumption.
*
* @return the variable of the type assumption
*/
protected String getVariable() {
return variableInputField.getOptionalValue().orElse(StringUtils.EMPTY);
}
/**
* Gets the type of the type assumption.
*
* @return the type of the type assumption
*/
protected String getType() {
return typeInputField.getOptionalValue().orElse(StringUtils.EMPTY);
}

View File

@ -18,6 +18,10 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Dialog which allows the user to create and delete type assumptions.
* The current type assumptions are stored after closing the dialog.
*/
@CssImport("./styles/view/main/type-assumptions-area.css")
public class TypeAssumptionsArea extends Dialog implements LocaleChangeObserver {
@ -37,6 +41,11 @@ public class TypeAssumptionsArea extends Dialog implements LocaleChangeObserver
private final List<TypeAssumptionField> fields = new ArrayList<>();
/**
* Creates a new TypeAssumptionsArea with initial type assumptions.
*
* @param types map containing the values for the initial type assumptions
*/
protected TypeAssumptionsArea(Map<String, String> types) {
heading = new H3(getTranslation("root.typeAssumptions"));
@ -70,6 +79,9 @@ public class TypeAssumptionsArea extends Dialog implements LocaleChangeObserver
add(layout);
}
/**
* Creates a new TypeAssumptionsArea.
*/
protected TypeAssumptionsArea() {
this(new HashMap<>());
}
@ -88,6 +100,11 @@ public class TypeAssumptionsArea extends Dialog implements LocaleChangeObserver
fields.clear();
}
/**
* Returns the current type assumptions.
*
* @return the current type assumptions as mappings from a variable to a type
*/
protected Map<String, String> getTypeAssumptions() {
return fields.stream()
.collect(Collectors.toMap(TypeAssumptionField::getVariable, TypeAssumptionField::getType));