/**
  * Reset Display
  *
  * @param selIndex select index
  * @return selected activity
  */
 private MWFActivity resetDisplay(int selIndex) {
   fAnswerText.setVisible(false);
   fAnswerList.setVisible(false);
   fAnswerButton.setVisible(false);
   fAnswerButton.setImage("/images/mWindow.png");
   fTextMsg.setReadonly(!(selIndex >= 0));
   bZoom.setEnabled(selIndex >= 0);
   bOK.setEnabled(selIndex >= 0);
   fForward.setValue(null);
   fForward.setReadWrite(selIndex >= 0);
   //
   statusBar.setStatusDB(String.valueOf(selIndex + 1) + "/" + m_activities.length);
   m_activity = null;
   m_column = null;
   if (m_activities.length > 0) {
     if (selIndex >= 0 && selIndex < m_activities.length) m_activity = m_activities[selIndex];
   }
   //	Nothing to show
   if (m_activity == null) {
     fNode.setText("");
     fDescription.setText("");
     fHelp.setText("");
     fHistory.setContent(HISTORY_DIV_START_TAG + "&nbsp;</div>");
     statusBar.setStatusDB("0/0");
     statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "WFNoActivities"));
   }
   return m_activity;
 } //	resetDisplay
  @SocketEvent(socketId = "changevmTemplate")
  public void updatePreviewMail(VmEmailTemplateData vmData) {

    final StringWriter body = new StringWriter();
    currentBodyRenderTemplate.setTemplateScript(vmData.getBody());
    velocityTemplateRenderer.render(currentBodyRenderTemplate, currentEmailContext, body);
    html.setContent(body.toString());
  }
 // 获取信息文档内容
 public void initInfocnt(List rlist) {
   String con = "";
   for (int i = 0; i < rlist.size(); i++) {
     WkTInfocnt inf = (WkTInfocnt) rlist.get(i);
     con += inf.getKiContent();
   }
   kicontent.setContent(con);
 }
  /** Display. Fill Editors */
  public void display(int index) {
    log.fine("Index=" + index);
    //
    m_activity = resetDisplay(index);
    //	Nothing to show
    if (m_activity == null) {
      return;
    }
    //	Display Activity
    fNode.setText(m_activity.getNodeName());
    fDescription.setValue(m_activity.getNodeDescription());
    fHelp.setValue(m_activity.getNodeHelp());
    //
    fHistory.setContent(HISTORY_DIV_START_TAG + m_activity.getHistoryHTML() + "</div>");

    //	User Actions
    MWFNode node = m_activity.getNode();
    if (MWFNode.ACTION_UserChoice.equals(node.getAction())) {
      if (m_column == null) m_column = node.getColumn();
      if (m_column != null && m_column.get_ID() != 0) {
        fAnswerList.removeAllItems();
        int dt = m_column.getAD_Reference_ID();
        if (dt == DisplayType.YesNo) {
          ValueNamePair[] values = MRefList.getList(Env.getCtx(), 319, false); // 	_YesNo
          for (int i = 0; i < values.length; i++) {
            fAnswerList.appendItem(values[i].getName(), values[i].getValue());
          }
          fAnswerList.setVisible(true);
        } else if (dt == DisplayType.List) {
          ValueNamePair[] values =
              MRefList.getList(Env.getCtx(), m_column.getAD_Reference_Value_ID(), false);
          for (int i = 0; i < values.length; i++) {
            fAnswerList.appendItem(values[i].getName(), values[i].getValue());
          }
          fAnswerList.setVisible(true);
        } else //	other display types come here
        {
          fAnswerText.setText("");
          fAnswerText.setVisible(true);
        }
      }
    }
    //	--
    else if (MWFNode.ACTION_UserWindow.equals(node.getAction())
        || MWFNode.ACTION_UserForm.equals(node.getAction())) {
      fAnswerButton.setLabel(node.getName());
      fAnswerButton.setTooltiptext(node.getDescription());
      fAnswerButton.setVisible(true);
    } else log.log(Level.SEVERE, "Unknown Node Action: " + node.getAction());

    statusBar.setStatusDB((m_index + 1) + "/" + m_activities.length);
    statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "WFActivities"));
  } //	display
 // 判断信息状态,控制界面显示,初始化信息值
 public void initInfo(WkTDistribute dis) {
   this.dis = dis;
   WkTInfo info = newsService.getWkTInfo(dis.getKiId());
   String state = dis.getKbStatus().trim();
   if (info.getKiType().trim().equals("1")) {
     ljnews.setVisible(false);
     bdnews.setVisible(false);
     initInfocnt(newsService.getChildNewsContent(info.getKiId()));
     kitype.setValue("输入");
     sep1.setVisible(true);
     sep2.setVisible(true);
   } else if (info.getKiType().trim().equals("2")) {
     ljnews.setVisible(false);
     wdnews.setVisible(false);
     wd.setVisible(false);
     tupian.setVisible(false);
     kitype.setValue("上传文件");
   } else if (info.getKiType().trim().equals("3")) {
     wdnews.setVisible(false);
     wd.setVisible(false);
     bdnews.setVisible(false);
     tupian.setVisible(false);
     kiaddress.setContent(
         "<a href=\""
             + info.getKiAddress()
             + "\" target=\"_blank\">"
             + info.getKiAddress()
             + "</a>");
     kitype.setValue("外部链接");
   }
   kititle.setValue(info.getKiTitle());
   kititle2.setValue(info.getKiTitle2());
   kbtitle.setValue(dis.getKbTitle());
   // 初始化显示图片
   if (info.getKiImage() != null && info.getKiImage().trim().length() > 0) {
     kiimage.setSrc("/upload/info/" + info.getKiImage().trim());
   }
   // 加载附件
   List flist = newsService.getFile(dis.getKiId());
   modelListbox.addAll(flist);
   upList.setModel(modelListbox);
 }
  @SocketEvent(socketId = "mail")
  public void displaySearchresult(MailInternalData mailData) {

    FlexibleSearchQuery query =
        new FlexibleSearchQuery(
            "Select {pk} from {EmailPage} where {uid}='" + mailData.getUid() + "'");
    SearchResult<EmailPageModel> searhResult = flexibleSearchService.search(query);
    final EmailPageModel emailPageModel = searhResult.getResult().get(0);

    FlexibleSearchQuery querybm =
        new FlexibleSearchQuery(
            "Select {pk} from {BusinessProcess } where {code}='"
                + mailData.getBusinessOrderCode()
                + "'");
    SearchResult<BusinessProcessModel> searhResultBs = flexibleSearchService.search(querybm);
    final BusinessProcessModel businessProcessModel = searhResultBs.getResult().get(0);

    final EmailPageTemplateModel emailPageTemplateModel =
        (EmailPageTemplateModel) emailPageModel.getMasterTemplate();
    currentBodyRenderTemplate = emailPageTemplateModel.getHtmlTemplate();
    currentEmailContext =
        this.executeInContext(
            new ImpersonationService.Executor<
                AbstractEmailContext<BusinessProcessModel>, RuntimeException>() {
              @Override
              public AbstractEmailContext<BusinessProcessModel> execute() throws RuntimeException {
                return emailContextFactory.create(
                    businessProcessModel, emailPageModel, currentBodyRenderTemplate);
              }
            });

    final StringWriter body = new StringWriter();
    rendererService.render(currentBodyRenderTemplate, currentEmailContext, body);
    html.setContent(body.toString());
    // label.setValue(emailPageTemplateModel.getHtmlTerendererServicemplate().getTemplateScript());
    VmEmailTemplateData vmData = new VmEmailTemplateData();
    vmData.setBody(emailPageTemplateModel.getHtmlTemplate().getTemplateScript());
    this.sendOutput("selectVmTemplate", vmData);
  }