package no.uio.ifi.trackfind.frontend;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
import com.vaadin.annotations.Widgetset;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.VaadinRequest;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.*;
import lombok.extern.slf4j.Slf4j;

/**
 * Hystrix Vaadin UI of the application.
 * Uses custom theme (VAADIN/themes/trackfind/trackfind.scss).
 * Uses custom WidgetSet (TrackFindWidgetSet.gwt.xml).
 *
 * @author Dmytro Titov
 */
@SpringUI(path = "/monitor")
@Widgetset("TrackFindWidgetSet")
@Title("Hystryx Dashboard")
@Theme("trackfind")
@Slf4j
public class TrackFindMonitorUI extends AbstractUI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        HorizontalLayout headerLayout = buildHeaderLayout();
        VerticalLayout referencesLayout = buildHystrixLayout();
        HorizontalLayout mainLayout = buildMainLayout(referencesLayout);
        HorizontalLayout footerLayout = buildFooterLayout();
        VerticalLayout outerLayout = buildOuterLayout(headerLayout, mainLayout, footerLayout);
        setContent(outerLayout);
    }

    private VerticalLayout buildHystrixLayout() {
        VerticalLayout layout = new VerticalLayout();
        layout.setSizeFull();
        BrowserFrame browser = new BrowserFrame("Browser", new ExternalResource("http://localhost/hystrix/monitor?stream=http%3A%2F%2Flocalhost%2Factuator%2Fhystrix.stream&title=TrackFind"));
        browser.setSizeFull();
        layout.addComponent(browser);
        Panel panel = new Panel("Circuits status", browser);
        panel.setSizeFull();
        layout.addComponents(panel);
        layout.setExpandRatio(panel, 1f);
        return layout;
    }


    private HorizontalLayout buildMainLayout(VerticalLayout leftLayout) {
        HorizontalLayout mainLayout = new HorizontalLayout(leftLayout);
        mainLayout.setExpandRatio(leftLayout, 0.66f);
        mainLayout.setSizeFull();
        return mainLayout;
    }

}

@@ -302,43 +302,273 @@
 .ui.
-*;%0Aimport lombok.extern.slf4j.Slf4j
+BrowserFrame;%0Aimport com.vaadin.ui.HorizontalLayout;%0Aimport com.vaadin.ui.Panel;%0Aimport com.vaadin.ui.VerticalLayout;%0Aimport lombok.extern.slf4j.Slf4j;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.net.URL
 ;%0A%0A/
@@ -1520,32 +1520,403 @@
 .setSizeFull();%0A
+        try (BufferedReader in = new BufferedReader(new InputStreamReader(new URL(%22http://checkip.amazonaws.com%22).openStream()))) %7B%0A            String host = %22localhost%22;%0A            String implementationVersion = getClass().getPackage().getImplementationVersion();%0A            if (implementationVersion != null) %7B%0A                host = in.readLine();%0A            %7D%0A    
         BrowserF
@@ -1957,16 +1957,36 @@
 rowser%22,
+%0A                   
  new Ext
@@ -2007,25 +2007,28 @@
 %22http://
-localhost
+%22 + host + %22
 /hystrix
@@ -2122,16 +2122,20 @@
         
+ 
+   
 browser.
@@ -2160,47 +2160,13 @@
     
- layout.addComponent(browser);%0A
      
-   
 Pane
@@ -2222,16 +2222,20 @@
         
+    
 panel.se
@@ -2251,24 +2251,28 @@
 ();%0A        
+  
+  
 layout.addCo
@@ -2288,16 +2288,20 @@
 panel);%0A
+    
         
@@ -2330,24 +2330,110 @@
 panel, 1f);%0A
+        %7D catch (IOException e) %7B%0A            log.error(e.getMessage(), e);%0A        %7D%0A
         retu

Load Hystrix stream from an external IP, if applicable