@Override
    protected Field<?> onCreateField(final Object propertyId) {
      if (propertyId.equals("roleid")) {
        return new AdminRoleSelectionField();
      } else if (propertyId.equals("firstname")
          || propertyId.equals("lastname")
          || propertyId.equals("email")) {
        final TextField tf = new TextField();
        tf.setNullRepresentation("");
        tf.setRequired(true);
        tf.setRequiredError("This field must be not null");
        return tf;
      } else if (propertyId.equals("dateofbirth")) {
        return new DateComboboxSelectionField();
      } else if (propertyId.equals("timezone")) {
        TimeZoneSelectionField cboTimezone = new TimeZoneSelectionField(false);
        if (UserAddViewImpl.this.user.getTimezone() != null) {
          cboTimezone.setTimeZone(
              TimezoneMapper.getTimezoneExt(UserAddViewImpl.this.user.getTimezone()));
        } else {
          if (AppContext.getSession().getTimezone() != null) {
            cboTimezone.setTimeZone(
                TimezoneMapper.getTimezoneExt(AppContext.getSession().getTimezone()));
          }
        }
        return cboTimezone;
      } else if (propertyId.equals("country")) {
        final CountryComboBox cboCountry = new CountryComboBox();
        cboCountry.addValueChangeListener(
            new Property.ValueChangeListener() {
              private static final long serialVersionUID = 1L;

              @Override
              public void valueChange(final Property.ValueChangeEvent event) {
                UserAddViewImpl.this.user.setCountry((String) cboCountry.getValue());
              }
            });
        return cboCountry;
      }
      return null;
    }
  private void displayUserAvatar() {
    this.userAvatar.removeAllComponents();
    this.userAvatar.addStyleName("avatar-pass-wrapper");
    this.userAvatar.setMargin(true);
    final Image cropField =
        UserAvatarControlFactory.createUserAvatarEmbeddedComponent(
            AppContext.getUserAvatarId(), 100);

    final HorizontalLayout avatarAndPass = new HorizontalLayout();
    avatarAndPass.setSpacing(true);
    avatarAndPass.setWidth("100%");
    avatarAndPass.addComponent(cropField);
    final Button btnChangePassword =
        new Button(
            LocalizationHelper.getMessage(UserI18nEnum.BUTTON_CHANGE_PASSWORD),
            new Button.ClickListener() {
              private static final long serialVersionUID = 1L;

              @Override
              public void buttonClick(final ClickEvent event) {
                UI.getCurrent().addWindow(new PasswordChangeWindow(formItem.user));
              }
            });
    final VerticalLayout passLayout = new VerticalLayout();
    passLayout.setMargin(new MarginInfo(true, false, false, false));
    final Label userName = new Label(AppContext.getSession().getDisplayName());
    userName.setStyleName("h1");
    passLayout.addComponent(userName);
    passLayout.addComponent(btnChangePassword);
    btnChangePassword.setStyleName("link");
    passLayout.setComponentAlignment(btnChangePassword, Alignment.MIDDLE_LEFT);
    avatarAndPass.addComponent(passLayout);
    avatarAndPass.setComponentAlignment(passLayout, Alignment.TOP_LEFT);
    avatarAndPass.setExpandRatio(passLayout, 1.0f);

    this.userAvatar.addComponent(avatarAndPass);

    final UploadField avatarUploadField =
        new UploadField() {
          private static final long serialVersionUID = 1L;

          @Override
          protected void updateDisplay() {
            byte[] imageData = (byte[]) this.getValue();
            String mimeType = this.getLastMimeType();
            if (mimeType.equals("image/jpeg")) {
              imageData = ImageUtil.convertJpgToPngFormat(imageData);
              if (imageData == null) {
                throw new UserInvalidInputException("Do not support image format for avatar");
              } else {
                mimeType = "image/png";
              }
            }

            if (mimeType.equals("image/png")) {
              EventBus.getInstance()
                  .fireEvent(new ProfileEvent.GotoUploadPhoto(ProfileReadViewImpl.this, imageData));
            } else {
              throw new UserInvalidInputException(
                  "Upload file does not have valid image format. The supported formats are jpg/png");
            }
          }
        };
    avatarUploadField.setButtonCaption("Change Avatar");
    avatarUploadField.setFieldType(FieldType.BYTE_ARRAY);
    this.userAvatar.addComponent(avatarUploadField);
  }
Esempio n. 3
0
 private void setUserInfo() {
   userAvatar.setSource(
       UserAvatarControlFactory.createAvatarResource(AppContext.getUserAvatarId(), 24));
   userName.setCaption(AppContext.getSession().getDisplayName());
 }