Example #1
0
  public void save(Button.ClickEvent event) {
    try {
      formFieldBindings.commit();

      service.saveAsNewCoin(coin, crawlerResult);

      String msg = String.format("Saved '%s'.", coin.getName());
      Notification.show(msg, Notification.Type.TRAY_NOTIFICATION);
      parentTable.refreshResults();
    } catch (FieldGroup.CommitException e) {
      e.printStackTrace();
    }
  }
Example #2
0
  public void edit(CrawlerResult crawlerResult) {
    this.crawlerResult = crawlerResult;
    if (crawlerResult != null) {
      coin = new Coin();
      coin.setName(crawlerResult.getName());
      coin.setNominal(NameUtils.parseNominal(crawlerResult.getName()));

      CoinVariant variant = new CoinVariant();
      //        variant.setReleaseDate(LocalDate.now());
      variant.setVariant(NameUtils.parseVariant(crawlerResult.getVariant()));
      if (variant.getVariant() == Variant.UNKNOWN) {
        variant.setVariant(NameUtils.parseVariant(crawlerResult.getName()));
      }
      coin.addVariant(variant);
      variantField.setValue(variant.getVariant());

      CoinVariantHistory history = new CoinVariantHistory();
      history.setDate(crawlerResult.getProcessed());
      history.setSource(crawlerResult.getSource().toString());
      Money price = PriceUtils.parse(crawlerResult.getPrice());
      if (price == null) {
        price = Money.euros(0.0);
      }
      history.setPrice(price);
      variant.addHistory(history);
      priceField.setValue(price.toString());

      formFieldBindings = BeanFieldGroup.bindFieldsBuffered(coin, this);

      sourceLink.setCaption(LinkUtils.getSourceUrl(crawlerResult));
      sourceLink.setResource(new ExternalResource(LinkUtils.getUrl(crawlerResult)));
      sourceLink.setTargetName("_blank");

      name.focus();
    }
    setVisible(crawlerResult != null);
  }