Search in sources :

Example 1 with InputStreamStreamSource

use of org.activiti.explorer.ui.util.InputStreamStreamSource in project Activiti by Activiti.

the class ProcessDefinitionImageStreamResourceBuilder method buildStreamResource.

public StreamResource buildStreamResource(ProcessInstance processInstance, RepositoryService repositoryService, RuntimeService runtimeService, ProcessDiagramGenerator diagramGenerator, ProcessEngineConfiguration processEngineConfig) {
    StreamResource imageResource = null;
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
    if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) {
        try {
            BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
            InputStream definitionImageStream = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstance.getId()), Collections.<String>emptyList(), processEngineConfig.getActivityFontName(), processEngineConfig.getLabelFontName(), processEngineConfig.getAnnotationFontName(), processEngineConfig.getClassLoader(), 1.0);
            if (definitionImageStream != null) {
                StreamSource streamSource = new InputStreamStreamSource(definitionImageStream);
                // Create image name
                String imageExtension = extractImageExtension(processDefinition.getDiagramResourceName());
                String fileName = processInstance.getId() + UUID.randomUUID() + "." + imageExtension;
                imageResource = new StreamResource(streamSource, fileName, ExplorerApp.get());
            }
        } catch (Throwable t) {
            // Image can't be generated, ignore this
            LOGGER.warn("Process image cannot be generated due to exception: {} - {}", t.getClass().getName(), t.getMessage());
        }
    }
    return imageResource;
}
Also used : StreamResource(com.vaadin.terminal.StreamResource) InputStream(java.io.InputStream) StreamSource(com.vaadin.terminal.StreamResource.StreamSource) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 2 with InputStreamStreamSource

use of org.activiti.explorer.ui.util.InputStreamStreamSource in project Activiti by Activiti.

the class ProcessDefinitionImageStreamResourceBuilder method buildStreamResource.

public StreamResource buildStreamResource(String processInstanceId, String processDefinitionId, RepositoryService repositoryService, RuntimeService runtimeService, ProcessDiagramGenerator diagramGenerator, ProcessEngineConfiguration processEngineConfig) {
    StreamResource imageResource = null;
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinitionId);
    if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) {
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
        InputStream definitionImageStream = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstanceId), Collections.<String>emptyList(), processEngineConfig.getActivityFontName(), processEngineConfig.getLabelFontName(), processEngineConfig.getAnnotationFontName(), processEngineConfig.getClassLoader(), 1.0);
        StreamSource streamSource = new InputStreamStreamSource(definitionImageStream);
        // Create image name
        String imageExtension = extractImageExtension(processDefinition.getDiagramResourceName());
        String fileName = processInstanceId + UUID.randomUUID() + "." + imageExtension;
        imageResource = new StreamResource(streamSource, fileName, ExplorerApp.get());
    }
    return imageResource;
}
Also used : StreamResource(com.vaadin.terminal.StreamResource) InputStream(java.io.InputStream) StreamSource(com.vaadin.terminal.StreamResource.StreamSource) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 3 with InputStreamStreamSource

use of org.activiti.explorer.ui.util.InputStreamStreamSource in project Activiti by Activiti.

the class GenericAttachmentRenderer method getDetailComponent.

public Component getDetailComponent(Attachment attachment) {
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setSizeUndefined();
    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()), ExplorerApp.get());
        link = new Link(attachment.getName(), res);
    }
    // Set generic image and external window 
    link.setTargetName(ExplorerLayout.LINK_TARGET_BLANK);
    linkLayout.addComponent(link);
    return verticalLayout;
}
Also used : StreamResource(com.vaadin.terminal.StreamResource) TaskService(org.activiti.engine.TaskService) Label(com.vaadin.ui.Label) StreamResource(com.vaadin.terminal.StreamResource) ExternalResource(com.vaadin.terminal.ExternalResource) Resource(com.vaadin.terminal.Resource) VerticalLayout(com.vaadin.ui.VerticalLayout) Embedded(com.vaadin.ui.Embedded) ExternalResource(com.vaadin.terminal.ExternalResource) Link(com.vaadin.ui.Link) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 4 with InputStreamStreamSource

use of org.activiti.explorer.ui.util.InputStreamStreamSource in project Activiti by Activiti.

the class ProcessDefinitionImageStreamResourceBuilder method buildStreamResource.

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, ExplorerApp.get());
    }
    return imageResource;
}
Also used : StreamResource(com.vaadin.terminal.StreamResource) InputStream(java.io.InputStream) StreamSource(com.vaadin.terminal.StreamResource.StreamSource) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource)

Example 5 with InputStreamStreamSource

use of org.activiti.explorer.ui.util.InputStreamStreamSource in project Activiti by Activiti.

the class UserProfileLink method initPicture.

protected void initPicture(IdentityService identityService, boolean renderPicture, final String userName) {
    if (renderPicture) {
        Picture picture = identityService.getUserPicture(userName);
        if (picture != null) {
            Resource imageResource = new StreamResource(new InputStreamStreamSource(picture.getInputStream()), userName + picture.getMimeType(), ExplorerApp.get());
            Embedded image = new Embedded(null, imageResource);
            image.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
            image.setType(Embedded.TYPE_IMAGE);
            image.setHeight(30, Embedded.UNITS_PIXELS);
            image.setWidth(30, Embedded.UNITS_PIXELS);
            image.addListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 7341560240277898495L;

                public void click(MouseEvents.ClickEvent event) {
                    viewManager.showProfilePopup(userName);
                }
            });
            addComponent(image);
            setComponentAlignment(image, Alignment.MIDDLE_LEFT);
        } else {
        // TODO: what when no image is available?
        }
    }
}
Also used : StreamResource(com.vaadin.terminal.StreamResource) Picture(org.activiti.engine.identity.Picture) StreamResource(com.vaadin.terminal.StreamResource) Resource(com.vaadin.terminal.Resource) Embedded(com.vaadin.ui.Embedded) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) MouseEvents(com.vaadin.event.MouseEvents)

Aggregations

StreamResource (com.vaadin.terminal.StreamResource)6 InputStreamStreamSource (org.activiti.explorer.ui.util.InputStreamStreamSource)6 InputStream (java.io.InputStream)4 Resource (com.vaadin.terminal.Resource)3 StreamSource (com.vaadin.terminal.StreamResource.StreamSource)3 Embedded (com.vaadin.ui.Embedded)3 ExternalResource (com.vaadin.terminal.ExternalResource)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Label (com.vaadin.ui.Label)2 Link (com.vaadin.ui.Link)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 BpmnModel (org.activiti.bpmn.model.BpmnModel)2 TaskService (org.activiti.engine.TaskService)2 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)2 MouseEvents (com.vaadin.event.MouseEvents)1 Picture (org.activiti.engine.identity.Picture)1