Package com.vaadin.ui

Examples of com.vaadin.ui.Upload$Receiver


public class UploadCssTest {

    private int debugIdCounter = 0;

    public UploadCssTest(TestSampler parent) {
        Upload up = new Upload();
        up.setId("upload" + debugIdCounter++);
        parent.addComponent(up);

        up = new Upload();
        up.setId("upload" + debugIdCounter++);
        up.setImmediate(true);
        parent.addComponent(up);
    }
View Full Code Here


     * VaadinRequest)
     */
    @Override
    protected void setup(VaadinRequest request) {

        Upload upload = new Upload();
        upload.setId("upload");
        upload.setImmediate(false);
        addComponent(upload);

        Upload immediateUpload = new Upload();
        immediateUpload.setId("immediateupload");
        immediateUpload.setImmediate(true);
        addComponent(immediateUpload);
    }
View Full Code Here

                    } else {

                        int separatorPos = name.lastIndexOf("_");
                        final String pid = name.substring(0, separatorPos);
                        final Upload uploadComponent = (Upload) idPaintableMap
                                .get(pid);
                        if (uploadComponent == null) {
                            throw new FileUploadException(
                                    "Upload component not found");
                        }
                        if (uploadComponent.isReadOnly()) {
                            throw new FileUploadException(
                                    "Warning: ignored file upload because upload component is set as read-only");
                        }
                        synchronized (application) {
                            // put upload component into receiving state
                            uploadComponent.startUpload();
                        }

                        // tell UploadProgressListener which component is
                        // receiving
                        // file
                        pl.setUpload(uploadComponent);

                        try {
                            uploadComponent.receiveUpload(upstream);
                        } catch (UploadException e) {
                            // error happened while receiving file. Handle the
                            // error in the same manner as it would have
                            // happened in
                            // variable change.
View Full Code Here

                logError("Upload of " + uploadedArtifact + " failed.");
            }
        };

        final Upload uploadArtifact = new Upload("Upload Artifact", uploadHandler);
        uploadArtifact.addListener((SucceededListener) uploadHandler);
        uploadArtifact.addListener((FailedListener) uploadHandler);
        uploadArtifact.setImmediate(true);

        final DragAndDropWrapper finalUploadedArtifacts = new DragAndDropWrapper(uploadedArtifacts);
        finalUploadedArtifacts.setDropHandler(new ArtifactDropHandler(uploadHandler));

        addListener(new Window.CloseListener() {
View Full Code Here

                final InputStream stream = item.openStream();
                if (item.isFormField()) {
                    // ignored, upload requests contains only files
                } else {
                    final String pid = name.split("_")[0];
                    final Upload uploadComponent = (Upload) idPaintableMap
                            .get(pid);
                    if (uploadComponent == null) {
                        throw new FileUploadException(
                                "Upload component not found");
                    }
                    if (uploadComponent.isReadOnly()) {
                        throw new FileUploadException(
                                "Warning: ignored file upload because upload component is set as read-only");
                    }
                    synchronized (application) {
                        // put upload component into receiving state
                        uploadComponent.startUpload();
                    }
                    final UploadStream upstream = new UploadStream() {

                        public String getContentName() {
                            return filename;
                        }

                        public String getContentType() {
                            return mimeType;
                        }

                        public InputStream getStream() {
                            return stream;
                        }

                        public String getStreamName() {
                            return "stream";
                        }

                    };

                    // tell UploadProgressListener which component is receiving
                    // file
                    pl.setUpload(uploadComponent);

                    try {
                        uploadComponent.receiveUpload(upstream);
                    } catch (UploadException e) {
                        // error happened while receiving file. Handle the
                        // error in the same manner as it would have happened in
                        // variable change.
                        synchronized (application) {
View Full Code Here

                    }
                }
            }
        };

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

        final DragAndDropWrapper finalUploadedArtifacts = new DragAndDropWrapper(uploadedArtifacts);
        finalUploadedArtifacts.setDropHandler(new ArtifactDropHandler(uploadHandler));
View Full Code Here

                    } else {

                        int separatorPos = name.lastIndexOf("_");
                        final String pid = name.substring(0, separatorPos);
                        final Upload uploadComponent = (Upload) idPaintableMap
                                .get(pid);
                        if (uploadComponent == null) {
                            throw new FileUploadException(
                                    "Upload component not found");
                        }
                        if (uploadComponent.isReadOnly()) {
                            throw new FileUploadException(
                                    "Warning: ignored file upload because upload component is set as read-only");
                        }
                        synchronized (application) {
                            // put upload component into receiving state
                            uploadComponent.startUpload();
                        }

                        // tell UploadProgressListener which component is
                        // receiving
                        // file
                        pl.setUpload(uploadComponent);

                        try {
                            uploadComponent.receiveUpload(upstream);
                        } catch (UploadException e) {
                            // error happened while receiving file. Handle the
                            // error in the same manner as it would have
                            // happened in
                            // variable change.
View Full Code Here

            layout.setSpacing(true);

            final TextField search = new TextField("search");
            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;
                try {
                  m_file = new File(m_sessionDir, filename);
                  if (m_file.exists()) {
                    throw new IOException("Uploaded file already exists.");
                  }
                    fos = new FileOutputStream(m_file);
                }
                catch (final IOException e) {
                        getMainWindow().showNotification(
                            "Upload artifact failed",
                            "File " + m_file.getName() + "<br />could not be accepted on the server.<br />" +
                            "Reason: " + e.getMessage(),
                            Notification.TYPE_ERROR_MESSAGE);
                        m_log.log(LogService.LOG_ERROR, "Upload of " + m_file.getAbsolutePath() + " failed.", e);
                    return null;
                }
                return fos;
              }
        });
           
            artifacts.setCaption("Artifacts in repository");
            uploadedArtifacts.setCaption("Uploaded artifacts");
            uploadedArtifacts.setSelectable(false);
           
            search.setValue("");
            try {
                getBundles(artifacts);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
           
            uploadArtifact.setImmediate(true);
           
            uploadArtifact.addListener(new Upload.SucceededListener() {
         
          public void uploadSucceeded(SucceededEvent event) {
            try {
              URL artifact = m_file.toURI().toURL();
                    Item item = uploadedArtifacts.addItem(artifact);
                    item.getItemProperty("symbolic name").setValue(m_file.getName());
                    item.getItemProperty("version").setValue("");
              m_uploadedArtifacts.add(m_file);
          }
            catch (IOException e) {
                        getMainWindow().showNotification(
                            "Upload artifact processing failed",
                            "<br />Reason: " + e.getMessage(),
                            Notification.TYPE_ERROR_MESSAGE);
                        m_log.log(LogService.LOG_ERROR, "Processing of " + m_file.getAbsolutePath() + " failed.", e);
          }
          }
        });
            uploadArtifact.addListener(new Upload.FailedListener() {
          public void uploadFailed(FailedEvent event) {
                    getMainWindow().showNotification(
                        "Upload artifact failed",
                        "File " + event.getFilename() + "<br />could not be uploaded to the server.<br />" +
                        "Reason: " + event.getReason().getMessage(),
View Full Code Here

    imageLayout.addComponent(picture);
    imageLayout.setWidth(picture.getWidth() + 5, picture.getWidthUnits());
   
    // Change picture button
    if (isCurrentLoggedInUser) {
      Upload changePictureButton = initChangePictureButton();
      imageLayout.addComponent(changePictureButton);
      imageLayout.setComponentAlignment(changePictureButton, Alignment.MIDDLE_CENTER);
    }
  }
View Full Code Here

      imageLayout.setComponentAlignment(changePictureButton, Alignment.MIDDLE_CENTER);
    }
  }
 
  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);
View Full Code Here

TOP

Related Classes of com.vaadin.ui.Upload$Receiver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.