List of usage examples for com.vaadin.server StreamVariable StreamVariable
StreamVariable
From source file:com.hivesys.dashboard.view.repository.DragAndDropBox.java
@Override public void drop(final DragAndDropEvent dropEvent) { // expecting this to be an html5 drag final DragAndDropWrapper.WrapperTransferable tr = (DragAndDropWrapper.WrapperTransferable) dropEvent .getTransferable();/*from w w w.j ava 2 s . c om*/ final Html5File[] files = tr.getFiles(); if (files != null) { for (final Html5File html5File : files) { final String fileName = html5File.getFileName(); if (html5File.getFileSize() > FILE_SIZE_LIMIT) { Notification.show("File rejected. Max 100Mb files are accepted!", Notification.Type.WARNING_MESSAGE); } else { final ByteArrayOutputStream bas = new ByteArrayOutputStream(); final StreamVariable streamVariable = new StreamVariable() { @Override public OutputStream getOutputStream() { return bas; } @Override public boolean listenProgress() { return false; } @Override public void onProgress(final StreamVariable.StreamingProgressEvent event) { } @Override public void streamingStarted(final StreamVariable.StreamingStartEvent event) { } @Override public void streamingFinished(final StreamVariable.StreamingEndEvent event) { progress.setVisible(false); showFile(fileName, html5File.getType(), bas); processFile(fileName, html5File.getType(), bas); } @Override public void streamingFailed(final StreamVariable.StreamingErrorEvent event) { progress.setVisible(false); } @Override public boolean isInterrupted() { return false; } }; html5File.setStreamVariable(streamVariable); progress.setVisible(true); } } } else { final String text = tr.getText(); if (text != null) { showText(text); } } }
From source file:com.klwork.explorer.ui.custom.UploadComponent.java
License:Apache License
public void drop(DragAndDropEvent event) { WrapperTransferable transferable = (WrapperTransferable) event.getTransferable(); Html5File[] files = transferable.getFiles(); if (files.length > 0) { final Html5File file = files[0]; // only support for one file upload at this moment file.setStreamVariable(new StreamVariable() { private static final long serialVersionUID = 1L; public void streamingStarted(StreamingStartEvent event) { uploadStarted(null); // event doesnt matter here }/*from ww w. j a v a 2s.c o m*/ public void streamingFinished(StreamingEndEvent event) { uploadFinished(null); // event doesnt matter here } public void streamingFailed(StreamingErrorEvent event) { uploadFailed(null); } public void onProgress(StreamingProgressEvent event) { updateProgress(event.getBytesReceived(), event.getContentLength()); } public boolean listenProgress() { return true; } public boolean isInterrupted() { return false; } public OutputStream getOutputStream() { return receiver.receiveUpload(file.getFileName(), file.getType()); } }); } }
From source file:com.wintindustries.pfserver.uploads.PFUploadUnit.java
public void upload() { final ProgressIndicator pi = new ProgressIndicator(); pi.setCaption(html5File.getFileName()); progress.setCaption(html5File.getFileName()); getprogressBarsLayout().addComponent(pi); final FileBuffer receiver = createReceiver(); html5File.setStreamVariable(new StreamVariable() { private String name; private String mime; public OutputStream getOutputStream() { return receiver.receiveUpload(name, mime); }/*from w w w . ja v a 2 s .com*/ public boolean listenProgress() { return true; } public void onProgress(StreamVariable.StreamingProgressEvent event) { float p = (float) event.getBytesReceived() / (float) event.getContentLength(); pi.setValue(p); progress.setProgress(p); } public void streamingStarted(StreamVariable.StreamingStartEvent event) { name = event.getFileName(); mime = event.getMimeType(); progress.setProgressState(progress.kUPLOADPROGRESS_UPLOADING); } public void streamingFinished(StreamVariable.StreamingEndEvent event) { getprogressBarsLayout().removeComponent(pi); handleFile(receiver.getFile(), html5File.getFileName(), html5File.getType(), html5File.getFileSize()); receiver.setValue(null); progress.setProgressState(progress.kUPLOADPROGRESS_DONE); } public void streamingFailed(StreamVariable.StreamingErrorEvent event) { getprogressBarsLayout().removeComponent(pi); progress.setProgressState(progress.kUPLOADPROGRESS_ERROR); progress.setErrmsg(event.toString()); Notification note = new Notification("Upload Failed", event.toString(), Notification.Type.ERROR_MESSAGE); note.show(Page.getCurrent()); } public boolean isInterrupted() { return false; } }); }
From source file:info.magnolia.ui.form.field.upload.AbstractUploadField.java
License:Open Source License
/** * Drop zone Handler./* www. j av a 2s . c om*/ */ @Override public void drop(DragAndDropEvent event) { final DragAndDropWrapper.WrapperTransferable transferable = (WrapperTransferable) event.getTransferable(); final Html5File[] files = transferable.getFiles(); if (files == null) { return; } // start polling immediately on drop startPolling(); for (final Html5File html5File : files) { html5File.setStreamVariable(new StreamVariable() { private String name; private String mime; @Override public OutputStream getOutputStream() { return getValue().receiveUpload(name, mime); } @Override public boolean listenProgress() { return true; } @Override public void onProgress(StreamingProgressEvent event) { updateProgress(event.getBytesReceived(), event.getContentLength()); } @Override public void streamingStarted(StreamingStartEvent event) { setDragAndDropUploadInterrupted(false); name = event.getFileName(); mime = event.getMimeType(); if (StringUtils.isEmpty(mime)) { String extension = StringUtils.substringAfterLast(name, "."); mime = MIMEMapping.getMIMEType(extension); if (StringUtils.isEmpty(mime)) { log.warn("Couldn't find mimeType in MIMEMappings for file extension: {}", extension); } } StartedEvent startEvent = new StartedEvent(upload, name, mime, event.getContentLength()); uploadStarted(startEvent); } @Override public void streamingFinished(StreamingEndEvent event) { FinishedEvent uploadEvent = new FinishedEvent(upload, event.getFileName(), event.getMimeType(), event.getContentLength()); uploadFinished(uploadEvent); } @Override public void streamingFailed(StreamingErrorEvent event) { FailedEvent failedEvent = new FailedEvent(upload, event.getFileName(), event.getMimeType(), event.getContentLength()); uploadFailed(failedEvent); setDragAndDropUploadInterrupted(false); } @Override public synchronized boolean isInterrupted() { return isDragAndDropUploadInterrupted(); } }); } }
From source file:net.pkhsolutions.pecsapp.ui.components.PictureLayout.java
License:Open Source License
private void uploadFile(Html5File file) { final MimeType mimeType = MimeType.valueOf(file.getType()); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final StreamVariable streamVariable = new StreamVariable() { @Override//from w ww .j a va 2s . c o m public OutputStream getOutputStream() { return baos; } @Override public boolean listenProgress() { return false; } @Override public void onProgress(StreamingProgressEvent event) { } @Override public void streamingStarted(StreamingStartEvent event) { } @Override public void streamingFinished(StreamingEndEvent event) { hideProgressBar(); model.upload(new ByteArrayInputStream(baos.toByteArray()), mimeType); } @Override public void streamingFailed(StreamingErrorEvent event) { hideProgressBar(); } @Override public boolean isInterrupted() { return false; } }; showProgressBar(); file.setStreamVariable(streamVariable); }
From source file:org.hip.vif.web.util.UploadComponent.java
License:Open Source License
private StreamVariable createStreamVariable(final String inFileName, // NOPMD final IBibliographyTask inTask) { return new StreamVariable() { @Override/* w w w. j a v a 2 s .co m*/ public OutputStream getOutputStream() { // NOPMD return createStream(inFileName); } @Override public void streamingStarted(final StreamingStartEvent inEvent) { // NOPMD fileInfo = new FileInfo(inEvent.getFileName(), inEvent.getMimeType()); tempUpload = null; // NOPMD uploadFinished = false; upload.setVisible(false); if (hasDownloads) { dialog.setVisible(true); // Google } } @Override public void streamingFinished(final StreamingEndEvent inEvent) { // NOPMD uploadFinished = true; upload.setVisible(true); if (!hasDownloads) { handleUpload(inTask, false); } } @Override public void streamingFailed(final StreamingErrorEvent inEvent) { // NOPMD handleDeleteTemp(); } @Override public void onProgress(final StreamingProgressEvent inEvent) { // NOPMD // intentionally left empty } @Override public boolean listenProgress() { // NOPMD return false; } @Override public boolean isInterrupted() { // NOPMD return false; } }; }
From source file:org.vaadin.easyuploads.MultiFileUploadExt.java
License:Open Source License
@Override public void drop(DragAndDropEvent event) { DragAndDropWrapper.WrapperTransferable transferable = (DragAndDropWrapper.WrapperTransferable) event .getTransferable();/* w w w .j a va 2s . c o m*/ Html5File[] files = transferable.getFiles(); for (final Html5File html5File : files) { final ProgressBar pi = new ProgressBar(); pi.setCaption(html5File.getFileName()); progressBars.addComponent(pi); final FileBuffer receiver = createReceiver(); html5File.setStreamVariable(new StreamVariable() { private static final long serialVersionUID = 1L; private String name; private String mime; @Override public OutputStream getOutputStream() { return receiver.receiveUpload(name, mime); } @Override public boolean listenProgress() { return true; } @Override public void onProgress(StreamVariable.StreamingProgressEvent event) { float p = (float) event.getBytesReceived() / (float) event.getContentLength(); pi.setValue(p); } @Override public void streamingStarted(StreamVariable.StreamingStartEvent event) { name = event.getFileName(); mime = event.getMimeType(); UI.getCurrent().setPollInterval(300); } @Override public void streamingFinished(StreamVariable.StreamingEndEvent event) { progressBars.removeComponent(pi); handleFile(receiver.getFile(), html5File.getFileName(), html5File.getType(), html5File.getFileSize()); receiver.setValue(null); } @Override public void streamingFailed(StreamVariable.StreamingErrorEvent event) { progressBars.removeComponent(pi); } @Override public boolean isInterrupted() { return false; } }); } }
From source file:ui.helper.ImageDropBox.java
License:Apache License
@Override public void drop(final DragAndDropEvent dropEvent) { // expecting this to be an html5 drag Notification.show("Drop Event...", Notification.Type.WARNING_MESSAGE); final DragAndDropWrapper.WrapperTransferable tr = (DragAndDropWrapper.WrapperTransferable) dropEvent .getTransferable();//w w w . j av a2 s. c o m final Html5File[] files = tr.getFiles(); if (files != null) { for (final Html5File html5File : files) { final String fileName = html5File.getFileName(); if (html5File.getFileSize() > FILE_SIZE_LIMIT) { Notification.show("File rejected. Max 2Mb files are accepted by Sampler", Notification.Type.WARNING_MESSAGE); } else { final ByteArrayOutputStream bas = new ByteArrayOutputStream(); final StreamVariable streamVariable = new StreamVariable() { @Override public OutputStream getOutputStream() { return bas; } @Override public boolean listenProgress() { return false; } @Override public void onProgress(final StreamVariable.StreamingProgressEvent event) { } @Override public void streamingStarted(final StreamVariable.StreamingStartEvent event) { } @Override public void streamingFinished(final StreamVariable.StreamingEndEvent event) { storeImageInDB(bas.toByteArray()); showFile(fileName, html5File.getType(), bas); progress.setVisible(false); } @Override public void streamingFailed(final StreamVariable.StreamingErrorEvent event) { progress.setVisible(false); } @Override public boolean isInterrupted() { return false; } private void storeImageInDB(byte[] bytes) { Notification.show("Storing in DB", Notification.Type.WARNING_MESSAGE); ServiceLocator.findLifetimeService().addUserPhoto(userId, bytes); } }; html5File.setStreamVariable(streamVariable); progress.setVisible(true); } } } else { final String text = tr.getText(); if (text != null) { showText(text); } } }