public void reset() {
   resetUsersPreferences();
   initialize();
   FacesUtils.clearFacesTreeValues();
   MessageDialog.addInfoMessage(
       MessagesViewsCommonBean.getInstance().getString("views.common.config.reset"));
 }
  /**
   * Action handler - gets invoked on send mail click button
   *
   * @param actionEvent
   * @throws Exception
   */
  public void sendMessage(ActionEvent actionEvent) throws Exception {
    try {
      Map<RecipientType, String[]> recipientDetails = new HashMap<RecipientType, String[]>();
      List<String> errorMsg = validateMailAddresses(recipientDetails);

      if (errorMsg.size() == 0) {
        String mailContent = editor.getContent();
        // Replace with <br/>, to maintain multiline msg entered on TextArea
        mailContent = mailContent.replaceAll("(\r\n|\n)", "<br />");
        // Send mail
        boolean sendMailSuccess =
            mailService.sendMail(
                recipientDetails, mailSender, mailSubject, mailContent, attachments);

        if (sendMailSuccess) {
          // Save document
          saveEmailDocument();
          PortalApplication.getInstance().closeFocusView();
        }
      } else {
        StringBuilder sb = new StringBuilder();
        for (String msg : errorMsg) {
          sb.append(msg);
          sb.append(",");
          sb.append("\n");
        }
        MessageDialog.addErrorMessage(sb.toString());
      }
    } catch (Exception e) {
      ExceptionHandler.handleException(e);
    }
  }
  /**
   * @param document
   * @param addAtTop
   * @return
   */
  private boolean addTemplate(Document document, boolean addAtTop) {
    if (isDocumentTemplate(document)) {
      String tempContent =
          new String(
              DocumentMgmtUtility.getDocumentManagementService()
                  .retrieveDocumentContent(document.getId()));

      tempContent = resolveExpressions(tempContent);

      editor.addContent(
          tempContent,
          addAtTop ? DocumentEditingPolicy.ADD_AT_TOP : DocumentEditingPolicy.ADD_AT_BOTTOM);

      return true;
    } else {
      MessageDialog.addErrorMessage(
          this.getMessages().getString("invalid.template.message")
              + " "
              + document.getContentType());
      return false;
    }
  }
 private void select() {
   if (model == null
       && departmentList != null
       && !departmentList.isEmpty()
       && departmentList.size() == 1) {
     for (Department d : departmentList) {
       addDepartmentData(d);
     }
   } else if (model != null) {
     DepartmentDialogBean deptBean = DepartmentDialogBean.getCurrent();
     deptBean.setModel(model);
     deptBean.openPopup();
   } else if (model == null) {
     // TODO support asynchronous/synchronous start selection?
     ActivityInstance nextActivityInstance = null;
     ProcessInstance processInstance = PPUtils.startProcess(processDefinition, true);
     if (!(ProcessInstanceUtils.isTransientProcess(processInstance)
         || ProcessInstanceUtils.isCompletedProcess(processInstance))) {
       nextActivityInstance = PPUtils.activateNextActivityInstance(processInstance);
       if (nextActivityInstance != null) {
         Map<String, Object> params = CollectionUtils.newTreeMap();
         if (WorklistsBean.getInstance()
             .isAssemblyLineActivity(nextActivityInstance.getActivity())) {
           params.put("assemblyLineActivity", true);
           params.put("worklistsBean", WorklistsBean.getInstance());
         }
         ActivityInstanceUtils.openActivity(nextActivityInstance, params);
       }
     }
     if (nextActivityInstance == null) {
       MessageDialog.addInfoMessage(
           MessagePropertiesBean.getInstance()
               .getParamString("common.processStarted.message", new String[] {getName()}));
     }
   }
 }
  public void save() {
    UserPreferencesHelper userPrefsHelper = getUserPrefenceHelper();
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG, F_IMAGE_VIEWER_SHOW_SIDE_PANEL, String.valueOf(showSidePanel));
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG, F_IMAGE_VIEWER_INVERT_IMAGE, String.valueOf(invertImage));
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG, F_IMAGE_VIEWER_SHOW_ANNOTATIONS, String.valueOf(showAnnotations));
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG,
        F_IMAGE_VIEWER_HIGHLIGHT_DATA_FIELDS_ENABLED,
        String.valueOf(highlightDataFieldsEnabled));
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG,
        F_IMAGE_VIEWER_DATANAME_IN_TARGET_INCLUDED,
        String.valueOf(datanameInTargetIncluded));
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG, F_IMAGE_VIEWER_MAGNIFY_FIELDS, String.valueOf(magnifyFields));
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG, F_IMAGE_VIEWER_BOLD_SELECTED, String.valueOf(boldSelected));
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG, F_IMAGE_VIEWER_ITALIC_SELECTED, String.valueOf(italicSelected));
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG,
        F_IMAGE_VIEWER_UNDERLINE_SELECTED,
        String.valueOf(underlineSelected));
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG, F_IMAGE_VIEWER_SELECTED_NOTE_FONT_SIZE, selectedNoteFontSize);
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG, F_IMAGE_VIEWER_SELECTED_STICKY_NOTE_COLOUR, stickyNoteColour);
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG, F_IMAGE_VIEWER_SELECTED_HIGHLIGHTER_COLOUR, highlighterColour);
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG,
        F_IMAGE_VIEWER_SELECTED_DATA_FIELD_HIGHLIGHTER_COLOUR,
        dataFieldHighlightColour);

    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG,
        F_IMAGE_VIEWER_SELECTED_DATA_FIELD_HIGHLIGHTER_OPACITY,
        dataFieldHighlightOpacity);
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG,
        F_IMAGE_VIEWER_SELECTED_DISPLAY_ZOOM_LIVEL,
        selectedDisplayZoomLevel);
    userPrefsHelper.setString(
        V_IMAGE_VIEWER_CONFIG,
        F_IMAGE_VIEWER_SELECTED_STAMP,
        ImageViewerStampsBean.getCurrent().getSelectedStampId());

    // non-admin user can't change values
    if (SessionContext.findSessionContext().getUser().isAdministrator()) {
      userPrefsHelper.setString(
          V_IMAGE_VIEWER_CONFIG,
          F_IMAGE_VIEWER_ENABLE_EXTRACT_PAGES,
          String.valueOf(enableExtractPage));
      allowDeleteFromOriginal = enableExtractPage && allowDeleteFromOriginal;
      userPrefsHelper.setString(
          V_IMAGE_VIEWER_CONFIG,
          F_IMAGE_VIEWER_ENABLE_PAGE_DELETE,
          String.valueOf(allowDeleteFromOriginal));
      userPrefsHelper.setString(
          V_IMAGE_VIEWER_CONFIG,
          F_IMAGE_VIEWER_SELECTED_DOC_PRIOR_VERSION_ACTION,
          docPriorVersionAction);
      userPrefsHelper.setString(
          V_IMAGE_VIEWER_CONFIG, F_IMAGE_VIEWER_SPAWN_PROCESS_TYPE, spawnProcessType);
    }
    MessageDialog.addInfoMessage(
        messageBean.getString("views.imageViewerConfig.save.successMessage"));
  }
  private void addDepartmentData(Department department) {
    Map<String, Object> map = null;
    if (department != null) {
      map = CollectionUtils.newMap();
      Department department1 = department;
      do {
        if (department1 == null) {
          break;
        }
        Organization organization = department1.getOrganization();
        if (organization != null) {
          String s = (String) organization.getAttribute("carnot:engine:dataId");
          if (s != null) {
            ModelCache modelCache = ModelCache.findModelCache();
            Model model = modelCache.getModel(organization.getModelOID());

            Data data = model.getData(s);
            String s1 = data.getTypeId();
            if ("primitive".equals(s1)) {
              map.put(s, department1.getId());
            } else if ("struct".equals(s1)) {
              Object obj = map.get(s);
              if (!(obj instanceof Map)) {
                obj = CollectionUtils.newMap();
                map.put(s, obj);
              }
              Map map1 = (Map) obj;
              String s2 = (String) organization.getAttribute("carnot:engine:dataPath");
              if (StringUtils.isEmpty(s2)) {
                map.put(s, department1.getId());
              } else {
                do {
                  int i;
                  if (0 >= (i = s2.indexOf('/'))) {
                    break;
                  }
                  String s3 = s2.substring(0, i).trim();
                  s2 = s2.substring(i + 1);
                  if (s3.length() > 0) {
                    Map map2 = (Map) map1.get(s3);
                    if (map2 == null) {
                      map2 = CollectionUtils.newMap();
                      map1.put(s3, map2);
                    }
                    map1 = map2;
                  }
                } while (true);
                s2 = s2.trim();
                if (s2.length() > 0) {
                  map1.put(s2, department1.getId());
                }
              }
            } else {
              throw new PublicException(
                  (new StringBuilder())
                      .append("Unsupported data type in manual triggers: ")
                      .append(s1)
                      .toString());
            }
            department1 = department1.getParentDepartment();
          }
        }
      } while (true);
    }

    ActivityInstance nextActivityInstance =
        PPUtils.activateNextActivityInstance(
            PPUtils.startProcess(getProcessDefinition(), map, true));

    if (nextActivityInstance != null) {
      ActivityInstanceUtils.openActivity(nextActivityInstance);
    } else {
      MessageDialog.addInfoMessage(
          MessagePropertiesBean.getInstance()
              .getParamString("common.processStarted.message", new String[] {getName()}));
    }
  }