List of usage examples for com.vaadin.server FileResource FileResource
public FileResource(File sourceFile)
From source file:annis.gui.controlpanel.ExportPanel.java
License:Apache License
@Override public void buttonClick(ClickEvent event) { // clean up old export if (tmpOutputFile != null && tmpOutputFile.exists()) { if (!tmpOutputFile.delete()) { log.warn("Could not delete {}", tmpOutputFile.getAbsolutePath()); }// w w w . jav a 2 s .c o m } tmpOutputFile = null; String exporterName = (String) cbExporter.getValue(); final Exporter exporter = exporterMap.get(exporterName); if (exporter != null) { if (corpusListPanel.getSelectedCorpora().isEmpty()) { Notification.show("Please select a corpus", Notification.Type.WARNING_MESSAGE); btExport.setEnabled(true); return; } Callable<File> callable = new Callable<File>() { @Override public File call() throws Exception { File currentTmpFile = File.createTempFile("annis-export", ".txt"); currentTmpFile.deleteOnExit(); exporter.convertText(queryPanel.getQuery(), Integer.parseInt((String) cbLeftContext.getValue()), Integer.parseInt((String) cbRightContext.getValue()), corpusListPanel.getSelectedCorpora(), null, (String) txtParameters.getValue(), Helper.getAnnisWebResource().path("query"), new OutputStreamWriter(new FileOutputStream(currentTmpFile), "UTF-8")); return currentTmpFile; } }; FutureTask<File> task = new FutureTask<File>(callable) { @Override protected void done() { VaadinSession session = VaadinSession.getCurrent(); session.lock(); try { btExport.setEnabled(true); progressIndicator.setEnabled(false); try { // copy the result to the class member in order to delete if // when not longer needed tmpOutputFile = get(); } catch (InterruptedException ex) { log.error(null, ex); } catch (ExecutionException ex) { log.error(null, ex); } if (tmpOutputFile == null) { Notification.show("Could not create the Exporter", "The server logs might contain more information about this " + "so you should contact the provider of this ANNIS installation " + "for help.", Notification.Type.ERROR_MESSAGE); } else { if (downloader != null && btDownload.getExtensions().contains(downloader)) { btDownload.removeExtension(downloader); } downloader = new FileDownloader(new FileResource(tmpOutputFile)); downloader.extend(btDownload); btDownload.setEnabled(true); Notification.show("Export finished", "Click on the button right to the export button to actually download the file.", Notification.Type.HUMANIZED_MESSAGE); } } finally { session.unlock(); } } }; progressIndicator.setEnabled(true); ExecutorService singleExecutor = Executors.newSingleThreadExecutor(); singleExecutor.submit(task); } }
From source file:annis.gui.ExportPanel.java
License:Apache License
public void showResult(File currentTmpFile, boolean manuallyCancelled) { btExport.setEnabled(true);//w w w . ja va 2s . c o m btCancel.setEnabled(false); progressBar.setVisible(false); progressLabel.setValue(""); // copy the result to the class member in order to delete if // when not longer needed tmpOutputFile = currentTmpFile; if (tmpOutputFile == null) { Notification.show("Could not create the Exporter", "The server logs might contain more information about this " + "so you should contact the provider of this ANNIS installation " + "for help.", Notification.Type.ERROR_MESSAGE); } else if (manuallyCancelled) { // we were aborted, don't do anything Notification.show("Export cancelled", Notification.Type.WARNING_MESSAGE); } else { if (downloader != null && btDownload.getExtensions().contains(downloader)) { btDownload.removeExtension(downloader); } downloader = new FileDownloader(new FileResource(tmpOutputFile)); downloader.extend(btDownload); btDownload.setEnabled(true); Notification.show("Export finished", "Click on the button right to the export button to actually download the file.", Notification.Type.HUMANIZED_MESSAGE); } }
From source file:au.org.scoutmaster.views.ContactView.java
private DateField overviewTab() { // Overview tab final SMMultiColumnFormLayout<Contact> overviewForm = new SMMultiColumnFormLayout<Contact>(3, this.fieldGroup); overviewForm.setColumnFieldWidth(0, 100); overviewForm.setColumnLabelWidth(1, 0); overviewForm.setColumnFieldWidth(1, 140); overviewForm.setColumnLabelWidth(2, 40); overviewForm.setColumnFieldWidth(2, 80); overviewForm.setMargin(true);//www .j av a 2 s . co m // overviewForm.setColumnLabelWidth(0, 100); // overviewForm.setColumnLabelWidth(1, 0); // overviewForm.setColumnLabelWidth(2, 60); // overviewForm.setColumnFieldWidth(0, 100); // overviewForm.setColumnFieldWidth(1, 100); // overviewForm.setColumnFieldWidth(2, 20); // overviewForm.setSizeFull(); final FormHelper<Contact> formHelper = overviewForm.getFormHelper(); // overviewForm.setMargin(true); this.tabs.addTab(overviewForm, "Overview"); overviewForm.bindBooleanField("Active", Contact_.active); overviewForm.newLine(); overviewForm.colspan(3); this.groupRoleField = formHelper.new EntityFieldBuilder<GroupRole>().setLabel("Role") .setField(Contact_.groupRole).setListFieldName(GroupRole_.name).build(); this.groupRoleField.addValueChangeListener(this.changeListener); overviewForm.newLine(); overviewForm.colspan(3); overviewForm.bindTextField("Firstname", Contact_.firstname); overviewForm.newLine(); overviewForm.colspan(3); overviewForm.bindTextField("Middle name", Contact_.middlename); overviewForm.newLine(); overviewForm.colspan(3); overviewForm.bindTextField("Lastname", Contact_.lastname); overviewForm.newLine(); this.birthDate = overviewForm.bindDateField("Birth Date", Contact_.birthDate, "yyyy-MM-dd", Resolution.DAY); // fieldOverviewSectionEligibity = overviewForm.addTextField(null); // fieldOverviewSectionEligibity.setReadOnly(true); this.ageField = overviewForm.bindLabel("Age"); // overviewForm.setComponentAlignment(this.ageField, // Alignment.MIDDLE_LEFT); overviewForm.newLine(); overviewForm.bindEnumField("Gender", Contact_.gender, Gender.class); overviewForm.newLine(); overviewForm.colspan(3); overviewForm.bindBooleanField("Do Not Send Bulk Communications", Contact_.doNotSendBulkCommunications); overviewForm.newLine(); overviewForm.colspan(3); overviewForm.bindEnumField("Preferred Communications", Contact_.preferredCommunications, PreferredCommunications.class); overviewForm.newLine(); overviewForm.colspan(3); final TextField homeEmail = overviewForm.bindTextField("Home Email", Contact_.homeEmail); final String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); final FileResource resource = new FileResource(new File(basepath + "/WEB-INF/images/email.png")); this.homeEmailImage = new Image(null, resource); this.homeEmailImage.setDescription("Click to send an email"); this.homeEmailImage.addClickListener(new MouseEventLogged.ClickListener() { private static final long serialVersionUID = 1L; @Override public void clicked(final com.vaadin.event.MouseEvents.ClickEvent event) { showMailForm(homeEmail); } }); overviewForm.addComponent(this.homeEmailImage); this.homeEmailImage.setVisible(false); overviewForm.newLine(); overviewForm.colspan(3); final TextField workEmail = overviewForm.bindTextField("Work Email", Contact_.workEmail); this.workEmailImage = new Image(null, resource); this.workEmailImage.setDescription("Click to send an email"); overviewForm.addComponent(this.workEmailImage); this.workEmailImage.addClickListener(new MouseEventLogged.ClickListener() { private static final long serialVersionUID = 1L; @Override public void clicked(final com.vaadin.event.MouseEvents.ClickEvent event) { showMailForm(workEmail); } }); this.workEmailImage.setVisible(false); overviewForm.newLine(); overviewForm.bindTextField("Phone 1", "phone1.phoneNo"); overviewForm.bindEnumField(null, "phone1.phoneType", PhoneType.class); this.primaryPhone1 = overviewForm.bindBooleanField("Primary", Contact_.phone1.getName() + "." + Phone_.primaryPhone.getName()); this.primaryPhone1.addValueChangeListener(new PhoneChangeListener()); overviewForm.newLine(); overviewForm.bindTextField("Phone 2", "phone2.phoneNo"); overviewForm.bindEnumField(null, "phone2.phoneType", PhoneType.class); this.primaryPhone2 = overviewForm.bindBooleanField("Primary", "phone2.primaryPhone"); this.primaryPhone2.addValueChangeListener(new PhoneChangeListener()); overviewForm.newLine(); overviewForm.bindTextField("Phone 3", "phone3.phoneNo"); overviewForm.bindEnumField(null, "phone3.phoneType", PhoneType.class); this.primaryPhone3 = overviewForm.bindBooleanField("Primary", "phone3.primaryPhone"); this.primaryPhone3.addValueChangeListener(new PhoneChangeListener()); overviewForm.newLine(); overviewForm.colspan(3); overviewForm.bindTextField("Street", "address.street"); overviewForm.newLine(); overviewForm.colspan(3); overviewForm.bindTextField("City", "address.city"); overviewForm.newLine(); overviewForm.bindTextField("State", "address.state"); overviewForm.bindTextField("Postcode", "address.postcode"); overviewForm.newLine(); overviewForm.colspan(3); this.tagField = overviewForm.bindTagField(this, "Tags", Contact_.tags); // tabs.addTab(overviewForm, "Contact"); return this.birthDate; }
From source file:by.bigvova.MainUI.java
License:Apache License
@Subscribe private void updateUserMenu(final ProfileUpdatedEvent event) { UserTo userTo = controller.getUserTo(); String imageName = userTo.getImageName(); String fullPathToProfileImage = pathToProfileImage + '/' + imageName; settingsItem.setText(userTo.getName()); String relativePathToProfileImage = UserControllerUtils.getPathToProfileImage(userTo, true); if (Files.exists(Paths.get(fullPathToProfileImage))) { resource = new FileResource(new File(fullPathToProfileImage)); } else {//from w ww . j a va 2s . co m resource = new ThemeResource(relativePathToProfileImage + "profile-pic-300px.jpg"); } settingsItem.setIcon(resource); }
From source file:ch.bfh.ti.soed.hs16.srs.view.views.helpers.Header.java
License:Open Source License
public Header() { /* init objects */ this.layout = new VerticalLayout(); // find application in directory String basePath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); // image as file resource // TODO Yep, logo appears. However, file should be retrieved from // location within JAR file. Consult Vaadin documentation on how to do // this.//from www . j a v a 2 s . com FileResource fileResource = new FileResource(new File(basePath + File.separator + "VAADIN" + File.separator + "themes" + File.separator + "mytheme" + File.separator + "srsLogo.jpg")); Image pic = new Image("", fileResource); /* add components to layout */ this.layout.addComponents(pic); }
From source file:com.adonis.ui.menu.Menu.java
private void createViewButtonWithEditableImage(final String name, String caption, String nameImage) { Button button = new Button(caption, new ClickListener() { @Override/*w w w.ja va 2 s .co m*/ public void buttonClick(ClickEvent event) { navigator.navigateTo(name); } }); button.setPrimaryStyleName(ValoTheme.BUTTON_FRIENDLY); // button.setWidth(50, Unit.PERCENTAGE); image.setWidth(90, Unit.PIXELS); image.setHeight(90, Unit.PIXELS); FileReader.createDirectoriesFromCurrent(getInitialPath()); final Image image = new Image("", new ThemeResource("img/" + nameImage)); try { FileReader.copyFile(VaadinUtils.getResourcePath(nameImage), VaadinUtils.getInitialPath() + File.separator + nameImage); image.setSource(new FileResource(new File(VaadinUtils.getInitialPath() + File.separator + nameImage))); } catch (IOException e) { e.printStackTrace(); image.setSource(new ThemeResource("img/" + nameImage)); } // image.setWidth(50, Unit.PERCENTAGE); image.setWidth(90, Unit.PIXELS); image.setHeight(90, Unit.PIXELS); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setPrimaryStyleName(ValoTheme.MENU_ITEM); horizontalLayout.addComponents(image, button); image.addClickListener(new MouseEvents.ClickListener() { @Override public void click(MouseEvents.ClickEvent event) { uploadFieldImage = new UploadField(); uploadFieldImage.setAcceptFilter("image/*"); uploadFieldImage.getUpload().addListener(new com.vaadin.v7.ui.Upload.FailedListener() { @Override public void uploadFailed(com.vaadin.v7.ui.Upload.FailedEvent event) { uploadFieldImage.clearDefaulLayout(); horizontalLayout.removeComponent(uploadFieldImage); } private static final long serialVersionUID = 1L; }); horizontalLayout.addComponent(uploadFieldImage, 2); uploadFieldImage.getUpload().addListener(new com.vaadin.v7.ui.Upload.SucceededListener() { @Override public void uploadSucceeded(com.vaadin.v7.ui.Upload.SucceededEvent event) { File file = (File) uploadFieldImage.getValue(); try { showUploadedImage(uploadFieldImage, image, file.getName(), nameImage); } catch (IOException e) { e.printStackTrace(); } uploadFieldImage.clearDefaulLayout(); horizontalLayout.removeComponent(uploadFieldImage); } }); uploadFieldImage.setFieldType(UploadField.FieldType.FILE); horizontalLayout.markAsDirty(); // image.setWidth(50, Unit.PERCENTAGE); image.setWidth(90, Unit.PIXELS); image.setHeight(90, Unit.PIXELS); image.setVisible(false); image.markAsDirty(); horizontalLayout.addComponent(image, 0); } }); button.setVisible(true); image.setVisible(true); menuItemsLayout.addComponents(horizontalLayout); viewButtons.put(name, button); }
From source file:com.anphat.customer.controller.CommonUploader.java
public void exportFileErr(String mess, String fileErrorName) { try {/*from ww w . ja v a2s . c o m*/ workbookEp.write(fileOut); fileOut.close(); fileOut.flush(); } catch (IOException ex) { ex.printStackTrace(); } File fileError = new File(fileErrorName); fileError.deleteOnExit(); Resource resource = new FileResource(fileError); Page.getCurrent().open(resource, null, false); // Notification.show(mess, Notification.Type.WARNING_MESSAGE); wp.close(); UI.getCurrent().setPollInterval(-1); }
From source file:com.anphat.customer.controller.ExportContractToDocController.java
private void buildFile() { try {//from w w w .jav a 2 s .co m FileOutputStream out = new FileOutputStream(pathFileOuput); document.write(out); out.close(); final File exportFile = new File(pathFileOuput); if (exportFile.exists()) { ConfirmDialog.show(UI.getCurrent(), BundleUtils.getString("delete.item.title"), BundleUtils.getString("confirm.contract.doc"), BundleUtils.getString("yes"), BundleUtils.getString("no"), new ConfirmDialog.Listener() { @Override public void onClose(ConfirmDialog dialog) { if (dialog.isConfirmed()) { Resource res = new FileResource(exportFile); Page.getCurrent().open(res, BundleUtils.getString("label.caption.download") .replace("@name", BundleUtils.getString("contract.doc.caption")), true); } } }); } else { //Thong bao khong the tai file CommonMessages.showExportFail("contract.doc.caption"); } exportFile.deleteOnExit(); } catch (IOException ex) { CommonMessages.showExportFail("contract.doc.caption"); // ex.printStackTrace(); } }
From source file:com.anphat.list.controller.ListStaffController.java
private void addActionListener() { btnExcelExport.addClickListener(new Button.ClickListener() { @Override/*from www . j a va 2 s . c o m*/ public void buttonClick(Button.ClickEvent event) { List<StaffDTO> lstStaffInfo = new ArrayList<>(); Collection collection = (Collection) tblStaffs.getItemIds(); lstStaffInfo.addAll(collection); if (!DataUtil.isListNullOrEmpty(lstStaffInfo)) { File fileExport = exportFile(lstStaffInfo); Resource res = new FileResource(fileExport); Page.getCurrent().open(res, BundleUtils.getString("label.caption.download").replace("@name", BundleUtils.getString("staff.department.listStaff")), true); } else { //Thong bao khong co du lieu xuat file CommonMessages.showWarningMessage(BundleUtils.getString("common.warning.export.noData")); } } }); }
From source file:com.cerebro.cable.xforce.view.GestioneRazze.java
public GestioneRazze() { setMargin(true);//w w w. j a va 2s . c o m TableQuery racesTQ = new TableQuery("races", connPool); SQLContainer racesContainer = null; try { racesContainer = new SQLContainer(racesTQ); } catch (Exception ex) { logger.error("Errore nella tabella delle razze: " + ex.getMessage()); } Grid racesTable = new Grid(racesContainer); racesTable.removeAllColumns(); for (int i = 0; i < racesTabCols.length; i++) { racesTable.addColumn(racesTabCols[i][0]); Grid.Column col = racesTable.getColumn(racesTabCols[i][0]); col.setHeaderCaption(racesTabCols[i][1]); } racesTable.getColumn("image").setRenderer(new ImageRenderer(), new Converter<Resource, String>() { @Override public String convertToModel(Resource value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException { return "not needed"; } @Override public Resource convertToPresentation(String value, Class<? extends Resource> targetType, Locale locale) throws Converter.ConversionException { return new FileResource( new File(VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + value)); } @Override public Class<String> getModelType() { return String.class; } @Override public Class<Resource> getPresentationType() { return Resource.class; } }); FormLayout raceEditor = new FormLayout(); addComponents(racesTable); }