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:annis.gui.AboutWindow.java

License:Apache License

public AboutWindow() {
    setSizeFull();//from   w w w  . j  av a 2 s  .c o m

    layout = new VerticalLayout();
    setContent(layout);
    layout.setSizeFull();
    layout.setMargin(true);

    HorizontalLayout hLayout = new HorizontalLayout();

    Embedded logoAnnis = new Embedded();
    logoAnnis.setSource(new ThemeResource("images/annis-logo-128.png"));
    logoAnnis.setType(Embedded.TYPE_IMAGE);
    hLayout.addComponent(logoAnnis);

    Embedded logoSfb = new Embedded();
    logoSfb.setSource(new ThemeResource("images/sfb-logo.jpg"));
    logoSfb.setType(Embedded.TYPE_IMAGE);
    hLayout.addComponent(logoSfb);

    Link lnkFork = new Link();
    lnkFork.setResource(new ExternalResource("https://github.com/korpling/ANNIS"));
    lnkFork.setIcon(
            new ExternalResource("https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"));
    lnkFork.setTargetName("_blank");
    hLayout.addComponent(lnkFork);

    hLayout.setComponentAlignment(logoAnnis, Alignment.MIDDLE_LEFT);
    hLayout.setComponentAlignment(logoSfb, Alignment.MIDDLE_RIGHT);
    hLayout.setComponentAlignment(lnkFork, Alignment.TOP_RIGHT);

    layout.addComponent(hLayout);

    layout.addComponent(new Label(
            "ANNIS is a project of the " + "<a href=\"http://www.sfb632.uni-potsdam.de/\">SFB632</a>.",
            Label.CONTENT_XHTML));
    layout.addComponent(new Label("Homepage: " + "<a href=\"http://corpus-tools.org/annis/\">"
            + "http://corpus-tools.org/annis/</a>.", Label.CONTENT_XHTML));
    layout.addComponent(new Label("Version: " + VersionInfo.getVersion()));
    layout.addComponent(new Label("Vaadin-Version: " + Version.getFullVersion()));

    TextArea txtThirdParty = new TextArea();
    txtThirdParty.setSizeFull();

    StringBuilder sb = new StringBuilder();

    sb.append("The ANNIS team wants to thank these third party software that "
            + "made the ANNIS GUI possible:\n");

    File thirdPartyFolder = new File(VaadinService.getCurrent().getBaseDirectory(), "THIRD-PARTY");
    if (thirdPartyFolder.isDirectory()) {
        for (File c : thirdPartyFolder.listFiles((FileFilter) new WildcardFileFilter("*.txt"))) {
            if (c.isFile()) {
                try {
                    sb.append(FileUtils.readFileToString(c)).append("\n");
                } catch (IOException ex) {
                    log.error("Could not read file", ex);
                }
            }
        }
    }

    txtThirdParty.setValue(sb.toString());
    txtThirdParty.setReadOnly(true);
    txtThirdParty.addStyleName("shared-text");
    txtThirdParty.setWordwrap(false);

    layout.addComponent(txtThirdParty);

    btClose = new Button("Close");
    final AboutWindow finalThis = this;
    btClose.addClickListener(new OkClickListener(finalThis));
    layout.addComponent(btClose);

    layout.setComponentAlignment(hLayout, Alignment.MIDDLE_CENTER);
    layout.setComponentAlignment(btClose, Alignment.MIDDLE_CENTER);
    layout.setExpandRatio(txtThirdParty, 1.0f);

}

From source file:annis.gui.EmbeddedVisUI.java

License:Apache License

private void generateVisFromRemoteURL(final String visName, final String rawUri, Map<String, String[]> args) {
    try {//  w w  w. j  a  va2s  . c o  m
        // find the matching visualizer
        final VisualizerPlugin visPlugin = this.getVisualizer(visName);
        if (visPlugin == null) {
            displayMessage("Unknown visualizer \"" + visName + "\"",
                    "This ANNIS instance does not know the given visualizer.");
            return;
        }

        URI uri = new URI(rawUri);
        // fetch content of the URI
        Client client = null;
        AnnisUser user = Helper.getUser();
        if (user != null) {
            client = user.getClient();
        }
        if (client == null) {
            client = Helper.createRESTClient();
        }
        final WebResource saltRes = client.resource(uri);

        displayLoadingIndicator();

        // copy the arguments for using them later in the callback
        final Map<String, String[]> argsCopy = new LinkedHashMap<>(args);

        Background.runWithCallback(new Callable<SaltProject>() {
            @Override
            public SaltProject call() throws Exception {
                return saltRes.get(SaltProject.class);
            }
        }, new FutureCallback<SaltProject>() {
            @Override
            public void onFailure(Throwable t) {
                displayMessage("Could not query the result.", t.getMessage());
            }

            @Override
            public void onSuccess(SaltProject p) {
                // TODO: allow to display several visualizers when there is more than one document
                SCorpusGraph firstCorpusGraph = null;
                SDocument doc = null;
                if (p.getCorpusGraphs() != null && !p.getCorpusGraphs().isEmpty()) {
                    firstCorpusGraph = p.getCorpusGraphs().get(0);
                    if (firstCorpusGraph.getDocuments() != null && !firstCorpusGraph.getDocuments().isEmpty()) {
                        doc = firstCorpusGraph.getDocuments().get(0);
                    }
                }
                if (doc == null) {
                    displayMessage("No documents found in provided URL.", "");
                    return;
                }

                if (argsCopy.containsKey(KEY_INSTANCE)) {
                    Map<String, InstanceConfig> allConfigs = loadInstanceConfig();
                    InstanceConfig newConfig = allConfigs.get(argsCopy.get(KEY_INSTANCE)[0]);
                    if (newConfig != null) {
                        setInstanceConfig(newConfig);
                    }
                }
                // now it is time to load the actual defined instance fonts
                loadInstanceFonts();

                // generate the visualizer
                VisualizerInput visInput = new VisualizerInput();
                visInput.setDocument(doc);
                if (getInstanceConfig() != null && getInstanceConfig().getFont() != null) {
                    visInput.setFont(getInstanceFont());
                }
                Properties mappings = new Properties();
                for (Map.Entry<String, String[]> e : argsCopy.entrySet()) {
                    if (!KEY_SALT.equals(e.getKey()) && e.getValue().length > 0) {
                        mappings.put(e.getKey(), e.getValue()[0]);
                    }
                }
                visInput.setMappings(mappings);
                String[] namespace = argsCopy.get(KEY_NAMESPACE);
                if (namespace != null && namespace.length > 0) {
                    visInput.setNamespace(namespace[0]);
                } else {
                    visInput.setNamespace(null);
                }

                String baseText = null;
                if (argsCopy.containsKey(KEY_BASE_TEXT)) {
                    String[] value = argsCopy.get(KEY_BASE_TEXT);
                    if (value.length > 0) {
                        baseText = value[0];
                    }
                }

                List<SNode> segNodes = CommonHelper.getSortedSegmentationNodes(baseText,
                        doc.getDocumentGraph());

                if (argsCopy.containsKey(KEY_MATCH)) {
                    String[] rawMatch = argsCopy.get(KEY_MATCH);
                    if (rawMatch.length > 0) {
                        // enhance the graph with match information from the arguments
                        Match match = Match.parseFromString(rawMatch[0]);
                        addMatchToDocumentGraph(match, doc);
                    }
                }

                Map<String, String> markedColorMap = new HashMap<>();
                Map<String, String> exactMarkedMap = Helper.calculateColorsForMarkedExact(doc);
                Map<String, Long> markedAndCovered = Helper.calculateMarkedAndCoveredIDs(doc, segNodes,
                        baseText);
                Helper.calulcateColorsForMarkedAndCovered(doc, markedAndCovered, markedColorMap);
                visInput.setMarkedAndCovered(markedAndCovered);
                visInput.setMarkableMap(markedColorMap);
                visInput.setMarkableExactMap(exactMarkedMap);
                visInput.setContextPath(Helper.getContext());
                String template = Helper.getContext() + "/Resource/" + visName + "/%s";
                visInput.setResourcePathTemplate(template);
                visInput.setSegmentationName(baseText);
                // TODO: which other thing do we have to provide?

                Component c = visPlugin.createComponent(visInput, null);
                // add the styles
                c.addStyleName("corpus-font");
                c.addStyleName("vis-content");

                Link link = new Link();
                link.setCaption("Show in ANNIS search interface");
                link.setIcon(ANNISFontIcon.LOGO);
                link.setVisible(false);
                link.addStyleName("dontprint");
                link.setTargetName("_blank");
                if (argsCopy.containsKey(KEY_SEARCH_INTERFACE)) {
                    String[] interfaceLink = argsCopy.get(KEY_SEARCH_INTERFACE);
                    if (interfaceLink.length > 0) {
                        link.setResource(new ExternalResource(interfaceLink[0]));
                        link.setVisible(true);
                    }
                }
                VerticalLayout layout = new VerticalLayout(link, c);
                layout.setComponentAlignment(link, Alignment.TOP_LEFT);
                layout.setSpacing(true);
                layout.setMargin(true);

                setContent(layout);

                IDGenerator.assignID(link);
            }

        });

    } catch (URISyntaxException ex) {
        displayMessage("Invalid URL", "The provided URL is malformed:<br />" + ex.getMessage());
    } catch (LoginDataLostException ex) {
        displayMessage("LoginData Lost",
                "No login data available any longer in the session:<br /> " + ex.getMessage());
    } catch (UniformInterfaceException ex) {
        if (ex.getResponse().getStatus() == Response.Status.FORBIDDEN.getStatusCode()) {
            displayMessage("Corpus access forbidden",
                    "You are not allowed to access this corpus. "
                            + "Please login at the <a target=\"_blank\" href=\"" + Helper.getContext()
                            + "\">main application</a> first and then reload this page.");
        } else {
            displayMessage("Service error", ex.getMessage());
        }
    } catch (ClientHandlerException ex) {
        displayMessage("Could not generate the visualization because the ANNIS service reported an error.",
                ex.getMessage());
    } catch (Throwable ex) {
        displayMessage("Could not generate the visualization.",
                ex.getMessage() == null
                        ? ("An unknown error of type " + ex.getClass().getSimpleName()) + " occured."
                        : ex.getMessage());
    }
}

From source file:annis.gui.HelpUsWindow.java

License:Apache License

public HelpUsWindow() {
    setSizeFull();//from   w ww  .j  a  v  a 2 s .co  m
    layout = new VerticalLayout();
    setContent(layout);

    layout.setSizeFull();
    layout.setMargin(new MarginInfo(false, false, true, false));

    HorizontalLayout hLayout = new HorizontalLayout();
    hLayout.setSizeFull();
    hLayout.setMargin(false);

    VerticalLayout labelLayout = new VerticalLayout();
    labelLayout.setMargin(true);
    labelLayout.setSizeFull();

    Label lblOpenSource = new Label();

    lblOpenSource.setValue("<h1>ANNIS is <a href=\"http://opensource.org/osd\">Open Source</a> "
            + "software.</h1>" + "<p>This means you are free to download the source code and add new "
            + "features or make other adjustments to ANNIS on your own.<p/>"
            + "Here are some examples how you can help ANNIS:" + "<ul>"
            + "<li>Fix or report problems (bugs) you encounter when using the ANNIS software.</li>"
            + "<li>Add new features.</li>" + "<li>Enhance the documentation</li>" + "</ul>"
            + "<p>Feel free to visit our GitHub page for more information: <a href=\"https://github.com/korpling/ANNIS\" target=\"_blank\">https://github.com/korpling/ANNIS</a></p>");
    lblOpenSource.setContentMode(ContentMode.HTML);
    lblOpenSource.setStyleName("opensource");
    lblOpenSource.setWidth("100%");
    lblOpenSource.setHeight("-1px");
    labelLayout.addComponent(lblOpenSource);

    Link lnkFork = new Link();
    lnkFork.setResource(new ExternalResource("https://github.com/korpling/ANNIS"));
    lnkFork.setIcon(
            new ExternalResource("https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"));
    lnkFork.setTargetName("_blank");

    hLayout.addComponent(labelLayout);
    hLayout.addComponent(lnkFork);
    hLayout.setComponentAlignment(labelLayout, Alignment.TOP_LEFT);
    hLayout.setComponentAlignment(lnkFork, Alignment.TOP_RIGHT);
    hLayout.setExpandRatio(labelLayout, 1.0f);

    layout.addComponent(hLayout);

    final HelpUsWindow finalThis = this;

    btClose = new Button("Close");
    btClose.addClickListener(new OkClickListener(finalThis));
    layout.addComponent(btClose);

    layout.setComponentAlignment(hLayout, Alignment.MIDDLE_CENTER);
    layout.setComponentAlignment(btClose, Alignment.MIDDLE_CENTER);
    layout.setExpandRatio(hLayout, 1.0f);
}

From source file:annis.gui.LoginWindow.java

License:Apache License

@Override
public void attach() {
    super.attach();

    this.loginURL = (String) VaadinSession.getCurrent().getAttribute(LOGIN_URL_KEY);

    Resource loginRes;/*  www. ja  v a 2s.co  m*/
    if (loginURL == null || loginURL.isEmpty()) {
        loginRes = new ExternalResource(Helper.getContext() + "/login");
    } else {
        loginRes = new ExternalResource(loginURL);
    }

    BrowserFrame frame = new BrowserFrame("login", loginRes);
    frame.setWidth("100%");
    frame.setHeight("100%");

    setContent(frame);

    String loginMaximizedRaw = (String) getSession().getAttribute(LOGIN_MAXIMIZED_KEY);
    if (Boolean.parseBoolean(loginMaximizedRaw)) {
        setWindowMode(WindowMode.MAXIMIZED);
    }
}

From source file:annis.gui.ShareSingleMatchGenerator.java

License:Apache License

@Override
public void select(SelectionEvent event) {
    Set<Object> selected = event.getSelected();
    if (selected.isEmpty()) {
        generatedLinks.setVisible(false);
    } else {//  www  .j  av  a 2 s .  c o m
        generatedLinks.setVisible(true);

        URI url = generatorURLForVisualizer((ResolverEntry) selected.iterator().next());
        String shortURL = Helper.shortenURL(url);
        directURL.setValue(shortURL);
        iframeCode.setValue("<iframe height=\"300px\" width=\"100%\" src=\"" + shortURL + "\"></iframe>");
        preview.setSource(new ExternalResource(shortURL));
    }
}

From source file:cb_server.LogInWindow.java

License:Open Source License

private LogInWindow() {

    super("Get API Key"); // Set window caption

    this.setWidth(50, Unit.PERCENTAGE);
    this.setHeight(80, Unit.PERCENTAGE);

    center();//  w  w w .  j  ava  2  s  . c o m

    URL url;
    try {

        String oAuthUrl = CB_Api.getGcAuthUrl();

        url = new URL(oAuthUrl);

        ExternalResource extRes = new ExternalResource(url);

        extRes.getURL();

        BrowserFrame browser = new BrowserFrame("", extRes);

        browser.setWidth(100, Unit.PERCENTAGE);
        browser.setHeight(100, Unit.PERCENTAGE);

        content = new VerticalLayout();
        content.setWidth(100, Unit.PERCENTAGE);
        content.setHeight(100, Unit.PERCENTAGE);
        setContent(content);

        //         browser.addListener(eventType, target, method);

        content.addComponent(browser);
    } catch (MalformedURLException e) {

        e.printStackTrace();
    }
}

From source file:cirad.cgh.vcf2fasta.view.Vcf2fastaForm.java

License:Open Source License

public void drawResult(List<String[]> links) {
    for (String[] link : links) {
        Link section1Down = new Link(link[0], new ExternalResource(link[1]), "_blank", 0, 0, null);
        section1Down.addStyleName("colored");
        resultLayout.addComponent(section1Down);
    }/*from   w  w  w .  j av a 2s  . com*/
}

From source file:com.cavisson.gui.dashboard.components.controls.ButtonsAndLinks.java

License:Apache License

/**
* 
*//*from   w  w w .  j  a  va2  s.  co m*/
public ButtonsAndLinks() {
    setMargin(true);

    Label h1 = new Label("Buttons");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    Button button = new Button("Normal");
    row.addComponent(button);

    button = new Button("Disabled");
    button.setEnabled(false);
    row.addComponent(button);

    button = new Button("Primary");
    button.addStyleName("primary");
    row.addComponent(button);

    button = new Button("Friendly");
    button.addStyleName("friendly");
    row.addComponent(button);

    button = new Button("Danger");
    button.addStyleName("danger");
    row.addComponent(button);

    TestIcon testIcon = new TestIcon(10);
    button = new Button("Small");
    button.addStyleName("small");
    button.setIcon(testIcon.get());
    row.addComponent(button);

    button = new Button("Large");
    button.addStyleName("large");
    button.setIcon(testIcon.get());
    row.addComponent(button);

    button = new Button("Top");
    button.addStyleName("icon-align-top");
    button.setIcon(testIcon.get());
    row.addComponent(button);

    button = new Button("Image icon");
    button.setIcon(testIcon.get(true, 16));
    row.addComponent(button);

    button = new Button("Image icon");
    button.addStyleName("icon-align-right");
    button.setIcon(testIcon.get(true));
    row.addComponent(button);

    button = new Button("Photos");
    button.setIcon(testIcon.get());
    row.addComponent(button);

    button = new Button();
    button.setIcon(testIcon.get());
    button.addStyleName("icon-only");
    row.addComponent(button);

    button = new Button("Borderless");
    button.setIcon(testIcon.get());
    button.addStyleName("borderless");
    row.addComponent(button);

    button = new Button("Borderless, colored");
    button.setIcon(testIcon.get());
    button.addStyleName("borderless-colored");
    row.addComponent(button);

    button = new Button("Quiet");
    button.setIcon(testIcon.get());
    button.addStyleName("quiet");
    row.addComponent(button);

    button = new Button("Link style");
    button.setIcon(testIcon.get());
    button.addStyleName("link");
    row.addComponent(button);

    button = new Button("Icon on right");
    button.setIcon(testIcon.get());
    button.addStyleName("icon-align-right");
    row.addComponent(button);

    CssLayout group = new CssLayout();
    group.addStyleName("v-component-group");
    row.addComponent(group);

    button = new Button("One");
    group.addComponent(button);
    button = new Button("Two");
    group.addComponent(button);
    button = new Button("Three");
    group.addComponent(button);

    button = new Button("Tiny");
    button.addStyleName("tiny");
    row.addComponent(button);

    button = new Button("Huge");
    button.addStyleName("huge");
    row.addComponent(button);

    NativeButton nbutton = new NativeButton("Native");
    row.addComponent(nbutton);

    h1 = new Label("Links");
    h1.addStyleName("h1");
    addComponent(h1);

    row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    Link link = new Link("vaadin.com", new ExternalResource("https://vaadin.com"));
    row.addComponent(link);

    link = new Link("Link with icon", new ExternalResource("https://vaadin.com"));
    link.addStyleName("color3");
    link.setIcon(testIcon.get());
    row.addComponent(link);

    link = new Link("Small", new ExternalResource("https://vaadin.com"));
    link.addStyleName("small");
    row.addComponent(link);

    link = new Link("Large", new ExternalResource("https://vaadin.com"));
    link.addStyleName("large");
    row.addComponent(link);

    link = new Link(null, new ExternalResource("https://vaadin.com"));
    link.setIcon(testIcon.get());
    link.addStyleName("large");
    row.addComponent(link);
}

From source file:com.constellio.app.ui.pages.base.MainLayoutImpl.java

protected Component buildFooter() {

    Link poweredByConstellioLink = new Link(
            $("MainLayout.footerAlt") + "  (" + presenter.getCurrentVersion() + ")",
            new ExternalResource("http://www.constellio.com"));
    poweredByConstellioLink.setTargetName("_blank");
    poweredByConstellioLink.addStyleName(ValoTheme.LINK_LARGE);
    poweredByConstellioLink.addStyleName("footer");
    return poweredByConstellioLink;
}

From source file:com.constellio.app.ui.pages.management.updates.UpdateManagerViewImpl.java

private Component buildUnlicensedLayout() {
    Label message = new Label($("UpdateManagerViewImpl.unlicensed"));
    message.addStyleName(ValoTheme.LABEL_BOLD);

    Link request = new Link($("UpdateManagerViewImpl.requestLicense"),
            new ExternalResource("mailto:sales@constellio.com?Subject=Demande de license Constellio"));

    VerticalLayout layout = new VerticalLayout(message, request);
    layout.setSpacing(true);/* ww w.j  a  v  a  2s.  c  o m*/

    return layout;
}