Search in sources :

Example 1 with MultiFilesOper

use of net.heartsome.cat.ts.ui.util.MultiFilesOper in project translationstudio8 by heartsome.

the class AutomaticQA method setInitData.

public void setInitData(XLFHandler handler) {
    this.handler = handler;
    preferenceStore = Activator.getDefault().getPreferenceStore();
    model = new QAModel();
    window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    filterMap = getNotIncludePara();
    root = ResourcesPlugin.getWorkspace().getRoot();
    xmlHandler = new QAXmlHandler();
    // 存储品质检查的检查项
    model.setBatchQAItemIdList(getAutoQAItems());
    // 存储品质检查的检查时不包括的文本段
    model.setNotInclude(filterMap);
    model.setShell(window.getShell());
    XLIFFEditorImplWithNatTable nattable = XLIFFEditorImplWithNatTable.getCurrent();
    boolean isMultiFile = nattable.isMultiFile();
    if (isMultiFile) {
        model.setMuliFiles(true);
        IFile multiTempIFile = ((FileEditorInput) nattable.getEditorInput()).getFile();
        ArrayList<IFile> selectIFiles = (ArrayList<IFile>) ResourceUtils.filesToIFiles(nattable.getMultiFileList());
        model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
    } else {
        model.setMuliFiles(false);
    }
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) ArrayList(java.util.ArrayList) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) QAModel(net.heartsome.cat.ts.ui.qa.model.QAModel)

Example 2 with MultiFilesOper

use of net.heartsome.cat.ts.ui.util.MultiFilesOper in project translationstudio8 by heartsome.

the class BatchQAHandler method execute.

@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
    isMultiFile = false;
    preferenceStore = Activator.getDefault().getPreferenceStore();
    // UNDO 如果焦点在其他视图上时,获取的文件错误。
    IFile multiTempIFile = null;
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    final Shell shell = window.getShell();
    //		ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
    ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
    if (HandlerUtil.getActivePart(event) instanceof IViewPart) {
        ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
        if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
            Iterator<Object> selectIt = structuredSelection.iterator();
            while (selectIt.hasNext()) {
                Object object = selectIt.next();
                if (object instanceof IFile) {
                    IFile selectFile = (IFile) object;
                    String fileExtension = selectFile.getFileExtension();
                    // 如果后缀名不是xlf,那么就进行提示
                    if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
                        boolean isSure = MessageDialog.openConfirm(shell, Messages.getString("qa.all.dialog.warning"), MessageFormat.format(Messages.getString("qa.all.tip.notXliff"), new Object[] { selectFile.getFullPath() }));
                        if (!isSure) {
                            return null;
                        }
                        continue;
                    }
                    selectIFiles.add(selectFile);
                } else if (object instanceof IProject) {
                    IProject selectProject = (IProject) object;
                    try {
                        ResourceUtils.getXliffs(selectProject, selectIFiles);
                    } catch (Exception e) {
                        e.printStackTrace();
                        logger.error(Messages.getString("qa.handlers.BatchQAHandler.log1"), e);
                    }
                } else if (object instanceof IContainer) {
                    IContainer selectContainer = (IContainer) object;
                    try {
                        ResourceUtils.getXliffs(selectContainer, selectIFiles);
                    } catch (Exception e) {
                        logger.error(Messages.getString("qa.handlers.BatchQAHandler.log1"), e);
                        e.printStackTrace();
                    }
                }
            }
        }
    } else {
        //如果左边未选择品质检查的类型,那么,获取nattable中打开的文件
        IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
        String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
        if (activeEditor != null && !activeEditor.getSite().getId().equals(XLIFF_EDITOR_ID)) {
            MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.tip2"));
            return null;
        }
        XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) activeEditor;
        isMultiFile = nattable.isMultiFile();
        multiTempIFile = ((FileEditorInput) nattable.getEditorInput()).getFile();
        if (isMultiFile) {
            List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
            for (String multiFileStr : multiFilesList) {
                selectIFiles.add(ResourceUtils.fileToIFile(multiFileStr));
            }
        } else {
            selectIFiles.add(multiTempIFile);
        }
    }
    CommonFunction.removeRepeateSelect(selectIFiles);
    if (selectIFiles.size() == 0) {
        MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.tip1"));
        return null;
    }
    List<IFile> lstFiles = new ArrayList<IFile>();
    XLFValidator.resetFlag();
    for (IFile iFile : selectIFiles) {
        if (!XLFValidator.validateXliffFile(iFile)) {
            lstFiles.add(iFile);
        }
    }
    XLFValidator.resetFlag();
    selectIFiles.removeAll(lstFiles);
    if (selectIFiles.size() == 0) {
        return null;
    }
    model = new QAModel();
    model.setQaXlfList(selectIFiles);
    quality = new QualityAssurance(model);
    BatchQADialog dialog = new BatchQADialog(shell, model, isMultiFile);
    int result = dialog.open();
    if (result == IDialogConstants.OK_ID) {
        // 先调用方法,查看品质检查结果视图是否处于显示状态,如果显示了的。删除数据
        IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart view = workbenchPage.findView(QAResultViewPart.ID);
        if (view != null) {
            // 运行时,将结果视图中列表的数据清除
            ((QAResultViewPart) view).clearTableData();
        }
        QAResult qaResult = new QAResult();
        // 存储品质检查的检查项
        model.setBatchQAItemIdList(getBatchQAItems());
        // 存储品质检查的检查时不包括的文本段
        model.setNotInclude(getNotIncludePara());
        //给品质检查结果视图发出通告,本次检查对象为合并打开文件
        //			qaResult.firePropertyChange(isMultiFile, new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
        // 将当前所处理的文件传至 qaResult
        List<String> fileList = new ArrayList<String>();
        for (IFile iFIle : model.getQaXlfList()) {
            fileList.add(iFIle.getLocation().toOSString());
        }
        qaResult.setFilePathList(fileList);
        HsMultiActiveCellEditor.commit(true);
        if (isMultiFile) {
            model.setMuliFiles(true);
            model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
            qaResult.setMultiOper(model.getMultiOper());
            quality.beginMultiFileQA(qaResult);
        } else {
            model.setMuliFiles(false);
            qaResult.setMultiOper(model.getMultiOper());
            quality.beginQA(qaResult);
        }
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) QualityAssurance(net.heartsome.cat.ts.ui.qa.QualityAssurance) QAModel(net.heartsome.cat.ts.ui.qa.model.QAModel) BatchQADialog(net.heartsome.cat.ts.ui.qa.dialogs.BatchQADialog) Shell(org.eclipse.swt.widgets.Shell) ISelection(org.eclipse.jface.viewers.ISelection) IContainer(org.eclipse.core.resources.IContainer) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorPart(org.eclipse.ui.IEditorPart) QAResult(net.heartsome.cat.ts.ui.qa.model.QAResult) QAResultViewPart(net.heartsome.cat.ts.ui.qa.views.QAResultViewPart) IProject(org.eclipse.core.resources.IProject) ExecutionException(org.eclipse.core.commands.ExecutionException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 3 with MultiFilesOper

use of net.heartsome.cat.ts.ui.util.MultiFilesOper in project translationstudio8 by heartsome.

the class OpenMultiXliffHandler method execute.

@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
    IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
    ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
    if (currentSelection.isEmpty() || !(currentSelection instanceof IStructuredSelection)) {
        return null;
    }
    IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
    Iterator<Object> selectIt = structuredSelection.iterator();
    final ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    shell = window.getShell();
    // 先验证是否跨项目
    IProject selectedProject = null;
    while (selectIt.hasNext()) {
        Object object = selectIt.next();
        if (object instanceof IFile) {
            IFile iFile = (IFile) object;
            if (!CommonFunction.validXlfExtension(iFile.getFileExtension())) {
                MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), MessageFormat.format(Messages.getString("handlers.OpenMultiXliffHandler.msg1"), iFile.getFullPath().toOSString()));
                continue;
            }
            selectIFiles.add(iFile);
            if (selectedProject == null) {
                selectedProject = iFile.getProject();
            } else {
                if (selectedProject != iFile.getProject()) {
                    MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg2"));
                    return null;
                }
            }
        } else if (object instanceof IContainer) {
            IContainer selectContainer = (IContainer) object;
            if (selectedProject == null) {
                selectedProject = selectContainer.getProject();
            }
            // 判断当前文件夹是否处于 XLIFF 文件夹下
            try {
                ResourceUtils.getXliffs(selectContainer, selectIFiles);
            } catch (CoreException e) {
                logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger1"), selectContainer.getFullPath().toOSString(), e);
            }
        }
    }
    // 过滤重复选择文件
    CommonFunction.removeRepeateSelect(selectIFiles);
    if (selectIFiles.size() < 2) {
        MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg3"));
        return null;
    }
    MultiFilesOper oper = new MultiFilesOper(selectedProject, selectIFiles);
    // 先验证这些文件是否已经合并打开,如果是,则退出
    if (oper.validExist()) {
        return null;
    }
    // 判断是否有重复打开的文件,并删除缓存中要合并打开的文件。
    if (oper.hasOpenedIFile()) {
        if (oper.getSelectIFiles().size() <= 0) {
            MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg4"));
            return null;
        } else {
            boolean isResponse = MessageDialog.openConfirm(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle2"), Messages.getString("handlers.OpenMultiXliffHandler.msg5"));
            if (isResponse) {
                if (oper.getSelectIFiles().size() < 2) {
                    MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg6"));
                    return null;
                }
            } else {
                return null;
            }
        }
    }
    final IFile multiIFile = oper.createMultiTempFile();
    if (multiIFile != null && multiIFile.exists()) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.getString("handler.OpenMultiXliffHandler.tip1"), 10);
                IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 7, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                // 进行判断所选择文件的语言对是否符合标准,先解析文件
                final XLFHandler xlfHander = new XLFHandler();
                final Map<String, Object> newResultMap = xlfHander.openFiles(ResourceUtils.iFilesToFiles(selectIFiles), subMonitor);
                // 针对解析失败
                if (newResultMap == null || QAConstant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) newResultMap.get(QAConstant.RETURNVALUE_RESULT)) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), (String) newResultMap.get(Constant.RETURNVALUE_MSG));
                        }
                    });
                    return;
                }
                // 验证是否有多个语言
                boolean hasDiffrentLangPair = false;
                Map<String, ArrayList<String>> langMap = xlfHander.getLanguages();
                if (langMap.size() > 1) {
                    hasDiffrentLangPair = true;
                } else {
                    for (Entry<String, ArrayList<String>> entry : langMap.entrySet()) {
                        if (entry.getValue().size() > 1) {
                            hasDiffrentLangPair = true;
                        }
                    }
                }
                if (monitor.isCanceled()) {
                    return;
                }
                monitor.worked(1);
                if (hasDiffrentLangPair) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg7"));
                        }
                    });
                    // 先删除临时文件,再退出
                    try {
                        multiIFile.delete(true, monitor);
                    } catch (CoreException e) {
                        logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
                    }
                    return;
                }
                final boolean[] validateResult = new boolean[] { false };
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        validateResult[0] = XLFValidator.validateXlifIFiles(selectIFiles);
                    }
                });
                if (!validateResult[0]) {
                    try {
                        multiIFile.delete(true, monitor);
                    } catch (CoreException e) {
                        logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
                    }
                    return;
                }
                final FileEditorInput input = new FileEditorInput(multiIFile);
                if (monitor.isCanceled()) {
                    return;
                }
                monitor.worked(1);
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        try {
                            // UNDO 这里合并打开时,要考虑传入参数xlfHandler,以防多次解析文件带来的消耗。
                            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, XLIFF_EDITOR_ID, true);
                        } catch (PartInitException e) {
                            e.printStackTrace();
                        }
                    }
                });
                if (monitor.isCanceled()) {
                    return;
                }
                monitor.worked(1);
                monitor.done();
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(true, true, runnable);
        } catch (Exception e) {
            logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger3"), e);
        }
    } else {
        MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg8"));
        return null;
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISelection(org.eclipse.jface.viewers.ISelection) PartInitException(org.eclipse.ui.PartInitException) IContainer(org.eclipse.core.resources.IContainer) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 4 with MultiFilesOper

use of net.heartsome.cat.ts.ui.util.MultiFilesOper in project translationstudio8 by heartsome.

the class NumberOrTagConsisQAHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    boolean isMultiFile = false;
    IFile multiTempIFile = null;
    IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
    // 改为布局
    if (editorPart != null && editorPart instanceof XLIFFEditorImplWithNatTable) {
        String qaItem = event.getParameter("qaItemId");
        XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) editorPart;
        ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
        FileEditorInput input = (FileEditorInput) nattable.getEditorInput();
        // 首先判断是否是合并打开的文件
        if (nattable.isMultiFile()) {
            isMultiFile = true;
        }
        if (isMultiFile) {
            multiTempIFile = input.getFile();
            List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
            for (String filePath : multiFilesList) {
                selectIFiles.add(ResourceUtils.fileToIFile(filePath));
            }
        } else {
            selectIFiles.add(input.getFile());
        }
        QAModel model = new QAModel();
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        shell = window.getShell();
        // 先调用方法,查看品质检查结果视图是否处于显示状态,如果是显示的,就删除数据
        IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart view = workbenchPage.findView(QAResultViewPart.ID);
        if (view != null) {
            // 运行时,将结果视图中列表的数据清除
            ((QAResultViewPart) view).clearTableData();
        }
        QAResult qaResult = new QAResult();
        // 存储品质检查的检查项
        // model.setBatchQAItemIdList(getBatchQAItems());
        // 存储品质检查的检查时不包括的文本段
        model.setNotInclude(getNotIncludePara());
        // 给品质检查结果视图发出通告,本次检查对象为合并打开文件
        qaResult.firePropertyChange(isMultiFile, new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
        if (isMultiFile) {
            model.setMuliFiles(true);
            model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
        } else {
            model.setMuliFiles(false);
        }
        boolean isNumberQA = false;
        if (QAConstant.QA_NUMBER.equals(qaItem)) {
            isNumberQA = true;
        } else if (QAConstant.QA_TAG.equals(qaItem)) {
            isNumberQA = false;
        }
        List<String> fileList = new ArrayList<String>();
        for (IFile iFIle : selectIFiles) {
            fileList.add(iFIle.getLocation().toOSString());
        }
        qaResult.setFilePathList(fileList);
        HsMultiActiveCellEditor.commit(true);
        beginQA(selectIFiles, model, isNumberQA, qaResult);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) QAResult(net.heartsome.cat.ts.ui.qa.model.QAResult) QAResultViewPart(net.heartsome.cat.ts.ui.qa.views.QAResultViewPart) QAModel(net.heartsome.cat.ts.ui.qa.model.QAModel) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 5 with MultiFilesOper

use of net.heartsome.cat.ts.ui.util.MultiFilesOper in project translationstudio8 by heartsome.

the class LockRepeatedSegmentHandler method execute.

@Override
public Object execute(final ExecutionEvent event, final List<IFile> iFileList) {
    list = iFileList;
    tmMatcher = new TmMatcher();
    isCancel = false;
    continuee = true;
    isLocked = false;
    if (list == null || list.isEmpty()) {
        if (list.size() == 0) {
            MessageDialog.openInformation(shell, Messages.getString("translation.LockRepeatedSegmentHandler.msgTitle"), Messages.getString("translation.LockRepeatedSegmentHandler.msg1"));
            return null;
        }
        return null;
    }
    try {
        window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    } catch (ExecutionException e1) {
        LOGGER.error("", e1);
        e1.printStackTrace();
    }
    // 首先验证是否是合并打开的文件 --robert
    if (isEditor) {
        IEditorReference[] editorRefe = window.getActivePage().findEditors(new FileEditorInput(list.get(0)), XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
        if (editorRefe.length <= 0) {
            return null;
        }
        nattable = (XLIFFEditorImplWithNatTable) editorRefe[0].getEditor(true);
        // 针对合并打开
        if (nattable.isMultiFile()) {
            list = ResourceUtils.filesToIFiles(nattable.getMultiFileList());
        }
    }
    // 添加验证 peason
    List<IFile> lstFiles = new ArrayList<IFile>();
    XLFValidator.resetFlag();
    for (IFile iFile : list) {
        if (!XLFValidator.validateXliffFile(iFile)) {
            lstFiles.add(iFile);
        }
    }
    XLFValidator.resetFlag();
    if (!(list instanceof ArrayList)) {
        list = new ArrayList<IFile>(list);
    }
    list.removeAll(lstFiles);
    if (list.size() == 0) {
        return null;
    }
    CommonFunction.removeRepeateSelect(list);
    final LockRepeatedSegmentDialog dialog = new LockRepeatedSegmentDialog(shell, list, Messages.getString("translation.LockRepeatedSegmentHandler.dialog"));
    if (dialog.open() == LockRepeatedSegmentDialog.OK) {
        isLockInnerRepeatedSegment = dialog.isLockInnerRepeatedSegment();
        isLockTM100Segment = dialog.isLockTM100Segment();
        isLockTM101Segment = dialog.isLockTM101Segment();
        if (!dialog.isLockInnerRepeatedSegment() && !dialog.isLockTM100Segment() && !dialog.isLockTM101Segment()) {
            // “锁定内部”、“锁定100%”、“锁定101%”都未选中。
            return null;
        }
        if (!isEditor) {
            // 如果针对单个文件, 先验证是否有合并打开的
            MultiFilesOper oper = new MultiFilesOper(list.get(0).getProject(), (ArrayList<IFile>) list);
            // 如果有合并打开的文件,那么将这种转换成针对编辑器的方式处理
            if (oper.validExist()) {
                final IFile multiTempIFile = oper.getMultiFilesTempIFile(true);
                IEditorReference[] editorRefe = window.getActivePage().findEditors(new FileEditorInput(multiTempIFile), XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                // 如果这几个文件没有合并打开,
                if (editorRefe.length > 0) {
                    nattable = (XLIFFEditorImplWithNatTable) editorRefe[0].getEditor(true);
                    continuee = false;
                }
            }
        }
        // 开始进行处理
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    int totalWork = dialog.isLockInnerRepeatedSegment() ? list.size() : 0;
                    totalWork = (dialog.isLockTM100Segment() || dialog.isLockTM101Segment()) ? totalWork * 2 : totalWork;
                    monitor.beginTask(Messages.getString("translation.LockRepeatedSegmentHandler.task1"), totalWork);
                    // 修改结果显示为是否成功
                    final LockRepeatedSegmentResultDialog lrsrd = new LockRepeatedSegmentResultDialog(shell, list);
                    // 是否进行外部匹配
                    boolean checkTM = false;
                    curProject = list.get(0).getProject();
                    // 锁定外部完全匹配与外部上下文匹配
                    if ((dialog.isLockTM100Segment() || dialog.isLockTM101Segment())) {
                        // 如果是针对编辑器,那么将里面的文件进行统一处理
                        if (isEditor) {
                            LockTMSegment lts = lockTMSegmentOFEditor(list, dialog.isLockTM100Segment(), dialog.isLockTM101Segment(), monitor);
                            // 用户指定退出操作
                            if (lts == null && isCancel) {
                                return;
                            }
                            lrsrd.setLockedFullMatchResult(lts.getLockedFullMatchResult());
                            lrsrd.setLockedContextResult(lts.getLockedContextResult());
                            lrsrd.setTuNumResult(lts.getTuNumResult());
                            checkTM = true;
                        } else {
                            if (continuee) {
                                Map<String, Integer> lockedFullMatchResultMap = new HashMap<String, Integer>();
                                Map<String, Integer> lockedContextMatchResultMap = new HashMap<String, Integer>();
                                Map<String, Integer> lockedTuNumResultMap = new HashMap<String, Integer>();
                                for (int i = 0; i < list.size(); i++) {
                                    IFile iFile = list.get(i);
                                    LockTMSegment lts = lockTMSegment(Arrays.asList(iFile), dialog.isLockTM100Segment(), dialog.isLockTM101Segment(), monitor);
                                    if (lts == null && isCancel) {
                                        return;
                                    }
                                    // 返回的为空,是解析异常的文件被删除了。
                                    if (lts != null) {
                                        lockedFullMatchResultMap.putAll(lts.getLockedFullMatchResult());
                                        lockedContextMatchResultMap.putAll(lts.getLockedContextResult());
                                        lockedTuNumResultMap.putAll(lts.getTuNumResult());
                                    } else {
                                        i--;
                                    }
                                }
                                lrsrd.setLockedFullMatchResult(lockedFullMatchResultMap);
                                lrsrd.setLockedContextResult(lockedContextMatchResultMap);
                                lrsrd.setTuNumResult(lockedTuNumResultMap);
                                checkTM = true;
                            } else {
                                LockTMSegment lts = lockTMSegmentOFEditor(list, dialog.isLockTM100Segment(), dialog.isLockTM101Segment(), monitor);
                                if (lts == null && isCancel) {
                                    return;
                                }
                                lrsrd.setLockedFullMatchResult(lts.getLockedFullMatchResult());
                                lrsrd.setLockedContextResult(lts.getLockedContextResult());
                                lrsrd.setTuNumResult(lts.getTuNumResult());
                                checkTM = true;
                            }
                        }
                    }
                    // 锁定内部重复
                    if (dialog.isLockInnerRepeatedSegment()) {
                        SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, list.size(), SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                        HashMap<String, Integer> lockedInnerRepeatedResault = new HashMap<String, Integer>();
                        HashMap<String, Integer> tuNumResult = null;
                        if (!checkTM) {
                            tuNumResult = new HashMap<String, Integer>();
                        }
                        Map<String, int[]> resMap = lockInnerRepeatedSegment(list, subMonitor, checkTM);
                        for (IFile iFile : list) {
                            String filePath = ResourceUtils.iFileToOSPath(iFile);
                            int[] res = resMap.get(filePath);
                            if (!checkTM) {
                                int countTU = res[0];
                                tuNumResult.put(filePath, countTU);
                            }
                            int countLockedInnerRepeatedSegment = res[1];
                            lockedInnerRepeatedResault.put(filePath, countLockedInnerRepeatedSegment);
                        }
                        lrsrd.setLockedInnerRepeatedResault(lockedInnerRepeatedResault);
                        if (!checkTM) {
                            lrsrd.setTuNumResult(tuNumResult);
                        }
                    }
                    Display.getDefault().asyncExec(new Runnable() {

                        public void run() {
                            IEditorPart editor = HandlerUtil.getActiveEditor(event);
                            if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
                                XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
                                xliffEditor.reloadXliff();
                            }
                            // lrsrd.open();
                            if (hasWrongResults(list, lrsrd)) {
                                MessageDialog.openInformation(shell, Messages.getString("translation.LockRepeatedSegmentHandler.msgTitle"), Messages.getString("dialog.LockRepeatedSegmentResultDialog.locksuccesful"));
                            } else {
                                MessageDialog.openInformation(shell, Messages.getString("translation.LockRepeatedSegmentHandler.msgTitle"), Messages.getString("dialog.LockRepeatedSegmentResultDialog.locksuccesful"));
                            }
                            lrsrd.close();
                            HsMultiActiveCellEditor.refrushCellsEditAbility();
                        }
                    });
                } finally {
                    monitor.done();
                }
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(true, true, runnable);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IEditorReference(org.eclipse.ui.IEditorReference) ExecutionException(org.eclipse.core.commands.ExecutionException) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) LockRepeatedSegmentDialog(net.heartsome.cat.ts.lockrepeat.dialog.LockRepeatedSegmentDialog) LockRepeatedSegmentResultDialog(net.heartsome.cat.ts.lockrepeat.dialog.LockRepeatedSegmentResultDialog) IEditorPart(org.eclipse.ui.IEditorPart) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TmMatcher(net.heartsome.cat.ts.tm.match.TmMatcher) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Aggregations

ArrayList (java.util.ArrayList)5 MultiFilesOper (net.heartsome.cat.ts.ui.util.MultiFilesOper)5 IFile (org.eclipse.core.resources.IFile)5 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)4 FileEditorInput (org.eclipse.ui.part.FileEditorInput)4 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)3 QAModel (net.heartsome.cat.ts.ui.qa.model.QAModel)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 IEditorPart (org.eclipse.ui.IEditorPart)3 IViewPart (org.eclipse.ui.IViewPart)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 QAResult (net.heartsome.cat.ts.ui.qa.model.QAResult)2 QAResultViewPart (net.heartsome.cat.ts.ui.qa.views.QAResultViewPart)2 IContainer (org.eclipse.core.resources.IContainer)2 IProject (org.eclipse.core.resources.IProject)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2