public Component generateCell(Table source, Object itemId, Object columnId) {
    Embedded embedded = new Embedded(null, image);

    if (clickListener != null) {
      embedded.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
      embedded.setData(itemId);
      embedded.addListener(clickListener);
    }

    return embedded;
  }
示例#2
0
  @Override
  protected void init(VaadinRequest request) {
    setContent(main);
    Embedded appResourceTest =
        new Embedded("Test of ApplicationResources with full path", new FlagSeResource());
    main.addComponent(appResourceTest);
    Embedded specialNameResourceTest =
        new Embedded("Test ApplicationResources with special names", new SpecialNameResource());
    specialNameResourceTest.addStyleName("hugeBorder");
    main.addComponent(specialNameResourceTest);

    userInfo.setCaption("User info");
    userInfo.setContentMode(ContentMode.PREFORMATTED);
    main.addComponent(userInfo);

    tf.setEnabled(false);
    tf.setImmediate(true);
    main.addComponent(tf);

    portletEdit.setEnabled(false);
    main.addComponent(portletEdit);
    portletMax.setEnabled(false);
    main.addComponent(portletMax);

    Upload upload =
        new Upload(
            "Upload a file",
            new Receiver() {

              @Override
              public OutputStream receiveUpload(String filename, String mimeType) {
                return new ByteArrayOutputStream();
              }
            });
    main.addComponent(upload);

    possiblyChangedModeOrState();
    getSession().addPortletListener(new DemoPortletListener());
  }
  private Component addFileUploadComponent(final int index) {
    HorizontalLayout outer = new HorizontalLayout();
    outer.setWidth("400px");
    outer.setHeight("165px");
    outer.addStyleName("v-upload");
    outer.setSpacing(true);

    VerticalLayout inner = new VerticalLayout();
    inner.setSpacing(true);
    inner.setWidth("200px");
    inner.addStyleName("v-preview-anon");

    final Embedded embedded = new Embedded();
    embedded.addStyleName("v-preview-anon");
    embedded.addStyleName("v-showhand");

    final TextField urlPaste = new TextField("Select Remote File");
    urlPaste.setWidth("100%");
    urlPaste.setInputPrompt("Paste URL here...");
    final UploadReceiver receiver = new UploadReceiver();
    final Upload uploadInstance = new Upload("Select Local File", receiver);
    uploadInstance.addStyleName("v-override");
    final Button uploadBtn = new Button("Upload");
    uploadInstance.setButtonCaption("Browse...");
    uploadInstance.addListener(
        new Upload.StartedListener() {
          @Override
          public void uploadStarted(Upload.StartedEvent event) {
            if (uploadInstance.getUploadSize() > MAX_FILE_SIZE) {
              uploadInstance.interruptUpload();
              DifferApplication.getCurrentApplication()
                  .getMainWindow()
                  .showNotification(
                      "File failed to upload",
                      "<br/>" + "File must not exceed 5MB for anonymous users",
                      Window.Notification.TYPE_WARNING_MESSAGE);
            }
            urlPaste.setEnabled(false);
            uploadBtn.setEnabled(false);
          }
        });
    uploadInstance.addListener(
        new Upload.FailedListener() {
          @Override
          public void uploadFailed(Upload.FailedEvent event) {
            urlPaste.setEnabled(true);
            uploadBtn.setEnabled(true);
          }
        });
    uploadInstance.addListener(
        new Upload.SucceededListener() {
          @Override
          public void uploadSucceeded(Upload.SucceededEvent event) {
            UploadFile ufile =
                new UploadFile(
                    UploadFile.TYPE.LOCAL_FILESYSTEM, receiver.getFile().getAbsolutePath());
            if (ufile.isValid()) {
              embedded.setVisible(true);
              try {
                embedded.setSource(
                    DifferApplication.getImageThumbnailProvider().getThumbnail(receiver.getFile()));
                DifferApplication.getTemporaryFilesCleaner().addFile(receiver.getFile());
              } catch (ImageDifferException ide) {
                DifferApplication.getCurrentApplication()
                    .getMainWindow()
                    .showNotification(
                        "Thumbnail can not be generated.",
                        "<br/>",
                        Window.Notification.TYPE_WARNING_MESSAGE);
              }
              compareButton.setEnabled(true);
              if (index == 0) {
                uploadA = receiver.getFile();
              } else {
                uploadB = receiver.getFile();
              }
              if (uploadA == null || uploadB == null) {
                compareButton.setCaption(BTN_TXT_PROCEED);
              } else {
                compareButton.setCaption(BTN_TXT_COMPARE);
              }
            } else {
              DifferApplication.getCurrentApplication()
                  .getMainWindow()
                  .showNotification(
                      "File failed to upload",
                      "<br/>" + ufile.getErrorMessage(),
                      Window.Notification.TYPE_WARNING_MESSAGE);
              urlPaste.setEnabled(true);
              uploadBtn.setEnabled(true);
            }
          }
        });
    uploadInstance.setImmediate(true);
    inner.addComponent(uploadInstance);

    final Label lbl = new Label("OR");
    lbl.addStyleName("v-labelspacer");
    inner.addComponent(lbl);

    urlPaste.addListener(
        new FieldEvents.TextChangeListener() {
          @Override
          public void textChange(FieldEvents.TextChangeEvent event) {
            if (event.getText().length() > 0) {
              uploadInstance.setEnabled(false);
            } else {
              uploadInstance.setEnabled(true);
            }
          }
        });
    urlPaste.setImmediate(true);
    urlPaste.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.EAGER);

    inner.addComponent(urlPaste);

    uploadBtn.addListener(
        new Button.ClickListener() {
          @Override
          public void buttonClick(Button.ClickEvent event) {
            UploadFile ufile =
                new UploadFile(UploadFile.TYPE.REMOTE_URL, (String) (urlPaste.getValue()));
            if (ufile.isValid()) {
              final File file = ufile.getFile();
              DifferApplication.getTemporaryFilesCleaner().addFile(file);
              embedded.setVisible(true);
              embedded.setSource(new FileResource(file, DifferApplication.getCurrentApplication()));
              embedded.addListener(
                  new MouseEvents.ClickListener() {
                    @Override
                    public void click(MouseEvents.ClickEvent event) {
                      Embedded fullview = new Embedded();
                      fullview.setSource(
                          new FileResource(file, DifferApplication.getCurrentApplication()));
                      DifferApplication.getMainApplicationWindow()
                          .addWindow(new FullSizeImageWindow(fullview));
                    }
                  });
              compareButton.setEnabled(true);
              if (index == 0) {
                uploadA = file;
              } else {
                uploadB = file;
              }
              if (uploadA == null || uploadB == null) {
                compareButton.setCaption(BTN_TXT_PROCEED);
              } else {
                compareButton.setCaption(BTN_TXT_COMPARE);
              }
            } else {
              DifferApplication.getCurrentApplication()
                  .getMainWindow()
                  .showNotification(
                      "File failed to upload",
                      "<br/>" + ufile.getErrorMessage(),
                      Window.Notification.TYPE_WARNING_MESSAGE);
              urlPaste.setValue("");
              uploadInstance.setEnabled(true);
            }
          }
        });
    inner.addComponent(uploadBtn);

    outer.addComponent(inner);
    outer.addComponent(embedded);

    return outer;
  }