Example usage for com.vaadin.ui ProgressBar setEnabled

List of usage examples for com.vaadin.ui ProgressBar setEnabled

Introduction

In this page you can find the example usage for com.vaadin.ui ProgressBar setEnabled.

Prototype

@Override
    public void setEnabled(boolean enabled) 

Source Link

Usage

From source file:com.esofthead.mycollab.mobile.module.project.ui.form.field.ProjectFormAttachmentUploadField.java

License:Open Source License

public ProjectFormAttachmentUploadField() {
    resourceService = ApplicationContextUtil.getSpringBean(ResourceService.class);
    currentPollInterval = UI.getCurrent().getPollInterval();

    receiver = createReceiver();//from  w w  w .  j  a v a  2 s . c  o  m

    attachmentBtn = new MultiUpload();
    attachmentBtn.setButtonCaption("Select File(s)");
    attachmentBtn.setImmediate(true);

    MultiUploadHandler handler = new MultiUploadHandler() {
        private LinkedList<ProgressBar> indicators;

        @Override
        public void streamingStarted(StreamVariable.StreamingStartEvent event) {
        }

        @Override
        public void streamingFinished(StreamVariable.StreamingEndEvent event) {
            String tempName = event.getFileName();
            final String fileName;
            int index = tempName.lastIndexOf(".");
            if (index > 0) {
                String fileExt = tempName.substring(index + 1, tempName.length());
                fileName = MobileAttachmentUtils.ATTACHMENT_NAME_PREFIX + System.currentTimeMillis() + "."
                        + fileExt;
            } else {
                fileName = MobileAttachmentUtils.ATTACHMENT_NAME_PREFIX + System.currentTimeMillis();
            }
            if (!indicators.isEmpty()) {
                rowWrap.replaceComponent(indicators.remove(0),
                        MobileAttachmentUtils.renderAttachmentFieldRow(
                                MobileAttachmentUtils.constructContent(fileName, attachmentPath),
                                new Button.ClickListener() {

                                    private static final long serialVersionUID = 581451358291203810L;

                                    @Override
                                    public void buttonClick(Button.ClickEvent event) {
                                        fileStores.remove(fileName);
                                    }
                                }));
            }

            if (indicators.size() == 0) {
                UI.getCurrent().setPollInterval(currentPollInterval);
            }

            File file = receiver.getFile();

            receiveFile(file, fileName, event.getMimeType(), event.getBytesReceived());
            receiver.setValue(null);

        }

        @Override
        public void streamingFailed(StreamVariable.StreamingErrorEvent event) {
            if (!indicators.isEmpty()) {
                Label uploadResult = new Label("Upload failed! File: " + event.getFileName());
                uploadResult.setStyleName("upload-status");
                rowWrap.replaceComponent(indicators.remove(0), uploadResult);
            }
        }

        @Override
        public void onProgress(StreamVariable.StreamingProgressEvent event) {
            long readBytes = event.getBytesReceived();
            long contentLength = event.getContentLength();
            float f = (float) readBytes / (float) contentLength;
            indicators.get(0).setValue(f);
        }

        @Override
        public OutputStream getOutputStream() {
            MultiUpload.FileDetail next = attachmentBtn.getPendingFileNames().iterator().next();
            return receiver.receiveUpload(next.getFileName(), next.getMimeType());
        }

        @Override
        public void filesQueued(Collection<MultiUpload.FileDetail> pendingFileNames) {
            UI.getCurrent().setPollInterval(500);
            if (indicators == null) {
                indicators = new LinkedList<ProgressBar>();
            }
            for (MultiUpload.FileDetail f : pendingFileNames) {
                ProgressBar pi = new ProgressBar();
                pi.setValue(0f);
                pi.setStyleName("upload-progress");
                pi.setWidth("100%");
                rowWrap.addComponentAsFirst(pi);
                pi.setEnabled(true);
                pi.setVisible(true);
                indicators.add(pi);
            }
        }

        @Override
        public boolean isInterrupted() {
            return false;
        }
    };
    attachmentBtn.setHandler(handler);

    fileStores = new HashMap<String, File>();

    constructUI();
}

From source file:com.esofthead.mycollab.mobile.module.project.ui.ProjectCommentInput.java

License:Open Source License

private void prepareUploadField() {
    receiver = createReceiver();/*from   ww  w . j  a  v a  2 s .  c om*/

    uploadField = new MultiUpload();
    uploadField.setButtonCaption("");
    uploadField.setImmediate(true);

    MultiUploadHandler handler = new MultiUploadHandler() {
        private LinkedList<ProgressBar> indicators;

        @Override
        public void streamingStarted(StreamVariable.StreamingStartEvent event) {
        }

        @Override
        public void streamingFinished(StreamVariable.StreamingEndEvent event) {
            String fileName = event.getFileName();
            int index = fileName.lastIndexOf(".");
            if (index > 0) {
                String fileExt = fileName.substring(index + 1, fileName.length());
                fileName = MobileAttachmentUtils.ATTACHMENT_NAME_PREFIX + System.currentTimeMillis() + "."
                        + fileExt;
            }

            if (!indicators.isEmpty()) {
                statusWrapper.replaceComponent(indicators.remove(0), createAttachmentRow(fileName));
            }

            if (indicators.size() == 0) {
                UI.getCurrent().setPollInterval(currentPollInterval);
            }

            File file = receiver.getFile();

            receiveFile(file, fileName, event.getMimeType(), event.getBytesReceived());
            receiver.setValue(null);
        }

        @Override
        public void streamingFailed(StreamVariable.StreamingErrorEvent event) {
            if (!indicators.isEmpty()) {
                Label uploadResult = new Label("Upload failed! File: " + event.getFileName());
                uploadResult.setStyleName("upload-status");
                statusWrapper.replaceComponent(indicators.remove(0), uploadResult);
            }
        }

        @Override
        public void onProgress(StreamVariable.StreamingProgressEvent event) {
            long readBytes = event.getBytesReceived();
            long contentLength = event.getContentLength();
            float f = (float) readBytes / (float) contentLength;
            indicators.get(0).setValue(f);
        }

        @Override
        public OutputStream getOutputStream() {
            MultiUpload.FileDetail next = uploadField.getPendingFileNames().iterator().next();
            return receiver.receiveUpload(next.getFileName(), next.getMimeType());
        }

        @Override
        public void filesQueued(Collection<MultiUpload.FileDetail> pendingFileNames) {
            UI.getCurrent().setPollInterval(500);
            if (indicators == null) {
                indicators = new LinkedList<ProgressBar>();
            }
            for (MultiUpload.FileDetail f : pendingFileNames) {
                ProgressBar pi = new ProgressBar();
                pi.setValue(0f);
                pi.setStyleName("upload-progress");
                pi.setWidth("100%");
                statusWrapper.addComponent(pi);
                pi.setEnabled(true);
                pi.setVisible(true);
                indicators.add(pi);
            }
        }

        @Override
        public boolean isInterrupted() {
            return false;
        }
    };
    uploadField.setHandler(handler);
}

From source file:org.hip.vif.admin.admin.ui.UpgradeView.java

License:Open Source License

/** UpgradeView constructor.
 *
 * @param inVersionInstance String the instance's version (i.e. the version of the tables)
 * @param inVersionSoftware String the version according to the installed version
 * @param inThread {@link UpgradeTask} the thread managing the upgrade */
public UpgradeView(final String inVersionInstance, final String inVersionSoftware,
        final UpgradeThread inThread) {
    final IMessages lMessages = Activator.getMessages();

    final VerticalLayout lLayout = initLayout(lMessages, "admin.menu.upgrade"); //$NON-NLS-1$

    final Label lFeedbackMsg = new Label(
            String.format(TMPL_FEEDBACK, lMessages.getMessage("admin.upgrade.feedback.failure")), //$NON-NLS-1$
            ContentMode.HTML);// w  ww .j  a v a  2 s  . com
    lFeedbackMsg.setVisible(false);
    lLayout.addComponent(lFeedbackMsg);
    final Label lFailures = new Label("", ContentMode.HTML); //$NON-NLS-1$
    lLayout.addComponent(lFailures);
    lFailures.setVisible(false);

    final LabelValueTable lTable = new LabelValueTable();
    lTable.addRow(lMessages.getMessage("admin.upgrade.version.instance"), inVersionInstance); //$NON-NLS-1$
    lTable.addRow(lMessages.getMessage("admin.upgrade.version.app"), inVersionSoftware); //$NON-NLS-1$
    lLayout.addComponent(lTable);
    lLayout.addComponent(RiplaViewHelper.createSpacer());

    final Button lUpgrade = new Button(lMessages.getMessage("admin.menu.upgrade")); //$NON-NLS-1$
    lLayout.addComponent(lUpgrade);

    lLayout.addComponent(RiplaViewHelper.createSpacer());
    final ProgressBar lProgress = new ProgressBar(new Float(0.0));
    lProgress.setWidth(200, Unit.PIXELS);
    lProgress.setVisible(false);
    lLayout.addComponent(lProgress);

    lUpgrade.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent inEvent) {
            lProgress.setVisible(true);
            lProgress.setEnabled(true);
            lUpgrade.setEnabled(false);
            UI.getCurrent().setPollInterval(POLL_RUN);

            final Collection<IVIFUpgrade> lFailed = inThread.upgrade(inVersionInstance, inVersionSoftware,
                    lProgress);

            lProgress.setVisible(false);
            if (lFailed.isEmpty()) {
                lFeedbackMsg.setVisible(false);
                lFailures.setVisible(false);
            } else {
                lFeedbackMsg.setVisible(true);
                lFailures.setPropertyDataSource(
                        new ObjectProperty<String>(renderFailures(lFailed), String.class));
                lFailures.setVisible(true);
            }
            lUpgrade.setEnabled(true);
        }
    });
}

From source file:org.ikasan.dashboard.ui.framework.window.ProgressBarWindow.java

License:BSD License

protected void init() {
    this.setModal(true);
    this.setWidth("15%");
    this.setHeight("15%");

    ProgressBar progressBar = new ProgressBar();
    progressBar.setIndeterminate(true);/*w ww .j ava2s  .c o  m*/
    progressBar.setEnabled(true);

    VerticalLayout layout = new VerticalLayout();
    layout.addComponent(progressBar);
    layout.setComponentAlignment(progressBar, Alignment.MIDDLE_CENTER);

    this.setContent(layout);
}

From source file:org.vaadin.easyuploads.MultiFileUploadExt.java

License:Open Source License

private void prepareUpload() {
    final FileBuffer receiver = createReceiver();

    upload = new MultiUpload();
    MultiUploadHandlerExt handler = new MultiUploadHandlerExt() {
        private static final long serialVersionUID = 1L;
        private LinkedList<ProgressBar> indicators;

        @Override/*from w  w  w .ja v a  2 s .c om*/
        public void streamingStarted(StreamVariable.StreamingStartEvent event) {
        }

        @Override
        public void streamingFinished(StreamVariable.StreamingEndEvent event) {
            if (!indicators.isEmpty()) {
                progressBars.removeComponent(indicators.remove(0));
            }

            if (indicators.size() == 0) {
                UI.getCurrent().setPollInterval(-1);
            }

            File file = receiver.getFile();
            String candidateFileName = event.getFileName();
            if (!StringUtils.isValidFileName(candidateFileName)) {
                String extension = FilenameUtils.getExtension(candidateFileName);
                candidateFileName = StringUtils.generateSoftUniqueId();
                if (!"".equals(extension)) {
                    candidateFileName += "." + extension;
                }
            }

            handleFile(file, candidateFileName, event.getMimeType(), event.getBytesReceived());
            receiver.setValue(null);
        }

        @Override
        public void streamingFailed(StreamVariable.StreamingErrorEvent event) {

            for (ProgressBar progressIndicator : indicators) {
                progressBars.removeComponent(progressIndicator);
            }
            UI.getCurrent().setPollInterval(-1);
        }

        @Override
        public void onProgress(StreamVariable.StreamingProgressEvent event) {
            long readBytes = event.getBytesReceived();
            long contentLength = event.getContentLength();
            float f = (float) readBytes / (float) contentLength;
            indicators.get(0).setValue(f);
        }

        @Override
        public OutputStream getOutputStream() {
            MultiUpload.FileDetail next = upload.getPendingFileNames().iterator().next();

            return receiver.receiveUpload(next.getFileName(), next.getMimeType());

        }

        @Override
        public void filesQueued(Collection<MultiUpload.FileDetail> pendingFiles) {
            UI.getCurrent().setPollInterval(1000);
            if (indicators == null) {
                indicators = new LinkedList<>();
            }

            for (MultiUpload.FileDetail f : pendingFiles) {
                ProgressBar pi = createProgressIndicator();
                progressBars.addComponent(pi);
                pi.setCaption(f.getFileName());
                pi.setEnabled(true);
                pi.setVisible(true);
                indicators.add(pi);
            }
        }

        @Override
        public boolean isInterrupted() {
            return false;
        }
    };
    upload.setHandler(handler);
    upload.setButtonCaption(uploadButtonCaption);
    uploads.addComponent(upload);

}