List of usage examples for com.vaadin.ui Embedded getMimeType
public String getMimeType()
From source file:edu.kit.dama.ui.commons.util.UIUtils7.java
License:Apache License
public static void openResourceSubWindow(File sourceFile) { boolean fileAccessible = sourceFile != null && sourceFile.exists() && sourceFile.canRead(); // Set subwindow for displaying file resource final Window window = new Window(fileAccessible ? sourceFile.getName() : "Information"); window.center();//w w w . ja v a 2 s .c o m // Set window layout VerticalLayout windowLayout = new VerticalLayout(); windowLayout.setSizeFull(); if (fileAccessible) { // Set resource that has to be embedded final Embedded resource = new Embedded(null, new FileResource(sourceFile)); if ("application/octet-stream".equals(resource.getMimeType())) { window.setWidth("570px"); window.setHeight("150px"); windowLayout.setMargin(true); Label attentionNote = new Label( "A file preview is not possible as the file type is not supported by your browser."); attentionNote.setContentMode(ContentMode.HTML); Link fileURL = new Link("Click here for downloading the file.", new FileResource(sourceFile)); windowLayout.addComponent(attentionNote); windowLayout.addComponent(fileURL); windowLayout.setComponentAlignment(attentionNote, Alignment.MIDDLE_CENTER); windowLayout.setComponentAlignment(fileURL, Alignment.MIDDLE_CENTER); } else { window.setResizable(true); window.setWidth("800px"); window.setHeight("500px"); final Image image = new Image(null, new FileResource(sourceFile)); image.setSizeFull(); windowLayout.addComponent(image); } } else { //file is not accessible window.setWidth("570px"); window.setHeight("150px"); windowLayout.setMargin(true); Label attentionNote = new Label("Provided file cannot be accessed."); attentionNote.setContentMode(ContentMode.HTML); windowLayout.addComponent(attentionNote); windowLayout.setComponentAlignment(attentionNote, Alignment.MIDDLE_CENTER); } window.setContent(windowLayout); UI.getCurrent().addWindow(window); }