Example usage for com.vaadin.ui Html5File getFileSize

List of usage examples for com.vaadin.ui Html5File getFileSize

Introduction

In this page you can find the example usage for com.vaadin.ui Html5File getFileSize.

Prototype

public long getFileSize() 

Source Link

Usage

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();//  ww  w . ja  v a2s .  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:gov.va.ds4p.ds4pmobileportal.ui.eHealthDirect.java

License:Open Source License

private Panel getDropPanel() {
    Panel p = new Panel();
    VerticalLayout v = (VerticalLayout) p.getContent();
    v.setSpacing(true);//  w ww  .j  a v  a  2  s .c o m
    //v.setHeight("100%");
    p.setStyleName(Runo.PANEL_LIGHT);

    Panel wrapperPanel = new Panel();
    VerticalLayout vDPanel = (VerticalLayout) wrapperPanel.getContent();
    deleteBTN.setIcon(new ThemeResource("../runo/icons/64/folder-add.png"));
    deleteBTN.setWidth("64px");
    deleteBTN.setHeight("64px");

    vDPanel.addComponent(deleteBTN);
    final DragAndDropWrapper wrapper = new DragAndDropWrapper(wrapperPanel);
    wrapper.setWidth("100px");
    wrapper.setHeight("100px");

    wrapperPanel.setStyleName(Runo.PANEL_LIGHT);

    wrapper.setDropHandler(new DropHandler() {

        @Override
        public void drop(DragAndDropEvent event) {
            // expecting this to be an html5 drag
            DragAndDropWrapper.WrapperTransferable tr = (DragAndDropWrapper.WrapperTransferable) event
                    .getTransferable();
            Html5File[] files = tr.getFiles();
            if (files != null) {
                for (final Html5File html5File : files) {
                    final String fileName = html5File.getFileName();

                    if (html5File.getFileSize() > FILE_SIZE_LIMIT) {
                        getWindow().showNotification("File rejected. Max 2MB files are accepted by Sampler",
                                Window.Notification.TYPE_WARNING_MESSAGE);
                    } else {

                        final ByteArrayOutputStream bas = new ByteArrayOutputStream();
                        StreamVariable streamVariable = new StreamVariable() {

                            public OutputStream getOutputStream() {
                                return bas;
                            }

                            public boolean listenProgress() {
                                return false;
                            }

                            public void onProgress(StreamVariable.StreamingProgressEvent event) {
                            }

                            public void streamingStarted(StreamVariable.StreamingStartEvent event) {
                            }

                            public void streamingFinished(StreamVariable.StreamingEndEvent event) {
                                progress.setVisible(false);
                                Boolean res = updateProviderProcessingInbox(bas.toByteArray());
                                if (res.booleanValue()) {
                                    getWindow().showNotification(
                                            "Processing Complete: " + fileName + " " + html5File.getType() + " "
                                                    + html5File.getFileSize(),
                                            Window.Notification.TYPE_HUMANIZED_MESSAGE);
                                } else {
                                    getWindow().showNotification(
                                            "Processing Error: You Do Not Have Necessary Permissions to Receive and Process Files.",
                                            Window.Notification.TYPE_TRAY_NOTIFICATION);
                                }
                            }

                            public void streamingFailed(StreamVariable.StreamingErrorEvent event) {
                                progress.setVisible(false);
                            }

                            public boolean isInterrupted() {
                                return false;
                            }
                        };
                        html5File.setStreamVariable(streamVariable);
                        progress.setVisible(true);
                    }
                }

            } else {
                String text = tr.getText();
                if (text != null) {
                    getWindow().showNotification(text, Window.Notification.TYPE_HUMANIZED_MESSAGE);
                }
            }
        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    v.addComponent(wrapper);

    return p;
}

From source file:org.escidoc.browser.ui.dnd.FilesDropBox.java

License:Open Source License

private void handleFiles(final DragAndDropEvent dropEvent) {
    numberOfFiles = getFilesFrom(dropEvent).length;

    for (final Html5File html5File : getFilesFrom(dropEvent)) {
        if (html5File.getFileSize() > FILE_SIZE_LIMIT) {
            showFileSizeWarning();//from   w  w w . j  a  v  a2  s.c  o m
            return;
        }
        html5File.setStreamVariable(createStreamVariable(html5File));
        progressView.setVisible(true);
    }
}

From source file:org.escidoc.browser.ui.dnd.FilesDropBox.java

License:Open Source License

private static boolean isFolder(final DragAndDropEvent dropEvent) {
    for (final Html5File html5File : getFilesFrom(dropEvent)) {
        return html5File.getFileSize() == 0;
    }/*from   w  w w  .  j  a va  2  s .  c om*/
    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();/*  www . j  av a2  s  .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();/*from   w  ww  . ja va2s . 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);
        }
    }
}

From source file:v7cr.vaadin.V7MultiFileUpload.java

License:Open Source License

public void drop(DragAndDropEvent event) {
    DragAndDropWrapper.WrapperTransferable transferable = (WrapperTransferable) event.getTransferable();
    Html5File[] files = transferable.getFiles();
    for (final Html5File html5File : files) {
        final ProgressIndicator pi = new ProgressIndicator();
        pi.setCaption(html5File.getFileName());
        progressBars.addComponent(pi);//from  ww  w. j a v a 2 s.c  o m
        final FileBuffer receiver = createReceiver();
        html5File.setStreamVariable(new StreamVariable() {

            private String name;
            private String mime;

            public OutputStream getOutputStream() {
                return receiver.receiveUpload(name, mime);
            }

            public boolean listenProgress() {
                return true;
            }

            public void onProgress(StreamingProgressEvent event) {
                float p = (float) event.getBytesReceived() / (float) event.getContentLength();
                pi.setValue(p);
            }

            public void streamingStarted(StreamingStartEvent event) {
                name = event.getFileName();
                mime = event.getMimeType();

            }

            public void streamingFinished(StreamingEndEvent event) {
                progressBars.removeComponent(pi);
                handleFile(receiver.getFile(), html5File.getFileName(), html5File.getType(),
                        html5File.getFileSize());
                receiver.setValue(null);
            }

            public void streamingFailed(StreamingErrorEvent event) {
                progressBars.removeComponent(pi);
            }

            public boolean isInterrupted() {
                return false;
            }
        });
    }

}