/**
   * Opens the Dialog window modal.
   *
   * <p>It checks if the dialog opens with a new or existing object and set the readOnly mode
   * accordingly.
   *
   * @param aBranche
   * @throws InterruptedException
   */
  public void doShowDialog(SecRole aRole) throws InterruptedException {

    // if aRole == null then we opened the Dialog without
    // args for a given entity, so we get a new Obj().
    if (aRole == null) {
      /** !!! DO NOT BREAK THE TIERS !!! */
      // We don't create a new DomainObject() in the frontend.
      // We GET it from the backend.
      aRole = getSecurityService().getNewSecRole();
      setRole(aRole);
    } else {
      setRole(aRole);
    }

    // set Readonly mode accordingly if the object is new or not.
    if (aRole.isNew()) {
      doEdit();
      btnCtrl.setInitNew();
    } else {
      btnCtrl.setInitEdit();
      doReadOnly();
    }

    try {
      // fill the components with the data
      doWriteBeanToComponents(aRole);

      // stores the inital data for comparing if they are changed
      // during user action.
      doStoreInitValues();

      secRoleDialogWindow.doModal(); // open the dialog in modal mode
    } catch (final Exception e) {
      Messagebox.show(e.toString());
    }
  }
  /**
   * Deletes a secRole object from database.<br>
   *
   * @throws InterruptedException
   */
  private void doDelete() throws InterruptedException {

    final SecRole aRole = getRole();

    // Show a confirm box
    String msg =
        Labels.getLabel("message.Question.Are_you_sure_to_delete_this_record")
            + "\n\n --> "
            + aRole.getRolShortdescription();
    String title = Labels.getLabel("message.Deleting.Record");

    MultiLineMessageBox.doSetTemplate();
    if (MultiLineMessageBox.show(
            msg,
            title,
            MultiLineMessageBox.YES | MultiLineMessageBox.NO,
            MultiLineMessageBox.QUESTION,
            true,
            new EventListener() {
              @Override
              public void onEvent(Event evt) {
                switch (((Integer) evt.getData()).intValue()) {
                  case MultiLineMessageBox.YES:
                    try {
                      delete();
                    } catch (InterruptedException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                    }
                  case MultiLineMessageBox.NO:
                    break; //
                }
              }

              // delete from database
              private void delete() throws InterruptedException {

                try {
                  getSecurityService().delete(aRole);
                } catch (DataAccessException e) {
                  ZksampleMessageUtils.showErrorMessage(e.getMostSpecificCause().toString());
                }

                // now synchronize the listBox
                final ListModelList lml = (ListModelList) listBoxSecRoles.getListModel();

                // Check if the object is new or updated
                // -1 means that the obj is not in the list, so it's
                // new..
                if (lml.indexOf(aRole) == -1) {
                } else {
                  lml.remove(lml.indexOf(aRole));
                }

                secRoleDialogWindow.onClose(); // close
                // the
                // dialog
              }
            })
        == MultiLineMessageBox.YES) {}
  }
  /**
   * Writes the components values to the bean.<br>
   *
   * @param aRole
   */
  public void doWriteComponentsToBean(SecRole aRole) {

    aRole.setRolShortdescription(rolShortdescription.getValue());
    aRole.setRolLongdescription(rolLongdescription.getValue());
  }
  /**
   * Writes the bean data to the components.<br>
   *
   * @param aRole
   */
  public void doWriteBeanToComponents(SecRole aRole) {

    rolShortdescription.setValue(aRole.getRolShortdescription());
    rolLongdescription.setValue(aRole.getRolLongdescription());
  }