better passing of TypeInferer to TypeInferenceView, allows for custom URL

This commit is contained in:
ucrhh 2021-02-01 14:02:16 +01:00
parent 64312cd172
commit fbb3d6fd63
2 changed files with 10 additions and 7 deletions

View File

@ -2,8 +2,6 @@ package edu.kit.typicalc.view.content.typeinferencecontent;
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.ComponentUtil;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.orderedlayout.Scroller;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
@ -29,8 +27,8 @@ public class TypeInferenceView extends VerticalLayout
private final Div content;
private final ControlPanel controlPanel;
public TypeInferenceView() {
typeInferer = ComponentUtil.getData(UI.getCurrent(), TypeInfererInterface.class);
public TypeInferenceView(TypeInfererInterface typeInferer) {
this.typeInferer = typeInferer;
setId("type-inference-view");
setSizeFull();
addAttachListener(this);

View File

@ -1,6 +1,5 @@
package edu.kit.typicalc.view.main;
import com.vaadin.flow.component.ComponentUtil;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.applayout.AppLayout;
import com.vaadin.flow.component.button.Button;
@ -13,6 +12,7 @@ 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.VerticalLayout;
import com.vaadin.flow.router.Location;
import edu.kit.typicalc.model.ModelImpl;
import edu.kit.typicalc.model.TypeInfererInterface;
import edu.kit.typicalc.model.parser.ParseError;
@ -30,7 +30,10 @@ import edu.kit.typicalc.view.content.typeinferencecontent.TypeInferenceView;
@JavaScript("./src/tex-svg-full.js")
public class MainViewImpl extends AppLayout implements MainView {
private static final long serialVersionUID = -2411433187835906976L;
private static final String ROUTE = "infer";
private static final String SLASH = "/";
private String termToType = "lambda x.x"; //todo replace with real value
/**
* Creates a new MainViewImpl.
*/
@ -39,12 +42,14 @@ public class MainViewImpl extends AppLayout implements MainView {
MainViewListener presenter = new Presenter(new ModelImpl(), this);
addToNavbar(true, new UpperBar(presenter));
addToDrawer(new DrawerContent());
}
@Override
public void setTypeInferenceView(final TypeInfererInterface typeInferer) {
ComponentUtil.setData(UI.getCurrent(), TypeInfererInterface.class, typeInferer);
this.getUI().ifPresent(ui -> ui.navigate(TypeInferenceView.class));
TypeInferenceView tiv = new TypeInferenceView(typeInferer);
UI.getCurrent().getPage().getHistory().replaceState(null, new Location(ROUTE + SLASH + termToType));
setContent(tiv);
}
@Override