Example usage for com.vaadin.ui Html5File getType

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

Introduction

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

Prototype

public String getType() 

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();/*from   w w w . ja  va2  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 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  www  .  j ava2 s.  co 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: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);//from  ww  w.  jav a2s.  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:net.pkhsolutions.pecsapp.ui.components.PictureLayout.java

License:Open Source License

private boolean isSupportedFile(Html5File file) {
    return model.isSupportedType(MimeType.valueOf(file.getType())); // TODO also check max size
}

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  w  w.  j  a va  2 s  .c  om
        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.activiti.explorer.ui.custom.UploadComponent.java

License:Apache License

public void drop(DragAndDropEvent event) {
    WrapperTransferable transferable = (WrapperTransferable) event.getTransferable();
    Html5File[] files = transferable.getFiles();
    if (files != null && 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  va 2 s.com

            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:org.vaadin.easyuploads.MultiFileUploadExt.java

License:Open Source License

@Override
public void drop(DragAndDropEvent event) {
    DragAndDropWrapper.WrapperTransferable transferable = (DragAndDropWrapper.WrapperTransferable) event
            .getTransferable();/*  w  ww  .ja 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 .  jav  a 2 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);
        }
    }
}

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  a2  s.c om
        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;
            }
        });
    }

}