/**
   * Search/filter data for the filled out fields<br>
   * <br>
   * 1. Count how many textboxes are filled. <br>
   * 2. Create a map with the count entries. <br>
   * 3. Store the propertynames(must corresponds to the domain classes properties) and values to the
   * map. <br>
   * 4. Call the ServiceDAO method with the map as parameter. <br>
   */
  private void doSearchArticle() {

    // ++ create the searchObject and init sorting ++//
    // only in sample app init with all orders
    HibernateSearchObject<Article> soArticle =
        new HibernateSearchObject<Article>(Article.class, getPageSizeArticleSearch());
    soArticle.addSort("artNr", false);

    if (StringUtils.isNotEmpty(tb_OrderPosition_SearchArticlelNo.getValue())) {
      soArticle.addFilter(
          new Filter(
              "artNr", "%" + tb_OrderPosition_SearchArticlelNo.getValue() + "%", Filter.OP_ILIKE));
    }

    if (StringUtils.isNotEmpty(tb_OrderPosition_SearchArticleDesc.getValue())) {
      soArticle.addFilter(
          new Filter(
              "artKurzbezeichnung",
              "%" + tb_OrderPosition_SearchArticleDesc.getValue() + "%",
              Filter.OP_ILIKE));
    }

    // Set the ListModel.
    getPlwArticles().init(soArticle, listBoxArticleSearch, paging_ListBoxArticleSearch);
  }
  /**
   * when the "search/filter" button is clicked. It searches over a period. <br>
   * Checks if EndDate not before StartDate.<br>
   *
   * @param event
   */
  public void onClick$button_SecLoginlogList_bb_SearchDate(Event event) throws Exception {

    if (!(this.dbox_LoginLog_DateFrom.getValue() == null)
        && !(this.dbox_LoginLog_DateTo.getValue() == null)) {

      if (this.dbox_LoginLog_DateFrom.getValue().after(this.dbox_LoginLog_DateTo.getValue())) {
        MultiLineMessageBox.doSetTemplate();
        MultiLineMessageBox.show(Labels.getLabel("message_EndDate_Before_BeginDate"));
      } else {
        Date dateFrom = this.dbox_LoginLog_DateFrom.getValue();
        Date dateTo = this.dbox_LoginLog_DateTo.getValue();

        final Calendar calFrom = Calendar.getInstance();
        calFrom.setTime(dateFrom);
        calFrom.set(Calendar.AM_PM, 0);
        calFrom.set(Calendar.HOUR, 0);
        calFrom.set(Calendar.MINUTE, 0);
        calFrom.set(Calendar.SECOND, 1);
        dateFrom = calFrom.getTime();

        final Calendar calTo = Calendar.getInstance();
        calTo.setTime(dateTo);
        calTo.set(Calendar.AM_PM, 1);
        calTo.set(Calendar.HOUR, 11);
        calTo.set(Calendar.MINUTE, 59);
        calTo.set(Calendar.SECOND, 59);
        dateTo = calTo.getTime();

        // ++ create the searchObject and init sorting ++//
        final HibernateSearchObject<SecLoginlog> soSecLoginlog =
            new HibernateSearchObject<SecLoginlog>(SecLoginlog.class, getCountRows());
        // deeper loading of the relations to prevent the lazy
        // loading problem.
        soSecLoginlog.addFetch("ip2Country.countryCode");
        soSecLoginlog.addSort("lglLogtime", true);

        soSecLoginlog.addFilter(new Filter("lglLogtime", dateFrom, Filter.OP_GREATER_OR_EQUAL));
        soSecLoginlog.addFilter(new Filter("lglLogtime", dateTo, Filter.OP_LESS_OR_EQUAL));

        // Set the ListModel
        getPagedListWrapper()
            .init(soSecLoginlog, this.listBoxSecUserlog, this.paging_SecUserLogList);

        this.checkbox_SecLoginlogList_ShowAll.setChecked(false);
      }
    }
  }
  /**
   * when the checkBox 'only failed' for filtering is checked. <br>
   *
   * @param event
   */
  public void onCheck$checkbox_SecLoginlogList_ShowOnlyFailed(Event event) {

    // empty the text search boxes
    this.tb_SecUserlog_LoginName.setValue(""); // clear
    this.checkbox_SecLoginlogList_ShowAll.setChecked(false);
    this.checkbox_SecLoginlogList_ShowOnlySuccess.setChecked(false);

    // ++ create the searchObject and init sorting ++//
    final HibernateSearchObject<SecLoginlog> soSecLoginlog =
        new HibernateSearchObject<SecLoginlog>(SecLoginlog.class, getCountRows());
    // deeper loading of the relations to prevent the lazy
    // loading problem.
    soSecLoginlog.addFetch("ip2Country.countryCode");
    soSecLoginlog.addSort("lglLogtime", true);

    soSecLoginlog.addFilter(new Filter("lglStatusid", 0, Filter.OP_EQUAL));

    // Set the ListModel
    getPagedListWrapper().init(soSecLoginlog, this.listBoxSecUserlog, this.paging_SecUserLogList);
  }
  /**
   * Filter the logins log list with 'like LoginName'. <br>
   * We check additionally if something is selected in the right type listbox <br>
   * for including in the search statement.<br>
   */
  public void onClick$button_SecLoginlogList_SearchLoginName(Event event) throws Exception {

    // if not empty
    if (!this.tb_SecUserlog_LoginName.getValue().isEmpty()) {
      this.checkbox_SecLoginlogList_ShowAll.setChecked(false); // clear

      // ++ create the searchObject and init sorting ++//
      final HibernateSearchObject<SecLoginlog> soSecLoginlog =
          new HibernateSearchObject<SecLoginlog>(SecLoginlog.class, getCountRows());
      // deeper loading of the relations to prevent the lazy
      // loading problem.
      soSecLoginlog.addFetch("ip2Country.countryCode");
      soSecLoginlog.addSort("lglLogtime", true);

      soSecLoginlog.addFilter(
          new Filter("lglLoginname", this.tb_SecUserlog_LoginName.getValue(), Filter.OP_EQUAL));

      // Set the ListModel
      getPagedListWrapper().init(soSecLoginlog, this.listBoxSecUserlog, this.paging_SecUserLogList);
    }
  }
  /**
   * Saves the components to table. <br>
   *
   * @throws InterruptedException
   */
  public void doSave() throws InterruptedException {

    Orderposition anOrderposition = getOrderposition();

    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // force validation, if on, than execute by component.getValue()
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    if (!isValidationOn()) {
      doSetValidation();
    }

    artNr.getValue();

    // additionally calculate new
    if (isDataChanged()) {
      doCalculate();
    }

    // fill the objects with the components data
    doWriteComponentsToBean(anOrderposition);

    // save it to database
    try {
      getOrderService().saveOrUpdate(anOrderposition);
    } catch (DataAccessException e) {
      ZksampleMessageUtils.showErrorMessage(e.getMostSpecificCause().toString());

      // Reset to init values
      doResetInitValues();

      doReadOnly();
      btnCtrl.setBtnStatus_Save();
      return;
    }

    /** Synchronize the listbox in the OrderDialog */
    HibernateSearchObject<Orderposition> soOrderPosition =
        new HibernateSearchObject<Orderposition>(
            Orderposition.class, orderDialogCtrl.getPageSizeOrderPosition());
    soOrderPosition.addFilter(new Filter("order", getOrder(), Filter.OP_EQUAL));
    // deeper loading of a relation to prevent the lazy
    // loading problem.
    soOrderPosition.addFetch("article");

    // Set the ListModel.
    getPlwOrderpositions()
        .init(
            soOrderPosition,
            orderDialogCtrl.listBoxOrderOrderPositions,
            orderDialogCtrl.paging_ListBoxOrderOrderPositions);

    /** Synchronize the OrderList */
    // Listbox listBoxOrderArticle = orderListCtrl.getListBoxOrderArticle();
    // listBoxOrderArticle.setModel(orderDialogCtrl.listBoxOrderOrderPositions.getModel());
    orderListCtrl
        .getListBoxOrderArticle()
        .setModel(orderDialogCtrl.listBoxOrderOrderPositions.getModel());

    // synchronize the TotalCount from the paging component
    orderListCtrl.paging_OrderArticleList.setTotalSize(
        orderDialogCtrl.paging_ListBoxOrderOrderPositions.getTotalSize());

    doReadOnly();
    btnCtrl.setBtnStatus_Save();
    // init the old values vars new
    doStoreInitValues();
  }