Search in sources :

Example 1 with SessionData

use of one.microstream.storage.restclient.app.types.SessionData in project microstream by microstream-one.

the class InternalErrorView method beforeEnter.

@Override
public void beforeEnter(final BeforeEnterEvent event) {
    final H3 header = new H3(getTranslation("INTERNAL_ERROR_TITLE"));
    header.addClassName(ClassNames.ERROR);
    this.add(header);
    final VaadinSession session = event.getUI().getSession();
    final SessionData sessionData = session.getAttribute(SessionData.class);
    if (sessionData != null) {
        this.add(new Label(getTranslation("INTERNAL_ERROR_HINT", sessionData.baseUrl())));
    }
    final Throwable t = (Throwable) session.getAttribute(ApplicationErrorHandler.THROWABLE_ATTRIBUTE);
    if (t != null) {
        this.add(new Hr());
        final StringWriter stringWriter = new StringWriter();
        try (final PrintWriter writer = new PrintWriter(stringWriter)) {
            t.printStackTrace(writer);
        }
        final TextArea stackTrace = new TextArea();
        stackTrace.setValue(stringWriter.toString());
        stackTrace.setReadOnly(true);
        stackTrace.setWidth("100%");
        final Details details = new Details(getTranslation("DETAILS"), stackTrace);
        details.setOpened(false);
        this.add(details);
        this.setHorizontalComponentAlignment(Alignment.STRETCH, details);
        this.setFlexGrow(1, details);
    }
}
Also used : Details(com.vaadin.flow.component.details.Details) VaadinSession(com.vaadin.flow.server.VaadinSession) StringWriter(java.io.StringWriter) TextArea(com.vaadin.flow.component.textfield.TextArea) Label(com.vaadin.flow.component.html.Label) Hr(com.vaadin.flow.component.html.Hr) H3(com.vaadin.flow.component.html.H3) SessionData(one.microstream.storage.restclient.app.types.SessionData) PrintWriter(java.io.PrintWriter)

Example 2 with SessionData

use of one.microstream.storage.restclient.app.types.SessionData in project microstream by microstream-one.

the class ConnectView method tryConnect.

private void tryConnect(final String baseUrl) {
    try (final StorageRestClientJersey client = StorageRestClientJersey.New(baseUrl)) {
        client.requestRoot();
        this.updateUrlCookie(baseUrl);
        final SessionData sessionData = new SessionData(baseUrl);
        this.getUI().ifPresent(ui -> {
            ui.getSession().setAttribute(SessionData.class, sessionData);
            ui.navigate(InstanceView.class);
        });
    } catch (final Exception e) {
        this.getUI().ifPresent(ui -> {
            final Notification notification = new Notification();
            final H3 header = new H3(this.getTranslation("CONNECT_ERROR"));
            header.addClassName(ClassNames.ERROR);
            final Button close = new Button(this.getTranslation("OK"), event -> notification.close());
            final VerticalLayout content = new VerticalLayout(header, new Hr(), new Label(this.getTranslation("INTERNAL_ERROR_HINT", baseUrl)), close);
            content.setHorizontalComponentAlignment(Alignment.END, close);
            notification.add(content);
            notification.setDuration(0);
            notification.setPosition(Position.MIDDLE);
            notification.open();
        });
    }
}
Also used : Arrays(java.util.Arrays) Image(com.vaadin.flow.component.html.Image) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Label(com.vaadin.flow.component.html.Label) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Route(com.vaadin.flow.router.Route) HttpServletRequest(javax.servlet.http.HttpServletRequest) DataProvider(com.vaadin.flow.data.provider.DataProvider) SessionData(one.microstream.storage.restclient.app.types.SessionData) Cookie(javax.servlet.http.Cookie) LinkedHashSet(java.util.LinkedHashSet) Notification(com.vaadin.flow.component.notification.Notification) StorageRestClientJersey(one.microstream.storage.restclient.jersey.types.StorageRestClientJersey) UIUtils.imagePath(one.microstream.storage.restclient.app.ui.UIUtils.imagePath) VaadinResponse(com.vaadin.flow.server.VaadinResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Position(com.vaadin.flow.component.notification.Notification.Position) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Set(java.util.Set) H3(com.vaadin.flow.component.html.H3) VaadinRequest(com.vaadin.flow.server.VaadinRequest) Hr(com.vaadin.flow.component.html.Hr) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) Button(com.vaadin.flow.component.button.Button) HasDynamicTitle(com.vaadin.flow.router.HasDynamicTitle) StorageRestClientJersey(one.microstream.storage.restclient.jersey.types.StorageRestClientJersey) Button(com.vaadin.flow.component.button.Button) Label(com.vaadin.flow.component.html.Label) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Hr(com.vaadin.flow.component.html.Hr) SessionData(one.microstream.storage.restclient.app.types.SessionData) H3(com.vaadin.flow.component.html.H3) Notification(com.vaadin.flow.component.notification.Notification)

Example 3 with SessionData

use of one.microstream.storage.restclient.app.types.SessionData in project microstream by microstream-one.

the class RootLayout method beforeEnter.

@Override
public void beforeEnter(final BeforeEnterEvent event) {
    final SessionData sessionData = event.getUI().getSession().getAttribute(SessionData.class);
    this.headerLabel.setText(sessionData != null ? this.getTranslation("CLIENT") + " - " + sessionData.baseUrl() : this.getTranslation("CLIENT"));
    this.toolBar.setVisible(sessionData != null && !event.getNavigationTarget().equals(ConnectView.class));
}
Also used : SessionData(one.microstream.storage.restclient.app.types.SessionData)

Aggregations

SessionData (one.microstream.storage.restclient.app.types.SessionData)3 H3 (com.vaadin.flow.component.html.H3)2 Hr (com.vaadin.flow.component.html.Hr)2 Label (com.vaadin.flow.component.html.Label)2 Button (com.vaadin.flow.component.button.Button)1 ComboBox (com.vaadin.flow.component.combobox.ComboBox)1 Details (com.vaadin.flow.component.details.Details)1 Image (com.vaadin.flow.component.html.Image)1 Notification (com.vaadin.flow.component.notification.Notification)1 Position (com.vaadin.flow.component.notification.Notification.Position)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 TextArea (com.vaadin.flow.component.textfield.TextArea)1 DataProvider (com.vaadin.flow.data.provider.DataProvider)1 HasDynamicTitle (com.vaadin.flow.router.HasDynamicTitle)1 Route (com.vaadin.flow.router.Route)1 VaadinRequest (com.vaadin.flow.server.VaadinRequest)1 VaadinResponse (com.vaadin.flow.server.VaadinResponse)1 VaadinSession (com.vaadin.flow.server.VaadinSession)1 PrintWriter (java.io.PrintWriter)1