コード例 #1
0
ファイル: EntityConfig.java プロジェクト: marcusbb/cql-util
  /**
   * Populates and iterates through a {@link Row} using {@link ColumnDefinitions} provided by the
   * driver.
   *
   * @param row
   * @return
   */
  public T get(Row row) {

    // Entity and its associated id object
    T entity = null;
    Object idObj = null;

    try {
      entity = entityClass.newInstance();
      idObj = null;
      ColumnMapping idcolmap = null;
      // Note that this early invocation means that
      // you can't populate on #setId in your java bean method
      if (embedded != null) {
        idObj = embedded.field.getType().newInstance();
        embedded.set(entity, idObj);
      } else {
        idObj = idMapping.field.getType().newInstance();
        idMapping.set(entity, idObj);
      }

    } catch (InstantiationException | IllegalAccessException e) {
      throw new IllegalAccessError(
          "A configuration exception has occurred in creating entity: " + entityClass);
    }
    ColumnDefinitions metaData = row.getColumnDefinitions();
    List<Definition> defList = metaData.asList();

    for (Definition def : defList) {
      ColumnMapping mapping = colsToFields.get(def.getName());

      if (mapping == null) {

        // it could be an id column
        if (idMapping != null && def.getName().equals(idMapping.name)) {
          idMapping.set(entity, getValue(row, idMapping, def));
          continue;
        }

        // else: need to find it, possible point of refactor
        ColumnMapping nembed = null;
        if (embedded != null) nembed = embedded.get(def.getName());
        if (nembed != null) nembed.set(idObj, getValue(row, nembed, def));

        continue;
      }

      Object value = getValue(row, mapping, def);
      // set it
      if (value != null) mapping.set(entity, value);
    }
    return entity;
  }
コード例 #2
0
 private void displayPreviewImage() {
   if (scaleImageData != null && scaleImageData.length > 0) {
     ByteArrayImageResource previewResource =
         new ByteArrayImageResource(scaleImageData, "image/png");
     previewImage.setSource(previewResource);
   }
 }
  private PersistentProperty createEmbedded(
      GrailsDomainClassMappingContext mappingContext,
      GrailsDomainClassProperty grailsDomainClassProperty) {
    final PropertyMapping<Property> mapping = createDefaultMapping(grailsDomainClassProperty);
    Embedded persistentProperty =
        new Embedded(
            this,
            mappingContext,
            grailsDomainClassProperty.getName(),
            grailsDomainClassProperty.getClass()) {
          public PropertyMapping getMapping() {
            return mapping;
          }
        };
    persistentProperty.setOwningSide(grailsDomainClassProperty.isOwningSide());
    persistentProperty.setReferencedPropertyName(
        grailsDomainClassProperty.getReferencedPropertyName());

    return persistentProperty;
  }
コード例 #4
0
  @SuppressWarnings("serial")
  @Override
  public void editPhoto(final byte[] imageData) {
    this.removeAllComponents();
    LOG.debug("Receive avatar upload with size: " + imageData.length);
    try {
      originalImage = ImageIO.read(new ByteArrayInputStream(imageData));
    } catch (IOException e) {
      throw new UserInvalidInputException("Invalid image type");
    }
    originalImage = ImageUtil.scaleImage(originalImage, 650, 650);

    MHorizontalLayout previewBox =
        new MHorizontalLayout()
            .withSpacing(true)
            .withMargin(new MarginInfo(false, true, true, false))
            .withWidth("100%");

    Resource defaultPhoto =
        UserAvatarControlFactory.createAvatarResource(AppContext.getUserAvatarId(), 100);
    previewImage = new Embedded(null, defaultPhoto);
    previewImage.setWidth("100px");
    previewBox.with(previewImage).withAlign(previewImage, Alignment.TOP_LEFT);

    VerticalLayout previewBoxRight = new VerticalLayout();
    previewBoxRight.setMargin(new MarginInfo(false, true, false, true));
    Label lbPreview =
        new Label(
            "<p style='margin: 0px;'><strong>To the left is what your profile photo will look like.</strong></p>"
                + "<p style='margin-top: 0px;'>To make adjustment, you can drag around and resize the selection square below. "
                + "When you are happy with your photo, click the &ldquo;Accept&ldquo; button.</p>",
            ContentMode.HTML);
    previewBoxRight.addComponent(lbPreview);

    MHorizontalLayout controlBtns = new MHorizontalLayout();
    controlBtns.setSizeUndefined();

    Button cancelBtn =
        new Button(
            AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
              @Override
              public void buttonClick(ClickEvent event) {
                EventBusFactory.getInstance()
                    .post(new ProfileEvent.GotoProfileView(ProfilePhotoUploadViewImpl.this, null));
              }
            });
    cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK);

    Button acceptBtn =
        new Button(
            AppContext.getMessage(GenericI18Enum.BUTTON_ACCEPT),
            new Button.ClickListener() {
              @Override
              public void buttonClick(ClickEvent event) {
                if (scaleImageData != null && scaleImageData.length > 0) {
                  try {
                    BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData));
                    UserAvatarService userAvatarService =
                        ApplicationContextUtil.getSpringBean(UserAvatarService.class);
                    userAvatarService.uploadAvatar(
                        image, AppContext.getUsername(), AppContext.getUserAvatarId());
                    Page.getCurrent().getJavaScript().execute("window.location.reload();");
                  } catch (IOException e) {
                    throw new MyCollabException("Error when saving user avatar", e);
                  }
                }
              }
            });
    acceptBtn.setStyleName(UIConstants.BUTTON_ACTION);
    acceptBtn.setIcon(FontAwesome.CHECK);

    controlBtns.with(acceptBtn, cancelBtn).alignAll(Alignment.MIDDLE_LEFT);

    previewBoxRight.addComponent(controlBtns);
    previewBoxRight.setComponentAlignment(controlBtns, Alignment.TOP_LEFT);

    previewBox.addComponent(previewBoxRight);
    previewBox.setExpandRatio(previewBoxRight, 1.0f);

    this.addComponent(previewBox);

    CssLayout cropBox = new CssLayout();
    cropBox.addStyleName(UIConstants.PHOTO_CROPBOX);
    cropBox.setWidth("100%");
    VerticalLayout currentPhotoBox = new VerticalLayout();
    Resource resource =
        new ByteArrayImageResource(ImageUtil.convertImageToByteArray(originalImage), "image/png");
    CropField cropField = new CropField(resource);
    cropField.setImmediate(true);
    cropField.setSelectionAspectRatio(1.0f);
    cropField.addValueChangeListener(
        new Property.ValueChangeListener() {

          @Override
          public void valueChange(Property.ValueChangeEvent event) {
            VCropSelection newSelection = (VCropSelection) event.getProperty().getValue();
            int x1 = newSelection.getXTopLeft();
            int y1 = newSelection.getYTopLeft();
            int x2 = newSelection.getXBottomRight();
            int y2 = newSelection.getYBottomRight();
            if (x2 > x1 && y2 > y1) {
              BufferedImage subImage = originalImage.getSubimage(x1, y1, (x2 - x1), (y2 - y1));
              ByteArrayOutputStream outStream = new ByteArrayOutputStream();
              try {
                ImageIO.write(subImage, "png", outStream);
                scaleImageData = outStream.toByteArray();
                displayPreviewImage();
              } catch (IOException e) {
                LOG.error("Error while scale image: ", e);
              }
            }
          }
        });
    currentPhotoBox.setWidth("650px");
    currentPhotoBox.setHeight("650px");

    currentPhotoBox.addComponent(cropField);

    cropBox.addComponent(currentPhotoBox);

    this.addComponent(previewBox);
    this.addComponent(cropBox);
    this.setExpandRatio(cropBox, 1.0f);
  }
コード例 #5
0
 private void setTooltip(String tt) {
   setDescription(tt); // abslay
   if (titleImage != null) titleImage.setDescription(tt);
   if (title != null) title.setDescription(tt);
   content.setDescription(tt);
 }
コード例 #6
0
  /** @param el */
  public BookImage(Books el, String user) {
    super();
    this.Book = el;

    this.setStyleName("cells");
    this.setHeight("250px");
    this.setWidth("200px");

    rating.setAnimated(true);
    rating.setCaption(null);
    rating.setMaxValue(5);
    rating.setStyleName("rating");
    rating.setReadOnly(true);

    rating_my.setAnimated(true);
    rating_my.setCaption(null);
    rating_my.setMaxValue(5);
    rating_my.setStyleName("rating_my");

    IRaitingService iRaitingService = new IRaitingService();
    try {
      double rate = iRaitingService.getRaiting(el.getId());
      rating.setReadOnly(false);
      rating.setValue(rate);
      rating.setReadOnly(true);
      double myrate = iRaitingService.getRaiting(user, el.getId());
      rating_my.setValue(myrate);
    } catch (SQLException e) {
      e.printStackTrace();
    }

    rating_my.addValueChangeListener(
        e -> {
          try {
            Rating rat =
                iRaitingService.getUser(
                    getUI().getSession().getAttribute("user").toString(), el.getId());

            rat.setRaiting(rating_my.getValue());

            iRaitingService.update(rat);

            double rate = iRaitingService.getRaiting(el.getId());
            rating.setReadOnly(false);
            rating.setValue(rate);
            rating.setReadOnly(true);

            new Notification(String.valueOf(rate), Notification.Type.TRAY_NOTIFICATION)
                .show(Page.getCurrent());
          } catch (SQLException e1) {
            e1.printStackTrace();
          }
        });

    rating_layout.addComponent(rating);
    rating_layout.addComponent(rating_my);
    rating_layout.setComponentAlignment(rating, Alignment.MIDDLE_LEFT);
    rating_layout.setComponentAlignment(rating_my, Alignment.MIDDLE_LEFT);
    rating_layout.setStyleName("ratinglayout");

    imageEmbedded.setSource(new FileResource(new File(Book.getImage())));

    title.setValue(Book.getTitle());
    author.setValue(Book.getAuthor());

    if (Book.getFile().isEmpty()) buttonDownload.setEnabled(false);

    buttonDownload.setWidth("80%");
    imageEmbedded.setWidth("100%");
    imageEmbedded.setHeight("100%");

    title.setWidth(null);
    author.setWidth(null);

    VerticalLayout bodyLayout = new VerticalLayout(title, author, imageEmbedded);

    bodyLayout.setExpandRatio(title, 12);
    bodyLayout.setExpandRatio(author, 8);
    bodyLayout.setExpandRatio(imageEmbedded, 80);
    bodyLayout.setSizeFull();
    bodyLayout.setComponentAlignment(title, Alignment.MIDDLE_CENTER);
    bodyLayout.setComponentAlignment(author, Alignment.MIDDLE_CENTER);
    bodyLayout.setComponentAlignment(imageEmbedded, Alignment.MIDDLE_CENTER);

    buttonDownload.setStyleName("super-button");
    title.setStyleName("name-label");
    author.setStyleName("author-label");

    this.addComponent(rating_layout);
    this.addComponent(bodyLayout);
    this.addComponent(buttonDownload);

    this.setComponentAlignment(rating_layout, Alignment.TOP_CENTER);
    this.setComponentAlignment(bodyLayout, Alignment.TOP_CENTER);
    this.setComponentAlignment(buttonDownload, Alignment.BOTTOM_CENTER);
    this.setExpandRatio(rating_layout, 5);
    this.setExpandRatio(bodyLayout, 85);
    this.setExpandRatio(buttonDownload, 10);

    StreamResource sr = getStream();
    FileDownloader fileDownloader = new FileDownloader(sr);
    fileDownloader.extend(buttonDownload);

    bodyLayout.addLayoutClickListener(
        e -> {
          BookWin win = new BookWin(this.Book);
          UI.getCurrent().addWindow(win);
        });
  }