Example usage for com.vaadin.server StreamResource StreamResource

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

Introduction

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

Prototype

public StreamResource(StreamSource streamSource, String filename) 

Source Link

Document

Creates a new stream resource for downloading from stream.

Usage

From source file:com.hybridbpm.ui.component.bpm.TaskFormHeader.java

License:Apache License

public void setUserImage() {
    User user = HybridbpmUI.getUser();/*from  w  ww  .  ja  v a2  s  .co m*/
    if (user.getImage() != null) {
        StreamResource.StreamSource imagesource = new UserImageSource(user.getImage().toStream());
        StreamResource resource = new StreamResource(imagesource, UUID.randomUUID().toString());
        userImage.setSource(resource);
    } else {
        userImage.setSource(new ThemeResource("img/profile-pic-300px.jpg"));
    }
}

From source file:com.hybridbpm.ui.component.comment.CommentViewLayout.java

License:Apache License

public void setUserImage() {
    User user = HybridbpmUI.getAccessAPI().getUserById(comment.getCreator());
    if (user.getImage() != null) {
        StreamResource.StreamSource imagesource = new UserImageSource(user.getImage().toStream());
        StreamResource resource = new StreamResource(imagesource, UUID.randomUUID().toString());
        userImage.setSource(resource);//w ww. j  a v  a 2s. c om
    } else {
        userImage.setSource(new ThemeResource("img/profile-pic-300px.jpg"));
    }
    senderUsername.setCaption("@" + user.getUsername());
    senderName.setValue(user.getFullName());
}

From source file:com.hybridbpm.ui.MainMenu.java

License:Apache License

public void setUserImage() {
    User user = HybridbpmUI.getUser();/*from  w ww .j  a v a  2s  .c o  m*/
    settingsItem.setText(user.getUsername());
    if (user.getImage() != null) {
        StreamResource.StreamSource imagesource = new UserImageSource(user.getImage().toStream());
        StreamResource resource = new StreamResource(imagesource, UUID.randomUUID().toString());
        userImage.setSource(resource);
    } else {
        userImage.setSource(new ThemeResource("img/profile-pic-300px.jpg"));
    }
}

From source file:com.jain.addon.component.download.JDownloader.java

License:Apache License

/**
 * Download actual file//from  ww  w. ja v  a 2s  . co  m
 */
public void download() {
    StreamResource resource = new StreamResource(source, fileName);
    resource.getStream().setParameter("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
    resource.setMIMEType("application/octet-stream");
    resource.setCacheTime(0);
    FileDownloader downloader = new FileDownloader(resource);
    downloader.extend(ui);
}

From source file:com.jain.addon.component.upload.JImage.java

License:Apache License

public void updateImage(final byte[] imageData, String fileName) {
    setValue(imageData);//w  w w.  j  a  va 2  s . c om
    JStreamSource source = new JStreamSource(new ByteArrayInputStream(imageData));
    image.setSource(new StreamResource(source, fileName));
    image.markAsDirty();
}

From source file:com.jain.addon.component.upload.JImage.java

License:Apache License

protected Component initContent() {
    layout = new HorizontalLayout();
    layout.setSpacing(true);/*w w w  .  j a  v a 2 s  .c  om*/
    layout.setWidth("100%");

    if (super.getInternalValue() != null) {
        createImage();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String fileName = "myfilename-" + df.format(new Date()) + ".png";
        JStreamSource source = new JStreamSource(new ByteArrayInputStream(super.getInternalValue()));
        image.setSource(new StreamResource(source, fileName));
        image.markAsDirty();
    }

    if (!isReadOnly()) {
        layout.addComponent(uploader);
        layout.setComponentAlignment(uploader, Alignment.MIDDLE_CENTER);
    }
    return layout;
}

From source file:com.jain.addon.web.table.JainColumnGenerator.java

License:Apache License

private Component createImage(final Property<?> itemProperty, final Table source) {
    if (itemProperty.getValue() != null) {
        JStreamSource streamSource = new JStreamSource((byte[]) itemProperty.getValue());
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String filename = "myfilename-" + df.format(new Date()) + ".png";
        StreamResource resource = new StreamResource(streamSource, filename);
        Embedded embedded = new Embedded("", resource);
        embedded.setHeight("20px");
        return embedded;
    }/*  www.  jav  a2s  .co  m*/
    return null;
}

From source file:com.klwork.explorer.ui.content.file.ImageAttachmentRenderer.java

License:Apache License

@Override
public Component getDetailComponent(Attachment attachment) {
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setSizeUndefined();/*  w w w. j  a v  a2  s  .co m*/
    verticalLayout.setSpacing(true);
    verticalLayout.setMargin(true);

    Label description = new Label(attachment.getDescription());
    description.setSizeUndefined();
    verticalLayout.addComponent(description);

    // Image
    TaskService taskService = ProcessEngines.getDefaultProcessEngine().getTaskService();

    String mimeType = extractMineType(attachment.getType());

    InputStream imageStream = ImageUtil.resizeImage(taskService.getAttachmentContent(attachment.getId()),
            mimeType, 900, 550);
    Resource resource = new StreamResource(new InputStreamStreamSource(imageStream),
            attachment.getName() + extractExtention(attachment.getType()));
    Embedded image = new Embedded(null, resource);
    verticalLayout.addComponent(image);

    // Linke
    HorizontalLayout LinkLayout = new HorizontalLayout();
    LinkLayout.setSpacing(true);
    verticalLayout.addComponent(LinkLayout);
    verticalLayout.setComponentAlignment(LinkLayout, Alignment.MIDDLE_CENTER);

    Label fullSizeLabel = new Label(
            ViewToolManager.getI18nManager().getMessage(Messages.RELATED_CONTENT_SHOW_FULL_SIZE));
    LinkLayout.addComponent(fullSizeLabel);

    Link link = null;
    if (attachment.getUrl() != null) {
        link = new Link(attachment.getUrl(), new ExternalResource(attachment.getUrl()));
    } else {
        taskService = ProcessEngines.getDefaultProcessEngine().getTaskService();
        Resource res = new StreamResource(
                new InputStreamStreamSource(taskService.getAttachmentContent(attachment.getId())),
                attachment.getName() + extractExtention(attachment.getType()));

        link = new Link(attachment.getName(), res);
    }

    link.setIcon(Images.RELATED_CONTENT_PICTURE);
    link.setTargetName(ExplorerLayout.LINK_TARGET_BLANK);
    LinkLayout.addComponent(link);

    return verticalLayout;
}

From source file:com.klwork.explorer.ui.content.GenericAttachmentRenderer.java

License:Apache License

public Component getDetailComponent(Attachment attachment) {
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setSizeUndefined();/*from  www  .  j a v a  2  s .c  o  m*/
    verticalLayout.setSpacing(true);
    verticalLayout.setMargin(true);

    Label description = new Label(attachment.getDescription());
    description.setSizeUndefined();
    verticalLayout.addComponent(description);

    HorizontalLayout linkLayout = new HorizontalLayout();
    linkLayout.setSpacing(true);
    verticalLayout.addComponent(linkLayout);

    // Image
    linkLayout.addComponent(new Embedded(null, getImage(attachment)));

    // Link
    Link link = null;
    if (attachment.getUrl() != null) {
        link = new Link(attachment.getUrl(), new ExternalResource(attachment.getUrl()));
    } else {
        TaskService taskService = ProcessEngines.getDefaultProcessEngine().getTaskService();
        Resource res = new StreamResource(
                new InputStreamStreamSource(taskService.getAttachmentContent(attachment.getId())),
                attachment.getName() + extractExtention(attachment.getType()));

        link = new Link(attachment.getName(), res);
    }

    // Set generic image and external window 
    link.setTargetName(ExplorerLayout.LINK_TARGET_BLANK);
    linkLayout.addComponent(link);

    return verticalLayout;
}

From source file:com.klwork.explorer.ui.process.ProcessDefinitionImageStreamResourceBuilder.java

License:Apache License

public StreamResource buildStreamResource(ProcessDefinition processDefinition,
        RepositoryService repositoryService) {

    StreamResource imageResource = null;

    if (processDefinition.getDiagramResourceName() != null) {
        final InputStream definitionImageStream = repositoryService.getResourceAsStream(
                processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName());

        StreamSource streamSource = new InputStreamStreamSource(definitionImageStream);

        // Creating image name based on process-definition ID is fine, since the diagram image cannot
        // be altered once deployed.
        String imageExtension = extractImageExtension(processDefinition.getDiagramResourceName());
        String fileName = processDefinition.getId() + "." + imageExtension;

        imageResource = new StreamResource(streamSource, fileName);
    }//  w  ww  .  j  av  a 2 s.  c om

    return imageResource;
}