Example usage for com.vaadin.ui Link setResource

List of usage examples for com.vaadin.ui Link setResource

Introduction

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

Prototype

public void setResource(Resource resource) 

Source Link

Document

Sets the resource this link opens.

Usage

From source file:org.vaadin.addonhelpers.TListUi.java

License:Apache License

private void loadTestClasses(TListUi aThis) {
    if (testClassess != null) {
        return;/*from   ww  w.j av a2  s  .  c o m*/
    }
    testClassess = listTestClasses();
    Table table = new Table("Test cases", testClassess);
    table.setVisibleColumns("name", "description");
    table.addGeneratedColumn("name", new Table.ColumnGenerator() {
        public Object generateCell(Table source, Object itemId, Object columnId) {
            String name = (String) source.getItem(itemId).getItemProperty(columnId).getValue();
            Class clazz = (Class) source.getItem(itemId).getItemProperty("clazz").getValue();
            Link link = new Link();
            link.setResource(new ExternalResource("/" + clazz.getName()));
            link.setCaption(name);
            link.setTargetName("_new");
            return link;
        }
    });
    table.addGeneratedColumn("description", new Table.ColumnGenerator() {
        public Object generateCell(Table source, Object itemId, Object columnId) {
            String description = (String) source.getItem(itemId).getItemProperty(columnId).getValue();
            return new Label(description);
        }
    });
    table.setSizeFull();
    table.setColumnExpandRatio("description", 1);
    VerticalLayout verticalLayout = new VerticalLayout();
    TextField filter = new TextField();
    filter.setInputPrompt("Filter list");
    filter.addTextChangeListener(new TextChangeListener() {
        @Override
        public void textChange(TextChangeEvent event) {
            String text = event.getText();
            testClassess.removeAllContainerFilters();
            testClassess.addContainerFilter("name", text, true, false);
        }
    });
    verticalLayout.addComponent(filter);
    filter.focus();
    verticalLayout.addComponent(table);
    verticalLayout.setSizeFull();
    verticalLayout.setExpandRatio(table, 1);
    verticalLayout.setMargin(true);
    setContent(verticalLayout);
}

From source file:ru.codeinside.gses.activiti.ftarchive.AttachmentField.java

License:Mozilla Public License

Component createDownloadLink(final FileValue fileValue) {
    final Link result = new Link();
    result.setCaption(fileValue.getFileName());
    result.setTargetName("_top");
    result.setImmediate(true);// ww  w .  j  a va  2s  .  c  o m
    result.setDescription("");
    StreamResource.StreamSource streamSource = new StreamResource.StreamSource() {
        public InputStream getStream() {
            return new ByteArrayInputStream(fileValue.getContent());
        }
    };
    StreamResource resource = new StreamResource(streamSource, fileValue.getFileName(), Flash.app()) {
        public DownloadStream getStream() {
            final StreamSource ss = getStreamSource();
            if (ss == null) {
                return null;
            }
            final DownloadStream ds = new DownloadStream(ss.getStream(), getMIMEType(), getFilename());
            ds.setCacheTime(0);
            try {
                WebBrowser browser = (WebBrowser) result.getWindow().getTerminal();
                if (browser.isIE()) {
                    URI uri = new URI(null, null, fileValue.getFileName(), null);
                    ds.setParameter("Content-Disposition", "attachment; filename=" + uri.toASCIIString());
                } else {
                    ds.setParameter("Content-Disposition", "attachment; filename=\""
                            + MimeUtility.encodeWord(fileValue.getFileName(), "utf-8", "Q") + "\"");
                }
            } catch (Exception e) {
                ds.setParameter("Content-Disposition", "attachment; filename=" + fileValue.getFileName());
            }
            return ds;
        }
    };
    resource.setMIMEType(fileValue.getMimeType());
    result.setResource(resource);
    return result;
}

From source file:ru.codeinside.gses.webui.utils.Components.java

License:Mozilla Public License

@Deprecated
public static Link createAttachShowButton(final FileValue attachment, final Application appl) {
    if (attachment == null) {
        return null;
    }/*from   ww  w. j  ava2  s .c  o  m*/
    final Link result = new Link();
    result.setCaption(attachment.getFileName());
    result.setTargetName("_top");
    result.setImmediate(true);
    //String description = attachment.getDescription();
    result.setDescription("");
    StreamSource streamSource = new StreamSource() {

        private static final long serialVersionUID = 456334952891567271L;

        public InputStream getStream() {
            return new ByteArrayInputStream(attachment.getContent());
        }
    };
    StreamResource resource = new StreamResource(streamSource, attachment.getFileName(), appl) {

        private static final long serialVersionUID = -3869546661105572851L;

        public DownloadStream getStream() {
            final StreamSource ss = getStreamSource();
            if (ss == null) {
                return null;
            }
            final DownloadStream ds = new DownloadStream(ss.getStream(), getMIMEType(), getFilename());
            ds.setBufferSize(getBufferSize());
            ds.setCacheTime(0);
            try {
                WebBrowser browser = (WebBrowser) result.getWindow().getTerminal();
                if (browser.isIE()) {
                    URI uri = new URI(null, null, attachment.getFileName(), null);
                    ds.setParameter("Content-Disposition", "attachment; filename=" + uri.toASCIIString());
                } else {
                    ds.setParameter("Content-Disposition", "attachment; filename=\""
                            + MimeUtility.encodeWord(attachment.getFileName(), "utf-8", "Q") + "\"");
                }
            } catch (Exception e) {
                ds.setParameter("Content-Disposition", "attachment; filename=" + attachment.getFileName());
            }
            return ds;
        }
    };
    String type = attachment.getMimeType();
    if (type != null) {
        resource.setMIMEType(type);
    }
    result.setResource(resource);
    return result;
}