Example usage for com.vaadin.ui Upload getReceiver

List of usage examples for com.vaadin.ui Upload getReceiver

Introduction

In this page you can find the example usage for com.vaadin.ui Upload getReceiver.

Prototype

public Receiver getReceiver() 

Source Link

Document

Returns the current receiver.

Usage

From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultRowEditingFormView.java

License:Apache License

private Upload buildUpload(final ContainerRow row, final ContainerBlob containerBlob,
        final FileMetadata metadata, final Link downloadLink) {
    final Upload upload = new Upload();
    if (metadata.getUploadCaption() != null) {
        upload.setButtonCaption(metadata.getUploadCaption());
    } else {//from  w  ww  . ja  v a2 s . c o  m
        upload.setButtonCaption("Upload");
    }
    upload.setImmediate(true);
    upload.setReceiver(new BlobUploadReceiver());

    upload.addFinishedListener(new Upload.FinishedListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void uploadFinished(FinishedEvent event) {
            BlobUploadReceiver receiver = (BlobUploadReceiver) upload.getReceiver();
            if (receiver.getBaos().size() <= 0 || receiver.getBaos().size() <= metadata.getMaxFileSize()) {
                containerBlob.setValue(receiver.getBaos().toByteArray());
                if (metadata.getFilenameColumn() != null) {
                    row.getValues().put(metadata.getFilenameColumn(), receiver.getFilename());

                }
                if (metadata.getMimetypeColumn() != null) {
                    row.getValues().put(metadata.getMimetypeColumn(), receiver.getMimetype());
                }
                updateDownloadLink(row, containerBlob, metadata, downloadLink);

            } else {
                Notification.show(
                        "Ein Datei darauf nicht grer als " + metadata.getMaxFileSize() + " Bytes sein.",
                        Notification.Type.ERROR_MESSAGE);
            }
        }
    });
    return upload;
}