Пример #1
0
  void handleSaveButtonClicked() {
    getUi().getForm().commit();
    @SuppressWarnings("unchecked")
    BeanItem<Company> companyBeanItem = (BeanItem<Company>) getUi().getForm().getItemDataSource();
    Company company = companyBeanItem.getBean();

    /**
     * Avoid duplicate entry for the same email address. This has to be checked programatically as
     * GAE does not support unique constraints
     */
    if (company.getId() == null && isCompanyExisting(company.getCname())) {
      getUi().showError(Lang.getMessage("DuplicateEntryMsg", "cname"), null);
      return;
    }

    // Encrypt and set the password, only if a new one is given
    // TODO fix me
    if (company.getNewPassword() != null && company.getNewPassword().length() > 0) {
      String hashedPassword = PasswordUtil.generateHashedPassword(company.getNewPassword());
      company.setPassword(hashedPassword);
    }

    try {
      // Store the Company
      FacadeFactory.getFacade().store(company);

    } catch (Exception e) {
      getUi().showError(Lang.getMessage("ChangesSaveFailedMsg"), "Details: " + e.getMessage());
    }
    updateTable();
  }
Пример #2
0
  void deleteCompany() {
    // Cache the current items neighbours
    Company selectedCompany = getSelectedCompany();
    System.out.println("in delete:" + selectedCompany);
    if (selectedCompany == null) return;

    Object nextNeighbour = getUi().getTable().nextItemId(selectedCompany);
    Object previousNeighbour = getUi().getTable().prevItemId(selectedCompany);

    // remove from store
    FacadeFactory.getFacade().delete(selectedCompany);

    // remove from container, refreshes the view
    compContainer.removeItem(selectedCompany);

    // Select some other row
    if (nextNeighbour != null) {
      getUi().getTable().select(nextNeighbour);
    } else if (previousNeighbour != null) {
      getUi().getTable().select(previousNeighbour);
    } else if (getUi().getTable().size() == 0) {
      getUi().getTable().select(null);

    } else {
      getUi().getTable().select(getUi().getTable().firstItemId());
    }
  }
Пример #3
0
  /**
   * Checks whether a Company with that given email address is already in the DB
   *
   * @param email
   * @return
   */
  private boolean isCompanyExisting(String cname) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("cname", cname);

    Company c =
        FacadeFactory.getFacade().find("SELECT c FROM Company c WHERE c.cname = :cname", params);

    if (c == null) {
      return false;
    } else {
      return true;
    }
  }