Search in sources :

Example 1 with QAResultViewPart

use of net.heartsome.cat.ts.ui.qa.views.QAResultViewPart 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 2 with QAResultViewPart

use of net.heartsome.cat.ts.ui.qa.views.QAResultViewPart 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)

Aggregations

ArrayList (java.util.ArrayList)2 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)2 QAModel (net.heartsome.cat.ts.ui.qa.model.QAModel)2 QAResult (net.heartsome.cat.ts.ui.qa.model.QAResult)2 QAResultViewPart (net.heartsome.cat.ts.ui.qa.views.QAResultViewPart)2 MultiFilesOper (net.heartsome.cat.ts.ui.util.MultiFilesOper)2 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)2 IFile (org.eclipse.core.resources.IFile)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IViewPart (org.eclipse.ui.IViewPart)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 QualityAssurance (net.heartsome.cat.ts.ui.qa.QualityAssurance)1 BatchQADialog (net.heartsome.cat.ts.ui.qa.dialogs.BatchQADialog)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IContainer (org.eclipse.core.resources.IContainer)1 IProject (org.eclipse.core.resources.IProject)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1