Search in sources :

Example 31 with IXliffEditor

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

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

the class ExecuteBingTransHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof IXliffEditor)) {
        return null;
    }
    // check the google translation state: check the key availability
    PrefrenceParameters ps = PrefrenceParameters.getInstance();
    if (!ps.isBingState()) {
        MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteBingTransHandler.msgTitle"), Messages.getString("handler.ExecuteBingTransHandler.msg"));
        return null;
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    ISimpleMatcher matcher = new SimpleMatcherBingImpl();
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher);
    }
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SimpleMatcherBingImpl(net.heartsome.cat.ts.machinetranslation.SimpleMatcherBingImpl) IViewPart(org.eclipse.ui.IViewPart) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) PrefrenceParameters(net.heartsome.cat.ts.machinetranslation.bean.PrefrenceParameters) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 33 with IXliffEditor

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

the class ExecuteGoogleTransHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof IXliffEditor)) {
        return null;
    }
    PrefrenceParameters ps = PrefrenceParameters.getInstance();
    if (!ps.isGoogleState()) {
        MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteGoogleTransHandler.msgTitle"), Messages.getString("handler.ExecuteGoogleTransHandler.msg"));
        return null;
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    ISimpleMatcher matcher = new SimpleMatcherGoogleImpl();
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher);
    }
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) PrefrenceParameters(net.heartsome.cat.ts.machinetranslation.bean.PrefrenceParameters) SimpleMatcherGoogleImpl(net.heartsome.cat.ts.machinetranslation.SimpleMatcherGoogleImpl) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 34 with IXliffEditor

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

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