Example usage for com.vaadin.ui Html5File getFileName

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

Introduction

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

Prototype

public String getFileName() 

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  .j a va  2s  . com*/
    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 ava  2  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:com.peergreen.webconsole.scope.deployment.internal.dd.DeploymentDropHandler.java

License:Open Source License

@Override
public void drop(DragAndDropEvent event) {
    final Component component = event.getTransferable().getSourceComponent();
    Collection<DeployableEntry> draggedDeployableEntries;
    if (component instanceof Table) {
        Table table = (Table) component;
        draggedDeployableEntries = (Collection<DeployableEntry>) table.getValue();

        DataBoundTransferable t = (DataBoundTransferable) event.getTransferable();
        DeployableEntry deployableEntry = (DeployableEntry) t.getItemId();

        if (draggedDeployableEntries.size() <= 1 || (draggedDeployableEntries.size() > 1
                && !draggedDeployableEntries.contains(deployableEntry))) {
            draggedDeployableEntries = Collections.singleton(deployableEntry);
        }//from ww w  . j  a va  2s  .  c om

        for (final DeployableEntry entry : draggedDeployableEntries) {
            if (!deployableContainer.equals(entry.getContainer())) {
                if (entry.isDeployable()) {
                    // single artifact
                    deployableContainer.receive(entry);
                } else {
                    // dragging a directory
                    String message = String.format(
                            "Would you like to create a deployment plan <br />with the content of <b>%s</b> ?",
                            entry.getName());
                    Label label = new Label(message, ContentMode.HTML);
                    ConfirmDialog.show(deployableContainer.getView().getUI(), label,
                            new ConfirmDialog.Listener() {
                                @Override
                                public void onClose(boolean isConfirmed) {
                                    if (isConfirmed) {
                                        for (DeployableEntry child : entry.getChildren()) {
                                            deploymentViewManager.addToDeploymentPlan(child.getUri());
                                        }
                                        deploymentViewManager.showDeploymentPlanView();
                                    }
                                }
                            });
                }
            }
        }
    } else {
        try {
            Html5File[] files = ((DragAndDropWrapper.WrapperTransferable) event.getTransferable()).getFiles();
            for (Html5File file : files) {
                FileOutputStream fos = null;
                try {
                    fos = new FileOutputStream(
                            Constants.STORAGE_DIRECTORY + File.separator + file.getFileName(), true);
                } catch (FileNotFoundException e) {
                    // do nothing
                }
                file.setStreamVariable(new DesktopDragAndDropStream(fos, file.getFileName(), notifierService,
                        deployableContainer));
            }
        } catch (Exception e) {
            // do nothing
        }
    }
}

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   w  ww.j  a va  2s .c om
    //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.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
            }//  w  w  w  .  j a v a 2 s.  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:org.hip.vif.web.util.UploadComponent.java

License:Open Source License

private Component createDropBox(final IBibliographyTask inTask) {
    final CssLayout lDropPane = new CssLayout();
    lDropPane.setWidth("200px"); //$NON-NLS-1$
    lDropPane.setHeight("40px"); //$NON-NLS-1$
    lDropPane.addStyleName("v-textfield"); //$NON-NLS-1$
    final Label lHint = new Label(Activator.getMessages().getMessage("ui.upload.drop.box")); //$NON-NLS-1$
    lHint.setStyleName("vif-drop-hint"); //$NON-NLS-1$
    lDropPane.addComponent(lHint);/*from w w  w . j  a  v a2 s  . c  om*/

    final DragAndDropWrapper outDrop = new DragAndDropWrapper(lDropPane);
    outDrop.setDropHandler(new DropHandler() {
        @Override
        public AcceptCriterion getAcceptCriterion() { // NOPMD
            return AcceptAll.get();
        }

        @Override
        public void drop(final DragAndDropEvent inEvent) { // NOPMD
            final Transferable lTransferable = inEvent.getTransferable();
            if (lTransferable instanceof WrapperTransferable) {
                final Html5File[] lFiles = ((WrapperTransferable) lTransferable).getFiles();
                for (final Html5File lFile : lFiles) {
                    lFile.setStreamVariable(createStreamVariable(lFile.getFileName(), inTask));
                }
            }
        }
    });

    outDrop.setSizeUndefined();
    outDrop.setImmediate(true);
    return outDrop;
}

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();/*from w w w.  ja  va 2  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();/* ww  w .  j av  a2s .  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   www .  j  a v  a  2 s  .  com*/
        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;
            }
        });
    }

}