Example usage for com.vaadin.ui BrowserFrame BrowserFrame

List of usage examples for com.vaadin.ui BrowserFrame BrowserFrame

Introduction

In this page you can find the example usage for com.vaadin.ui BrowserFrame BrowserFrame.

Prototype

public BrowserFrame(String caption, Resource source) 

Source Link

Document

Creates a new browser frame with the given caption and content.

Usage

From source file:org.opennms.features.vaadin.dashboard.dashlets.UrlDashlet.java

License:Open Source License

@Override
public DashletComponent getWallboardComponent() {
    if (m_dashletComponent == null) {
        m_dashletComponent = new AbstractDashletComponent() {
            private VerticalLayout m_verticalLayout = new VerticalLayout();

            {/*from  w  w w  . ja va  2 s  .c om*/
                m_verticalLayout.setCaption(getName());
                m_verticalLayout.setSizeFull();
            }

            @Override
            public void refresh() {
                m_verticalLayout.removeAllComponents();

                String url = "";
                String username = "";
                String password = "";

                if (getDashletSpec().getParameters().containsKey("url")) {
                    url = getDashletSpec().getParameters().get("url");
                }

                if (getDashletSpec().getParameters().containsKey("username")) {
                    username = getDashletSpec().getParameters().get("username");
                }

                if (getDashletSpec().getParameters().containsKey("password")) {
                    password = getDashletSpec().getParameters().get("password");
                }

                String usernamePassword = "";

                if (!"".equals(username) && !"".equals(password)) {
                    usernamePassword = username + ":" + password;

                }

                if (!"".equals(url)) {
                    /**
                     * Try to parse the given URL...
                     */
                    URL parsedUrl = null;

                    try {
                        parsedUrl = new URL(url);
                    } catch (MalformedURLException e) {
                        m_verticalLayout.addComponent(new Label("MalformedURLException: " + e.getMessage()));
                        return;
                    }

                    /**
                     * If successful, construct a wellformed URL including the basic auth credentials
                     */
                    URL urlWithAuth = null;

                    try {
                        urlWithAuth = new URI(parsedUrl.getProtocol(), usernamePassword, parsedUrl.getHost(),
                                parsedUrl.getPort() == -1 ? parsedUrl.getDefaultPort() : parsedUrl.getPort(),
                                parsedUrl.getPath(), parsedUrl.getQuery(), parsedUrl.getRef()).toURL();
                    } catch (MalformedURLException e) {
                        m_verticalLayout.addComponent(new Label("MalformedURLException: " + e.getMessage()));
                        return;
                    } catch (URISyntaxException e) {
                        m_verticalLayout.addComponent(new Label("URISyntaxException: " + e.getMessage()));
                        return;
                    }

                    /**
                     * creating browser frame to display the URL
                     */
                    BrowserFrame browserFrame = new BrowserFrame(null, new ExternalResource(urlWithAuth));
                    browserFrame.setSizeFull();
                    m_verticalLayout.addComponent(browserFrame);
                } else {
                    m_verticalLayout.addComponent(new Label("No URL specified!"));
                }
            }

            @Override
            public Component getComponent() {
                return m_verticalLayout;
            }
        };
    }

    return m_dashletComponent;
}

From source file:org.opennms.features.vaadin.pmatrix.dashlet.PmatrixDashlet.java

License:Open Source License

@Override
public DashletComponent getWallboardComponent() {
    if (m_dashletComponent == null) {
        m_dashletComponent = new AbstractDashletComponent() {
            private VerticalLayout m_verticalLayout = new VerticalLayout();

            {/*from w  w  w  . j  a v  a  2s.  co m*/
                m_verticalLayout.setCaption(getName());
                m_verticalLayout.setSizeFull();
            }

            @Override
            public void refresh() {
                m_verticalLayout.removeAllComponents();
                String searchString = "";

                if (getDashletSpec().getParameters().containsKey("uiComponent")) {
                    searchString = getDashletSpec().getParameters().get("uiComponent");
                }

                BrowserFrame browserFrame = new BrowserFrame(null,
                        new ExternalResource("/opennms/vaadin-pmatrix/?uiComponent=" + searchString));
                browserFrame.setSizeFull();
                m_verticalLayout.addComponent(browserFrame);
            }

            @Override
            public Component getComponent() {
                return m_verticalLayout;
            }
        };
    }

    return m_dashletComponent;
}

From source file:ui.tabsheet.DocumentsTabSheet.java

License:Apache License

private Component getView(final Certificate c) {
    BrowserFrame pdf = new BrowserFrame("", new StreamResource(new StreamResource.StreamSource() {

        @Override//from ww w . j  a  v a2  s  . c  o  m
        public InputStream getStream() {
            return new ByteArrayInputStream(c.getImage());
        }
    }, "cert" + "_" + c.getAchievementId() + ".pdf"));

    pdf.setSizeFull();

    VerticalLayout layout = new VerticalLayout(pdf);
    layout.setSizeFull();

    Panel p = new Panel(layout);
    return pdf;
}

From source file:ui.wizard.PdfLayout.java

License:Apache License

private Component getView(final byte[] bytes) {
    BrowserFrame pdf = new BrowserFrame("", new StreamResource(new StreamResource.StreamSource() {

        @Override/*from   w ww  .j a v  a2 s. com*/
        public InputStream getStream() {
            return new ByteArrayInputStream(bytes);
        }
    }, "cv" + "_" + getUsername() + ".pdf"));

    pdf.setSizeFull();

    VerticalLayout layout = new VerticalLayout(pdf);
    layout.setSizeFull();

    Panel p = new Panel(layout);
    return pdf;
}