コード例 #1
0
  public UploadableProfileImagePanel(String id, final long userId) {
    super(id, userId);
    final Form<Void> form = new Form<Void>("form");
    form.setMultiPart(true);
    form.setMaxSize(Bytes.bytes(getBean(ConfigurationDao.class).getMaxUploadSize()));
    // Model is necessary here to avoid writing image to the User object
    form.add(
        fileUploadField =
            new FileUploadField(
                "image",
                new IModel<List<FileUpload>>() {
                  private static final long serialVersionUID = 1L;

                  // FIXME this need to be eliminated
                  public void detach() {}

                  public void setObject(List<FileUpload> object) {}

                  public List<FileUpload> getObject() {
                    return null;
                  }
                }));
    form.add(new UploadProgressBar("progress", form, fileUploadField));
    fileUploadField.add(
        new AjaxFormSubmitBehavior(form, "onchange") {
          private static final long serialVersionUID = 2160216679027859231L;

          @Override
          protected void onSubmit(AjaxRequestTarget target) {
            FileUpload fu = fileUploadField.getFileUpload();
            if (fu != null) {
              StoredFile sf = new StoredFile(fu.getClientFileName());
              if (sf.isImage()) {
                boolean asIs = sf.isAsIs();
                try {
                  // FIXME need to work with InputStream !!!
                  getBean(GenerateImage.class)
                      .convertImageUserProfile(fu.writeToTempFile(), userId, asIs);
                } catch (Exception e) {
                  // TODO display error
                  e.printStackTrace();
                }
              } else {
                // TODO display error
              }
            }
            target.add(profile, form);
          }
        });
    add(form.setOutputMarkupId(true));
    add(BootstrapFileUploadBehavior.INSTANCE);
  }
コード例 #2
0
  public UserPicturePanel(final String id, final User usr) {
    super(id);
    this.user = usr;

    // Form for uploading profile images
    fileUploadForm = new Form<>("fileUploadForm");
    fileUploadForm.setOutputMarkupId(true);

    // User image
    userPhoto =
        new NonCachingImage("userImage", user.getProfilePicture(User.PictureDimensions.Large));
    userPhoto.setOutputMarkupId(true);
    fileUploadForm.add(userPhoto);
    uploadField = new FileUploadField("fileUploadField");
    fileUploadForm.add(uploadField.setOutputMarkupId(true));
    fileUploadForm.setMaxSize(Bytes.kilobytes(MAX_SIZE));
    fileUploadForm.add(new Label("max", Model.of(Bytes.kilobytes(MAX_SIZE))));
    fileUploadForm.add(
        new AjaxSubmitLink("submit") {

          private static final long serialVersionUID = 1L;

          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            // Check whether an image has been provided to be uploaded
            FileUpload fileUpload = uploadField.getFileUpload();

            if (fileUpload != null) {
              try {
                uploadHelper.processUserFileUpload(fileUpload, user);
                userPhoto.setImageResource(user.getProfilePicture(User.PictureDimensions.Large));
                uploadField.clearInput();
                target.add(uploadField);
                target.add(userPhoto);
              } catch (IOException e) {
                getPage().error(e.getLocalizedMessage());
                target.add(((BasePage) getPage()).getFeedbackPanel());
              }
            }
          }
        });

    fileUploadForm.add(
        new AjaxSubmitLink("clear") {

          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            uploadHelper.removeUserPictures(user);
            target.add(userPhoto);
          }
        });
    fileUploadForm.add(new UploadProgressBar("progress", fileUploadForm, uploadField));
    add(fileUploadForm);

    fileUploadForm.add(
        new AjaxSubmitLink("uploadGravatar") {

          /** */
          private static final long serialVersionUID = 1L;

          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            // Attempt to download image from gravatar
            try {
              byte[] rawImage = gv.download(user.getMail());
              if (rawImage != null) {
                uploadHelper.processUserFileUpload(rawImage, user);
                userPhoto.setImageResource(user.getProfilePicture(User.PictureDimensions.Large));
                uploadField.clearInput();
                target.add(uploadField);
                target.add(userPhoto);
              }
            } catch (IOException e) {
              uploadHelper.removeUserPictures(user);
              target.add(userPhoto);
            }
          }
        });
  }
コード例 #3
0
  protected void initUI(StyleInfo style) {
    IModel<StyleInfo> styleModel =
        new CompoundPropertyModel(
            style != null
                ? new StyleDetachableModel(style)
                : getCatalog().getFactory().createStyle());

    styleForm =
        new Form("form", styleModel) {
          @Override
          protected void onSubmit() {
            super.onSubmit();
            onStyleFormSubmit();
          }
        };
    styleForm.setMarkupId("mainForm");
    add(styleForm);

    styleForm.add(nameTextField = new TextField("name"));
    nameTextField.setRequired(true);

    DropDownChoice<WorkspaceInfo> wsChoice =
        new DropDownChoice("workspace", new WorkspacesModel(), new WorkspaceChoiceRenderer());
    wsChoice.setNullValid(true);
    if (!isAuthenticatedAsAdmin()) {
      wsChoice.setNullValid(false);
      wsChoice.setRequired(true);
    }

    styleForm.add(wsChoice);
    styleForm.add(editor = new CodeMirrorEditor("SLD", new PropertyModel(this, "rawSLD")));
    // force the id otherwise this blasted thing won't be usable from other forms
    editor.setTextAreaMarkupId("editor");
    editor.setOutputMarkupId(true);
    editor.setRequired(true);
    styleForm.add(editor);

    if (style != null) {
      try {
        setRawSLD(readFile(style));
      } catch (IOException e) {
        // ouch, the style file is gone! Register a generic error message
        Session.get()
            .error(new ParamResourceModel("sldNotFound", this, style.getFilename()).getString());
      }
    }

    // style copy functionality
    styles =
        new DropDownChoice(
            "existingStyles", new Model(), new StylesModel(), new StyleChoiceRenderer());
    styles.setOutputMarkupId(true);
    styles.add(
        new AjaxFormComponentUpdatingBehavior("onchange") {

          @Override
          protected void onUpdate(AjaxRequestTarget target) {
            styles.validate();
            copyLink.setEnabled(styles.getConvertedInput() != null);
            target.addComponent(copyLink);
          }
        });
    styleForm.add(styles);
    copyLink = copyLink();
    copyLink.setEnabled(false);
    styleForm.add(copyLink);

    uploadForm = uploadForm(styleForm);
    uploadForm.setMultiPart(true);
    uploadForm.setMaxSize(Bytes.megabytes(1));
    uploadForm.setMarkupId("uploadForm");
    add(uploadForm);

    uploadForm.add(fileUploadField = new FileUploadField("filename"));

    add(validateLink());
    Link cancelLink =
        new Link("cancel") {
          @Override
          public void onClick() {
            setResponsePage(StylePage.class);
          }
        };
    add(cancelLink);
  }