Search in sources :

Example 1 with FileAnalysisDialog

use of net.heartsome.cat.ts.ui.qa.dialogs.FileAnalysisDialog in project translationstudio8 by heartsome.

the class FileAnalysisHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    model = new FAModel();
    faItemId = event.getParameter("faItemId");
    allTUSize = 0;
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    shell = window.getShell();
    IFile multiTempIFile = null;
    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;
            @SuppressWarnings("unchecked") 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;
                        }
                    }
                    selectIFiles.add(selectFile);
                } else if (object instanceof IContainer) {
                    IContainer selectContainer = (IContainer) object;
                    try {
                        ResourceUtils.getXliffs(selectContainer, selectIFiles);
                    } catch (Exception e) {
                        e.printStackTrace();
                        logger.error(Messages.getString("qa.handlers.FileAnalysisHandler.log1"), e);
                    }
                }
            }
        }
    } else if (HandlerUtil.getActivePart(event) instanceof IEditorPart) {
        // 如果左边未选择品质检查的类型,那么,获取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);
        }
    } else {
        MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip3"));
        return null;
    }
    CommonFunction.removeRepeateSelect(selectIFiles);
    if (selectIFiles.size() <= 0) {
        MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.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;
    }
    // 判断要分析的文件是否是属于同一个项目中的.
    IProject project = selectIFiles.get(0).getProject();
    if (selectIFiles.size() >= 2) {
        for (int i = 1; i < selectIFiles.size(); i++) {
            if (selectIFiles.get(i).getProject() != project) {
                MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip2"));
                return null;
            }
        }
    }
    model.setAnalysisIFileList(selectIFiles);
    model.setShell(shell);
    model.setMultiFile(isMultiFile);
    if (isMultiFile) {
        model.setMultiTempIFile(multiTempIFile);
    }
    // 文件分析框的框名
    title = model.getAnalysisItemMap().get(faItemId).get(QAConstant.FA_ITEM_NAME);
    FileAnalysisDialog dialog = new FileAnalysisDialog(shell, model, title, faItemId);
    int result = dialog.open();
    if (result == IDialogConstants.OK_ID) {
        analysisFile(title);
    }
    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) FileAnalysisDialog(net.heartsome.cat.ts.ui.qa.dialogs.FileAnalysisDialog) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) List(java.util.List) IContainer(org.eclipse.core.resources.IContainer) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorPart(org.eclipse.ui.IEditorPart) ExecutionException(org.eclipse.core.commands.ExecutionException) IProject(org.eclipse.core.resources.IProject) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FAModel(net.heartsome.cat.ts.core.qa.FAModel) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)1 FAModel (net.heartsome.cat.ts.core.qa.FAModel)1 FileAnalysisDialog (net.heartsome.cat.ts.ui.qa.dialogs.FileAnalysisDialog)1 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IContainer (org.eclipse.core.resources.IContainer)1 IFile (org.eclipse.core.resources.IFile)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 IEditorPart (org.eclipse.ui.IEditorPart)1 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1