Search in sources :

Example 11 with StreamResource

use of com.vaadin.terminal.StreamResource in project Activiti by Activiti.

the class ProcessInstanceDetailPanel method addProcessImage.

protected void addProcessImage() {
    ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinition.getId());
    // Only show when graphical notation is defined
    if (processDefinitionEntity != null) {
        boolean didDrawImage = false;
        if (ExplorerApp.get().isUseJavascriptDiagram()) {
            try {
                final InputStream definitionStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
                XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
                XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
                BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
                if (!bpmnModel.getFlowLocationMap().isEmpty()) {
                    int maxX = 0;
                    int maxY = 0;
                    for (String key : bpmnModel.getLocationMap().keySet()) {
                        GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
                        double elementX = graphicInfo.getX() + graphicInfo.getWidth();
                        if (maxX < elementX) {
                            maxX = (int) elementX;
                        }
                        double elementY = graphicInfo.getY() + graphicInfo.getHeight();
                        if (maxY < elementY) {
                            maxY = (int) elementY;
                        }
                    }
                    // using panel for scrollbars
                    Panel imagePanel = new Panel();
                    imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
                    imagePanel.setWidth(100, UNITS_PERCENTAGE);
                    imagePanel.setHeight(100, UNITS_PERCENTAGE);
                    URL explorerURL = ExplorerApp.get().getURL();
                    URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "diagram-viewer/index.html?processDefinitionId=" + processDefinition.getId() + "&processInstanceId=" + processInstance.getId());
                    Embedded browserPanel = new Embedded("", new ExternalResource(url));
                    browserPanel.setType(Embedded.TYPE_BROWSER);
                    browserPanel.setWidth(maxX + 350 + "px");
                    browserPanel.setHeight(maxY + 220 + "px");
                    HorizontalLayout panelLayoutT = new HorizontalLayout();
                    panelLayoutT.setSizeUndefined();
                    imagePanel.setContent(panelLayoutT);
                    imagePanel.addComponent(browserPanel);
                    panelLayout.addComponent(imagePanel);
                    didDrawImage = true;
                }
            } catch (Exception e) {
                LOGGER.error("Error loading process diagram component", e);
            }
        }
        if (!didDrawImage && processDefinitionEntity.isGraphicalNotationDefined()) {
            ProcessEngineConfiguration processEngineConfiguration = ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration();
            ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
            StreamResource diagram = new ProcessDefinitionImageStreamResourceBuilder().buildStreamResource(processInstance, repositoryService, runtimeService, diagramGenerator, processEngineConfiguration);
            if (diagram != null) {
                Label header = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
                header.addStyleName(ExplorerLayout.STYLE_H3);
                header.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
                header.addStyleName(ExplorerLayout.STYLE_NO_LINE);
                panelLayout.addComponent(header);
                Embedded embedded = new Embedded(null, diagram);
                embedded.setType(Embedded.TYPE_IMAGE);
                embedded.setSizeUndefined();
                // using panel for scrollbars
                Panel imagePanel = new Panel();
                imagePanel.setScrollable(true);
                imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
                imagePanel.setWidth(100, UNITS_PERCENTAGE);
                imagePanel.setHeight(100, UNITS_PERCENTAGE);
                HorizontalLayout panelLayoutT = new HorizontalLayout();
                panelLayoutT.setSizeUndefined();
                imagePanel.setContent(panelLayoutT);
                imagePanel.addComponent(embedded);
                panelLayout.addComponent(imagePanel);
            }
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Label(com.vaadin.ui.Label) PrettyTimeLabel(org.activiti.explorer.ui.custom.PrettyTimeLabel) ExternalResource(com.vaadin.terminal.ExternalResource) URL(java.net.URL) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Panel(com.vaadin.ui.Panel) DetailPanel(org.activiti.explorer.ui.custom.DetailPanel) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) StreamResource(com.vaadin.terminal.StreamResource) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) Embedded(com.vaadin.ui.Embedded) ProcessDefinitionImageStreamResourceBuilder(org.activiti.explorer.ui.process.ProcessDefinitionImageStreamResourceBuilder) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 12 with StreamResource

use of com.vaadin.terminal.StreamResource 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 13 with StreamResource

use of com.vaadin.terminal.StreamResource in project Activiti by Activiti.

the class ProcessDefinitionInfoComponent method initImage.

protected void initImage() {
    processImageContainer = new VerticalLayout();
    Label processTitle = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
    processTitle.addStyleName(ExplorerLayout.STYLE_H3);
    processImageContainer.addComponent(processTitle);
    boolean didDrawImage = false;
    if (ExplorerApp.get().isUseJavascriptDiagram()) {
        try {
            final InputStream definitionStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
            XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
            XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
            BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
            if (!bpmnModel.getFlowLocationMap().isEmpty()) {
                int maxX = 0;
                int maxY = 0;
                for (String key : bpmnModel.getLocationMap().keySet()) {
                    GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
                    double elementX = graphicInfo.getX() + graphicInfo.getWidth();
                    if (maxX < elementX) {
                        maxX = (int) elementX;
                    }
                    double elementY = graphicInfo.getY() + graphicInfo.getHeight();
                    if (maxY < elementY) {
                        maxY = (int) elementY;
                    }
                }
                // using panel for scrollbars
                Panel imagePanel = new Panel();
                imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
                imagePanel.setWidth(100, UNITS_PERCENTAGE);
                imagePanel.setHeight(100, UNITS_PERCENTAGE);
                URL explorerURL = ExplorerApp.get().getURL();
                URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "diagram-viewer/index.html?processDefinitionId=" + processDefinition.getId());
                Embedded browserPanel = new Embedded("", new ExternalResource(url));
                browserPanel.setType(Embedded.TYPE_BROWSER);
                browserPanel.setWidth(maxX + 350 + "px");
                browserPanel.setHeight(maxY + 220 + "px");
                HorizontalLayout panelLayout = new HorizontalLayout();
                panelLayout.setSizeUndefined();
                imagePanel.setContent(panelLayout);
                imagePanel.addComponent(browserPanel);
                processImageContainer.addComponent(imagePanel);
                didDrawImage = true;
            }
        } catch (Exception e) {
            LOGGER.error("Error loading process diagram component", e);
        }
    }
    if (didDrawImage == false) {
        StreamResource diagram = null;
        // Try generating process-image stream
        if (processDefinition.getDiagramResourceName() != null) {
            diagram = new ProcessDefinitionImageStreamResourceBuilder().buildStreamResource(processDefinition, repositoryService);
        }
        if (diagram != null) {
            Embedded embedded = new Embedded(null, diagram);
            embedded.setType(Embedded.TYPE_IMAGE);
            embedded.setSizeUndefined();
            // using panel for scrollbars
            Panel imagePanel = new Panel();
            imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
            imagePanel.setWidth(100, UNITS_PERCENTAGE);
            imagePanel.setHeight(100, UNITS_PERCENTAGE);
            HorizontalLayout panelLayout = new HorizontalLayout();
            panelLayout.setSizeUndefined();
            imagePanel.setContent(panelLayout);
            imagePanel.addComponent(embedded);
            processImageContainer.addComponent(imagePanel);
            didDrawImage = true;
        }
    }
    if (didDrawImage == false) {
        Label noImageAvailable = new Label(i18nManager.getMessage(Messages.PROCESS_NO_DIAGRAM));
        processImageContainer.addComponent(noImageAvailable);
    }
    addComponent(processImageContainer);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) Label(com.vaadin.ui.Label) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) ExternalResource(com.vaadin.terminal.ExternalResource) URL(java.net.URL) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Panel(com.vaadin.ui.Panel) StreamResource(com.vaadin.terminal.StreamResource) VerticalLayout(com.vaadin.ui.VerticalLayout) Embedded(com.vaadin.ui.Embedded) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 14 with StreamResource

use of com.vaadin.terminal.StreamResource in project Activiti by Activiti.

the class DeploymentDetailPanel method addResourceLinks.

protected void addResourceLinks() {
    List<String> resourceNames = repositoryService.getDeploymentResourceNames(deployment.getId());
    // small nr of elements, so we can do it in-memory
    Collections.sort(resourceNames);
    if (!resourceNames.isEmpty()) {
        Label resourceHeader = new Label(i18nManager.getMessage(Messages.DEPLOYMENT_HEADER_RESOURCES));
        resourceHeader.setWidth("95%");
        resourceHeader.addStyleName(ExplorerLayout.STYLE_H3);
        resourceHeader.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
        addDetailComponent(resourceHeader);
        // resources
        VerticalLayout resourceLinksLayout = new VerticalLayout();
        resourceLinksLayout.setSpacing(true);
        resourceLinksLayout.setMargin(true, false, false, false);
        addDetailComponent(resourceLinksLayout);
        for (final String resourceName : resourceNames) {
            StreamResource.StreamSource streamSource = new StreamSource() {

                public InputStream getStream() {
                    return repositoryService.getResourceAsStream(deployment.getId(), resourceName);
                }
            };
            Link resourceLink = new Link(resourceName, new StreamResource(streamSource, resourceName, ExplorerApp.get()));
            resourceLinksLayout.addComponent(resourceLink);
        }
    }
}
Also used : StreamSource(com.vaadin.terminal.StreamResource.StreamSource) StreamResource(com.vaadin.terminal.StreamResource) StreamSource(com.vaadin.terminal.StreamResource.StreamSource) Label(com.vaadin.ui.Label) PrettyTimeLabel(org.activiti.explorer.ui.custom.PrettyTimeLabel) VerticalLayout(com.vaadin.ui.VerticalLayout) Link(com.vaadin.ui.Link)

Example 15 with StreamResource

use of com.vaadin.terminal.StreamResource 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)16 Embedded (com.vaadin.ui.Embedded)12 StreamSource (com.vaadin.terminal.StreamResource.StreamSource)9 InputStream (java.io.InputStream)9 Label (com.vaadin.ui.Label)8 InputStreamStreamSource (org.activiti.explorer.ui.util.InputStreamStreamSource)6 HorizontalLayout (com.vaadin.ui.HorizontalLayout)5 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)5 ExternalResource (com.vaadin.terminal.ExternalResource)4 Resource (com.vaadin.terminal.Resource)4 VerticalLayout (com.vaadin.ui.VerticalLayout)4 BpmnModel (org.activiti.bpmn.model.BpmnModel)4 Picture (org.activiti.engine.identity.Picture)4 PrettyTimeLabel (org.activiti.explorer.ui.custom.PrettyTimeLabel)4 Link (com.vaadin.ui.Link)3 Panel (com.vaadin.ui.Panel)3 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)3 ProcessDefinitionImageStreamResourceBuilder (org.activiti.explorer.ui.process.ProcessDefinitionImageStreamResourceBuilder)3 ProcessDiagramGenerator (org.activiti.image.ProcessDiagramGenerator)3 URL (java.net.URL)2