@Override
 protected void configureShell(Shell newShell) {
   super.configureShell(newShell);
   newShell.setText(
       isAdd
           ? Messages.getString("qa.preference.NonTranslationQAPage.addModle")
           : Messages.getString("qa.preference.NonTranslationQAPage.editModle"));
 }
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridDataFactory.fillDefaults().hint(500, 180).grab(true, true).applyTo(tparent);

    Composite composite = new Composite(tparent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
    GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).applyTo(composite);

    GridLayoutFactory.fillDefaults()
        .extendedMargins(0, 0, 0, 0)
        .equalWidth(false)
        .numColumns(2)
        .applyTo(composite);

    GridData textData = new GridData(GridData.FILL, SWT.CENTER, true, false);
    // 非译元素的名称
    Label tipLbl = new Label(composite, SWT.NONE);
    tipLbl.setText(Messages.getString("qa.preference.NonTranslationQAPage.tip"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(tipLbl);

    tipTxt = new Text(composite, SWT.BORDER);
    tipTxt.setLayoutData(textData);

    // 非译元素的非译内容
    Label contentLbl = new Label(composite, SWT.NONE);
    contentLbl.setText(Messages.getString("qa.preference.NonTranslationQAPage.content"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(contentLbl);

    contentTxt = new Text(composite, SWT.BORDER);
    contentTxt.setLayoutData(textData);

    // 非译元素的正则表达式
    Label regularLbl = new Label(composite, SWT.NONE);
    regularLbl.setText(Messages.getString("qa.preference.NonTranslationQAPage.regular"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(regularLbl);

    regularTxt = new Text(composite, SWT.BORDER);
    regularTxt.setLayoutData(textData);

    // 正则表达式自定义选项
    new Label(composite, SWT.NONE);
    Composite pesonalCmp = new Composite(composite, SWT.NONE);
    pesonalCmp.setLayoutData(textData);
    GridLayoutFactory.fillDefaults().equalWidth(true).numColumns(2).applyTo(pesonalCmp);

    wordBtn = new Button(pesonalCmp, SWT.CHECK);
    wordBtn.setText(Messages.getString("qa.preference.NonTranslationQAPage.addTip1"));

    ignoreCaseBtn = new Button(pesonalCmp, SWT.CHECK);
    ignoreCaseBtn.setText(Messages.getString("qa.preference.NonTranslationQAPage.addTip2"));

    new Label(composite, SWT.NONE);
    initListener();
    initValue();
    return tparent;
  }
  @Override
  protected void createButtonsForButtonBar(Composite parent) {
    super.createButtonsForButtonBar(parent);
    Button okBtn = getButton(IDialogConstants.OK_ID);
    okBtn.setText(Messages.getString("qa.preference.NonTranslationQAPage.enterBtn"));

    Button cancelBtn = getButton(IDialogConstants.CANCEL_ID);
    cancelBtn.setText(Messages.getString("qa.preference.NonTranslationQAPage.cancelBtn"));
  }
 /**
  * 验证非译元素是否重复添加,如果是,则返回 true,如果不是,则返回 false
  *
  * @param bean
  * @return
  */
 private boolean validElementIsRepeate(NontransElementBean bean) {
   // 判断是否是重复添加
   int eleSum = tableViewer.getTable().getItemCount();
   for (int i = 0; i < eleSum; i++) {
     if (tableViewer.getElementAt(i) instanceof NontransElementBean) {
       NontransElementBean curBean = (NontransElementBean) tableViewer.getElementAt(i);
       if (bean.equalsOfEdit(curBean)) {
         MessageDialog.openWarning(
             getShell(),
             Messages.getString("qa.all.dialog.warning"),
             Messages.getString("qa.preference.NonTranslationQAPage.addTip6"));
         return true;
       }
     } else {
       continue;
     }
   }
   return false;
 }
  @Override
  protected void okPressed() {
    String name = tipTxt.getText();
    String content = contentTxt.getText();
    String regular = regularTxt.getText();

    if ("".equals(name) || name == null) {
      MessageDialog.openWarning(
          getShell(),
          Messages.getString("qa.all.dialog.warning"),
          Messages.getString("qa.preference.NonTranslationQAPage.tip2"));
      return;
    }

    if ("".equals(content) || content == null) {
      MessageDialog.openWarning(
          getShell(),
          Messages.getString("qa.all.dialog.warning"),
          Messages.getString("qa.preference.NonTranslationQAPage.tip3"));
      return;
    }

    // 添加模式时才会指定 id
    if (isAdd) {
      String id = "" + System.nanoTime();
      curElementBean.setId(id);
    }
    curElementBean.setName(name);
    curElementBean.setContent(content);
    curElementBean.setRegular(regular);
    // 如果重复,将不添加
    if (validElementIsRepeate(curElementBean)) {
      return;
    }
    super.okPressed();
  }
Beispiel #6
0
  @Override
  public String startQA(
      final QAModel model,
      IProgressMonitor monitor,
      IFile iFile,
      QAXmlHandler xmlHandler,
      Map<String, String> tuMap) {
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    hasError = false;
    isContinue = false;
    // 目标语言
    final String target_lan = tuMap.get("target_lan");

    // 若未配置该目标语言的词典,退出程序的执行
    if (nonSpellTarLangList.indexOf(target_lan) != -1) {
      return "";
    }

    String targetPureText = TextUtil.resetSpecialString(tuMap.get("tarPureText"));

    String lineNumber = tuMap.get("lineNumber");
    String langPair = tuMap.get("langPair");
    String iFileFullPath = tuMap.get("iFileFullPath");
    String rowId = tuMap.get("rowId");

    if (spelling == null) {
      if (isHunspell) {
        spelling = new Hunspell(model.getShell());
        if (ignoreNontrans) {
          nontransOper = new NonTransElementOperate();
          nontransOper.openNonTransDB();
        }
      } else {
        spelling = new AspellChecker();
      }
    }

    // 若拼写检查器错误,或者出错,返回 null
    if (spelling == null || spelling.isError()) {
      return null;
    }

    // 如果该拼写检查实例为空,退出执行,并且下次遇到相同目标语言不再检查
    if (!spelling.checkLangAvailable(target_lan)) {
      nonSpellTarLangList.add(target_lan);
      if (!isHunspell) {
        Display.getDefault()
            .syncExec(
                new Runnable() {
                  public void run() {
                    String message = Messages.getString("qa.SpellQA.addTip1");
                    message = MessageFormat.format(message, new Object[] {target_lan});
                    isContinue =
                        MessageDialog.openConfirm(
                            model.getShell(), Messages.getString("qa.all.dialog.ok"), message);
                  }
                });

        if (!isContinue) {
          monitor.setCanceled(true);
        }
      }
      return "";
    }

    List<SingleWord> errorWords;
    if (isHunspell) {
      LinkedList<SingleWord> wordList = new LinkedList<SingleWord>();
      getSingleWords(targetPureText, wordList);
      errorWords = spelling.getErrorWords(null, wordList, target_lan);
    } else {
      LinkedList<SingleWord> wordList = new LinkedList<SingleWord>();
      getSingleWords(targetPureText, wordList);
      errorWords = spelling.getErrorWords(targetPureText, wordList, target_lan);
    }

    if (spelling.isError()) {
      return null;
    }

    // 开始输入结果
    if (errorWords == null || errorWords.size() == 0) {
      return "";
    }

    String errorTip = Messages.getString("qa.SpellQA.tip1");
    String qaType = Messages.getString("qa.all.qaItem.SpellQA");

    for (int i = 0; i < errorWords.size(); i++) {
      errorTip += "'" + errorWords.get(i).getPureWord() + "' 、";
    }
    errorTip = errorTip.substring(0, errorTip.length() - 1);
    errorTip += Messages.getString("qa.SpellQA.tip2");

    hasError = true;
    super.printQAResult(
        new QAResultBean(
            lineNumber,
            qaType,
            errorTip,
            iFileFullPath,
            langPair,
            rowId,
            tipLevel,
            QAConstant.QA_SPELL));
    String result = "";
    if (hasError && tipLevel == 0) {
      result = QAConstant.QA_SPELL;
    }
    return result;
  }