/** <code>clearActionPerformed()</code> defines for reseting all components. */
 private void clearActionPerformed() {
   txfTitle.setText("");
   txfNumber.setText("");
   txfFromDate.setDate(null);
   txfToDate.setDate(null);
   txfUserName.setText("");
   rdoCopyrightReq.setSelected(true);
   rdoNoAnswerReq.setSelected(true);
   rdoHasNumber.setSelected(true);
   chkAnswerDate.setSelected(false);
   chkRequestDate.setSelected(false);
   chkSetNumberDate.setSelected(false);
   txfFromDate.setEnabled(false);
   txfToDate.setEnabled(false);
   cmbDocType.setEnabled(false);
   userId = 0;
   dataFetcher.setReportObject(null);
   grid.refresh();
 }
  /**
   * <code>guiInit()</code> defined for component initialization and setting up actions and models
   * of each component
   */
  private void guiInit() {
    setTitle(props.getProperty("page.name"));

    ButtonGroup typeButtonGroup = new ButtonGroup();
    typeButtonGroup.add(rdoCopyrightReq);
    typeButtonGroup.add(rdoDepositReq);

    ButtonGroup isAnsweredButtonGroup = new ButtonGroup();
    isAnsweredButtonGroup.add(rdoAnswerReq);
    isAnsweredButtonGroup.add(rdoNoAnswerReq);

    ButtonGroup hasNumberButtonGroup = new ButtonGroup();
    hasNumberButtonGroup.add(rdoHasNumber);
    hasNumberButtonGroup.add(rdoNoNumber);

    lblNumberSufix.setText(
        StringConsts.LRM
            + String.valueOf('\u062D')
            + " "
            + StringConsts.LRM
            + WorkflowConstants.NO_DATA);

    ConstantTableDefinition docType =
        ConstantPool.getInstance().findConstantTableByName(ConstantTables.COPYRIGHT_NONE_BOOK_TYPE);
    cmbDocType =
        ComponentFactory.createConstantTableCombo(
            docType, new Dimension(150, 16), true, screenLocale);
    cmbDocType.setSelectedIndex(0);

    componentsInit();

    btnSelectUser.setIcon(WorkflowUiUtils.SELECT_USER_ICON);
    btnSelectUser.setBorder(null);

    setGridColumns();

    setGridActions();
  }
  /**
   * <code>reportActionPerformed()</code> defiens for searching copyrights in DB according to search
   * keys.
   */
  private void reportActionPerformed() {
    filterObject = new TempRequestReport();
    int counter = 0;
    previewHeaderText = new String();
    radioValue = new String();

    if (!txfTitle.getText().equals(""))
      filterObject.setTitle((txfTitle.getText().toUpperCase().trim()));

    if (!txfNumber.getText().equals(""))
      filterObject.setNumber(StringUtils.arabicToLatinDigit(txfNumber.getText()).trim());

    if (rdoAnswerReq.isSelected()) {
      filterObject.setIsAnswered(WorkflowConstants.IS_ANSWERED_REQUEST);
      radioValue = props.getProperty("print_answered_req.name");
    } else if (rdoNoAnswerReq.isSelected()) {
      filterObject.setIsAnswered(WorkflowConstants.IS_NOT_ANSWERED_REQUEST);
      radioValue = props.getProperty("print_no_answered_req.name");
    }

    if (rdoHasNumber.isSelected()) {
      filterObject.setHasNumber(WorkflowConstants.HAS_NUMBER);
      radioValue += " " + props.getProperty("print_has_number_req.name");
    } else if (rdoNoNumber.isSelected()) {
      filterObject.setHasNumber(WorkflowConstants.NO_NUMBER);
      radioValue += " " + props.getProperty("print_no_number_req.name");
    }

    if (txfUserName.getText() != null
        && txfUserName.getText() != ""
        && txfUserName.getText().length() != 0) filterObject.setUserId(userId);

    if (rdoCopyrightReq.isSelected()) {
      filterObject.setType(WorkflowConstants.COPY_RIGHT_BOOK_TYPE);
      filterObject.setDocType("");
      radioValue += " " + props.getProperty("print_copy_right_req.name");
    } else if (rdoDepositReq.isSelected()) {
      filterObject.setType(WorkflowConstants.COPY_RIGHT_NON_BOOK_TYPE);
      if (cmbDocType.getSelectedIndex() != 0) {
        filterObject.setDocType(((ConstantTableItem) cmbDocType.getSelected()).getCode());
      } else filterObject.setDocType("");
      radioValue += " " + props.getProperty("print_deposit_req.name");
    }

    if (chkAnswerDate.isSelected()) {
      filterObject.setAnswerDate(WorkflowConstants.SELECTED);
      previewHeaderText = props.getProperty("answer_date.name");
      counter++;
    }
    if (chkRequestDate.isSelected()) {
      filterObject.setRequestDate(WorkflowConstants.SELECTED);
      if (counter > 0)
        previewHeaderText += " " + '\u060c' + " " + props.getProperty("request_date.name");
      else previewHeaderText += " " + props.getProperty("request_date.name");
      counter++;
    }

    if (chkSetNumberDate.isSelected()) {
      filterObject.setSetNumberDate(WorkflowConstants.SELECTED);
      if (counter > 0)
        previewHeaderText += " " + '\u060c' + " " + props.getProperty("set_number_date.name");
      else previewHeaderText += " " + props.getProperty("set_number_date.name");
    }

    if (txfFromDate.getDate() != null && txfToDate.getDate() != null) {
      if (txfFromDate.getDate().getTime() > txfToDate.getDate().getTime()) {
        MessagePanes.showErrorDialog(
            this, props.getProperty("from_date_larger.name"), LocaleUtils.PERSIAN);
        return;
      }
    }

    if (txfFromDate.getDate() != null) {
      filterObject.setFromDate(txfFromDate.getDate());
      if (!previewHeaderText.equals(""))
        previewHeaderText +=
            " "
                + props.getProperty("from_date.name")
                + " "
                + StringUtils.RTL_MARK
                + txfFromDate.getDate();
    }
    if (txfToDate.getDate() != null) {
      filterObject.setToDate(txfToDate.getDate());
      if (!previewHeaderText.equals(""))
        previewHeaderText +=
            " "
                + props.getProperty("to_date.name")
                + " "
                + StringUtils.RTL_MARK
                + txfToDate.getDate();
    }
    if (txfToDate.getDate() == null && txfFromDate.getDate() == null)
      previewHeaderText = new String();

    dataFetcher.setReportObject(filterObject);
    grid.refresh();
    if (grid.getDataModel().getData().getDataList() == null
        || grid.getDataModel().getData().getDataList().size() == 0)
      MessagePanes.showInfoDialog(this, props.getProperty("empty_list.name"), LocaleUtils.PERSIAN);
  }
  private void componentsInit() {
    rdoCopyrightReq.setSelected(true);
    rdoNoAnswerReq.setSelected(true);
    rdoHasNumber.setSelected(true);
    cmbDocType.setEnabled(false);
    txfFromDate.setEnabled(false);
    txfToDate.setEnabled(false);
    txfUserName.setEnabled(false);

    chkAnswerDate.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (chkAnswerDate.isSelected()) {
              txfFromDate.setEnabled(true);
              txfToDate.setEnabled(true);
            } else {
              if (!chkRequestDate.isSelected() && !chkSetNumberDate.isSelected()) {
                txfFromDate.setEnabled(false);
                txfToDate.setEnabled(false);
              }
            }
          }
        });

    chkRequestDate.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (chkRequestDate.isSelected()) {
              txfFromDate.setEnabled(true);
              txfToDate.setEnabled(true);
            } else {
              if (!chkAnswerDate.isSelected() && !chkSetNumberDate.isSelected()) {
                txfFromDate.setEnabled(false);
                txfToDate.setEnabled(false);
              }
            }
          }
        });

    chkSetNumberDate.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (chkSetNumberDate.isSelected()) {
              txfFromDate.setEnabled(true);
              txfToDate.setEnabled(true);
            } else {
              if (!chkAnswerDate.isSelected() && !chkRequestDate.isSelected()) {
                txfFromDate.setEnabled(false);
                txfToDate.setEnabled(false);
              }
            }
          }
        });

    GuiUtils.switchKeyboardOnFocus(txfTitle, LocaleUtils.PERSIAN_LOCALE);
    GuiUtils.switchKeyboardOnFocus(txfNumber, LocaleUtils.ENGLISH_LOCALE);
    txfTitle.addKeyListener(
        new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            if (!(e.getSource() instanceof JTextComponent) || !Character.isDigit(e.getKeyChar()))
              return;
            JTextComponent tc = (JTextComponent) e.getSource();
            if (tc.getInputContext() == null || tc.getInputContext().getLocale() == null) return;
            Locale locale = tc.getInputContext().getLocale();
            if ("fa".equals(locale.getLanguage()))
              e.setKeyChar(StringUtils.latinToExtendedArabicDigit(e.getKeyChar()));
            else if ("ar".equals(locale.getLanguage()))
              e.setKeyChar(StringUtils.latinToArabicDigit(e.getKeyChar()));
          }
        });

    ActionListener actionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (rdoCopyrightReq.isSelected()) {
              cmbDocType.setEnabled(false);
              lblNumberSufix.setText(
                  StringConsts.LRM
                      + String.valueOf('\u062D')
                      + " "
                      + StringConsts.LRM
                      + WorkflowConstants.NO_DATA);
            }
            if (rdoDepositReq.isSelected()) {
              cmbDocType.setEnabled(true);
              lblNumberSufix.setText(
                  StringConsts.LRM
                      + String.valueOf('\u0648')
                      + " "
                      + StringConsts.LRM
                      + WorkflowConstants.NO_DATA);
            }
          }
        };
    rdoCopyrightReq.addActionListener(actionListener);
    rdoDepositReq.addActionListener(actionListener);
  }