Search in sources :

Example 66 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.

the class UpdateTMHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);
    String partId = HandlerUtil.getActivePartId(event);
    ArrayList<IFile> lstXliff = new ArrayList<IFile>();
    //		boolean isShowCurrentLangBtn = true;
    if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
        // 导航视图处于激活状态
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
        StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
        // ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
            List<?> lstObj = ((IStructuredSelection) selection).toList();
            for (Object obj : lstObj) {
                if (obj instanceof IFile) {
                    IFile file = (IFile) obj;
                    // Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
                    if (file.getFileExtension() != null && CommonFunction.validXlfExtension(file.getFileExtension())) {
                        lstXliff.add(file);
                    }
                } else if (obj instanceof IFolder) {
                    try {
                        ResourceUtils.getXliffs((IFolder) obj, lstXliff);
                    } catch (CoreException e) {
                        LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger1"), e);
                        MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg1"));
                    }
                } else if (obj instanceof IProject) {
                    try {
                        ResourceUtils.getXliffs((IProject) obj, lstXliff);
                    } catch (CoreException e) {
                        LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger2"), e);
                        MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg2"));
                    }
                }
            }
            CommonFunction.removeRepeateSelect(lstXliff);
            if (lstXliff.size() == 0) {
                MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
                return null;
            }
            Iterator<IFile> iterator = lstXliff.iterator();
            while (iterator.hasNext()) {
                IFile file = iterator.next();
                FileEditorInput editorInput = new FileEditorInput(file);
                IEditorPart editorPart = page.findEditor(editorInput);
                if (editorPart == null || (editorPart != null && !(editorPart instanceof IXliffEditor))) {
                    //						isShowCurrentLangBtn = false;
                    break;
                }
            }
        } else {
            MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
            return null;
        }
    } else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
        // nattable 处于激活状态
        IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
        IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
        IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        if (xliffEditor.isMultiFile()) {
            List<String> lstFile = new XLFHandler().getMultiFiles(iFile);
            if (lstFile.size() > 0) {
                for (String filePath : lstFile) {
                    lstXliff.add(ResourceUtils.fileToIFile(filePath));
                }
            }
        } else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
            lstXliff.add(iFile);
        }
    }
    if (lstXliff.size() > 0) {
        if (lstXliff.size() > 1) {
            String projectPath = lstXliff.get(0).getProject().getFullPath().toOSString();
            for (int i = 1; i < lstXliff.size(); i++) {
                String projectPath2 = lstXliff.get(i).getProject().getFullPath().toOSString();
                if (!projectPath.equals(projectPath2)) {
                    MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg4"));
                    return null;
                }
            }
        }
        ArrayList<IFile> lstFiles = new ArrayList<IFile>();
        XLFValidator.resetFlag();
        for (IFile iFile : lstXliff) {
            if (!XLFValidator.validateXliffFile(iFile)) {
                lstFiles.add(iFile);
            }
        }
        XLFValidator.resetFlag();
        lstXliff.removeAll(lstFiles);
        if (lstXliff.size() == 0) {
            return null;
        }
        ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(lstXliff.get(0).getProject());
        if (projectConfig.getDefaultTMDb() == null) {
            MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg5"));
            return null;
        }
        UpdateTMWizard wizard = new UpdateTMWizard(lstXliff);
        TSWizardDialog dialog = new UpdateTMWizardDialog(shell, wizard);
        //			UpdateTMDialog dialog = new UpdateTMDialog(shell, isShowCurrentLangBtn, lstXliff);
        dialog.open();
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) 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) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) UpdateTMWizard(net.heartsome.cat.database.ui.tm.wizard.UpdateTMWizard) Shell(org.eclipse.swt.widgets.Shell) UpdateTMWizardDialog(net.heartsome.cat.database.ui.tm.wizard.UpdateTMWizardDialog) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) ArrayList(java.util.ArrayList) List(java.util.List) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) IEditorInput(org.eclipse.ui.IEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) IFolder(org.eclipse.core.resources.IFolder)

Example 67 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.

the class ExcutePreMachineTranlateHandler method execute.

/**
	 * (non-Javadoc)
	 * @see net.heartsome.cat.common.ui.handlers.AbstractSelectProjectFilesHandler#execute(org.eclipse.core.commands.ExecutionEvent,
	 *      java.util.List)
	 */
@Override
public Object execute(ExecutionEvent event, List<IFile> list) {
    if (!CommonFunction.checkEdition("U")) {
        MessageDialog.openInformation(shell, Messages.getString("handler.ExcutePreMachineTranlateHandler.tips"), Messages.getString("handler.ExcutePreMachineTranlateHandler.unsuportversion"));
        return null;
    }
    // 首先验证是否是合并打开的文件 --robert 2012-10-17
    if (isEditor) {
        try {
            IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
            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;
            }
            IXliffEditor xlfEditor = (IXliffEditor) editorRefe[0].getEditor(true);
            // 针对合并打开
            if (xlfEditor.isMultiFile()) {
                list = ResourceUtils.filesToIFiles(xlfEditor.getMultiFileList());
            }
        } catch (ExecutionException e) {
            logger.error("", e);
        }
    }
    CommonFunction.removeRepeateSelect(list);
    PreMachineTransUitls.executeTranslation(list, shell);
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorReference(org.eclipse.ui.IEditorReference) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ExecutionException(org.eclipse.core.commands.ExecutionException) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 68 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.

the class PreTransUitls method executeTranslation.

public static void executeTranslation(List<IFile> list, final Shell shell) {
    HsMultiActiveCellEditor.commit(true);
    try {
        if (list.size() == 0) {
            MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg1"));
            return;
        }
        List<IFile> lstFiles = new ArrayList<IFile>();
        XLFValidator.resetFlag();
        for (IFile iFile : list) {
            if (!XLFValidator.validateXliffFile(iFile)) {
                lstFiles.add(iFile);
            }
        }
        XLFValidator.resetFlag();
        list = new ArrayList<IFile>(list);
        list.removeAll(lstFiles);
        if (list.size() == 0) {
            return;
        }
        final IProject project = list.get(0).getProject();
        final List<String> filesWithOsPath = ResourceUtils.IFilesToOsPath(list);
        final XLFHandler xlfHandler = new XLFHandler();
        Map<String, Object> resultMap = xlfHandler.openFiles(filesWithOsPath);
        if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
            // 打开文件失败。
            MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg2"));
            return;
        }
        Map<String, List<XliffBean>> map = xlfHandler.getXliffInfo();
        final PreTransParameters parameters = new PreTransParameters();
        PreTranslationDialog dialog = new PreTranslationDialog(shell, map, parameters);
        if (dialog.open() == Window.OK) {
            if (project == null) {
                MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg3"));
                return;
            }
            if (filesWithOsPath == null || filesWithOsPath.size() == 0) {
                MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg4"));
                return;
            }
            final List<IFile> lstFile = list;
            IRunnableWithProgress runnable = new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    PreTranslation pt = new PreTranslation(xlfHandler, filesWithOsPath, project, parameters);
                    try {
                        final List<PreTranslationCounter> result = pt.executeTranslation(monitor);
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                PreTranslationResultDialog dialog = new PreTranslationResultDialog(shell, result);
                                dialog.open();
                            }
                        });
                        project.refreshLocal(IResource.DEPTH_INFINITE, null);
                        result.clear();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (CoreException e) {
                        logger.error("", e);
                        e.printStackTrace();
                    } finally {
                        pt.clearResources();
                    }
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                            for (IFile file : lstFile) {
                                FileEditorInput editorInput = new FileEditorInput(file);
                                IEditorPart editorPart = page.findEditor(editorInput);
                                // 选择所有语言
                                XLFHandler handler = null;
                                if (editorPart != null && editorPart instanceof IXliffEditor) {
                                    // xliff 文件已用 XLIFF 编辑器打开
                                    IXliffEditor xliffEditor = (IXliffEditor) editorPart;
                                    handler = xliffEditor.getXLFHandler();
                                    handler.resetCache();
                                    VTDGen vg = new VTDGen();
                                    String path = ResourceUtils.iFileToOSPath(file);
                                    if (vg.parseFile(path, true)) {
                                        handler.getVnMap().put(path, vg.getNav());
                                        xliffEditor.refresh();
                                    }
                                }
                            }
                        }
                    });
                }
            };
            try {
                new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
            } catch (InvocationTargetException e) {
                logger.error(Messages.getString("pretranslation.PreTransUitls.logger1"), e);
            } catch (InterruptedException e) {
                logger.error(Messages.getString("pretranslation.PreTransUitls.logger1"), e);
            }
        }
    } finally {
        HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
    }
}
Also used : PreTranslationResultDialog(net.heartsome.cat.ts.pretranslation.dialog.PreTranslationResultDialog) IFile(org.eclipse.core.resources.IFile) PreTransParameters(net.heartsome.cat.ts.pretranslation.bean.PreTransParameters) ArrayList(java.util.ArrayList) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ArrayList(java.util.ArrayList) List(java.util.List) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) PreTranslationDialog(net.heartsome.cat.ts.pretranslation.dialog.PreTranslationDialog) VTDGen(com.ximpleware.VTDGen) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PreTranslationCounter(net.heartsome.cat.ts.pretranslation.bean.PreTranslationCounter) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 69 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.

the class MergeXliffWizard method performFinish.

@Override
public boolean performFinish() {
    final IRunnableWithProgress mergeProgress = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) {
            Vector<String> mergeXlfPaths = new Vector<String>();
            for (int i = 0; i < model.getMergeXliffFile().size(); i++) {
                mergeXlfPaths.add(model.getMergeXliffFile().get(i).getLocation().toOSString());
            }
            canFinish = mergeXliff.merge(mergeXlfPaths, monitor);
        }
    };
    try {
        getContainer().run(true, true, mergeProgress);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    if (canFinish) {
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        FileEditorInput input = new FileEditorInput(ResourceUtils.fileToIFile(mergeXliff.getTargetFilePath()));
        try {
            page.openEditor(input, XLIFF_EDITOR_ID);
        } catch (PartInitException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        }
    }
    return canFinish;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) Vector(java.util.Vector) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 70 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput 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

FileEditorInput (org.eclipse.ui.part.FileEditorInput)87 IFile (org.eclipse.core.resources.IFile)55 CoreException (org.eclipse.core.runtime.CoreException)31 IEditorPart (org.eclipse.ui.IEditorPart)29 PartInitException (org.eclipse.ui.PartInitException)24 ArrayList (java.util.ArrayList)20 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)19 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)18 IEditorReference (org.eclipse.ui.IEditorReference)17 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)16 IEditorInput (org.eclipse.ui.IEditorInput)16 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)15 IProject (org.eclipse.core.resources.IProject)13 File (java.io.File)11 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)11 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ExecutionException (org.eclipse.core.commands.ExecutionException)9 List (java.util.List)7