use of com.vaadin.terminal.StreamResource.StreamSource in project Activiti by Activiti.
the class TaskEventsPanel method addTaskEventPicture.
protected void addTaskEventPicture(final org.activiti.engine.task.Event taskEvent, GridLayout eventGrid) {
final Picture userPicture = identityService.getUserPicture(taskEvent.getUserId());
Embedded authorPicture = null;
if (userPicture != null) {
StreamResource imageresource = new StreamResource(new StreamSource() {
private static final long serialVersionUID = 1L;
public InputStream getStream() {
return userPicture.getInputStream();
}
}, "event_" + taskEvent.getUserId() + "." + Constants.MIMETYPE_EXTENSION_MAPPING.get(userPicture.getMimeType()), ExplorerApp.get());
authorPicture = new Embedded(null, imageresource);
} else {
authorPicture = new Embedded(null, Images.USER_50);
}
authorPicture.setType(Embedded.TYPE_IMAGE);
authorPicture.setHeight("48px");
authorPicture.setWidth("48px");
authorPicture.addStyleName(ExplorerLayout.STYLE_TASK_EVENT_PICTURE);
eventGrid.addComponent(authorPicture);
}
use of com.vaadin.terminal.StreamResource.StreamSource in project Activiti by Activiti.
the class UserDetailsComponent method addUserPicture.
protected void addUserPicture() {
// default icon
Resource pictureResource = Images.USER_32;
if (user != null) {
final Picture userPicture = identityService.getUserPicture(user.getId());
if (userPicture != null) {
pictureResource = new StreamResource(new StreamSource() {
public InputStream getStream() {
return userPicture.getInputStream();
}
}, user.getId(), ExplorerApp.get());
}
}
Embedded picture = new Embedded(null, pictureResource);
picture.setType(Embedded.TYPE_IMAGE);
picture.addStyleName(ExplorerLayout.STYLE_TASK_EVENT_PICTURE);
if (user != null) {
// Only set fixed height and width when user has image, otherwise icon's dimensions will be used
picture.setHeight("32px");
picture.setWidth("32px");
}
addComponent(picture);
// Add profile popup listener
if (user != null) {
picture.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
picture.addListener(new com.vaadin.event.MouseEvents.ClickListener() {
public void click(ClickEvent event) {
viewManager.showProfilePopup(user.getId());
}
});
}
}
use of com.vaadin.terminal.StreamResource.StreamSource 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;
}
use of com.vaadin.terminal.StreamResource.StreamSource 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;
}
use of com.vaadin.terminal.StreamResource.StreamSource in project Activiti by Activiti.
the class SimpleTableEditor method showDiagram.
protected void showDiagram() {
StreamResource.StreamSource streamSource = new StreamSource() {
private static final long serialVersionUID = 6993112534181068935L;
public InputStream getStream() {
WorkflowDefinitionConversion workflowDefinitionConversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(createWorkflow());
final ProcessEngineImpl defaultProcessEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
final ProcessEngineConfiguration processEngineConfiguration = defaultProcessEngine.getProcessEngineConfiguration();
final ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
return diagramGenerator.generateDiagram(workflowDefinitionConversion.getBpmnModel(), "png", processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader());
}
};
// resource must have unique id (or cache-crap can happen)!
StreamResource imageresource = new StreamResource(streamSource, UUID.randomUUID() + ".png", ExplorerApp.get());
Embedded diagram = new Embedded("", imageresource);
diagram.setType(Embedded.TYPE_IMAGE);
diagram.setSizeUndefined();
// using panel for scrollbars
imagePanel = new Panel();
imagePanel.setScrollable(true);
imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
imagePanel.setWidth(100, UNITS_PERCENTAGE);
imagePanel.setHeight("100%");
mainLayout.addComponent(imagePanel);
HorizontalLayout panelLayout = new HorizontalLayout();
panelLayout.setSizeUndefined();
imagePanel.setContent(panelLayout);
imagePanel.addComponent(diagram);
}
Aggregations