List of usage examples for com.vaadin.server FileResource FileResource
public FileResource(File sourceFile)
From source file:com.haulmont.cuba.web.gui.components.WebEmbedded.java
License:Apache License
@Override public void setSource(String src) { if (src != null) { if (src.startsWith("http") || src.startsWith("https")) { try { setSource(new URL(src)); } catch (MalformedURLException e) { throw new RuntimeException("Unable to parse url for embedded source", e); }// w ww . j ava 2 s .c om } else if (src.startsWith("theme://")) { String themeResource = src.substring("theme://".length()); resource = new VersionedThemeResource(themeResource); component.setSource(resource); } else { File file = new File(src); if (!file.isAbsolute()) { Configuration configuration = AppBeans.get(Configuration.NAME); String root = configuration.getConfig(WebConfig.class).getResourcesRoot(); if (root != null) { if (!root.endsWith(File.separator)) { root += File.separator; } file = new File(root + file.getPath()); } } resource = new FileResource(file); component.setSource(resource); } } else { resetSource(); } }
From source file:com.haulmont.cuba.web.gui.icons.FileIconProvider.java
License:Apache License
@Override public Resource getIconResource(String iconPath) { Preconditions.checkNotEmptyString(iconPath, "Icon path should not be empty"); String icon = iconPath.substring(FILE_PREFIX.length()); File iconFile = new File(icon); if (!iconFile.exists()) { throw new IllegalArgumentException("Icon file does not exist: " + icon); }// w w w .j a v a 2 s . c o m return new FileResource(iconFile); }
From source file:com.logicbomb.newschool.MyAppWidgetSet.core.UserDetailsWidgetOld.java
public UserDetailsWidgetOld() { setSpacing(true);//from w ww .j av a 2s . c o m Panel iPanel = new Panel(); iPanel.setWidth("50px"); iPanel.setHeight("50px"); iPanel.setStyleName("backColorWhite"); addComponent(iPanel); String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); // Image as a file resource FileResource resource = new FileResource(new File(basepath + "/VAADIN/themes/mytheme/img/loginPage.jpg")); // Show the image in the application Image image = new Image("", resource); image.setSizeFull(); iPanel.setContent(image); }
From source file:com.parship.roperty.ui.LoginUI.java
License:Apache License
/** * The constructor should first build the main layout, set the * composition root and then do any custom initialization. * The constructor will not be automatically regenerated by the * visual editor.//from w w w . ja v a2 s . c o m */ public LoginUI() { buildMainLayout(); setCompositionRoot(mainLayout); // Set Logo // Find the application directory String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); FileResource resourceLogo = new FileResource(new File(basepath + "/WEB-INF/images/roperty-logo.png")); logoImage.setSource(resourceLogo); /* MenuBar */ // About MenuBar.MenuItem about = menuBar.addItem("About Roperty", null); about.addItem("Visit Website", null); about.addItem("Team", null); // Debug MenuBar.MenuItem debug = menuBar.addItem("Debug", null); debug.addItem("Logout", new LogoutCommand()); // Enter-Listener for login ShortcutListener enterListener = new ShortcutListener("ENTER", ShortcutAction.KeyCode.ENTER, null) { private static final long serialVersionUID = 1L; @Override public void handleAction(Object sender, Object target) { if (target == passTextField || target == userTextField) { buttonClick(null); } } }; this.userTextField.addShortcutListener(enterListener); this.passTextField.addShortcutListener(enterListener); this.userTextField.setInputPrompt("Username"); this.passTextField.setInputPrompt("Password"); String prevUser = RopertyUiSession.getPreviousUserName(); if (prevUser != null) { this.userTextField.setValue(prevUser); this.passTextField.focus(); } else { this.userTextField.focus(); } String rememberMe = RopertyUiSession.wasRememberMe(); if (rememberMe != null && rememberMe.equals("true")) { this.keeploggedinLabel.setValue(true); } this.loginButton.addClickListener(this); if (UserManager.isLoggedIn()) { buttonClick(null); } }
From source file:com.parship.roperty.ui.NavigationViewUI.java
License:Apache License
/** * The constructor should first build the main layout, set the * composition root and then do any custom initialization. * The constructor will not be automatically regenerated by the * visual editor./*from w w w.java2s. co m*/ */ public NavigationViewUI() { buildMainLayout(); setCompositionRoot(mainLayout); /* Menu Bar */ // User Menu User currentUser = UserManager.getCurrentUser(); if (currentUser != null) { String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); FileResource resourceCloudIcon = new FileResource( new File(basepath + "/WEB-INF/images/icons/111-user.png")); MenuBar.MenuItem userMenu = mainMenuBar.addItem(currentUser.getFullName(), null); userMenu.setIcon(resourceCloudIcon); userMenu.addItem("Logout", new LogoutCommand()); } }
From source file:com.piccritic.website.post.CreatePost.java
public CreatePost(String handle, Post post) { this(handle); if (post != null) { this.post = post; title.setValue(post.getTitle()); description.setValue(post.getDescription()); setupImagereceiver();// www .j a va 2 s .c om image.setSource(new FileResource(receiver.getFile())); image.setVisible(true); confirm.setEnabled(true); } tags.setVisible(false); }
From source file:com.piccritic.website.post.CreatePost.java
@Override public void uploadSucceeded(SucceededEvent event) { // Show the uploaded file in the image viewer confirm.setEnabled(true);/*from ww w. jav a 2 s . com*/ image.setVisible(true); image.setSource(new FileResource(receiver.getFile())); Notification.show("Image Saved", Type.TRAY_NOTIFICATION); upload.setButtonCaption(null); }
From source file:com.piccritic.website.post.ViewPost.java
@Override public void enter(ViewChangeEvent event) { PostServiceInterface service = MasterService.postService; post = service.getPost(event.getParameters()); if (post == null) { Notification.show("Error 404" + event.getParameters(), Type.ERROR_MESSAGE); return;//from w w w .jav a 2 s.c o m } commentForm.setPost(post); image.setCaption(post.getTitle()); image.setSource(new FileResource(new File(post.getPath()))); image.setSizeFull(); postDescription.setValue(post.getDescription()); license.setCaption(post.getLicense().getLicenseType()); if (event.getParameters().matches("users/" + LoginService.getHandle() + "/.*")) { addComponent(delete); delete.addClickListener(e -> { try { service.deletePost(post); Notification.show("Post deleted successfuly", Type.TRAY_NOTIFICATION); } catch (PostException | CommentException | VoteException e1) { Notification.show(e1.getLocalizedMessage(), Type.WARNING_MESSAGE); } }); addComponent(edit); edit.addClickListener(e -> { UI.getCurrent().addWindow(new CreatePost(LoginService.getHandle(), post)); }); } if (LoginService.getLoginStatus() == LoginStatus.LOGGED_IN) { addComponent(commentForm); } try { comments = fs.getComments(post); } catch (PostException e) { e.printStackTrace(); } for (Comment comment : comments) { CommentComponent commentComponent = new CommentComponent(comment, fs, us); addComponent(commentComponent); } }
From source file:com.saax.gestorweb.presenter.ChatPresenter.java
/** * Cria botao para download de anexo/*from w ww . j av a 2s . co m*/ */ private Button buildButtonDownload(Anexo anexos) { Button exportar = new Button(); exportar.setIcon(FontAwesome.DOWNLOAD); exportar.addStyleName(ValoTheme.BUTTON_ICON_ONLY); exportar.addStyleName(ValoTheme.BUTTON_BORDERLESS); FileDownloader fd = new FileDownloader(new FileResource(new File(anexos.getCaminhoCompleto()))); fd.extend(exportar); return exportar; }
From source file:com.salsaw.msalsa.PhylogeneticTreeView.java
License:Apache License
public PhylogeneticTreeView(ClustalFileMapper clustalFileMapper) throws IOException { initializeUiComponents();//from w ww . ja v a 2 s. co m // Download alignment file Button aligmentButton = new Button("Download alignment"); Resource resAlignment = new FileResource(new File(clustalFileMapper.getAlignmentFilePath())); FileDownloader fdAln = new FileDownloader(resAlignment); fdAln.extend(aligmentButton); mainLayout.addComponent(aligmentButton); mainLayout.setComponentAlignment(aligmentButton, Alignment.MIDDLE_CENTER); // Download tree file Button downloadTreeButton = new Button("Download phylogentic tree"); Resource resTree = new FileResource(new File(clustalFileMapper.getTreeFilePath())); FileDownloader fdTree = new FileDownloader(resTree); fdTree.extend(downloadTreeButton); mainLayout.addComponent(downloadTreeButton); mainLayout.setComponentAlignment(downloadTreeButton, Alignment.MIDDLE_CENTER); // Add and center with HTML div svgHTMLPhylogenticTree = new Label("<div id='svgCanvas'></div>", ContentMode.HTML); svgHTMLPhylogenticTree.setWidth("-1px"); svgHTMLPhylogenticTree.setHeight("-1px"); mainLayout.addComponent(svgHTMLPhylogenticTree); mainLayout.setComponentAlignment(svgHTMLPhylogenticTree, Alignment.MIDDLE_CENTER); // Add tab with aligment content String aligmentFileContent = new String( Files.readAllBytes(Paths.get(clustalFileMapper.getAlignmentFilePath()))); TextArea aligmentFileTextArea = new TextArea("M-SALSA Aligment"); aligmentFileTextArea.setWordwrap(false); aligmentFileTextArea.setValue(aligmentFileContent); aligmentFileTextArea.setWidth("100%"); aligmentFileTextArea.setHeight("100%"); mainLayout.addComponent(aligmentFileTextArea); mainLayout.setComponentAlignment(aligmentFileTextArea, Alignment.MIDDLE_CENTER); // Add JavaScript component to generate phylogentic tree JsPhyloSVG jsPhyloSVG = new JsPhyloSVG(getPhylogeneticTreeFileContent(clustalFileMapper)); mainLayout.addComponent(jsPhyloSVG); setCompositionRoot(mainLayout); }