Search in sources :

Example 11 with IXliffEditor

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

the class ExecuteQuickTranslation method execute.

/** (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    if (TranslateParameter.getInstance().isAutoQuickTrans()) {
        return null;
    }
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    final IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof IXliffEditor)) {
        return null;
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    //		TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(selectedRowIndexs[selectedRowIndexs.length - 1]);
    IComplexMatch matcher = new QuickTranslationImpl();
    //		FileEditorInput input = (FileEditorInput) editor.getEditorInput();
    //		IProject project = input.getFile().getProject();
    //		List<AltTransBean> newAltTrans = matcher.executeTranslation(transUnitBean, project);
    //		if(newAltTrans.size() == 0){
    //			return null;
    //		}
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        matchView.manualExecComplexTranslation(selectedRowIndexs[0], xliffEditor, matcher);
    //			matchView.replaceMatchs(newAltTrans);
    //			matchView.refreshView(xliffEditor, selectedRowIndexs[selectedRowIndexs.length - 1]);
    }
    //		}
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IComplexMatch(net.heartsome.cat.ts.tm.complexMatch.IComplexMatch) QuickTranslationImpl(net.heartsome.cat.ts.quicktranslation.QuickTranslationImpl) IViewPart(org.eclipse.ui.IViewPart) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 12 with IXliffEditor

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

the class AbstractExportHandler method initExportConfig.

public boolean initExportConfig(ExecutionEvent event) throws ExecutionException {
    config = new ExportConfig();
    Shell shell = HandlerUtil.getActiveShell(event);
    String partId = HandlerUtil.getActivePartId(event);
    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();
        if (selection != null && !selection.isEmpty()) {
            for (Object obj : selection.toList()) {
                if (obj instanceof IFile) {
                    addXLFFile((IFile) obj);
                } else if (obj instanceof IFolder) {
                    traversalFile((IFolder) obj);
                } else if (obj instanceof IProject) {
                    IProject proj = (IProject) obj;
                    traversalFile(proj.getFolder(XLF));
                }
            }
            if (config.getProjects() == null || config.getProjects().size() < 1) {
                MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("xlf2tmx.info.notfoundxlf"));
                return false;
            }
        }
    } 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()) {
            MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg2"));
            return false;
        } else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
            addXLFFile(iFile);
        }
    }
    return true;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ExportConfig(net.heartsome.cat.ts.ui.external.ExportConfig) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder)

Example 13 with IXliffEditor

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

the class ExportDocxHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);
    String partId = HandlerUtil.getActivePartId(event);
    IFile file = null;
    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();
            ArrayList<IFile> lstXliff = new ArrayList<IFile>();
            for (Object obj : lstObj) {
                if (obj instanceof IFile) {
                    IFile tempFile = (IFile) obj;
                    // Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
                    if (tempFile.getFileExtension() != null && CommonFunction.validXlfExtension(tempFile.getFileExtension())) {
                        lstXliff.add(tempFile);
                    }
                }
            }
            if (lstXliff.size() > 1) {
                MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg1"));
                return null;
            }
            if (lstXliff.size() == 1) {
                file = lstXliff.get(0);
            }
        }
    } 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()) {
            MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg2"));
            return null;
        } else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
            file = iFile;
        }
    }
    if (file != null) {
        XLFValidator.resetFlag();
        if (!XLFValidator.validateXliffFile(file)) {
            return null;
        }
        XLFValidator.resetFlag();
    }
    ExportDocxDialog dialog = new ExportDocxDialog(shell, file == null ? "" : file.getFullPath().toOSString(), file == null ? "" : ResourceUtils.iFileToOSPath(file));
    dialog.open();
    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) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) ExportDocxDialog(net.heartsome.cat.ts.ui.docx.dialog.ExportDocxDialog) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput)

Example 14 with IXliffEditor

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

the class QAResultViewPart method openMultiFilesEditor.

/**
	 * 处理合并打开文件 nattable editor的相关问题
	 * @return ;
	 */
public IXliffEditor openMultiFilesEditor() {
    IXliffEditor xliffEditor = null;
    FileEditorInput fileInput = new FileEditorInput(oper.getCurMultiTempFile());
    IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
    IEditorPart editorPart = 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 (!oper.getCurMultiTempFile().getLocation().toFile().exists()) {
                // 检查这两个文件是否重新进行合并打开了的。
                IFile findMultiTempIfile = oper.getMultiFilesTempIFile(true);
                if (findMultiTempIfile != null) {
                    fileInput = new FileEditorInput(findMultiTempIfile);
                    oper.setCurMultiTempFile(findMultiTempIfile);
                } else {
                    //先验证这些所处理的文件是否有已经被打开的
                    List<IFile> openedFileList = oper.getOpenedIfile();
                    if (openedFileList.size() > 0) {
                        String openFileStr = "";
                        for (IFile ifile : openedFileList) {
                            openFileStr += "\t" + ifile.getFullPath().toOSString() + "\n";
                        }
                        MessageDialog.openInformation(getSite().getShell(), Messages.getString("views.QAResultViewPart.msgTitle"), MessageFormat.format(Messages.getString("qa.views.QAResultViewPart.addTip1"), openFileStr));
                        return null;
                    }
                    // 如果选中的文件没有合并打开,那么就重新打开它们
                    IFile multiIFile = oper.createMultiTempFile();
                    if (multiIFile != null && multiIFile.exists()) {
                        fileInput = new FileEditorInput(multiIFile);
                        oper.setCurMultiTempFile(multiIFile);
                    } else {
                        MessageDialog.openInformation(getSite().getShell(), Messages.getString("views.QAResultViewPart.msgTitle"), Messages.getString("views.QAResultViewPart.msg1"));
                        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 : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) 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 15 with IXliffEditor

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

the class MatchViewPart method selectionChanged.

/**
	 * 监听XLFEditor的选择事件
	 */
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
    if (part == null || selection == null) {
        return;
    }
    if (!(part instanceof IEditorPart)) {
        updateActionState();
        return;
    }
    if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
        updateActionState();
        return;
    }
    IXliffEditor editor = (IXliffEditor) part;
    IStructuredSelection structuredSelecion = (IStructuredSelection) selection;
    final Object object = structuredSelecion.getFirstElement();
    if (object instanceof Integer) {
        int rowIndex = -1;
        int selRowIndex = (Integer) object;
        if (rowIndex == selRowIndex) {
            if (gridTable.getItemCount() != 0) {
                updateActionState();
            }
            return;
        } else {
            rowIndex = selRowIndex;
        }
        XLFHandler handler = editor.getXLFHandler();
        String rowId = handler.getRowId(rowIndex);
        // handler.getTransUnit(rowId);
        TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
        if (transUnit == null) {
            updateActionState();
            return;
        }
        TransUnitInfo2TranslationBean tuInfoBean = getTuInfoBean(transUnit, handler, rowId);
        FileEditorInput input = (FileEditorInput) getSite().getPage().getActiveEditor().getEditorInput();
        IProject currentProject = input.getFile().getProject();
        copyEnable.resetSelection();
        gridTable.removeAll();
        altTransCacheList.clear();
        menuMgr.setEditor(editor);
        menuMgr.setRowIndex(rowIndex);
        executeMatch(editor, rowId, transUnit, tuInfoBean, currentProject);
    }
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) Point(org.eclipse.swt.graphics.Point) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean) IProject(org.eclipse.core.resources.IProject)

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