Example usage for com.vaadin.server ExternalResource ExternalResource

List of usage examples for com.vaadin.server ExternalResource ExternalResource

Introduction

In this page you can find the example usage for com.vaadin.server ExternalResource ExternalResource.

Prototype

public ExternalResource(String sourceURL) 

Source Link

Document

Creates a new download component for downloading directly from given URL.

Usage

From source file:com.haulmont.cuba.web.gui.components.WebRelativePathResource.java

License:Apache License

@Override
protected void createResource() {
    try {//from  w w  w.  j a  v  a  2 s .co m
        URL context = new URL(ControllerUtils.getLocationWithoutParams());
        resource = new ExternalResource(new URL(context, path));
    } catch (MalformedURLException e) {
        throw new RuntimeException("Can't create RelativePathResource", e);
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebUrlResource.java

License:Apache License

@Override
protected void createResource() {
    resource = new ExternalResource(url);

    ((ExternalResource) resource).setMIMEType(mimeType);
}

From source file:com.haulmont.cuba.web.toolkit.ui.renderers.CubaImageRenderer.java

License:Apache License

@Override
public JsonValue encode(String value) {
    Resource resource = null;/*from w w  w.  ja  va 2  s  . c om*/
    if (value != null) {
        if (value.startsWith("file:") || value.startsWith("jar:") || value.contains("icon:")) {
            throw new IllegalArgumentException(
                    "ImageRenderer only supports ExternalResource and ThemeResource");
        }

        if (value.startsWith("http") || value.startsWith("https")) {
            try {
                resource = new ExternalResource(new URL(value));
            } catch (MalformedURLException e) {
                throw new RuntimeException("Unable to parse url for value", e);
            }
        } else {
            if (value.startsWith("theme://")) {
                value = value.substring("theme://".length());
            }
            resource = new VersionedThemeResource(value);
        }
    }

    return encode(ResourceReference.create(resource, this, null), URLReference.class);
}

From source file:com.haulmont.cuba.web.widgets.renderers.CubaImageRenderer.java

License:Apache License

@Override
public JsonValue encode(String value) {
    Resource resource = null;/*from  w ww.j a v  a2s  .  c o m*/
    if (value != null) {
        if (value.startsWith("file:") || value.startsWith("jar:") || value.contains("icon:")) {
            throw new IllegalArgumentException(
                    "ImageRenderer only supports ExternalResource and ThemeResource");
        }

        if (value.startsWith("http") || value.startsWith("https")) {
            try {
                resource = new ExternalResource(new URL(value));
            } catch (MalformedURLException e) {
                throw new RuntimeException("Unable to parse url for value", e);
            }
        } else {
            if (value.startsWith("theme://")) {
                value = value.substring("theme://".length());
            }
            resource = ((EnhancedUI) getUI()).createVersionedResource(value);
        }
    }

    return encode(ResourceReference.create(resource, this, null), URLReference.class);
}

From source file:com.hivesys.dashboard.view.search.TextualView.java

public void UpdateSearchPane(String searchString) {
    css.removeAllComponents();/*  www  .j  av a  2  s. co  m*/

    SearchResponse response = ElasticSearchContext.getInstance().searchSimpleQuery(searchString);
    logResponse(response);
    SearchHits results = response.getHits();

    Label labelResultSummary = new Label("About " + results.getHits().length + " results found <br><br>",
            ContentMode.HTML);
    css.addComponent(labelResultSummary);

    for (SearchHit hit : results) {
        CssLayout cssResult = new CssLayout();
        cssResult.setStyleName("search-result");

        try {
            String filename = DocumentDB.getInstance().getDocumentNameFromHash(hit.getId());
            String boxviewID = DocumentDB.getInstance().getBoxViewIDFromHash(hit.getId());

            String highlight = "";
            HighlightField objhighlight = hit.highlightFields().get("file");
            if (objhighlight != null) {
                for (Text fgmt : objhighlight.getFragments()) {
                    highlight += fgmt.string() + "<br>";
                }
            }

            Button lblfileName = new Button(filename);
            lblfileName.addClickListener((Button.ClickEvent event) -> {
                if (boxviewID != null) {
                    String url = BoxViewDocuments.getInstance().getViewURL(boxviewID);
                    if (url != null || !url.equals("")) {
                        url = BoxViewDocuments.getInstance().getViewURL(boxviewID);
                        BrowserFrame bframe = new BrowserFrame(filename, new ExternalResource(url));
                        VerticalLayout vlayout = new VerticalLayout(bframe);

                        final Window w = new Window();
                        w.setSizeFull();
                        w.setModal(true);
                        w.setWindowMode(WindowMode.MAXIMIZED);
                        w.setContent(vlayout);
                        vlayout.setSizeFull();
                        vlayout.setMargin(true);
                        w.setResizable(false);
                        w.setDraggable(false);

                        UI.getCurrent().addWindow(w);
                        bframe.setSizeFull();
                        return;
                    }
                    Notification.show("Preview not available for this document!");
                }
            });
            lblfileName.setPrimaryStyleName("filename");

            Label lblHighlight = new Label(highlight, ContentMode.HTML);
            lblHighlight.setStyleName("highlight");

            cssResult.addComponent(lblfileName);
            cssResult.addComponent(lblHighlight);

            css.addComponent(cssResult);
            css.addComponent(new Label("<br>", ContentMode.HTML));

        } catch (SQLException ex) {
        }

    }

}

From source file:com.karus.EnglishCheckerUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    VaadinServiceSession.getCurrent().setErrorHandler(this);
    setSizeFull();/*from  w ww. jav a2 s . c o  m*/

    try {
        DiscoveryNavigator navigator = new DiscoveryNavigator(this, getContent());
        navigator.navigateTo(UI.getCurrent().getPage().getFragment());
    }
    /**
     * Exception on page load
     */
    catch (AccessDeniedException e) {
        Label label = new Label(e.getMessage());
        label.setWidth(-1, Unit.PERCENTAGE);

        Link goToMain = new Link("Go to login page", new ExternalResource("/login/"));

        VerticalLayout layout = new VerticalLayout();
        layout.addComponent(label);
        layout.addComponent(goToMain);
        layout.setComponentAlignment(label, Alignment.MIDDLE_CENTER);
        layout.setComponentAlignment(goToMain, Alignment.MIDDLE_CENTER);

        VerticalLayout mainLayout = new VerticalLayout();
        mainLayout.setSizeFull();
        mainLayout.addComponent(layout);
        mainLayout.setComponentAlignment(layout, Alignment.MIDDLE_CENTER);

        setContent(mainLayout);
        Notification.show(e.getMessage(), Notification.Type.ERROR_MESSAGE);
    }
}

From source file:com.klwork.explorer.ui.business.social.QQWeiboDisplayPage.java

License:Apache License

/**
 * ?/*from   w w w .  ja v  a  2  s  .c  o m*/
 * @param userWeibo
 * @return
 */
public Link initUserScreenName(final SocialUserWeibo userWeibo) {
    Link goToMain = new Link(userWeibo.getUserScreenName() + ":",
            new ExternalResource(getWeiboMainUrl() + userWeibo.getUserName()));
    goToMain.setTargetName("_blank");
    return goToMain;
}

From source file:com.klwork.explorer.ui.business.social.QQWeiboDisplayPage.java

License:Apache License

/**
 * ?/*www  .  j  a va  2 s. co m*/
 * @param orginWeibo
 * @return
 */
@Override
public Link initRetweetedUserScreenName(final SocialUserWeibo orginWeibo) {
    Link link = new Link("@" + orginWeibo.getUserScreenName(),
            new ExternalResource(getWeiboMainUrl() + orginWeibo.getUserName()));
    link.setTargetName("_blank");
    return link;
}

From source file:com.klwork.explorer.ui.business.social.SinaWeiboDisplayPage.java

License:Apache License

/**
 * ?//from   ww  w .j  a  va  2 s  .c om
 * @param userWeibo
 * @return
 */
@Override
public Link initUserScreenName(final SocialUserWeibo userWeibo) {
    Link goToMain = new Link(userWeibo.getUserScreenName() + ":",
            new ExternalResource(getWeiboMainUrl() + userWeibo.getWeiboUid()));
    goToMain.setTargetName("_blank");
    return goToMain;
}

From source file:com.klwork.explorer.ui.business.social.SinaWeiboDisplayPage.java

License:Apache License

/**
 * ?/*from  w  w w  .  j a  v a 2  s.c  o  m*/
 * @param orginWeibo
 * @return
 */
@Override
public Link initRetweetedUserScreenName(final SocialUserWeibo orginWeibo) {
    Link link = new Link("@" + orginWeibo.getUserScreenName(),
            new ExternalResource(getWeiboMainUrl() + orginWeibo.getWeiboId()));
    link.setTargetName("_blank");
    return link;
}