com.vaadin.ui.Upload类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中com.vaadin.ui.Upload类的一些代码示例,展示了Upload类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Upload类的具体详情如下:
包路径:com.vaadin.ui.Upload
类名称:Upload

Upload介绍

[英]Component for uploading files from client to server.

The visible component consists of a file name input box and a browse button and an upload submit button to start uploading.

The Upload component needs a java.io.OutputStream to write the uploaded data. You need to implement the Upload.Receiver interface and return the output stream in the receiveUpload() method.

You can get an event regarding starting (StartedEvent), progress (ProgressEvent), and finishing (FinishedEvent) of upload by implementing StartedListener, ProgressListener, and FinishedListener, respectively. The FinishedListener is called for both failed and succeeded uploads. If you wish to separate between these two cases, you can use SucceededListener (SucceededEvenet) and FailedListener (FailedEvent).

The upload component does not itself show upload progress, but you can use the ProgressIndicator for providing progress feedback by implementing ProgressListener and updating the indicator in updateProgress().

Setting upload component immediate with #setImmediateMode(boolean)initiates the upload as soon as a file is selected, instead of the common pattern of file selection field and upload button.

Note! Because of browser dependent implementations of element, setting size for Upload component is not supported. For some browsers setting size may work to some extend.
[中]用于将文件从客户端上载到服务器的组件。
可见组件由一个文件名输入框、一个浏览按钮和一个上传提交按钮组成,用于开始上传。
上传组件需要一个java。伊奥。OutputStream写入上传的数据。你需要实现上传。Receiver接口,并在receiveUpload()方法中返回输出流。
通过分别实现StartedListener、ProgressListener和FinishedListener,可以获得一个关于开始(StartedEvent)、进度(ProgressEvent)和完成(FinishedEvent)上传的事件。对于失败和成功的上载,都会调用FinishedListener。如果希望区分这两种情况,可以使用SucceededListener(SucceedeVenet)和FailedListener(FailedEvent)。
upload组件本身并不显示上载进度,但您可以通过实现ProgressListener并在updateProgress()中更新指示器来使用ProgressIndicator提供进度反馈。
使用#setImmediateMode(布尔值)设置upload component immediate(立即上载组件)会在选择文件后立即启动上载,而不是文件选择字段和上载按钮的常见模式。
笔记由于元素的浏览器依赖实现,因此不支持设置上载组件的大小。对于某些浏览器,设置大小可能会在一定程度上起作用。

代码示例

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Adds the upload received event listener.
 *
 * @param listener
 *            the Listener to be added, not null
 * @since 8.0
 */
public Registration addFinishedListener(FinishedListener listener) {
  return addListener(FinishedEvent.class, listener,
      UPLOAD_FINISHED_METHOD);
}

代码示例来源:origin: org.activiti/activiti-explorer

protected void addUpload() {
 this.upload = new Upload(null, receiver);
 upload.setButtonCaption(i18nManager.getMessage(Messages.UPLOAD_SELECT));
 upload.setImmediate(true);
 addComponent(upload);
 setComponentAlignment(upload, Alignment.MIDDLE_CENTER);
 
 // register ourselves as listener for upload events
 upload.addListener((StartedListener) this);
 upload.addListener((FailedListener) this);
 upload.addListener((FinishedListener) this);
 upload.addListener((ProgressListener) this);
}

代码示例来源:origin: org.eclipse.hawkbit/hawkbit-ui

void buildLayout() {
  final HorizontalLayout horizontalLayout = new HorizontalLayout();
  upload = new Upload();
  upload.setEnabled(false);
  upload.setButtonCaption(i18n.getMessage("caption.bulk.upload"));
  upload.setReceiver(this);
  upload.setImmediate(true);
  upload.setWidthUndefined();
  upload.addSucceededListener(this);
  upload.addFailedListener(this);
  upload.addStartedListener(this);
  horizontalLayout.addComponent(upload);
  horizontalLayout.setComponentAlignment(upload, Alignment.BOTTOM_RIGHT);
  setCompositionRoot(horizontalLayout);
}

代码示例来源:origin: org.ikasan/ikasan-dashboard-jar

progressLayout.addComponent(uploadLabel);
final Upload upload = new Upload("", receiver);
upload.addSucceededListener(receiver);
upload.addFinishedListener(new Upload.FinishedListener() {
  public void uploadFinished(Upload.FinishedEvent event) {
    upload.setVisible(false);
upload.addStartedListener(new Upload.StartedListener() {
  public void uploadStarted(Upload.StartedEvent event) {
upload.addProgressListener(new Upload.ProgressListener() {
  public void updateProgress(long readBytes, long contentLength) {

代码示例来源:origin: org.aperteworkflow/gui-commons

private void initComponent() {
  progressIndicator = new ProgressIndicator();
  progressIndicator.setPollingInterval(100);
  progressIndicator.setSizeFull();
  resetAndHideProgressIndicator();
  upload = new Upload(null, this);
  upload.setImmediate(true);
  upload.addListener((Upload.SucceededListener) this);
  upload.addListener((Upload.FailedListener) this);
  upload.addListener((Upload.ProgressListener) this);
  addComponent(upload);
  addComponent(progressIndicator);
}

代码示例来源:origin: org.aperteworkflow/cmis-widget

Upload upload = new Upload();
    upload.setButtonCaption(getI18NSource().getMessage("pt.ext.cmis.list.update.button"));
    upload.setReceiver(new UpdateReceiver(doc));
    upload.setImmediate(true);
if ("normal".equalsIgnoreCase(mode) || !hasAnyDocuments) {
  vl.addComponent(new Label(getI18NSource().getMessage("pt.ext.cmis.list.upload")));
  Upload upload = new Upload();
  upload.setImmediate(true);
  upload.setButtonCaption(getI18NSource().getMessage("pt.ext.cmis.list.upload.button"));
  upload.setReceiver(new Upload.Receiver() {
    @Override
    public OutputStream receiveUpload(final String filename, final String MIMEType) {

代码示例来源:origin: nz.co.senanque/madura-workflow-vaadin

public void load(final long pid) {
  panel.removeAllComponents();
  final Upload upload = new Upload(null, receiver);
  upload.setImmediate(true);
  upload.setButtonCaption(m_messageSourceAccessor.getMessage("upload.file", "Upload File"));
  checkbox = new CheckBox(m_messageSourceAccessor.getMessage("upload.protected", "Protected"));
  comment = new TextField(m_messageSourceAccessor.getMessage("upload.comment", "Comment"));
  panel.addComponent(comment);
  panel.addComponent(checkbox);
  panel.addComponent(upload);
  upload.addFinishedListener(new Upload.FinishedListener() {
    private static final long serialVersionUID = 1L;
    public void uploadFinished(FinishedEvent event) {
      Attachment attachment = receiver.getWrapper().getCurrentAttachment();
      attachment.setProcessInstanceId(pid);
      attachment.setComment((String)comment.getValue());
      attachment.setProtectedDocument((boolean)checkbox.getValue());
      m_workflowDAO.addAttachment(attachment);
      close();
    }
  });
  
  if (getParent() == null) {
    UI.getCurrent().addWindow(this);
    this.center();
  }
}
public void close() {

代码示例来源:origin: org.ikasan/ikasan-dashboard-jar

public void buttonClick(ClickEvent event) {
    upload.interruptUpload();
  }
});

代码示例来源:origin: org.aperteworkflow/base-widgets

public FileUploadComponent(I18NSource i18NSource) {
  this.i18NSource = i18NSource;
  uploadFile.addStyleName("default");
  uploadFile.setButtonCaption(i18NSource.getMessage(UPLOAD_START));
  uploadFile.addListener((FailedListener) this);
  uploadFile.addListener((FinishedListener) this);
  uploadFile.addListener((ProgressListener) this);
  uploadFile.addListener((StartedListener) this);
  uploadFile.addListener((SucceededListener) this);
  mainPanel.setMargin(true);
  initView();
  setCompositionRoot(mainPanel);
}

代码示例来源:origin: apache/ace

/**
 * Install this upload handler for the given {@link Upload} component.
 * 
 * @param upload
 *            the upload component to install this handler on, cannot be <code>null</code>.
 */
public void install(Upload upload) {
  upload.setReceiver(this);
  upload.addListener((Upload.FailedListener) this);
  upload.addListener((Upload.FinishedListener) this);
  upload.addListener((Upload.ProgressListener) this);
  upload.addListener((Upload.SucceededListener) this);
}

代码示例来源:origin: apache/ace

final Upload uploadArtifact = new Upload();
uploadArtifact.setCaption("Upload Artifact");
uploadHandler.install(uploadArtifact);

代码示例来源:origin: org.aperteworkflow/gui-commons

public void setUploadImmediate(boolean immediate) {
  upload.setImmediate(immediate);
}

代码示例来源:origin: org.activiti/activiti-explorer

public void setReceiver(Receiver receiver) {
  this.receiver = receiver;
 upload.setReceiver(receiver);
}

代码示例来源:origin: org.activiti/activiti-explorer

protected void addUpload() {
 this.upload = new Upload(null, receiver);
 upload.setButtonCaption(i18nManager.getMessage(Messages.UPLOAD_SELECT));
 upload.setImmediate(true);
 addComponent(upload);
 setComponentAlignment(upload, Alignment.MIDDLE_CENTER);
 
 // register ourselves as listener for upload events
 upload.addListener((StartedListener) this);
 upload.addListener((FailedListener) this);
 upload.addListener((FinishedListener) this);
 upload.addListener((ProgressListener) this);
}

代码示例来源:origin: eclipse/hawkbit

void buildLayout() {
  final HorizontalLayout horizontalLayout = new HorizontalLayout();
  upload = new Upload();
  upload.setEnabled(false);
  upload.setButtonCaption(i18n.getMessage("caption.bulk.upload"));
  upload.setReceiver(this);
  upload.setImmediate(true);
  upload.setWidthUndefined();
  upload.addSucceededListener(this);
  upload.addFailedListener(this);
  upload.addStartedListener(this);
  horizontalLayout.addComponent(upload);
  horizontalLayout.setComponentAlignment(upload, Alignment.BOTTOM_RIGHT);
  setCompositionRoot(horizontalLayout);
}

代码示例来源:origin: org.ikasan/ikasan-dashboard-jar

progressLayout.addComponent(uploadLabel);
final Upload upload = new Upload("", receiver);
upload.addSucceededListener(receiver);
upload.addFinishedListener(new Upload.FinishedListener() {
  public void uploadFinished(FinishedEvent event) {
    upload.setVisible(false);
upload.addStartedListener(new Upload.StartedListener() {
  public void uploadStarted(StartedEvent event) {
upload.addProgressListener(new Upload.ProgressListener() {
  public void updateProgress(long readBytes, long contentLength) {

代码示例来源:origin: org.apache.ace/org.apache.ace.webui.vaadin

final Table artifacts = new ArtifactTable(main);
final Table uploadedArtifacts = new ArtifactTable(main);
final Upload uploadArtifact = new Upload("Upload Artifact", new Upload.Receiver() {
  public OutputStream receiveUpload(String filename, String MIMEType) {
    FileOutputStream fos = null;
uploadArtifact.setImmediate(true);
uploadArtifact.addListener(new Upload.SucceededListener() {
uploadArtifact.addListener(new Upload.FailedListener() {
  public void uploadFailed(FailedEvent event) {
    getMainWindow().showNotification(

代码示例来源:origin: org.eclipse.hawkbit/hawkbit-ui

@Override
public void interruptUpload() {
  super.interruptUpload();
  uploadInterrupted = true;
}

代码示例来源:origin: org.activiti/activiti-explorer

/**
 * @param upload The component that will serve this receiver
 * @param maxFileSize The maximum size of files that will be accepted (in bytes). -1 in case of no limit.
 */
public InMemoryUploadReceiver(Upload upload, long maxFileSize) {
 this.upload = upload;
 this.maxFileSize = maxFileSize;
 this.notificationManager = ExplorerApp.get().getNotificationManager();
 
 upload.setReceiver(this);
 upload.addListener((StartedListener) this);
 upload.addListener((ProgressListener) this);
}

代码示例来源:origin: org.aperteworkflow/base-widgets

private void initView() {
  uploadFile.setImmediate(true);

相关文章