Search in sources :

Example 26 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class XlfEditor method getAllRowIds.

/**
	 * @return List<String> 当前文件中所有文本段的 RowID,合并、分割文本段后应重新获取 (每个 RowID 由 XLIFF 文件路径、源文件路径、trans-unit ID 组成)
	 */
public List<String> getAllRowIds() {
    WorkbenchContentsFinder finder = new WorkbenchContentsFinder();
    IEditorPart activateEditor = finder.activeWorkbenchWindow().getActivePage().getActiveEditor();
    IXliffEditor xliffEditor = (IXliffEditor) activateEditor;
    XLFHandler handler = xliffEditor.getXLFHandler();
    return handler.getAllRowIds();
}
Also used : IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) WorkbenchContentsFinder(org.eclipse.swtbot.eclipse.finder.finders.WorkbenchContentsFinder)

Example 27 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class QAResultViewPart method openEditor.

public IXliffEditor openEditor(String filePath) {
    IFile ifile = ResourceUtils.fileToIFile(filePath);
    FileEditorInput fileInput = new FileEditorInput(ifile);
    IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
    IEditorPart editorPart = null;
    IXliffEditor xliffEditor = null;
    if (editorRefer.length >= 1) {
        editorPart = editorRefer[0].getEditor(true);
        xliffEditor = (IXliffEditor) editorPart;
        // 若该文件未激活,激活此文件
        if (window.getActivePage().getActiveEditor() != editorPart) {
            window.getActivePage().activate(editorPart);
        }
        // 对于已经打开过的文件,进行重排序
        xliffEditor.resetOrder();
    } else {
        // 如果文件没有打开,那么先打开文件
        try {
            if (!validateXliffCanOpen(ifile)) {
                return null;
            }
            xliffEditor = (IXliffEditor) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
        } catch (PartInitException e) {
            e.printStackTrace();
            logger.error(Messages.getString("qa.views.QAResultViewPart.log2"), e);
        }
    }
    return xliffEditor;
}
Also used : IFile(org.eclipse.core.resources.IFile) IEditorReference(org.eclipse.ui.IEditorReference) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 28 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class QAResultViewPart method locationRow.

/**
	 * 双击或按回车键,将品质检查结果中的数据定位到翻译界面上去。
	 */
public void locationRow() {
    int[] selectRow = table.getRowSelection();
    if (selectRow.length <= 0) {
        return;
    }
    // 获取第一行选择的值
    QAResultBean bean = dataList.get(selectRow[0] - 1);
    // 如果是合并打开的文件
    if (isMultiFile) {
        IXliffEditor xliffEditor = openMultiFilesEditor();
        if (xliffEditor == null) {
            return;
        }
        int lineNumber = xliffEditor.getXLFHandler().getRowIndex(bean.getRowId());
        // 跳转到错误行
        xliffEditor.setFocus();
        xliffEditor.jumpToRow(lineNumber, true);
        return;
    } else {
        // 检查该文件是否已经打开,如果没有打开,就在界面上打开,再返回这个
        IXliffEditor xliffEditor = openEditor(RowIdUtil.getFileNameByRowId(bean.getRowId()));
        if (xliffEditor == null) {
            return;
        }
        int lineNumber = xliffEditor.getXLFHandler().getRowIndex(bean.getRowId());
        // 跳转到错误行
        xliffEditor.setFocus();
        xliffEditor.jumpToRow(lineNumber, false);
    }
}
Also used : QAResultBean(net.heartsome.cat.ts.ui.qa.model.QAResultBean) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) Point(org.eclipse.swt.graphics.Point)

Example 29 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor 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 30 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class XlfEditor method getRowIds.

/**
	 * @return List&lt;String&gt; 当前所有可见文本段的 RowID,合并、分割文本段后应重新获取
	 */
public ArrayList<String> getRowIds() {
    WorkbenchContentsFinder finder = new WorkbenchContentsFinder();
    IEditorPart activateEditor = finder.activeWorkbenchWindow().getActivePage().getActiveEditor();
    IXliffEditor xliffEditor = (IXliffEditor) activateEditor;
    XLFHandler handler = xliffEditor.getXLFHandler();
    return handler.getRowIds();
}
Also used : IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) WorkbenchContentsFinder(org.eclipse.swtbot.eclipse.finder.finders.WorkbenchContentsFinder)

Aggregations

IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)34 IEditorPart (org.eclipse.ui.IEditorPart)24 FileEditorInput (org.eclipse.ui.part.FileEditorInput)18 IFile (org.eclipse.core.resources.IFile)17 IEditorReference (org.eclipse.ui.IEditorReference)10 IViewPart (org.eclipse.ui.IViewPart)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)8 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)8 PartInitException (org.eclipse.ui.PartInitException)8 ArrayList (java.util.ArrayList)7 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)7 IProject (org.eclipse.core.resources.IProject)7 CoreException (org.eclipse.core.runtime.CoreException)7 MatchViewPart (net.heartsome.cat.ts.ui.translation.view.MatchViewPart)5 ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)4 ISimpleMatcher (net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher)4 ExecutionException (org.eclipse.core.commands.ExecutionException)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 List (java.util.List)3