Search in sources :

Example 1 with FinishedListener

use of com.vaadin.ui.Upload.FinishedListener in project Activiti by Activiti.

the class ProfilePanel method initChangePictureButton.

protected Upload initChangePictureButton() {
    final Upload changePictureUpload = new Upload();
    changePictureUpload.setImmediate(true);
    changePictureUpload.setButtonCaption(i18nManager.getMessage(Messages.PROFILE_CHANGE_PICTURE));
    final InMemoryUploadReceiver receiver = initPictureReceiver(changePictureUpload);
    changePictureUpload.addListener(new FinishedListener() {

        private static final long serialVersionUID = 1L;

        public void uploadFinished(FinishedEvent event) {
            if (!receiver.isInterruped()) {
                picture = new Picture(receiver.getBytes(), receiver.getMimeType());
                identityService.setUserPicture(userId, picture);
                // reset picture
                imageLayout.removeAllComponents();
                initPicture();
            } else {
                receiver.reset();
            }
        }
    });
    return changePictureUpload;
}
Also used : InMemoryUploadReceiver(org.activiti.explorer.ui.custom.InMemoryUploadReceiver) FinishedEvent(com.vaadin.ui.Upload.FinishedEvent) Picture(org.activiti.engine.identity.Picture) Upload(com.vaadin.ui.Upload) FinishedListener(com.vaadin.ui.Upload.FinishedListener)

Example 2 with FinishedListener

use of com.vaadin.ui.Upload.FinishedListener in project Activiti by Activiti.

the class FileAttachmentEditorComponent method initFileUpload.

protected void initFileUpload() {
    uploadComponent = ExplorerApp.get().getComponentFactory(UploadComponentFactory.class).create();
    Receiver receiver = new Receiver() {

        private static final long serialVersionUID = 1L;

        public OutputStream receiveUpload(String filename, String mType) {
            fileName = filename;
            // Try extracting the extention as well, and append it to the mime-type
            String extention = extractExtention(filename);
            if (extention != null) {
                mimeType = mType + MIME_TYPE_EXTENTION_SPLIT_CHAR + extention;
            } else {
                mimeType = mType;
            }
            // TODO: Refactor, don't use BAOS!!
            byteArrayOutputStream = new ByteArrayOutputStream();
            return byteArrayOutputStream;
        }
    };
    uploadComponent.setReceiver(receiver);
    uploadComponent.addFinishedListener(new FinishedListener() {

        private static final long serialVersionUID = 1L;

        public void uploadFinished(FinishedEvent event) {
            // Update UI
            if (getAttachmentName() == null || "".equals(getAttachmentName())) {
                setAttachmentName(getFriendlyName(fileName));
            }
            fileUploaded = true;
            successIndicator.setVisible(true);
            successIndicator.setCaption(i18nManager.getMessage(Messages.RELATED_CONTENT_TYPE_FILE_UPLOADED, fileName));
            form.setComponentError(null);
        }
    });
    addComponent(uploadComponent);
    setExpandRatio(uploadComponent, 1.0f);
}
Also used : FinishedEvent(com.vaadin.ui.Upload.FinishedEvent) Receiver(com.vaadin.ui.Upload.Receiver) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FinishedListener(com.vaadin.ui.Upload.FinishedListener)

Aggregations

FinishedEvent (com.vaadin.ui.Upload.FinishedEvent)2 FinishedListener (com.vaadin.ui.Upload.FinishedListener)2 Upload (com.vaadin.ui.Upload)1 Receiver (com.vaadin.ui.Upload.Receiver)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Picture (org.activiti.engine.identity.Picture)1 InMemoryUploadReceiver (org.activiti.explorer.ui.custom.InMemoryUploadReceiver)1