Search in sources :

Example 1 with NontransElementBean

use of net.heartsome.cat.ts.ui.qa.model.NontransElementBean in project translationstudio8 by heartsome.

the class NonTranslationQA method startQA.

@Override
public String startQA(QAModel model, IProgressMonitor monitor, IFile iFile, QAXmlHandler xmlHandler, QATUDataBean tuDataBean) {
    if (tuDataBean.getTgtContent() == null || "".equals(tuDataBean.getTgtContent())) {
        return "";
    }
    hasError = false;
    if (nonTransElementsMap == null) {
        //非译元素库的操作类 
        NonTransElementOperate operater = new NonTransElementOperate();
        //先打开库
        operater.openNonTransDB();
        //开始从非译元素库中获取相关信息
        nonTransElementsMap = operater.getNonTransElements();
    }
    srcNonTransData = new LinkedList<String>();
    tgtNonTransData = new LinkedList<String>();
    //获取纯文本
    String sourceText = tuDataBean.getSrcPureText();
    String targetText = tuDataBean.getTgtPureText();
    String rowId = tuDataBean.getRowId();
    srcLang = tuDataBean.getSrcLang();
    tgtLang = tuDataBean.getTgtLang();
    // UNDO 这里存在一个问题,就是web地址检查与ip地址检查的语句差不多,故存在会引起一个非译元素会同时被检查并多次提示。
    for (int index = 0; index < nonTransElementsMap.size(); index++) {
        NontransElementBean elementBean = nonTransElementsMap.get(index);
        String elementContent = elementBean.getContent();
        String elementRegular = elementBean.getRegular();
        matchNontrans(sourceText, targetText, elementContent, elementRegular);
    }
    // UNDO 非译元素检查时,把数字也检查出来了
    String lineNumber = tuDataBean.getLineNumber();
    String fileName = tuDataBean.getFileName();
    String qaTypeText = Messages.getString("qa.all.qaItem.NonTranslationQA");
    //处理源文中的非译元素在译文中丢失的情况
    if (srcNonTransData.size() > 0) {
        String nonTransStr = "";
        for (int index = 0; index < srcNonTransData.size(); index++) {
            nonTransStr += "'" + srcNonTransData.get(index) + "', ";
        }
        nonTransStr = nonTransStr.substring(0, nonTransStr.length() - 2);
        //			String errorTip = MessageFormat.format(Messages.getString("qa.NonTranslationQA.tip1"), nonTransStr);
        hasError = true;
    }
    //处理译文中的非译元素在源文中丢失的情况
    if (tgtNonTransData.size() > 0) {
        String nonTransStr = "";
        for (int index = 0; index < tgtNonTransData.size(); index++) {
            nonTransStr += "'" + tgtNonTransData.get(index) + "', ";
        }
        nonTransStr = nonTransStr.substring(0, nonTransStr.length() - 2);
        //			String errorTip = MessageFormat.format(Messages.getString("qa.NonTranslationQA.tip2"), nonTransStr);
        hasError = true;
    }
    if (hasError) {
        super.printQAResult(new QAResultBean(level, QAConstant.QA_NONTRANSLATION, qaTypeText, null, fileName, lineNumber, sourceText, targetText, rowId));
    }
    String result = "";
    if (hasError && level == 0) {
        result = QAConstant.QA_NONTRANSLATION;
    }
    return result;
}
Also used : NonTransElementOperate(net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate) NontransElementBean(net.heartsome.cat.ts.ui.qa.model.NontransElementBean) QAResultBean(net.heartsome.cat.ts.ui.qa.model.QAResultBean)

Example 2 with NontransElementBean

use of net.heartsome.cat.ts.ui.qa.model.NontransElementBean in project translationstudio8 by heartsome.

the class NonTransElementOperate method getNonTransElements.

public List<NontransElementBean> getNonTransElements() {
    List<NontransElementBean> result = new ArrayList<NontransElementBean>();
    List<Map<String, String>> elementList = handler.getNonTransElements(path, "/nonTrans/element");
    for (Map<String, String> element : elementList) {
        String id = element.get("id");
        String name = element.get("name");
        String content = element.get("content");
        String regular = TextUtil.resetSpecialString(element.get("regular"));
        result.add(new NontransElementBean(id, name, content, regular));
    }
    return result;
}
Also used : NontransElementBean(net.heartsome.cat.ts.ui.qa.model.NontransElementBean) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 3 with NontransElementBean

use of net.heartsome.cat.ts.ui.qa.model.NontransElementBean in project translationstudio8 by heartsome.

the class NonTranslationQAPage method addNonTransElement.

/**
	 * 添加非译元素
	 */
public void addNonTransElement() {
    NontransElementBean bean = new NontransElementBean();
    AddOrEditNontransElementDialog dialog = new AddOrEditNontransElementDialog(getShell(), true, tableViewer, bean);
    int result = dialog.open();
    if (result == IDialogConstants.OK_ID) {
        // 先添加到listViewer中
        dataList.add(bean);
        tableViewer.refresh();
        tableViewer.setSelection(new StructuredSelection(bean));
    }
}
Also used : NontransElementBean(net.heartsome.cat.ts.ui.qa.model.NontransElementBean) AddOrEditNontransElementDialog(net.heartsome.cat.ts.ui.qa.dialogs.AddOrEditNontransElementDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Point(org.eclipse.swt.graphics.Point)

Example 4 with NontransElementBean

use of net.heartsome.cat.ts.ui.qa.model.NontransElementBean in project translationstudio8 by heartsome.

the class NonTranslationQAPage method editNontransElement.

/**
	 * 编辑非译元素
	 */
private void editNontransElement() {
    NontransElementBean bean = null;
    ISelection selection = tableViewer.getSelection();
    if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (structuredSelection.getFirstElement() instanceof NontransElementBean) {
            bean = (NontransElementBean) structuredSelection.getFirstElement();
            if (validIsInternalElementNonTip(bean)) {
                return;
            }
            AddOrEditNontransElementDialog dialog = new AddOrEditNontransElementDialog(getShell(), false, tableViewer, bean);
            int result = dialog.open();
            if (result == IDialogConstants.OK_ID) {
                tableViewer.refresh();
            }
        }
    }
}
Also used : NontransElementBean(net.heartsome.cat.ts.ui.qa.model.NontransElementBean) AddOrEditNontransElementDialog(net.heartsome.cat.ts.ui.qa.dialogs.AddOrEditNontransElementDialog) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.swt.graphics.Point)

Example 5 with NontransElementBean

use of net.heartsome.cat.ts.ui.qa.model.NontransElementBean in project translationstudio8 by heartsome.

the class NonTranslationQAPage method initListener.

/**
	 * 一些事件的添加
	 */
public void initListener() {
    // 非译元素的添加事件
    addBtn.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            addNonTransElement();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            addNonTransElement();
        }
    });
    editBtn.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent arg0) {
            editNontransElement();
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
            editNontransElement();
        }
    });
    // 删除按钮的点击操作
    deleteBtn.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            deleteElement();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            deleteElement();
        }
    });
    // 给comboViewer添加事件,同时传入内置元素
    comboViewer.getCombo().addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            addInternalElement();
            comboViewer.getCombo().setText(Messages.getString("qa.preference.NonTranslationQAPage.addInterElement"));
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            addInternalElement();
            comboViewer.getCombo().setText(Messages.getString("qa.preference.NonTranslationQAPage.addInterElement"));
        }
    });
    // 非译元素列表的点击事件
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = tableViewer.getSelection();
            if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                if (structuredSelection.getFirstElement() instanceof NontransElementBean) {
                    if (structuredSelection.size() == 1 && !validIsInternalElementNonTip((NontransElementBean) structuredSelection.getFirstElement())) {
                        editBtn.setEnabled(true);
                    } else {
                        editBtn.setEnabled(false);
                    }
                    deleteBtn.setEnabled(true);
                } else {
                    setAddModel();
                }
            } else {
                setAddModel();
            }
        }
    });
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent arg0) {
            editNontransElement();
        }
    });
}
Also used : NontransElementBean(net.heartsome.cat.ts.ui.qa.model.NontransElementBean) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

NontransElementBean (net.heartsome.cat.ts.ui.qa.model.NontransElementBean)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 ISelection (org.eclipse.jface.viewers.ISelection)4 Point (org.eclipse.swt.graphics.Point)4 ArrayList (java.util.ArrayList)2 AddOrEditNontransElementDialog (net.heartsome.cat.ts.ui.qa.dialogs.AddOrEditNontransElementDialog)2 NonTransElementOperate (net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate)2 Map (java.util.Map)1 QAResultBean (net.heartsome.cat.ts.ui.qa.model.QAResultBean)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1