List of usage examples for com.vaadin.server StreamResource StreamResource
public StreamResource(StreamSource streamSource, String filename)
From source file:com.klwork.explorer.ui.process.ProcessDefinitionImageStreamResourceBuilder.java
License:Apache License
public StreamResource buildStreamResource(ProcessInstance processInstance, RepositoryService repositoryService, RuntimeService runtimeService) { StreamResource imageResource = null; ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) .getDeployedProcessDefinition(processInstance.getProcessDefinitionId()); if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) { try {// w w w . ja v a 2 s . c om BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getId()); InputStream definitionImageStream = ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstance.getId())); 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); } } 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; }
From source file:com.klwork.explorer.ui.process.ProcessDefinitionImageStreamResourceBuilder.java
License:Apache License
public StreamResource buildStreamResource(String processInstanceId, String processDefinitionId, RepositoryService repositoryService, RuntimeService runtimeService) { StreamResource imageResource = null; ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) .getDeployedProcessDefinition(processDefinitionId); if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) { BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId); InputStream definitionImageStream = ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstanceId)); StreamSource streamSource = new InputStreamStreamSource(definitionImageStream); // Create image name String imageExtension = extractImageExtension(processDefinition.getDiagramResourceName()); String fileName = processInstanceId + UUID.randomUUID() + "." + imageExtension; imageResource = new StreamResource(streamSource, fileName); }/*from www .j a v a 2 s . com*/ return imageResource; }
From source file:com.klwork.explorer.ui.task.ProcessInstanceEventsPanel.java
License:Apache License
protected void addTaskEventPicture(final Comment taskEvent, GridLayout eventGrid) { final Picture userPicture = identityService.getUserPicture(taskEvent.getUserId()); Embedded authorPicture = null;/*from w w w . j av a2 s.c o m*/ 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())); 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); }
From source file:com.klwork.explorer.ui.task.UserDetailsComponent.java
License:Apache License
protected void addUserPicture() { Resource pictureResource = Images.USER_32; // default icon if (user != null) { final Picture userPicture = identityService.getUserPicture(user.getId()); if (userPicture != null) { //WW_TODO ?, pictureResource = new StreamResource(new StreamSource() { public InputStream getStream() { return userPicture.getInputStream(); }/*from w w w.j a v a2s . c o m*/ }, user.getId()); } } 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.addClickListener(new com.vaadin.event.MouseEvents.ClickListener() { public void click(ClickEvent event) { // ViewToolManager.showProfilePopup(user.getId()); ViewToolManager.showPopupWindow(new ProfilePopupWindow(user.getId())); } }); } }
From source file:com.klwork.explorer.ui.user.ProfilePanel.java
License:Apache License
protected void initPicture() { StreamResource imageresource = new StreamResource(new StreamSource() { private static final long serialVersionUID = 1L; public InputStream getStream() { return picture.getInputStream(); }/*from w w w .j a v a 2s. c o m*/ }, user.getId()); imageresource.setCacheTime(0); Embedded picture = new Embedded(null, imageresource); picture.setType(Embedded.TYPE_IMAGE); picture.setHeight(200, UNITS_PIXELS); picture.setWidth(200, UNITS_PIXELS); picture.addStyleName(ExplorerLayout.STYLE_PROFILE_PICTURE); imageLayout.addComponent(picture); imageLayout.setWidth(picture.getWidth() + 5, picture.getWidthUnits()); // Change picture button if (isCurrentLoggedInUser) { Upload changePictureButton = initChangePictureButton(); imageLayout.addComponent(changePictureButton); imageLayout.setComponentAlignment(changePictureButton, Alignment.MIDDLE_CENTER); } }
From source file:com.klwork.explorer.ui.user.UserEventsPanel.java
License:Apache License
protected void addTaskEventPicture(final org.activiti.engine.task.Event taskEvent, GridLayout eventGrid) { if (taskEvent.getUserId() == null) { return;//from w w w. ja va 2s . c om } 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())); 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); }
From source file:com.mycollab.module.project.view.FollowingTicketViewImpl.java
License:Open Source License
private StreamResource constructStreamResource(final ReportExportType exportType) { LazyStreamSource streamSource = new LazyStreamSource() { private static final long serialVersionUID = 1L; @Override/*from w w w. j av a 2 s . c om*/ protected StreamSource buildStreamSource() { SimpleReportTemplateExecutor reportTemplateExecutor = new SimpleReportTemplateExecutor.AllItems<>( "Following Tickets", new RpFieldsBuilder(ticketTable.getDisplayColumns()), exportType, FollowingTicket.class, AppContextUtil.getSpringBean(ProjectFollowingTicketService.class)); //TODO: correct the report of following tickets return null; } }; return new StreamResource(streamSource, exportType.getDefaultFileName()); }
From source file:com.mycollab.vaadin.web.ui.DefaultMassEditActionHandler.java
License:Open Source License
@Override public StreamResource buildStreamResource(ReportExportType exportType) { IPagedBeanTable pagedBeanTable = ((IListView) presenter.getView()).getPagedBeanTable(); final Map<String, Object> addtionalParamters = new HashMap<>(); addtionalParamters.put("siteUrl", MyCollabUI.getSiteUrl()); addtionalParamters.put(SimpleReportTemplateExecutor.CRITERIA, presenter.searchCriteria); ReportTemplateExecutor reportTemplateExecutor; if (presenter.isSelectAll) { reportTemplateExecutor = new SimpleReportTemplateExecutor.AllItems(getReportTitle(), new RpFieldsBuilder(pagedBeanTable.getDisplayColumns()), exportType, getReportModelClassType(), presenter.getSearchService()); } else {/*from w ww. j ava 2 s . com*/ reportTemplateExecutor = new SimpleReportTemplateExecutor.ListData(getReportTitle(), new RpFieldsBuilder(pagedBeanTable.getDisplayColumns()), exportType, presenter.getSelectedItems(), getReportModelClassType()); } return new StreamResource(new ReportStreamSource(reportTemplateExecutor) { @Override protected void initReportParameters(Map<String, Object> parameters) { parameters.putAll(addtionalParamters); } }, exportType.getDefaultFileName()); }
From source file:com.ocs.dynamo.ui.component.DefaultEmbedded.java
License:Apache License
/** * Constructor/*from w ww . j a v a 2 s . c om*/ * * @param caption * the caption of the component * @param bytes * the bytes that represent the */ public DefaultEmbedded(String caption, final byte[] bytes) { super(caption); if (bytes != null) { setSource(new StreamResource(new StreamSource() { @Override public InputStream getStream() { return new ByteArrayInputStream(bytes); } }, System.nanoTime() + ".png")); } }
From source file:com.ocs.dynamo.ui.component.DownloadButton.java
License:Apache License
/** * Constructor//from www .ja v a 2s .c om * * @param caption * the caption of the button * @param fileName * the name of the file to download */ public DownloadButton(String caption) { super(caption); resource = new StreamResource(new StreamSource() { private static final long serialVersionUID = -4870779918745663459L; @Override public InputStream getStream() { byte[] content = doCreateContent(); if (content != null) { return new ByteArrayInputStream(content); } return null; } }, doCreateFileName()); FileDownloader downloader = new FileDownloader(resource); downloader.extend(this); }